| author | |
| committer | |
| log | 3f9fe9e28f83119f8ecf2fdafcd12967417634e9 |
| tree | 0027863d7bf1aa63d959eb39082e74a1adaf68b4 |
| parent | 80fe9b2b7fc981166cbfe98165e17dad6107cb34 |
| parent | c106e2759578e787e5be235c8f6b227623ff2c3b |
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/368765 files changed, 78 insertions(+), 32 deletions(-)
lib/compiler/Maker/Step/Options.zig+16-3| ... | ... | @@ -30,7 +30,7 @@ pub fn make( |
| 30 | 30 | // generated zig file are observable by dependant steps. |
| 31 | 31 | // Pathnames added to Options.args are assumed to be generated files whose |
| 32 | 32 | // contents are also observable, while pathnames added to |
| 33 | // Options.args_untracked are treated as pure path string data with no | |
| 33 | // Options.untracked_paths are treated as pure path string data with no | |
| 34 | 34 | // tracking of the path's state or contents. |
| 35 | 35 | |
| 36 | 36 | step.clearWatchInputs(maker); |
| ... | ... | @@ -40,7 +40,7 @@ pub fn make( |
| 40 | 40 | |
| 41 | 41 | var args_bytes: std.ArrayList(u8) = .empty; |
| 42 | 42 | |
| 43 | for (conf_options.args.slice) |arg| { | |
| 43 | for (conf_options.files.slice) |arg| { | |
| 44 | 44 | const name = arg.name.slice(conf); |
| 45 | 45 | const lazy_path = arg.path.get(conf); |
| 46 | 46 | try step.addWatchInput(maker, arena, lazy_path); |
| ... | ... | @@ -51,7 +51,20 @@ pub fn make( |
| 51 | 51 | }); |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | for (conf_options.args_untracked.slice) |arg| { | |
| 54 | for (conf_options.directories.slice) |arg| { | |
| 55 | const name = arg.name.slice(conf); | |
| 56 | const lazy_path = arg.path.get(conf); | |
| 57 | _ = try step.addDirectoryWatchInput(maker, lazy_path); | |
| 58 | const arg_path = try maker.resolveLazyPath(arena, lazy_path, step_index); | |
| 59 | _ = try man.addInputPath(arg_path, .{ | |
| 60 | .handle = .{ .dir = null }, | |
| 61 | }); | |
| 62 | try args_bytes.print(arena, "pub const {f}: []const u8 = \"{f}\";\n", .{ | |
| 63 | std.zig.fmtId(name), arg_path.fmtEscapeString(), | |
| 64 | }); | |
| 65 | } | |
| 66 | ||
| 67 | for (conf_options.untracked_paths.slice) |arg| { | |
| 55 | 68 | const name = arg.name.slice(conf); |
| 56 | 69 | const lazy_path = arg.path.get(conf); |
| 57 | 70 | const arg_path = try maker.resolveLazyPath(arena, lazy_path, step_index); |
lib/std/Build/Cache.zig+8-3| ... | ... | @@ -514,6 +514,11 @@ pub const Manifest = struct { |
| 514 | 514 | pub fn path(off: File.Offset, contents: []const u8) [:0]const u8 { |
| 515 | 515 | return pathFallible(off, contents) catch unreachable; |
| 516 | 516 | } |
| 517 | ||
| 518 | pub fn pathOrDot(off: File.Offset, contents: []const u8) [:0]const u8 { | |
| 519 | const p = pathFallible(off, contents) catch unreachable; | |
| 520 | return if (p.len == 0) "." else p; | |
| 521 | } | |
| 517 | 522 | }; |
| 518 | 523 | |
| 519 | 524 | /// Intentionally matches if the files are different only by flags other than prefix. |
| ... | ... | @@ -1176,7 +1181,7 @@ pub const Manifest = struct { |
| 1176 | 1181 | const io = cache.io; |
| 1177 | 1182 | const input_file = file_off.get(contents); |
| 1178 | 1183 | const parent_dir = cache.prefixes()[input_file.flags.prefix].handle; |
| 1179 | const file_path = file_off.path(contents); | |
| 1184 | const file_path = file_off.pathOrDot(contents); | |
| 1180 | 1185 | const gpa = cache.gpa; |
| 1181 | 1186 | |
| 1182 | 1187 | if (input_path.have_digest) return; |
| ... | ... | @@ -1352,7 +1357,7 @@ pub const Manifest = struct { |
| 1352 | 1357 | const disk_file = file_off.get(disk_contents); |
| 1353 | 1358 | const input_file = file_off.get(input_contents); |
| 1354 | 1359 | const parent_dir = cache.prefixes()[disk_file.flags.prefix].handle; |
| 1355 | const file_path = file_off.path(disk_contents); | |
| 1360 | const file_path = file_off.pathOrDot(disk_contents); | |
| 1356 | 1361 | |
| 1357 | 1362 | assert(disk_file.flags == input_file.flags); |
| 1358 | 1363 | |
| ... | ... | @@ -1536,7 +1541,7 @@ pub const Manifest = struct { |
| 1536 | 1541 | const gpa = cache.gpa; |
| 1537 | 1542 | const io = cache.io; |
| 1538 | 1543 | const parent_dir = cache.prefixes()[file.flags.prefix].handle; |
| 1539 | const file_path = file_off.path(contents); | |
| 1544 | const file_path = file_off.pathOrDot(contents); | |
| 1540 | 1545 | |
| 1541 | 1546 | if (file.flags.metadata_only) { |
| 1542 | 1547 | const actual_stat = parent_dir.statFile(io, file_path, .{}) catch |err| switch (err) { |
lib/std/Build/Configuration.zig+8-6| ... | ... | @@ -1378,19 +1378,21 @@ pub const Step = extern struct { |
| 1378 | 1378 | flags: @This().Flags, |
| 1379 | 1379 | generated_file: GeneratedFileIndex, |
| 1380 | 1380 | contents: Bytes, |
| 1381 | args: Storage.FlagLengthPrefixedList(.flags, .args, Arg), | |
| 1382 | args_untracked: Storage.FlagLengthPrefixedList(.flags, .args_untracked, Arg), | |
| 1381 | files: Storage.FlagLengthPrefixedList(.flags, .files, NamedPath), | |
| 1382 | directories: Storage.FlagLengthPrefixedList(.flags, .directories, NamedPath), | |
| 1383 | untracked_paths: Storage.FlagLengthPrefixedList(.flags, .untracked_paths, NamedPath), | |
| 1383 | 1384 | |
| 1384 | pub const Arg = extern struct { | |
| 1385 | pub const NamedPath = extern struct { | |
| 1385 | 1386 | name: String, |
| 1386 | 1387 | path: LazyPath.Index, |
| 1387 | 1388 | }; |
| 1388 | 1389 | |
| 1389 | 1390 | pub const Flags = packed struct(u32) { |
| 1390 | 1391 | tag: Tag = .options, |
| 1391 | args: bool, | |
| 1392 | args_untracked: bool, | |
| 1393 | _: u25 = 0, | |
| 1392 | files: bool, | |
| 1393 | directories: bool, | |
| 1394 | untracked_paths: bool, | |
| 1395 | _: u24 = 0, | |
| 1394 | 1396 | }; |
| 1395 | 1397 | }; |
| 1396 | 1398 |
lib/std/Build/Serialize.zig+16-8| ... | ... | @@ -648,27 +648,35 @@ pub fn write(b: *std.Build, wc: *Configuration.Wip, writer: *std.Io.Writer) !voi |
| 648 | 648 | .options => e: { |
| 649 | 649 | const so: *Step.Options = @fieldParentPtr("step", step); |
| 650 | 650 | |
| 651 | const args = try arena.alloc(Configuration.Step.Options.Arg, so.args.items.len); | |
| 652 | for (args, so.args.items) |*dest, src| dest.* = .{ | |
| 651 | const files = try arena.alloc(Configuration.Step.Options.NamedPath, so.files.items.len); | |
| 652 | for (files, so.files.items) |*dest, src| dest.* = .{ | |
| 653 | 653 | .name = src.name, |
| 654 | 654 | .path = try s.addLazyPath(src.path), |
| 655 | 655 | }; |
| 656 | 656 | |
| 657 | const args_untracked = try arena.alloc(Configuration.Step.Options.Arg, so.args_untracked.items.len); | |
| 658 | for (args_untracked, so.args_untracked.items) |*dest, src| dest.* = .{ | |
| 657 | const directories = try arena.alloc(Configuration.Step.Options.NamedPath, so.directories.items.len); | |
| 658 | for (directories, so.directories.items) |*dest, src| dest.* = .{ | |
| 659 | .name = src.name, | |
| 660 | .path = try s.addLazyPath(src.path), | |
| 661 | }; | |
| 662 | ||
| 663 | const untracked_paths = try arena.alloc(Configuration.Step.Options.NamedPath, so.untracked_paths.items.len); | |
| 664 | for (untracked_paths, so.untracked_paths.items) |*dest, src| dest.* = .{ | |
| 659 | 665 | .name = src.name, |
| 660 | 666 | .path = try s.addLazyPath(src.path), |
| 661 | 667 | }; |
| 662 | 668 | |
| 663 | 669 | break :e try wc.addExtraErased(Configuration.Step.Options, .{ |
| 664 | 670 | .flags = .{ |
| 665 | .args = so.args.items.len != 0, | |
| 666 | .args_untracked = so.args_untracked.items.len != 0, | |
| 671 | .files = so.files.items.len != 0, | |
| 672 | .directories = so.directories.items.len != 0, | |
| 673 | .untracked_paths = so.untracked_paths.items.len != 0, | |
| 667 | 674 | }, |
| 668 | 675 | .generated_file = so.generated_file, |
| 669 | 676 | .contents = try wc.addBytes(so.contents.items), |
| 670 | .args = .{ .slice = args }, | |
| 671 | .args_untracked = .{ .slice = args_untracked }, | |
| 677 | .files = .{ .slice = files }, | |
| 678 | .directories = .{ .slice = directories }, | |
| 679 | .untracked_paths = .{ .slice = untracked_paths }, | |
| 672 | 680 | }); |
| 673 | 681 | }, |
| 674 | 682 | })), |
lib/std/Build/Step/Options.zig+30-12| ... | ... | @@ -12,13 +12,14 @@ const Configuration = std.Build.Configuration; |
| 12 | 12 | step: Step, |
| 13 | 13 | generated_file: Configuration.GeneratedFileIndex, |
| 14 | 14 | contents: std.ArrayList(u8) = .empty, |
| 15 | args: std.ArrayList(Arg) = .empty, | |
| 16 | args_untracked: std.ArrayList(Arg) = .empty, | |
| 15 | files: std.ArrayList(NamedPath) = .empty, | |
| 16 | directories: std.ArrayList(NamedPath) = .empty, | |
| 17 | untracked_paths: std.ArrayList(NamedPath) = .empty, | |
| 17 | 18 | encountered_types: std.StringHashMapUnmanaged(void), |
| 18 | 19 | |
| 19 | 20 | pub const base_tag: Step.Tag = .options; |
| 20 | 21 | |
| 21 | pub const Arg = struct { | |
| 22 | pub const NamedPath = struct { | |
| 22 | 23 | name: Configuration.String, |
| 23 | 24 | path: LazyPath, |
| 24 | 25 | }; |
| ... | ... | @@ -421,28 +422,45 @@ fn printStructValue( |
| 421 | 422 | } |
| 422 | 423 | } |
| 423 | 424 | |
| 424 | /// The added option has type `[]const u8` and value of the provided path. | |
| 425 | /// This interface assumes the provided path is a generated file, and causes a | |
| 426 | /// transitive dependency through Options on the file's contents. | |
| 425 | /// The added option has type `[]const u8` and value of the provided file path. If the provided path is a | |
| 426 | /// generated file, causes a transitive dependency on the file's contents. | |
| 427 | 427 | /// |
| 428 | 428 | /// See also: |
| 429 | /// * `addOptionPathDirectory` | |
| 429 | 430 | /// * `addOptionPathUntracked` |
| 430 | 431 | pub fn addOptionPath(options: *Options, name: []const u8, path: LazyPath) void { |
| 431 | 432 | const graph = options.step.owner.graph; |
| 432 | 433 | const arena = graph.arena; |
| 433 | 434 | const wc = &graph.wip_configuration; |
| 434 | 435 | |
| 435 | options.args.append(arena, .{ | |
| 436 | options.files.append(arena, .{ | |
| 436 | 437 | .name = wc.addString(name) catch @panic("OOM"), |
| 437 | 438 | .path = path.dupe(options.step.owner.graph), |
| 438 | 439 | }) catch @panic("OOM"); |
| 439 | 440 | path.addStepDependencies(&options.step); |
| 440 | 441 | } |
| 441 | 442 | |
| 442 | /// The added option has type `[]const u8` and value of the provided path. | |
| 443 | /// This interface treats the resolved path string as pure data, meaning it | |
| 444 | /// does not track anything about the meaning or contents of this path, and | |
| 445 | /// therefore also does not create any related dependencies. | |
| 443 | /// The added option has type `[]const u8` and value of the provided directory path. Causes a transitive | |
| 444 | /// dependency through Options on the directory's contents. | |
| 445 | /// | |
| 446 | /// See also: | |
| 447 | /// * `addOptionPath` | |
| 448 | /// * `addOptionPathUntracked` | |
| 449 | pub fn addOptionPathDirectory(options: *Options, name: []const u8, path: LazyPath) void { | |
| 450 | const graph = options.step.owner.graph; | |
| 451 | const arena = graph.arena; | |
| 452 | const wc = &graph.wip_configuration; | |
| 453 | ||
| 454 | options.directories.append(arena, .{ | |
| 455 | .name = wc.addString(name) catch @panic("OOM"), | |
| 456 | .path = path.dupe(options.step.owner.graph), | |
| 457 | }) catch @panic("OOM"); | |
| 458 | path.addStepDependencies(&options.step); | |
| 459 | } | |
| 460 | ||
| 461 | /// The added option has type `[]const u8` and value of the provided path. The resolved path is interpreted as | |
| 462 | /// a string without tracking anything about the meaning or contents, and therefore may be a file, directory, | |
| 463 | /// not exist, or even be an invalid path, and likewise does not create any file system or `Step` dependencies. | |
| 446 | 464 | /// |
| 447 | 465 | /// See also: |
| 448 | 466 | /// * `addOptionPath` |
| ... | ... | @@ -451,7 +469,7 @@ pub fn addOptionPathUntracked(options: *Options, name: []const u8, path: LazyPat |
| 451 | 469 | const arena = graph.arena; |
| 452 | 470 | const wc = &graph.wip_configuration; |
| 453 | 471 | |
| 454 | options.args_untracked.append(arena, .{ | |
| 472 | options.untracked_paths.append(arena, .{ | |
| 455 | 473 | .name = wc.addString(name) catch @panic("OOM"), |
| 456 | 474 | .path = path.dupe(options.step.owner.graph), |
| 457 | 475 | }) catch @panic("OOM"); |