| ... | @@ -4,6 +4,7 @@ const io = std.io; | ... | @@ -4,6 +4,7 @@ const io = std.io; |
| 4 | const fs = std.fs; | 4 | const fs = std.fs; |
| 5 | const mem = std.mem; | 5 | const mem = std.mem; |
| 6 | const debug = std.debug; | 6 | const debug = std.debug; |
| | 7 | const panic = std.debug.panic; |
| 7 | const assert = debug.assert; | 8 | const assert = debug.assert; |
| 8 | const warn = std.debug.warn; | 9 | const warn = std.debug.warn; |
| 9 | const ArrayList = std.ArrayList; | 10 | const ArrayList = std.ArrayList; |
| ... | @@ -42,8 +43,8 @@ pub const Builder = struct { | ... | @@ -42,8 +43,8 @@ pub const Builder = struct { |
| 42 | top_level_steps: ArrayList(*TopLevelStep), | 43 | top_level_steps: ArrayList(*TopLevelStep), |
| 43 | install_prefix: ?[]const u8, | 44 | install_prefix: ?[]const u8, |
| 44 | dest_dir: ?[]const u8, | 45 | dest_dir: ?[]const u8, |
| 45 | lib_dir: ?[]const u8, | 46 | lib_dir: []const u8, |
| 46 | exe_dir: ?[]const u8, | 47 | exe_dir: []const u8, |
| 47 | install_path: []const u8, | 48 | install_path: []const u8, |
| 48 | search_prefixes: ArrayList([]const u8), | 49 | search_prefixes: ArrayList([]const u8), |
| 49 | installed_files: ArrayList(InstalledFile), | 50 | installed_files: ArrayList(InstalledFile), |
| ... | @@ -129,8 +130,8 @@ pub const Builder = struct { | ... | @@ -129,8 +130,8 @@ pub const Builder = struct { |
| 129 | .env_map = env_map, | 130 | .env_map = env_map, |
| 130 | .search_prefixes = ArrayList([]const u8).init(allocator), | 131 | .search_prefixes = ArrayList([]const u8).init(allocator), |
| 131 | .install_prefix = null, | 132 | .install_prefix = null, |
| 132 | .lib_dir = null, | 133 | .lib_dir = undefined, |
| 133 | .exe_dir = null, | 134 | .exe_dir = undefined, |
| 134 | .dest_dir = env_map.get("DESTDIR"), | 135 | .dest_dir = env_map.get("DESTDIR"), |
| 135 | .installed_files = ArrayList(InstalledFile).init(allocator), | 136 | .installed_files = ArrayList(InstalledFile).init(allocator), |
| 136 | .install_tls = TopLevelStep{ | 137 | .install_tls = TopLevelStep{ |
| ... | @@ -163,11 +164,13 @@ pub const Builder = struct { | ... | @@ -163,11 +164,13 @@ pub const Builder = struct { |
| 163 | self.allocator.destroy(self); | 164 | self.allocator.destroy(self); |
| 164 | } | 165 | } |
| 165 | | 166 | |
| | 167 | /// This function is intended to be called by std/special/build_runner.zig, not a build.zig file. |
| 166 | pub fn setInstallPrefix(self: *Builder, optional_prefix: ?[]const u8) void { | 168 | pub fn setInstallPrefix(self: *Builder, optional_prefix: ?[]const u8) void { |
| 167 | self.install_prefix = optional_prefix; | 169 | self.install_prefix = optional_prefix; |
| 168 | } | 170 | } |
| 169 | | 171 | |
| 170 | fn resolveInstallPrefix(self: *Builder) void { | 172 | /// This function is intended to be called by std/special/build_runner.zig, not a build.zig file. |
| | 173 | pub fn resolveInstallPrefix(self: *Builder) void { |
| 171 | if (self.dest_dir) |dest_dir| { | 174 | if (self.dest_dir) |dest_dir| { |
| 172 | const install_prefix = self.install_prefix orelse "/usr"; | 175 | const install_prefix = self.install_prefix orelse "/usr"; |
| 173 | self.install_path = fs.path.join(self.allocator, [_][]const u8{ dest_dir, install_prefix }) catch unreachable; | 176 | self.install_path = fs.path.join(self.allocator, [_][]const u8{ dest_dir, install_prefix }) catch unreachable; |
| ... | @@ -437,7 +440,7 @@ pub const Builder = struct { | ... | @@ -437,7 +440,7 @@ pub const Builder = struct { |
| 437 | .description = description, | 440 | .description = description, |
| 438 | }; | 441 | }; |
| 439 | if ((self.available_options_map.put(name, available_option) catch unreachable) != null) { | 442 | if ((self.available_options_map.put(name, available_option) catch unreachable) != null) { |
| 440 | debug.panic("Option '{}' declared twice", name); | 443 | panic("Option '{}' declared twice", name); |
| 441 | } | 444 | } |
| 442 | self.available_options_list.append(available_option) catch unreachable; | 445 | self.available_options_list.append(available_option) catch unreachable; |
| 443 | | 446 | |
| ... | @@ -463,8 +466,8 @@ pub const Builder = struct { | ... | @@ -463,8 +466,8 @@ pub const Builder = struct { |
| 463 | return null; | 466 | return null; |
| 464 | }, | 467 | }, |
| 465 | }, | 468 | }, |
| 466 | TypeId.Int => debug.panic("TODO integer options to build script"), | 469 | TypeId.Int => panic("TODO integer options to build script"), |
| 467 | TypeId.Float => debug.panic("TODO float options to build script"), | 470 | TypeId.Float => panic("TODO float options to build script"), |
| 468 | TypeId.String => switch (entry.value.value) { | 471 | TypeId.String => switch (entry.value.value) { |
| 469 | UserValue.Flag => { | 472 | UserValue.Flag => { |
| 470 | warn("Expected -D{} to be a string, but received a boolean.\n", name); | 473 | warn("Expected -D{} to be a string, but received a boolean.\n", name); |
| ... | @@ -478,7 +481,7 @@ pub const Builder = struct { | ... | @@ -478,7 +481,7 @@ pub const Builder = struct { |
| 478 | }, | 481 | }, |
| 479 | UserValue.Scalar => |s| return s, | 482 | UserValue.Scalar => |s| return s, |
| 480 | }, | 483 | }, |
| 481 | TypeId.List => debug.panic("TODO list options to build script"), | 484 | TypeId.List => panic("TODO list options to build script"), |
| 482 | } | 485 | } |
| 483 | } | 486 | } |
| 484 | | 487 | |
| ... | @@ -644,8 +647,6 @@ pub const Builder = struct { | ... | @@ -644,8 +647,6 @@ pub const Builder = struct { |
| 644 | } | 647 | } |
| 645 | | 648 | |
| 646 | pub fn validateUserInputDidItFail(self: *Builder) bool { | 649 | pub fn validateUserInputDidItFail(self: *Builder) bool { |
| 647 | self.resolveInstallPrefix(); | | |
| 648 | | | |
| 649 | // make sure all args are used | 650 | // make sure all args are used |
| 650 | var it = self.user_input_options.iterator(); | 651 | var it = self.user_input_options.iterator(); |
| 651 | while (true) { | 652 | while (true) { |
| ... | @@ -855,7 +856,7 @@ pub const Builder = struct { | ... | @@ -855,7 +856,7 @@ pub const Builder = struct { |
| 855 | var stdout_file_in_stream = child.stdout.?.inStream(); | 856 | var stdout_file_in_stream = child.stdout.?.inStream(); |
| 856 | try stdout_file_in_stream.stream.readAllBuffer(&stdout, max_output_size); | 857 | try stdout_file_in_stream.stream.readAllBuffer(&stdout, max_output_size); |
| 857 | | 858 | |
| 858 | const term = child.wait() catch |err| std.debug.panic("unable to spawn {}: {}", argv[0], err); | 859 | const term = child.wait() catch |err| panic("unable to spawn {}: {}", argv[0], err); |
| 859 | switch (term) { | 860 | switch (term) { |
| 860 | .Exited => |code| { | 861 | .Exited => |code| { |
| 861 | if (code != 0) { | 862 | if (code != 0) { |
| ... | @@ -882,8 +883,8 @@ pub const Builder = struct { | ... | @@ -882,8 +883,8 @@ pub const Builder = struct { |
| 882 | fn getInstallPath(self: *Builder, dir: InstallDir, dest_rel_path: []const u8) []const u8 { | 883 | fn getInstallPath(self: *Builder, dir: InstallDir, dest_rel_path: []const u8) []const u8 { |
| 883 | const base_dir = switch (dir) { | 884 | const base_dir = switch (dir) { |
| 884 | .Prefix => self.install_path, | 885 | .Prefix => self.install_path, |
| 885 | .Bin => self.exe_dir.?, | 886 | .Bin => self.exe_dir, |
| 886 | .Lib => self.lib_dir.?, | 887 | .Lib => self.lib_dir, |
| 887 | }; | 888 | }; |
| 888 | return fs.path.resolve( | 889 | return fs.path.resolve( |
| 889 | self.allocator, | 890 | self.allocator, |
| ... | @@ -1318,6 +1319,9 @@ pub const LibExeObjStep = struct { | ... | @@ -1318,6 +1319,9 @@ pub const LibExeObjStep = struct { |
| 1318 | } | 1319 | } |
| 1319 | | 1320 | |
| 1320 | fn initExtraArgs(builder: *Builder, name: []const u8, root_src: ?[]const u8, kind: Kind, is_dynamic: bool, ver: Version) LibExeObjStep { | 1321 | fn initExtraArgs(builder: *Builder, name: []const u8, root_src: ?[]const u8, kind: Kind, is_dynamic: bool, ver: Version) LibExeObjStep { |
| | 1322 | if (mem.indexOf(u8, name, "/") != null or mem.indexOf(u8, name, "\\") != null) { |
| | 1323 | panic("invalid name: '{}'. It looks like a file path, but it is supposed to be the library or application name.", name); |
| | 1324 | } |
| 1321 | var self = LibExeObjStep{ | 1325 | var self = LibExeObjStep{ |
| 1322 | .strip = false, | 1326 | .strip = false, |
| 1323 | .builder = builder, | 1327 | .builder = builder, |