authorgravatar for alex_naskos@hotmail.comAlexandros Naskos <alex_naskos@hotmail.com> 2020-05-25 11:20:31+03:00
committergravatar for alex_naskos@hotmail.comAlexandros Naskos <alex_naskos@hotmail.com> 2020-05-25 11:20:31+03:00
logd268e0cf2e3cd152017a165ca80085a5823c45a2
treed90b74798f0417c82131894f240ed1a21504e68c
parent3052fd84c812280334245513d1edc631ae5e4ae2

Added and id and a cast function to build steps


7 files changed, 55 insertions(+), 19 deletions(-)

lib/std/build.zig+49-13
......@@ -154,11 +154,11 @@ pub const Builder = struct {
154154 .dest_dir = env_map.get("DESTDIR"),
155155 .installed_files = ArrayList(InstalledFile).init(allocator),
156156 .install_tls = TopLevelStep{
157 .step = Step.initNoOp("install", allocator),
157 .step = Step.initNoOp(.TopLevel, "install", allocator),
158158 .description = "Copy build artifacts to prefix path",
159159 },
160160 .uninstall_tls = TopLevelStep{
161 .step = Step.init("uninstall", allocator, makeUninstall),
161 .step = Step.init(.TopLevel, "uninstall", allocator, makeUninstall),
162162 .description = "Remove build artifacts from prefix path",
163163 },
164164 .release_mode = null,
......@@ -500,7 +500,7 @@ pub const Builder = struct {
500500 pub fn step(self: *Builder, name: []const u8, description: []const u8) *Step {
501501 const step_info = self.allocator.create(TopLevelStep) catch unreachable;
502502 step_info.* = TopLevelStep{
503 .step = Step.initNoOp(name, self.allocator),
503 .step = Step.initNoOp(.TopLevel, name, self.allocator),
504504 .description = description,
505505 };
506506 self.top_level_steps.append(step_info) catch unreachable;
......@@ -1286,7 +1286,7 @@ pub const LibExeObjStep = struct {
12861286 .root_src = root_src,
12871287 .name = name,
12881288 .frameworks = BufSet.init(builder.allocator),
1289 .step = Step.init(name, builder.allocator, make),
1289 .step = Step.init(.LibExeObj, name, builder.allocator, make),
12901290 .version = ver,
12911291 .out_filename = undefined,
12921292 .out_h_filename = builder.fmt("{}.h", .{name}),
......@@ -2223,7 +2223,7 @@ pub const LibExeObjStep = struct {
22232223 }
22242224};
22252225
2226const InstallArtifactStep = struct {
2226pub const InstallArtifactStep = struct {
22272227 step: Step,
22282228 builder: *Builder,
22292229 artifact: *LibExeObjStep,
......@@ -2239,7 +2239,7 @@ const InstallArtifactStep = struct {
22392239 const self = builder.allocator.create(Self) catch unreachable;
22402240 self.* = Self{
22412241 .builder = builder,
2242 .step = Step.init(builder.fmt("install {}", .{artifact.step.name}), builder.allocator, make),
2242 .step = Step.init(.InstallArtifact, builder.fmt("install {}", .{artifact.step.name}), builder.allocator, make),
22432243 .artifact = artifact,
22442244 .dest_dir = switch (artifact.kind) {
22452245 .Obj => unreachable,
......@@ -2313,7 +2313,7 @@ pub const InstallFileStep = struct {
23132313 builder.pushInstalledFile(dir, dest_rel_path);
23142314 return InstallFileStep{
23152315 .builder = builder,
2316 .step = Step.init(builder.fmt("install {}", .{src_path}), builder.allocator, make),
2316 .step = Step.init(.InstallFile, builder.fmt("install {}", .{src_path}), builder.allocator, make),
23172317 .src_path = src_path,
23182318 .dir = dir,
23192319 .dest_rel_path = dest_rel_path,
......@@ -2347,7 +2347,7 @@ pub const InstallDirStep = struct {
23472347 builder.pushInstalledFile(options.install_dir, options.install_subdir);
23482348 return InstallDirStep{
23492349 .builder = builder,
2350 .step = Step.init(builder.fmt("install {}/", .{options.source_dir}), builder.allocator, make),
2350 .step = Step.init(.InstallDir, builder.fmt("install {}/", .{options.source_dir}), builder.allocator, make),
23512351 .options = options,
23522352 };
23532353 }
......@@ -2383,7 +2383,7 @@ pub const LogStep = struct {
23832383 pub fn init(builder: *Builder, data: []const u8) LogStep {
23842384 return LogStep{
23852385 .builder = builder,
2386 .step = Step.init(builder.fmt("log {}", .{data}), builder.allocator, make),
2386 .step = Step.init(.Log, builder.fmt("log {}", .{data}), builder.allocator, make),
23872387 .data = data,
23882388 };
23892389 }
......@@ -2402,7 +2402,7 @@ pub const RemoveDirStep = struct {
24022402 pub fn init(builder: *Builder, dir_path: []const u8) RemoveDirStep {
24032403 return RemoveDirStep{
24042404 .builder = builder,
2405 .step = Step.init(builder.fmt("RemoveDir {}", .{dir_path}), builder.allocator, make),
2405 .step = Step.init(.RemoveDir, builder.fmt("RemoveDir {}", .{dir_path}), builder.allocator, make),
24062406 .dir_path = dir_path,
24072407 };
24082408 }
......@@ -2418,15 +2418,34 @@ pub const RemoveDirStep = struct {
24182418 }
24192419};
24202420
2421const ThisModule = @This();
24212422pub const Step = struct {
2423 id: Id,
24222424 name: []const u8,
24232425 makeFn: fn (self: *Step) anyerror!void,
24242426 dependencies: ArrayList(*Step),
24252427 loop_flag: bool,
24262428 done_flag: bool,
24272429
2428 pub fn init(name: []const u8, allocator: *Allocator, makeFn: fn (*Step) anyerror!void) Step {
2430 pub const Id = enum {
2431 TopLevel,
2432 LibExeObj,
2433 InstallArtifact,
2434 InstallFile,
2435 InstallDir,
2436 Log,
2437 RemoveDir,
2438 Fmt,
2439 TranslateC,
2440 WriteFile,
2441 Run,
2442 CheckFile,
2443 InstallRaw,
2444 };
2445
2446 pub fn init(id: Id, name: []const u8, allocator: *Allocator, makeFn: fn (*Step) anyerror!void) Step {
24292447 return Step{
2448 .id = id,
24302449 .name = name,
24312450 .makeFn = makeFn,
24322451 .dependencies = ArrayList(*Step).init(allocator),
......@@ -2434,8 +2453,8 @@ pub const Step = struct {
24342453 .done_flag = false,
24352454 };
24362455 }
2437 pub fn initNoOp(name: []const u8, allocator: *Allocator) Step {
2438 return init(name, allocator, makeNoOp);
2456 pub fn initNoOp(id: Id, name: []const u8, allocator: *Allocator) Step {
2457 return init(id, name, allocator, makeNoOp);
24392458 }
24402459
24412460 pub fn make(self: *Step) !void {
......@@ -2450,6 +2469,23 @@ pub const Step = struct {
24502469 }
24512470
24522471 fn makeNoOp(self: *Step) anyerror!void {}
2472
2473 pub fn cast(step: *Step, comptime T: type) ?*T {
2474 if (step.id == comptime typeToId(T)) {
2475 return @fieldParentPtr(T, "step", step);
2476 }
2477 return null;
2478 }
2479
2480 fn typeToId(comptime T: type) Id {
2481 inline for (@typeInfo(Id).Enum.fields) |f| {
2482 if (std.mem.eql(u8, f.name, "TopLevel")) continue;
2483 if (T == @field(ThisModule, f.name ++ "Step")) {
2484 return @field(Id, f.name);
2485 }
2486 }
2487 unreachable;
2488 }
24532489};
24542490
24552491fn doAtomicSymLinks(allocator: *Allocator, output_path: []const u8, filename_major_only: []const u8, filename_name_only: []const u8) !void {
lib/std/build/check_file.zig+1-1
......@@ -21,7 +21,7 @@ pub const CheckFileStep = struct {
2121 const self = builder.allocator.create(CheckFileStep) catch unreachable;
2222 self.* = CheckFileStep{
2323 .builder = builder,
24 .step = Step.init("CheckFile", builder.allocator, make),
24 .step = Step.init(.CheckFile, "CheckFile", builder.allocator, make),
2525 .source = source,
2626 .expected_matches = expected_matches,
2727 };
lib/std/build/emit_raw.zig+1-1
......@@ -182,7 +182,7 @@ pub const InstallRawStep = struct {
182182 pub fn create(builder: *Builder, artifact: *LibExeObjStep, dest_filename: []const u8) *Self {
183183 const self = builder.allocator.create(Self) catch unreachable;
184184 self.* = Self{
185 .step = Step.init(builder.fmt("install raw binary {}", .{artifact.step.name}), builder.allocator, make),
185 .step = Step.init(.InstallRaw, builder.fmt("install raw binary {}", .{artifact.step.name}), builder.allocator, make),
186186 .builder = builder,
187187 .artifact = artifact,
188188 .dest_dir = switch (artifact.kind) {
lib/std/build/fmt.zig+1-1
......@@ -14,7 +14,7 @@ pub const FmtStep = struct {
1414 const self = builder.allocator.create(FmtStep) catch unreachable;
1515 const name = "zig fmt";
1616 self.* = FmtStep{
17 .step = Step.init(name, builder.allocator, make),
17 .step = Step.init(.Fmt, name, builder.allocator, make),
1818 .builder = builder,
1919 .argv = builder.allocator.alloc([]u8, paths.len + 2) catch unreachable,
2020 };
lib/std/build/run.zig+1-1
......@@ -49,7 +49,7 @@ pub const RunStep = struct {
4949 const self = builder.allocator.create(RunStep) catch unreachable;
5050 self.* = RunStep{
5151 .builder = builder,
52 .step = Step.init(name, builder.allocator, make),
52 .step = Step.init(.Run, name, builder.allocator, make),
5353 .argv = ArrayList(Arg).init(builder.allocator),
5454 .cwd = null,
5555 .env_map = null,
lib/std/build/translate_c.zig+1-1
......@@ -20,7 +20,7 @@ pub const TranslateCStep = struct {
2020 pub fn create(builder: *Builder, source: build.FileSource) *TranslateCStep {
2121 const self = builder.allocator.create(TranslateCStep) catch unreachable;
2222 self.* = TranslateCStep{
23 .step = Step.init("translate-c", builder.allocator, make),
23 .step = Step.init(.TranslateC, "translate-c", builder.allocator, make),
2424 .builder = builder,
2525 .source = source,
2626 .output_dir = null,
lib/std/build/write_file.zig+1-1
......@@ -20,7 +20,7 @@ pub const WriteFileStep = struct {
2020 pub fn init(builder: *Builder) WriteFileStep {
2121 return WriteFileStep{
2222 .builder = builder,
23 .step = Step.init("writefile", builder.allocator, make),
23 .step = Step.init(.WriteFile, "writefile", builder.allocator, make),
2424 .files = ArrayList(File).init(builder.allocator),
2525 .output_dir = undefined,
2626 };