@@ -227,12 +227,19 @@ pub fn create(
227227 .h_dir = undefined ,
228228 .dest_dir = env_map .get ("DESTDIR" ),
229229 .installed_files = ArrayList (InstalledFile ).init (allocator ),
230- .install_tls = TopLevelStep {
231- .step = Step .initNoOp (.top_level , "install" , allocator ),
230+ .install_tls = .{
231+ .step = Step .init (allocator , .{
232+ .id = .top_level ,
233+ .name = "install" ,
234+ }),
232235 .description = "Copy build artifacts to prefix path" ,
233236 },
234- .uninstall_tls = TopLevelStep {
235- .step = Step .init (.top_level , "uninstall" , allocator , makeUninstall ),
237+ .uninstall_tls = .{
238+ .step = Step .init (allocator , .{
239+ .id = .top_level ,
240+ .name = "uninstall" ,
241+ .makeFn = makeUninstall ,
242+ }),
236243 .description = "Remove build artifacts from prefix path" ,
237244 },
238245 .zig_lib_dir = null ,
@@ -264,11 +271,18 @@ fn createChildOnly(parent: *Build, dep_name: []const u8, build_root: Cache.Direc
264271 child .* = .{
265272 .allocator = allocator ,
266273 .install_tls = .{
267- .step = Step .initNoOp (.top_level , "install" , allocator ),
274+ .step = Step .init (allocator , .{
275+ .id = .top_level ,
276+ .name = "install" ,
277+ }),
268278 .description = "Copy build artifacts to prefix path" ,
269279 },
270280 .uninstall_tls = .{
271- .step = Step .init (.top_level , "uninstall" , allocator , makeUninstall ),
281+ .step = Step .init (allocator , .{
282+ .id = .top_level ,
283+ .name = "uninstall" ,
284+ .makeFn = makeUninstall ,
285+ }),
272286 .description = "Remove build artifacts from prefix path" ,
273287 },
274288 .user_input_options = UserInputOptionsMap .init (allocator ),
@@ -634,7 +648,11 @@ pub fn addConfigHeader(
634648 options : ConfigHeaderStep.Options ,
635649 values : anytype ,
636650) * ConfigHeaderStep {
637- const config_header_step = ConfigHeaderStep .create (b , options );
651+ var options_copy = options ;
652+ if (options_copy .first_ret_addr == null )
653+ options_copy .first_ret_addr = @returnAddress ();
654+
655+ const config_header_step = ConfigHeaderStep .create (b , options_copy );
638656 config_header_step .addValues (values );
639657 return config_header_step ;
640658}
@@ -858,7 +876,10 @@ pub fn option(self: *Build, comptime T: type, name_raw: []const u8, description_
858876pub fn step (self : * Build , name : []const u8 , description : []const u8 ) * Step {
859877 const step_info = self .allocator .create (TopLevelStep ) catch @panic ("OOM" );
860878 step_info .* = TopLevelStep {
861- .step = Step .initNoOp (.top_level , name , self .allocator ),
879+ .step = Step .init (self .allocator , .{
880+ .id = .top_level ,
881+ .name = name ,
882+ }),
862883 .description = self .dupe (description ),
863884 };
864885 self .top_level_steps .put (self .allocator , step_info .step .name , step_info ) catch @panic ("OOM" );
@@ -1153,7 +1174,7 @@ pub fn spawnChildEnvMap(self: *Build, cwd: ?[]const u8, env_map: *const EnvMap,
11531174 printCmd (self .allocator , cwd , argv );
11541175 }
11551176
1156- if (! std . process .can_spawn )
1177+ if (! process .can_spawn )
11571178 return error .ExecNotSupported ;
11581179
11591180 var child = std .ChildProcess .init (argv , self .allocator );
@@ -1355,7 +1376,7 @@ pub fn execAllowFail(
13551376) ExecError ! []u8 {
13561377 assert (argv .len != 0 );
13571378
1358- if (! std . process .can_spawn )
1379+ if (! process .can_spawn )
13591380 return error .ExecNotSupported ;
13601381
13611382 const max_output_size = 400 * 1024 ;
@@ -1395,7 +1416,7 @@ pub fn execFromStep(b: *Build, argv: []const []const u8, s: *Step) ![]u8 {
13951416 printCmd (b .allocator , null , argv );
13961417 }
13971418
1398- if (! std . process .can_spawn ) {
1419+ if (! process .can_spawn ) {
13991420 s .result .stderr = b .fmt ("Unable to spawn the following command: cannot spawn child processes\n {s}" , .{
14001421 try allocPrintCmd (b .allocator , null , argv ),
14011422 });
@@ -1458,7 +1479,7 @@ fn unwrapExecResult(
14581479/// inside step make() functions. If any errors occur, it fails the build with
14591480/// a helpful message.
14601481pub fn exec (b : * Build , argv : []const []const u8 ) []u8 {
1461- if (! std . process .can_spawn ) {
1482+ if (! process .can_spawn ) {
14621483 std .debug .print ("unable to spawn the following command: cannot spawn child process\n {s}" , .{
14631484 try allocPrintCmd (b .allocator , null , argv ),
14641485 });
@@ -1539,7 +1560,7 @@ pub fn dependency(b: *Build, name: []const u8, args: anytype) *Dependency {
15391560
15401561 const full_path = b .pathFromRoot ("build.zig.zon" );
15411562 std .debug .print ("no dependency named '{s}' in '{s}'. All packages used in build.zig must be declared in this file.\n " , .{ name , full_path });
1542- std . process .exit (1 );
1563+ process .exit (1 );
15431564}
15441565
15451566fn dependencyInner (
@@ -1555,7 +1576,7 @@ fn dependencyInner(
15551576 std .debug .print ("unable to open '{s}': {s}\n " , .{
15561577 build_root_string , @errorName (err ),
15571578 });
1558- std . process .exit (1 );
1579+ process .exit (1 );
15591580 },
15601581 };
15611582 const sub_builder = b .createChild (name , build_root , args ) catch @panic ("unhandled error" );
@@ -1599,7 +1620,7 @@ pub const GeneratedFile = struct {
15991620
16001621 pub fn getPath (self : GeneratedFile ) []const u8 {
16011622 return self .path orelse std .debug .panic (
1602- "getPath() was called on a GeneratedFile that wasn't build yet. Is there a missing Step dependency on step '{s}'?" ,
1623+ "getPath() was called on a GeneratedFile that wasn't built yet. Is there a missing Step dependency on step '{s}'?" ,
16031624 .{self .step .name },
16041625 );
16051626 }
@@ -1639,12 +1660,16 @@ pub const FileSource = union(enum) {
16391660 }
16401661
16411662 /// Should only be called during make(), returns a path relative to the build root or absolute.
1642- pub fn getPath (self : FileSource , builder : * Build ) []const u8 {
1643- const path = switch (self ) {
1644- .path = > | p | builder .pathFromRoot (p ),
1645- .generated = > | gen | gen .getPath (),
1646- };
1647- return path ;
1663+ pub fn getPath (self : FileSource , src_builder : * Build ) []const u8 {
1664+ switch (self ) {
1665+ .path = > | p | return src_builder .pathFromRoot (p ),
1666+ .generated = > | gen | return gen .path orelse {
1667+ std .debug .getStderrMutex ().lock ();
1668+ const stderr = std .io .getStdErr ();
1669+ dumpBadGetPathHelp (gen .step , stderr , src_builder ) catch {};
1670+ @panic ("unable to get path" );
1671+ },
1672+ }
16481673 }
16491674
16501675 /// Duplicates the file source for a given builder.
@@ -1656,6 +1681,27 @@ pub const FileSource = union(enum) {
16561681 }
16571682};
16581683
1684+ fn dumpBadGetPathHelp (s : * Step , stderr : fs.File , src_builder : * Build ) anyerror ! void {
1685+ try stderr .writer ().print (
1686+ \\getPath() was called on a GeneratedFile that wasn't built yet.
1687+ \\ source package path: {s}
1688+ \\ Is there a missing Step dependency on step '{s}'?
1689+ \\ The step was created by this stack trace:
1690+ \\
1691+ , .{
1692+ src_builder .build_root .path orelse "." ,
1693+ s .name ,
1694+ });
1695+ const debug_info = std .debug .getSelfDebugInfo () catch | err | {
1696+ try stderr .writer ().print ("Unable to dump stack trace: Unable to open debug info: {s}\n " , .{@errorName (err )});
1697+ return ;
1698+ };
1699+ std .debug .writeStackTrace (s .getStackTrace (), stderr .writer (), debug_info .allocator , debug_info , std .debug .detectTTYConfig (stderr )) catch | err | {
1700+ try stderr .writer ().print ("Unable to dump stack trace: {s}\n " , .{@errorName (err )});
1701+ return ;
1702+ };
1703+ }
1704+
16591705/// Allocates a new string for assigning a value to a named macro.
16601706/// If the value is omitted, it is set to 1.
16611707/// `name` and `value` need not live longer than the function call.
0 commit comments