authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-11-10 12:40:15-05:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2021-11-10 12:40:15-05:00
loge5bc092408d7a02b74011e07beaee3c98ec9a268
treebec54c7cfcddaade09a54d43bd8e3c8d0059e833
parent51efd553ae94fbf958974284a2f30091e4e1a2fa
parentc13166ee8574c79afd1487e26722861cfaa632d9
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #10058 from marler8997/builderPathJoin

add pathJoin to builder

1 files changed, 33 insertions(+), 36 deletions(-)

lib/std/build.zig+33-36
......@@ -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(&.{ 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(&.{ 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(&.{
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(&.{
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(&.{
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(&.{ self.install_path, path }),
12291234 };
12301235 return fs.path.resolve(
12311236 self.allocator,
......@@ -1705,11 +1710,9 @@ pub const LibExeObjStep = struct {
17051710 }
17061711 }
17071712 if (self.output_dir != null) {
1708 self.output_lib_path_source.path =
1709 fs.path.join(
1710 self.builder.allocator,
1711 &[_][]const u8{ self.output_dir.?, self.out_lib_filename },
1712 ) catch unreachable;
1713 self.output_lib_path_source.path = self.builder.pathJoin(
1714 &.{ self.output_dir.?, self.out_lib_filename },
1715 );
17131716 }
17141717 }
17151718 }
......@@ -2136,14 +2139,14 @@ pub const LibExeObjStep = struct {
21362139 const triplet = try self.target.vcpkgTriplet(allocator, if (linkage == .static) .Static else .Dynamic);
21372140 defer self.builder.allocator.free(triplet);
21382141
2139 const include_path = try fs.path.join(allocator, &[_][]const u8{ root, "installed", triplet, "include" });
2142 const include_path = self.builder.pathJoin(&.{ root, "installed", triplet, "include" });
21402143 errdefer allocator.free(include_path);
21412144 try self.include_dirs.append(IncludeDir{ .raw_path = include_path });
21422145
2143 const lib_path = try fs.path.join(allocator, &[_][]const u8{ root, "installed", triplet, "lib" });
2146 const lib_path = self.builder.pathJoin(&.{ root, "installed", triplet, "lib" });
21442147 try self.lib_paths.append(lib_path);
21452148
2146 self.vcpkg_bin_path = try fs.path.join(allocator, &[_][]const u8{ root, "installed", triplet, "bin" });
2149 self.vcpkg_bin_path = self.builder.pathJoin(&.{ root, "installed", triplet, "bin" });
21472150 },
21482151 }
21492152 }
......@@ -2655,11 +2658,11 @@ pub const LibExeObjStep = struct {
26552658
26562659 for (builder.search_prefixes.items) |search_prefix| {
26572660 try zig_args.append("-L");
2658 try zig_args.append(try fs.path.join(builder.allocator, &[_][]const u8{
2661 try zig_args.append(builder.pathJoin(&.{
26592662 search_prefix, "lib",
26602663 }));
26612664 try zig_args.append("-isystem");
2662 try zig_args.append(try fs.path.join(builder.allocator, &[_][]const u8{
2665 try zig_args.append(builder.pathJoin(&.{
26632666 search_prefix, "include",
26642667 }));
26652668 }
......@@ -2764,26 +2767,20 @@ pub const LibExeObjStep = struct {
27642767
27652768 // Update generated files
27662769 if (self.output_dir != null) {
2767 self.output_path_source.path =
2768 fs.path.join(
2769 self.builder.allocator,
2770 &[_][]const u8{ self.output_dir.?, self.out_filename },
2771 ) catch unreachable;
2770 self.output_path_source.path = builder.pathJoin(
2771 &.{ self.output_dir.?, self.out_filename },
2772 );
27722773
27732774 if (self.emit_h) {
2774 self.output_h_path_source.path =
2775 fs.path.join(
2776 self.builder.allocator,
2777 &[_][]const u8{ self.output_dir.?, self.out_h_filename },
2778 ) catch unreachable;
2775 self.output_h_path_source.path = builder.pathJoin(
2776 &.{ self.output_dir.?, self.out_h_filename },
2777 );
27792778 }
27802779
27812780 if (self.target.isWindows() or self.target.isUefi()) {
2782 self.output_pdb_path_source.path =
2783 fs.path.join(
2784 self.builder.allocator,
2785 &[_][]const u8{ self.output_dir.?, self.out_pdb_filename },
2786 ) catch unreachable;
2781 self.output_pdb_path_source.path = builder.pathJoin(
2782 &.{ self.output_dir.?, self.out_pdb_filename },
2783 );
27872784 }
27882785 }
27892786
......@@ -2964,11 +2961,11 @@ pub const InstallDirStep = struct {
29642961 }
29652962 }
29662963
2967 const full_path = try fs.path.join(self.builder.allocator, &[_][]const u8{
2964 const full_path = self.builder.pathJoin(&.{
29682965 full_src_dir, entry.path,
29692966 });
29702967
2971 const dest_path = try fs.path.join(self.builder.allocator, &[_][]const u8{
2968 const dest_path = self.builder.pathJoin(&.{
29722969 dest_prefix, entry.path,
29732970 });
29742971