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 {...@@ -204,10 +204,10 @@ pub const Builder = struct {
204 pub fn resolveInstallPrefix(self: *Builder, install_prefix: ?[]const u8, dir_list: DirList) void {204 pub fn resolveInstallPrefix(self: *Builder, install_prefix: ?[]const u8, dir_list: DirList) void {
205 if (self.dest_dir) |dest_dir| {205 if (self.dest_dir) |dest_dir| {
206 self.install_prefix = install_prefix orelse "/usr";206 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 });
208 } else {208 } else {
209 self.install_prefix = install_prefix orelse209 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" }));
211 self.install_path = self.install_prefix;211 self.install_path = self.install_prefix;
212 }212 }
213213
...@@ -230,9 +230,9 @@ pub const Builder = struct {...@@ -230,9 +230,9 @@ pub const Builder = struct {
230 h_list[1] = dir;230 h_list[1] = dir;
231 }231 }
232232
233 self.lib_dir = fs.path.join(self.allocator, &lib_list) catch unreachable;233 self.lib_dir = self.pathJoin(&lib_list);
234 self.exe_dir = fs.path.join(self.allocator, &exe_list) catch unreachable;234 self.exe_dir = self.pathJoin(&exe_list);
235 self.h_dir = fs.path.join(self.allocator, &h_list) catch unreachable;235 self.h_dir = self.pathJoin(&h_list);
236 }236 }
237237
238 fn convertOptionalPathToFileSource(path: ?[]const u8) ?FileSource {238 fn convertOptionalPathToFileSource(path: ?[]const u8) ?FileSource {
...@@ -1086,6 +1086,11 @@ pub const Builder = struct {...@@ -1086,6 +1086,11 @@ pub const Builder = struct {
1086 return fs.path.resolve(self.allocator, &[_][]const u8{ self.build_root, rel_path }) catch unreachable;1086 return fs.path.resolve(self.allocator, &[_][]const u8{ self.build_root, rel_path }) catch unreachable;
1087 }1087 }
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
1089 pub fn fmt(self: *Builder, comptime format: []const u8, args: anytype) []u8 {1094 pub fn fmt(self: *Builder, comptime format: []const u8, args: anytype) []u8 {
1090 return fmt_lib.allocPrint(self.allocator, format, args) catch unreachable;1095 return fmt_lib.allocPrint(self.allocator, format, args) catch unreachable;
1091 }1096 }
...@@ -1098,7 +1103,7 @@ pub const Builder = struct {...@@ -1098,7 +1103,7 @@ pub const Builder = struct {
1098 if (fs.path.isAbsolute(name)) {1103 if (fs.path.isAbsolute(name)) {
1099 return name;1104 return name;
1100 }1105 }
1101 const full_path = try fs.path.join(self.allocator, &[_][]const u8{1106 const full_path = self.pathJoin(&[_][]const u8{
1102 search_prefix,1107 search_prefix,
1103 "bin",1108 "bin",
1104 self.fmt("{s}{s}", .{ name, exe_extension }),1109 self.fmt("{s}{s}", .{ name, exe_extension }),
...@@ -1113,7 +1118,7 @@ pub const Builder = struct {...@@ -1113,7 +1118,7 @@ pub const Builder = struct {
1113 }1118 }
1114 var it = mem.tokenize(u8, PATH, &[_]u8{fs.path.delimiter});1119 var it = mem.tokenize(u8, PATH, &[_]u8{fs.path.delimiter});
1115 while (it.next()) |path| {1120 while (it.next()) |path| {
1116 const full_path = try fs.path.join(self.allocator, &[_][]const u8{1121 const full_path = self.pathJoin(&[_][]const u8{
1117 path,1122 path,
1118 self.fmt("{s}{s}", .{ name, exe_extension }),1123 self.fmt("{s}{s}", .{ name, exe_extension }),
1119 });1124 });
...@@ -1126,7 +1131,7 @@ pub const Builder = struct {...@@ -1126,7 +1131,7 @@ pub const Builder = struct {
1126 return name;1131 return name;
1127 }1132 }
1128 for (paths) |path| {1133 for (paths) |path| {
1129 const full_path = try fs.path.join(self.allocator, &[_][]const u8{1134 const full_path = self.pathJoin(&[_][]const u8{
1130 path,1135 path,
1131 self.fmt("{s}{s}", .{ name, exe_extension }),1136 self.fmt("{s}{s}", .{ name, exe_extension }),
1132 });1137 });
...@@ -1225,7 +1230,7 @@ pub const Builder = struct {...@@ -1225,7 +1230,7 @@ pub const Builder = struct {
1225 .bin => self.exe_dir,1230 .bin => self.exe_dir,
1226 .lib => self.lib_dir,1231 .lib => self.lib_dir,
1227 .header => self.h_dir,1232 .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 }),
1229 };1234 };
1230 return fs.path.resolve(1235 return fs.path.resolve(
1231 self.allocator,1236 self.allocator,
...@@ -1701,11 +1706,9 @@ pub const LibExeObjStep = struct {...@@ -1701,11 +1706,9 @@ pub const LibExeObjStep = struct {
1701 }1706 }
1702 }1707 }
1703 if (self.output_dir != null) {1708 if (self.output_dir != null) {
1704 self.output_lib_path_source.path =1709 self.output_lib_path_source.path = self.builder.pathJoin(
1705 fs.path.join(
1706 self.builder.allocator,
1707 &[_][]const u8{ self.output_dir.?, self.out_lib_filename },1710 &[_][]const u8{ self.output_dir.?, self.out_lib_filename },
1708 ) catch unreachable;1711 );
1709 }1712 }
1710 }1713 }
1711 }1714 }
...@@ -2132,14 +2135,14 @@ pub const LibExeObjStep = struct {...@@ -2132,14 +2135,14 @@ pub const LibExeObjStep = struct {
2132 const triplet = try self.target.vcpkgTriplet(allocator, if (linkage == .static) .Static else .Dynamic);2135 const triplet = try self.target.vcpkgTriplet(allocator, if (linkage == .static) .Static else .Dynamic);
2133 defer self.builder.allocator.free(triplet);2136 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" });
2136 errdefer allocator.free(include_path);2139 errdefer allocator.free(include_path);
2137 try self.include_dirs.append(IncludeDir{ .raw_path = include_path });2140 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" });
2140 try self.lib_paths.append(lib_path);2143 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" });
2143 },2146 },
2144 }2147 }
2145 }2148 }
...@@ -2639,11 +2642,11 @@ pub const LibExeObjStep = struct {...@@ -2639,11 +2642,11 @@ pub const LibExeObjStep = struct {
26392642
2640 for (builder.search_prefixes.items) |search_prefix| {2643 for (builder.search_prefixes.items) |search_prefix| {
2641 try zig_args.append("-L");2644 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{
2643 search_prefix, "lib",2646 search_prefix, "lib",
2644 }));2647 }));
2645 try zig_args.append("-isystem");2648 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{
2647 search_prefix, "include",2650 search_prefix, "include",
2648 }));2651 }));
2649 }2652 }
...@@ -2748,26 +2751,20 @@ pub const LibExeObjStep = struct {...@@ -2748,26 +2751,20 @@ pub const LibExeObjStep = struct {
27482751
2749 // Update generated files2752 // Update generated files
2750 if (self.output_dir != null) {2753 if (self.output_dir != null) {
2751 self.output_path_source.path =2754 self.output_path_source.path = builder.pathJoin(
2752 fs.path.join(
2753 self.builder.allocator,
2754 &[_][]const u8{ self.output_dir.?, self.out_filename },2755 &[_][]const u8{ self.output_dir.?, self.out_filename },
2755 ) catch unreachable;2756 );
27562757
2757 if (self.emit_h) {2758 if (self.emit_h) {
2758 self.output_h_path_source.path =2759 self.output_h_path_source.path = builder.pathJoin(
2759 fs.path.join(
2760 self.builder.allocator,
2761 &[_][]const u8{ self.output_dir.?, self.out_h_filename },2760 &[_][]const u8{ self.output_dir.?, self.out_h_filename },
2762 ) catch unreachable;2761 );
2763 }2762 }
27642763
2765 if (self.target.isWindows() or self.target.isUefi()) {2764 if (self.target.isWindows() or self.target.isUefi()) {
2766 self.output_pdb_path_source.path =2765 self.output_pdb_path_source.path = builder.pathJoin(
2767 fs.path.join(
2768 self.builder.allocator,
2769 &[_][]const u8{ self.output_dir.?, self.out_pdb_filename },2766 &[_][]const u8{ self.output_dir.?, self.out_pdb_filename },
2770 ) catch unreachable;2767 );
2771 }2768 }
2772 }2769 }
27732770
...@@ -2948,11 +2945,11 @@ pub const InstallDirStep = struct {...@@ -2948,11 +2945,11 @@ pub const InstallDirStep = struct {
2948 }2945 }
2949 }2946 }
29502947
2951 const full_path = try fs.path.join(self.builder.allocator, &[_][]const u8{2948 const full_path = self.builder.pathJoin(&[_][]const u8{
2952 full_src_dir, entry.path,2949 full_src_dir, entry.path,
2953 });2950 });
29542951
2955 const dest_path = try fs.path.join(self.builder.allocator, &[_][]const u8{2952 const dest_path = self.builder.pathJoin(&[_][]const u8{
2956 dest_prefix, entry.path,2953 dest_prefix, entry.path,
2957 });2954 });
29582955