| ... | @@ -154,11 +154,11 @@ pub const Builder = struct { | ... | @@ -154,11 +154,11 @@ pub const Builder = struct { |
| 154 | .dest_dir = env_map.get("DESTDIR"), | 154 | .dest_dir = env_map.get("DESTDIR"), |
| 155 | .installed_files = ArrayList(InstalledFile).init(allocator), | 155 | .installed_files = ArrayList(InstalledFile).init(allocator), |
| 156 | .install_tls = TopLevelStep{ | 156 | .install_tls = TopLevelStep{ |
| 157 | .step = Step.initNoOp("install", allocator), | 157 | .step = Step.initNoOp(.TopLevel, "install", allocator), |
| 158 | .description = "Copy build artifacts to prefix path", | 158 | .description = "Copy build artifacts to prefix path", |
| 159 | }, | 159 | }, |
| 160 | .uninstall_tls = TopLevelStep{ | 160 | .uninstall_tls = TopLevelStep{ |
| 161 | .step = Step.init("uninstall", allocator, makeUninstall), | 161 | .step = Step.init(.TopLevel, "uninstall", allocator, makeUninstall), |
| 162 | .description = "Remove build artifacts from prefix path", | 162 | .description = "Remove build artifacts from prefix path", |
| 163 | }, | 163 | }, |
| 164 | .release_mode = null, | 164 | .release_mode = null, |
| ... | @@ -500,7 +500,7 @@ pub const Builder = struct { | ... | @@ -500,7 +500,7 @@ pub const Builder = struct { |
| 500 | pub fn step(self: *Builder, name: []const u8, description: []const u8) *Step { | 500 | pub fn step(self: *Builder, name: []const u8, description: []const u8) *Step { |
| 501 | const step_info = self.allocator.create(TopLevelStep) catch unreachable; | 501 | const step_info = self.allocator.create(TopLevelStep) catch unreachable; |
| 502 | step_info.* = TopLevelStep{ | 502 | step_info.* = TopLevelStep{ |
| 503 | .step = Step.initNoOp(name, self.allocator), | 503 | .step = Step.initNoOp(.TopLevel, name, self.allocator), |
| 504 | .description = description, | 504 | .description = description, |
| 505 | }; | 505 | }; |
| 506 | self.top_level_steps.append(step_info) catch unreachable; | 506 | self.top_level_steps.append(step_info) catch unreachable; |
| ... | @@ -1286,7 +1286,7 @@ pub const LibExeObjStep = struct { | ... | @@ -1286,7 +1286,7 @@ pub const LibExeObjStep = struct { |
| 1286 | .root_src = root_src, | 1286 | .root_src = root_src, |
| 1287 | .name = name, | 1287 | .name = name, |
| 1288 | .frameworks = BufSet.init(builder.allocator), | 1288 | .frameworks = BufSet.init(builder.allocator), |
| 1289 | .step = Step.init(name, builder.allocator, make), | 1289 | .step = Step.init(.LibExeObj, name, builder.allocator, make), |
| 1290 | .version = ver, | 1290 | .version = ver, |
| 1291 | .out_filename = undefined, | 1291 | .out_filename = undefined, |
| 1292 | .out_h_filename = builder.fmt("{}.h", .{name}), | 1292 | .out_h_filename = builder.fmt("{}.h", .{name}), |
| ... | @@ -2223,7 +2223,7 @@ pub const LibExeObjStep = struct { | ... | @@ -2223,7 +2223,7 @@ pub const LibExeObjStep = struct { |
| 2223 | } | 2223 | } |
| 2224 | }; | 2224 | }; |
| 2225 | | 2225 | |
| 2226 | const InstallArtifactStep = struct { | 2226 | pub const InstallArtifactStep = struct { |
| 2227 | step: Step, | 2227 | step: Step, |
| 2228 | builder: *Builder, | 2228 | builder: *Builder, |
| 2229 | artifact: *LibExeObjStep, | 2229 | artifact: *LibExeObjStep, |
| ... | @@ -2239,7 +2239,7 @@ const InstallArtifactStep = struct { | ... | @@ -2239,7 +2239,7 @@ const InstallArtifactStep = struct { |
| 2239 | const self = builder.allocator.create(Self) catch unreachable; | 2239 | const self = builder.allocator.create(Self) catch unreachable; |
| 2240 | self.* = Self{ | 2240 | self.* = Self{ |
| 2241 | .builder = builder, | 2241 | .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), |
| 2243 | .artifact = artifact, | 2243 | .artifact = artifact, |
| 2244 | .dest_dir = switch (artifact.kind) { | 2244 | .dest_dir = switch (artifact.kind) { |
| 2245 | .Obj => unreachable, | 2245 | .Obj => unreachable, |
| ... | @@ -2313,7 +2313,7 @@ pub const InstallFileStep = struct { | ... | @@ -2313,7 +2313,7 @@ pub const InstallFileStep = struct { |
| 2313 | builder.pushInstalledFile(dir, dest_rel_path); | 2313 | builder.pushInstalledFile(dir, dest_rel_path); |
| 2314 | return InstallFileStep{ | 2314 | return InstallFileStep{ |
| 2315 | .builder = builder, | 2315 | .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), |
| 2317 | .src_path = src_path, | 2317 | .src_path = src_path, |
| 2318 | .dir = dir, | 2318 | .dir = dir, |
| 2319 | .dest_rel_path = dest_rel_path, | 2319 | .dest_rel_path = dest_rel_path, |
| ... | @@ -2347,7 +2347,7 @@ pub const InstallDirStep = struct { | ... | @@ -2347,7 +2347,7 @@ pub const InstallDirStep = struct { |
| 2347 | builder.pushInstalledFile(options.install_dir, options.install_subdir); | 2347 | builder.pushInstalledFile(options.install_dir, options.install_subdir); |
| 2348 | return InstallDirStep{ | 2348 | return InstallDirStep{ |
| 2349 | .builder = builder, | 2349 | .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), |
| 2351 | .options = options, | 2351 | .options = options, |
| 2352 | }; | 2352 | }; |
| 2353 | } | 2353 | } |
| ... | @@ -2383,7 +2383,7 @@ pub const LogStep = struct { | ... | @@ -2383,7 +2383,7 @@ pub const LogStep = struct { |
| 2383 | pub fn init(builder: *Builder, data: []const u8) LogStep { | 2383 | pub fn init(builder: *Builder, data: []const u8) LogStep { |
| 2384 | return LogStep{ | 2384 | return LogStep{ |
| 2385 | .builder = builder, | 2385 | .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), |
| 2387 | .data = data, | 2387 | .data = data, |
| 2388 | }; | 2388 | }; |
| 2389 | } | 2389 | } |
| ... | @@ -2402,7 +2402,7 @@ pub const RemoveDirStep = struct { | ... | @@ -2402,7 +2402,7 @@ pub const RemoveDirStep = struct { |
| 2402 | pub fn init(builder: *Builder, dir_path: []const u8) RemoveDirStep { | 2402 | pub fn init(builder: *Builder, dir_path: []const u8) RemoveDirStep { |
| 2403 | return RemoveDirStep{ | 2403 | return RemoveDirStep{ |
| 2404 | .builder = builder, | 2404 | .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), |
| 2406 | .dir_path = dir_path, | 2406 | .dir_path = dir_path, |
| 2407 | }; | 2407 | }; |
| 2408 | } | 2408 | } |
| ... | @@ -2418,15 +2418,35 @@ pub const RemoveDirStep = struct { | ... | @@ -2418,15 +2418,35 @@ pub const RemoveDirStep = struct { |
| 2418 | } | 2418 | } |
| 2419 | }; | 2419 | }; |
| 2420 | | 2420 | |
| | 2421 | const ThisModule = @This(); |
| 2421 | pub const Step = struct { | 2422 | pub const Step = struct { |
| | 2423 | id: Id, |
| 2422 | name: []const u8, | 2424 | name: []const u8, |
| 2423 | makeFn: fn (self: *Step) anyerror!void, | 2425 | makeFn: fn (self: *Step) anyerror!void, |
| 2424 | dependencies: ArrayList(*Step), | 2426 | dependencies: ArrayList(*Step), |
| 2425 | loop_flag: bool, | 2427 | loop_flag: bool, |
| 2426 | done_flag: bool, | 2428 | done_flag: bool, |
| 2427 | | 2429 | |
| 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 | Custom, |
| | 2445 | }; |
| | 2446 | |
| | 2447 | pub fn init(id: Id, name: []const u8, allocator: *Allocator, makeFn: fn (*Step) anyerror!void) Step { |
| 2429 | return Step{ | 2448 | return Step{ |
| | 2449 | .id = id, |
| 2430 | .name = name, | 2450 | .name = name, |
| 2431 | .makeFn = makeFn, | 2451 | .makeFn = makeFn, |
| 2432 | .dependencies = ArrayList(*Step).init(allocator), | 2452 | .dependencies = ArrayList(*Step).init(allocator), |
| ... | @@ -2434,8 +2454,8 @@ pub const Step = struct { | ... | @@ -2434,8 +2454,8 @@ pub const Step = struct { |
| 2434 | .done_flag = false, | 2454 | .done_flag = false, |
| 2435 | }; | 2455 | }; |
| 2436 | } | 2456 | } |
| 2437 | pub fn initNoOp(name: []const u8, allocator: *Allocator) Step { | 2457 | pub fn initNoOp(id: Id, name: []const u8, allocator: *Allocator) Step { |
| 2438 | return init(name, allocator, makeNoOp); | 2458 | return init(id, name, allocator, makeNoOp); |
| 2439 | } | 2459 | } |
| 2440 | | 2460 | |
| 2441 | pub fn make(self: *Step) !void { | 2461 | pub fn make(self: *Step) !void { |
| ... | @@ -2450,6 +2470,25 @@ pub const Step = struct { | ... | @@ -2450,6 +2470,25 @@ pub const Step = struct { |
| 2450 | } | 2470 | } |
| 2451 | | 2471 | |
| 2452 | fn makeNoOp(self: *Step) anyerror!void {} | 2472 | fn makeNoOp(self: *Step) anyerror!void {} |
| | 2473 | |
| | 2474 | pub fn cast(step: *Step, comptime T: type) ?*T { |
| | 2475 | if (step.id == comptime typeToId(T)) { |
| | 2476 | return @fieldParentPtr(T, "step", step); |
| | 2477 | } |
| | 2478 | return null; |
| | 2479 | } |
| | 2480 | |
| | 2481 | fn typeToId(comptime T: type) Id { |
| | 2482 | inline for (@typeInfo(Id).Enum.fields) |f| { |
| | 2483 | if (std.mem.eql(u8, f.name, "TopLevel") or |
| | 2484 | std.mem.eql(u8, f.name, "Custom")) continue; |
| | 2485 | |
| | 2486 | if (T == @field(ThisModule, f.name ++ "Step")) { |
| | 2487 | return @field(Id, f.name); |
| | 2488 | } |
| | 2489 | } |
| | 2490 | unreachable; |
| | 2491 | } |
| 2453 | }; | 2492 | }; |
| 2454 | | 2493 | |
| 2455 | fn doAtomicSymLinks(allocator: *Allocator, output_path: []const u8, filename_major_only: []const u8, filename_name_only: []const u8) !void { | 2494 | fn doAtomicSymLinks(allocator: *Allocator, output_path: []const u8, filename_major_only: []const u8, filename_name_only: []const u8) !void { |