| ... | @@ -1,20 +1,15 @@ | ... | @@ -1,20 +1,15 @@ |
| 1 | const Step = @This(); | 1 | const Step = @This(); |
| 2 | const builtin = @import("builtin"); | | |
| 3 | | 2 | |
| 4 | const std = @import("../std.zig"); | 3 | const std = @import("../std.zig"); |
| 5 | const Io = std.Io; | | |
| 6 | const Build = std.Build; | 4 | const Build = std.Build; |
| 7 | const Allocator = std.mem.Allocator; | | |
| 8 | const assert = std.debug.assert; | 5 | const assert = std.debug.assert; |
| 9 | const Cache = Build.Cache; | 6 | const Configuration = std.Build.Configuration; |
| 10 | const Path = Cache.Path; | | |
| 11 | const ArrayList = std.ArrayList; | | |
| 12 | | 7 | |
| 13 | tag: std.Build.Configuration.Step.Tag, | 8 | tag: Configuration.Step.Tag, |
| 14 | name: []const u8, | 9 | name: []const u8, |
| 15 | owner: *Build, | 10 | owner: *Build, |
| 16 | | 11 | |
| 17 | dependencies: ArrayList(*Step), | 12 | dependencies: std.ArrayList(*Step), |
| 18 | | 13 | |
| 19 | /// Set this field to declare an upper bound on the amount of bytes of memory it will | 14 | /// Set this field to declare an upper bound on the amount of bytes of memory it will |
| 20 | /// take to run the step. Zero means no limit. | 15 | /// take to run the step. Zero means no limit. |
| ... | @@ -37,43 +32,30 @@ dependencies: ArrayList(*Step), | ... | @@ -37,43 +32,30 @@ dependencies: ArrayList(*Step), |
| 37 | /// total system memory available. | 32 | /// total system memory available. |
| 38 | max_rss: usize, | 33 | max_rss: usize, |
| 39 | | 34 | |
| 40 | state: State, | | |
| 41 | | | |
| 42 | /// The return address associated with creation of this step that can be useful | 35 | /// The return address associated with creation of this step that can be useful |
| 43 | /// to print along with debugging messages. | 36 | /// to print along with debugging messages. |
| 44 | debug_stack_trace: std.debug.StackTrace, | 37 | debug_stack_trace: std.debug.StackTrace, |
| 45 | | 38 | |
| 46 | pub const State = enum { | 39 | pub const Tag = Configuration.Step.Tag; |
| 47 | precheck_unstarted, | | |
| 48 | precheck_started, | | |
| 49 | /// This is also used to indicate "dirty" steps that have been modified | | |
| 50 | /// after a previous build completed, in which case, the step may or may | | |
| 51 | /// not have been completed before. Either way, one or more of its direct | | |
| 52 | /// file system inputs have been modified, meaning that the step needs to | | |
| 53 | /// be re-evaluated. | | |
| 54 | precheck_done, | | |
| 55 | dependency_failure, | | |
| 56 | }; | | |
| 57 | | | |
| 58 | pub const Tag = std.Build.Configuration.Step.Tag; | | |
| 59 | | 40 | |
| 60 | pub fn Type(comptime tag: Tag) type { | 41 | pub fn Type(comptime tag: Tag) type { |
| 61 | return switch (tag) { | 42 | return switch (tag) { |
| 62 | .top_level => Build.TopLevelStep, | 43 | .check_file => CheckFile, |
| 63 | .compile => Compile, | 44 | .compile => Compile, |
| 64 | .install_artifact => InstallArtifact, | 45 | .config_header => ConfigHeader, |
| 65 | .install_file => InstallFile, | | |
| 66 | .install_dir => InstallDir, | | |
| 67 | .fail => Fail, | 46 | .fail => Fail, |
| | 47 | .find_program => FindProgram, |
| 68 | .fmt => Fmt, | 48 | .fmt => Fmt, |
| 69 | .translate_c => TranslateC, | 49 | .install_artifact => InstallArtifact, |
| 70 | .write_file => WriteFile, | 50 | .install_dir => InstallDir, |
| 71 | .update_source_files => UpdateSourceFiles, | 51 | .install_file => InstallFile, |
| 72 | .run => Run, | | |
| 73 | .check_file => CheckFile, | | |
| 74 | .config_header => ConfigHeader, | | |
| 75 | .obj_copy => ObjCopy, | 52 | .obj_copy => ObjCopy, |
| 76 | .options => Options, | 53 | .options => Options, |
| | 54 | .run => Run, |
| | 55 | .top_level => TopLevel, |
| | 56 | .translate_c => TranslateC, |
| | 57 | .update_source_files => UpdateSourceFiles, |
| | 58 | .write_file => WriteFile, |
| 77 | }; | 59 | }; |
| 78 | } | 60 | } |
| 79 | | 61 | |
| ... | @@ -116,7 +98,6 @@ pub fn init(options: StepOptions) Step { | ... | @@ -116,7 +98,6 @@ pub fn init(options: StepOptions) Step { |
| 116 | .name = arena.dupe(u8, options.name) catch @panic("OOM"), | 98 | .name = arena.dupe(u8, options.name) catch @panic("OOM"), |
| 117 | .owner = options.owner, | 99 | .owner = options.owner, |
| 118 | .dependencies = .empty, | 100 | .dependencies = .empty, |
| 119 | .state = .precheck_unstarted, | | |
| 120 | .max_rss = options.max_rss, | 101 | .max_rss = options.max_rss, |
| 121 | .debug_stack_trace = blk: { | 102 | .debug_stack_trace = blk: { |
| 122 | const addr_buf = arena.alloc(usize, options.owner.debug_stack_frames_count) catch @panic("OOM"); | 103 | const addr_buf = arena.alloc(usize, options.owner.debug_stack_frames_count) catch @panic("OOM"); |
| ... | @@ -132,14 +113,12 @@ pub fn dependOn(step: *Step, other: *Step) void { | ... | @@ -132,14 +113,12 @@ pub fn dependOn(step: *Step, other: *Step) void { |
| 132 | } | 113 | } |
| 133 | | 114 | |
| 134 | pub fn cast(step: *Step, comptime T: type) ?*T { | 115 | pub fn cast(step: *Step, comptime T: type) ?*T { |
| 135 | if (step.tag == T.base_tag) { | 116 | if (step.tag == T.base_tag) return @fieldParentPtr("step", step); |
| 136 | return @fieldParentPtr("step", step); | | |
| 137 | } | | |
| 138 | return null; | 117 | return null; |
| 139 | } | 118 | } |
| 140 | | 119 | |
| 141 | /// For debugging purposes, prints identifying information about this Step. | 120 | /// For debugging purposes, prints identifying information about this Step. |
| 142 | pub fn dump(step: *Step, t: Io.Terminal) void { | 121 | pub fn dump(step: *Step, t: std.Io.Terminal) void { |
| 143 | const w = t.writer; | 122 | const w = t.writer; |
| 144 | if (step.debug_stack_trace.return_addresses.len > 0) { | 123 | if (step.debug_stack_trace.return_addresses.len > 0) { |
| 145 | w.print("name: '{s}'. creation stack trace:\n", .{step.name}) catch {}; | 124 | w.print("name: '{s}'. creation stack trace:\n", .{step.name}) catch {}; |
| ... | @@ -155,16 +134,18 @@ pub fn dump(step: *Step, t: Io.Terminal) void { | ... | @@ -155,16 +134,18 @@ pub fn dump(step: *Step, t: Io.Terminal) void { |
| 155 | | 134 | |
| 156 | test { | 135 | test { |
| 157 | _ = CheckFile; | 136 | _ = CheckFile; |
| | 137 | _ = Compile; |
| | 138 | _ = ConfigHeader; |
| 158 | _ = Fail; | 139 | _ = Fail; |
| | 140 | _ = FindProgram; |
| 159 | _ = Fmt; | 141 | _ = Fmt; |
| 160 | _ = InstallArtifact; | 142 | _ = InstallArtifact; |
| 161 | _ = InstallDir; | 143 | _ = InstallDir; |
| 162 | _ = InstallFile; | 144 | _ = InstallFile; |
| 163 | _ = ObjCopy; | 145 | _ = ObjCopy; |
| 164 | _ = Compile; | | |
| 165 | _ = Options; | 146 | _ = Options; |
| 166 | _ = Run; | 147 | _ = Run; |
| 167 | _ = TranslateC; | 148 | _ = TranslateC; |
| 168 | _ = WriteFile; | | |
| 169 | _ = UpdateSourceFiles; | 149 | _ = UpdateSourceFiles; |
| | 150 | _ = WriteFile; |
| 170 | } | 151 | } |