authorgravatar for johnnymarler@gmail.comJonathan Marler <johnnymarler@gmail.com> 2021-10-29 11:55:52-06:00
committergravatar for johnnymarler@gmail.comJonathan Marler <johnnymarler@gmail.com> 2021-11-09 14:20:28-07:00
logcebac8c66256e1f904b44b101c0d9ee583c26148
tree9b7c97a0fb5ce3b937d58437d4cce3b73fd2a329
parent9bb7ff68ccab8700cb787a83359df02a5bb4370f

add pathJoin to builder


1 files changed, 29 insertions(+), 32 deletions(-)

lib/std/build.zig+29-32
......@@ -204,10 +204,10 @@ pub const Builder = struct {
204204 pub fn resolveInstallPrefix(self: *Builder, install_prefix: ?[]const u8, dir_list: DirList) void {
205205 if (self.dest_dir) |dest_dir| {
206206 self.install_prefix = install_prefix orelse "/usr";
207 self.install_path = fs.path.join(self.allocator, &[_][]const u8{ dest_dir, self.install_prefix }) catch unreachable;
207 self.install_path = self.pathJoin(&[_][]const u8{ dest_dir, self.install_prefix });
208208 } else {
209209 self.install_prefix = install_prefix orelse
210 (fs.path.join(self.allocator, &[_][]const u8{ self.build_root, "zig-out" }) catch unreachable);
210 (self.pathJoin(&[_][]const u8{ self.build_root, "zig-out" }));
211211 self.install_path = self.install_prefix;
212212 }
213213
......@@ -230,9 +230,9 @@ pub const Builder = struct {
230230 h_list[1] = dir;
231231 }
232232
233 self.lib_dir = fs.path.join(self.allocator, &lib_list) catch unreachable;
234 self.exe_dir = fs.path.join(self.allocator, &exe_list) catch unreachable;
235 self.h_dir = fs.path.join(self.allocator, &h_list) catch unreachable;
233 self.lib_dir = self.pathJoin(&lib_list);
234 self.exe_dir = self.pathJoin(&exe_list);
235 self.h_dir = self.pathJoin(&h_list);
236236 }
237237
238238 fn convertOptionalPathToFileSource(path: ?[]const u8) ?FileSource {
......@@ -1086,6 +1086,11 @@ pub const Builder = struct {
10861086 return fs.path.resolve(self.allocator, &[_][]const u8{ self.build_root, rel_path }) catch unreachable;
10871087 }
10881088
1089 /// Shorthand for `std.fs.path.join(builder.allocator, paths) catch unreachable`
1090 pub fn pathJoin(self: *Builder, paths: []const []const u8) []u8 {
1091 return fs.path.join(self.allocator, paths) catch unreachable;
1092 }
1093
10891094 pub fn fmt(self: *Builder, comptime format: []const u8, args: anytype) []u8 {
10901095 return fmt_lib.allocPrint(self.allocator, format, args) catch unreachable;
10911096 }
......@@ -1098,7 +1103,7 @@ pub const Builder = struct {
10981103 if (fs.path.isAbsolute(name)) {
10991104 return name;
11001105 }
1101 const full_path = try fs.path.join(self.allocator, &[_][]const u8{
1106 const full_path = self.pathJoin(&[_][]const u8{
11021107 search_prefix,
11031108 "bin",
11041109 self.fmt("{s}{s}", .{ name, exe_extension }),
......@@ -1113,7 +1118,7 @@ pub const Builder = struct {
11131118 }
11141119 var it = mem.tokenize(u8, PATH, &[_]u8{fs.path.delimiter});
11151120 while (it.next()) |path| {
1116 const full_path = try fs.path.join(self.allocator, &[_][]const u8{
1121 const full_path = self.pathJoin(&[_][]const u8{
11171122 path,
11181123 self.fmt("{s}{s}", .{ name, exe_extension }),
11191124 });
......@@ -1126,7 +1131,7 @@ pub const Builder = struct {
11261131 return name;
11271132 }
11281133 for (paths) |path| {
1129 const full_path = try fs.path.join(self.allocator, &[_][]const u8{
1134 const full_path = self.pathJoin(&[_][]const u8{
11301135 path,
11311136 self.fmt("{s}{s}", .{ name, exe_extension }),
11321137 });
......@@ -1225,7 +1230,7 @@ pub const Builder = struct {
12251230 .bin => self.exe_dir,
12261231 .lib => self.lib_dir,
12271232 .header => self.h_dir,
1228 .custom => |path| fs.path.join(self.allocator, &[_][]const u8{ self.install_path, path }) catch unreachable,
1233 .custom => |path| self.pathJoin(&[_][]const u8{ self.install_path, path }),
12291234 };
12301235 return fs.path.resolve(
12311236 self.allocator,
......@@ -1701,11 +1706,9 @@ pub const LibExeObjStep = struct {
17011706 }
17021707 }
17031708 if (self.output_dir != null) {
1704 self.output_lib_path_source.path =
1705 fs.path.join(
1706 self.builder.allocator,
1709 self.output_lib_path_source.path = self.builder.pathJoin(
17071710 &[_][]const u8{ self.output_dir.?, self.out_lib_filename },
1708 ) catch unreachable;
1711 );
17091712 }
17101713 }
17111714 }
......@@ -2132,14 +2135,14 @@ pub const LibExeObjStep = struct {
21322135 const triplet = try self.target.vcpkgTriplet(allocator, if (linkage == .static) .Static else .Dynamic);
21332136 defer self.builder.allocator.free(triplet);
21342137
2135 const include_path = try fs.path.join(allocator, &[_][]const u8{ root, "installed", triplet, "include" });
2138 const include_path = self.pathJoin(&[_][]const u8{ root, "installed", triplet, "include" });
21362139 errdefer allocator.free(include_path);
21372140 try self.include_dirs.append(IncludeDir{ .raw_path = include_path });
21382141
2139 const lib_path = try fs.path.join(allocator, &[_][]const u8{ root, "installed", triplet, "lib" });
2142 const lib_path = self.pathJoin(&[_][]const u8{ root, "installed", triplet, "lib" });
21402143 try self.lib_paths.append(lib_path);
21412144
2142 self.vcpkg_bin_path = try fs.path.join(allocator, &[_][]const u8{ root, "installed", triplet, "bin" });
2145 self.vcpkg_bin_path = self.pathJoin(&[_][]const u8{ root, "installed", triplet, "bin" });
21432146 },
21442147 }
21452148 }
......@@ -2639,11 +2642,11 @@ pub const LibExeObjStep = struct {
26392642
26402643 for (builder.search_prefixes.items) |search_prefix| {
26412644 try zig_args.append("-L");
2642 try zig_args.append(try fs.path.join(builder.allocator, &[_][]const u8{
2645 try zig_args.append(builder.pathJoin(&[_][]const u8{
26432646 search_prefix, "lib",
26442647 }));
26452648 try zig_args.append("-isystem");
2646 try zig_args.append(try fs.path.join(builder.allocator, &[_][]const u8{
2649 try zig_args.append(builder.pathJoin(&[_][]const u8{
26472650 search_prefix, "include",
26482651 }));
26492652 }
......@@ -2748,26 +2751,20 @@ pub const LibExeObjStep = struct {
27482751
27492752 // Update generated files
27502753 if (self.output_dir != null) {
2751 self.output_path_source.path =
2752 fs.path.join(
2753 self.builder.allocator,
2754 self.output_path_source.path = builder.pathJoin(
27542755 &[_][]const u8{ self.output_dir.?, self.out_filename },
2755 ) catch unreachable;
2756 );
27562757
27572758 if (self.emit_h) {
2758 self.output_h_path_source.path =
2759 fs.path.join(
2760 self.builder.allocator,
2759 self.output_h_path_source.path = builder.pathJoin(
27612760 &[_][]const u8{ self.output_dir.?, self.out_h_filename },
2762 ) catch unreachable;
2761 );
27632762 }
27642763
27652764 if (self.target.isWindows() or self.target.isUefi()) {
2766 self.output_pdb_path_source.path =
2767 fs.path.join(
2768 self.builder.allocator,
2765 self.output_pdb_path_source.path = builder.pathJoin(
27692766 &[_][]const u8{ self.output_dir.?, self.out_pdb_filename },
2770 ) catch unreachable;
2767 );
27712768 }
27722769 }
27732770
......@@ -2948,11 +2945,11 @@ pub const InstallDirStep = struct {
29482945 }
29492946 }
29502947
2951 const full_path = try fs.path.join(self.builder.allocator, &[_][]const u8{
2948 const full_path = self.builder.pathJoin(&[_][]const u8{
29522949 full_src_dir, entry.path,
29532950 });
29542951
2955 const dest_path = try fs.path.join(self.builder.allocator, &[_][]const u8{
2952 const dest_path = self.builder.pathJoin(&[_][]const u8{
29562953 dest_prefix, entry.path,
29572954 });
29582955