| author | |
| committer | |
| log | d7eab060db6aff326a957e4dbffcd09263f7ffbd |
| tree | 6c09212927ff8b7558f9f5ca5b79d81b30a018c0 |
| parent | f9f00c2dee151231361df7aa45a71ca33f90dcd1 |
5 files changed, 63 insertions(+), 65 deletions(-)
lib/compiler/Maker/Step/UpdateSourceFiles.zig+4-4| ... | ... | @@ -35,7 +35,7 @@ pub fn make( |
| 35 | 35 | for (conf_usf.embeds.slice) |*embed| { |
| 36 | 36 | const dest_path: Path = .{ |
| 37 | 37 | .root_dir = build_root, |
| 38 | .sub_path = embed.dest_path.slice(conf), | |
| 38 | .sub_path = embed.sub_path.slice(conf), | |
| 39 | 39 | }; |
| 40 | 40 | if (Io.Dir.path.dirname(dest_path.sub_path)) |dirname| { |
| 41 | 41 | const dirname_path: Path = .{ |
| ... | ... | @@ -47,7 +47,7 @@ pub fn make( |
| 47 | 47 | } |
| 48 | 48 | dest_path.root_dir.handle.writeFile(io, .{ |
| 49 | 49 | .sub_path = dest_path.sub_path, |
| 50 | .data = embed.bytes.slice(conf), | |
| 50 | .data = embed.contents.slice(conf), | |
| 51 | 51 | }) catch |err| return step.fail(maker, "failed to write file {f}: {t}", .{ dest_path, err }); |
| 52 | 52 | any_miss = true; |
| 53 | 53 | progress_node.completeOne(); |
| ... | ... | @@ -56,7 +56,7 @@ pub fn make( |
| 56 | 56 | for (conf_usf.copies.slice) |*copy| { |
| 57 | 57 | const dest_path: Path = .{ |
| 58 | 58 | .root_dir = build_root, |
| 59 | .sub_path = copy.dest_path.slice(conf), | |
| 59 | .sub_path = copy.sub_path.slice(conf), | |
| 60 | 60 | }; |
| 61 | 61 | if (Io.Dir.path.dirname(dest_path.sub_path)) |dirname| { |
| 62 | 62 | const dirname_path: Path = .{ |
| ... | ... | @@ -66,7 +66,7 @@ pub fn make( |
| 66 | 66 | dirname_path.root_dir.handle.createDirPath(io, dirname_path.sub_path) catch |err| |
| 67 | 67 | return step.fail(maker, "failed to create path {f}: {t}", .{ dirname_path, err }); |
| 68 | 68 | } |
| 69 | const src_lazy_path = copy.src_path.get(conf); | |
| 69 | const src_lazy_path = copy.src_file.get(conf); | |
| 70 | 70 | const source_path = try maker.resolveLazyPath(arena, src_lazy_path, step_index); |
| 71 | 71 | if (!step.inputs.populated()) try step.addWatchInput(maker, arena, src_lazy_path); |
| 72 | 72 |
lib/compiler/configurer.zig+22-9| ... | ... | @@ -464,6 +464,15 @@ const Serialize = struct { |
| 464 | 464 | return result; |
| 465 | 465 | } |
| 466 | 466 | |
| 467 | fn initCopyList(s: *Serialize, list: []const Step.WriteFile.Copy) ![]const Configuration.Step.WriteFile.Copy { | |
| 468 | const result = try s.arena.alloc(Configuration.Step.WriteFile.Copy, list.len); | |
| 469 | for (result, list) |*dest, src| dest.* = .{ | |
| 470 | .sub_path = src.sub_path, | |
| 471 | .src_file = try s.addLazyPath(src.src_file), | |
| 472 | }; | |
| 473 | return result; | |
| 474 | } | |
| 475 | ||
| 467 | 476 | fn initOptionalStringList(s: *Serialize, list: []const ?[]const u8) ![]const Configuration.OptionalString { |
| 468 | 477 | const wc = s.wc; |
| 469 | 478 | const result = try s.arena.alloc(Configuration.OptionalString, list.len); |
| ... | ... | @@ -905,12 +914,6 @@ fn serialize(b: *std.Build, wc: *Configuration.Wip, writer: *Io.Writer) !void { |
| 905 | 914 | .write_file => e: { |
| 906 | 915 | const wf: *Step.WriteFile = @fieldParentPtr("step", step); |
| 907 | 916 | |
| 908 | const copies = try arena.alloc(Configuration.Step.WriteFile.Copy, wf.copies.items.len); | |
| 909 | for (copies, wf.copies.items) |*dest, src| dest.* = .{ | |
| 910 | .sub_path = src.sub_path, | |
| 911 | .src_file = try s.addLazyPath(src.src_file), | |
| 912 | }; | |
| 913 | ||
| 914 | 917 | const directories = try arena.alloc( |
| 915 | 918 | Configuration.Step.WriteFile.Directory, |
| 916 | 919 | wf.directories.items.len, |
| ... | ... | @@ -925,7 +928,7 @@ fn serialize(b: *std.Build, wc: *Configuration.Wip, writer: *Io.Writer) !void { |
| 925 | 928 | break :e @enumFromInt(try wc.addExtra(@as(Configuration.Step.WriteFile, .{ |
| 926 | 929 | .flags = .{ |
| 927 | 930 | .embeds = wf.embeds.items.len != 0, |
| 928 | .copies = copies.len != 0, | |
| 931 | .copies = wf.copies.items.len != 0, | |
| 929 | 932 | .directories = directories.len != 0, |
| 930 | 933 | .mode = switch (wf.mode) { |
| 931 | 934 | .whole_cached => .whole_cached, |
| ... | ... | @@ -935,7 +938,7 @@ fn serialize(b: *std.Build, wc: *Configuration.Wip, writer: *Io.Writer) !void { |
| 935 | 938 | }, |
| 936 | 939 | .generated_directory = wf.generated_directory, |
| 937 | 940 | .embeds = .{ .slice = wf.embeds.items }, |
| 938 | .copies = .{ .slice = copies }, | |
| 941 | .copies = .{ .slice = try s.initCopyList(wf.copies.items) }, | |
| 939 | 942 | .directories = .{ .slice = directories }, |
| 940 | 943 | .mutate_path = .{ .value = switch (wf.mode) { |
| 941 | 944 | .mutate => |lp| try s.addLazyPath(lp), |
| ... | ... | @@ -943,7 +946,17 @@ fn serialize(b: *std.Build, wc: *Configuration.Wip, writer: *Io.Writer) !void { |
| 943 | 946 | } }, |
| 944 | 947 | }))); |
| 945 | 948 | }, |
| 946 | .update_source_files => @panic("TODO"), | |
| 949 | .update_source_files => e: { | |
| 950 | const usf: *Step.UpdateSourceFiles = @fieldParentPtr("step", step); | |
| 951 | break :e @enumFromInt(try wc.addExtra(@as(Configuration.Step.UpdateSourceFiles, .{ | |
| 952 | .flags = .{ | |
| 953 | .embeds = usf.embeds.items.len != 0, | |
| 954 | .copies = usf.copies.items.len != 0, | |
| 955 | }, | |
| 956 | .embeds = .{ .slice = usf.embeds.items }, | |
| 957 | .copies = .{ .slice = try s.initCopyList(usf.copies.items) }, | |
| 958 | }))); | |
| 959 | }, | |
| 947 | 960 | .run => e: { |
| 948 | 961 | const run: *Step.Run = @fieldParentPtr("step", step); |
| 949 | 962 | var expect_stderr_exact: ?Configuration.Bytes = null; |
lib/std/Build/Configuration.zig+2-11| ... | ... | @@ -1229,17 +1229,8 @@ pub const Step = extern struct { |
| 1229 | 1229 | embeds: Storage.FlagLengthPrefixedList(.flags, .embeds, Embed), |
| 1230 | 1230 | copies: Storage.FlagLengthPrefixedList(.flags, .copies, Copy), |
| 1231 | 1231 | |
| 1232 | pub const Embed = extern struct { | |
| 1233 | /// Relative to build root. | |
| 1234 | dest_path: String, | |
| 1235 | bytes: Bytes, | |
| 1236 | }; | |
| 1237 | ||
| 1238 | pub const Copy = extern struct { | |
| 1239 | /// Relative to build root. | |
| 1240 | dest_path: String, | |
| 1241 | src_path: LazyPath.Index, | |
| 1242 | }; | |
| 1232 | pub const Embed = WriteFile.Embed; | |
| 1233 | pub const Copy = WriteFile.Copy; | |
| 1243 | 1234 | |
| 1244 | 1235 | pub const Flags = packed struct(u32) { |
| 1245 | 1236 | tag: Tag = .update_source_files, |
lib/std/Build/Step/UpdateSourceFiles.zig+35-36| ... | ... | @@ -6,64 +6,63 @@ |
| 6 | 6 | const UpdateSourceFiles = @This(); |
| 7 | 7 | |
| 8 | 8 | const std = @import("std"); |
| 9 | const Io = std.Io; | |
| 10 | 9 | const Step = std.Build.Step; |
| 11 | const fs = std.fs; | |
| 12 | const ArrayList = std.ArrayList; | |
| 10 | const Configuration = std.Build.Configuration; | |
| 13 | 11 | |
| 14 | 12 | step: Step, |
| 15 | output_source_files: std.ArrayList(OutputSourceFile), | |
| 13 | embeds: std.ArrayList(Embed) = .empty, | |
| 14 | copies: std.ArrayList(Copy) = .empty, | |
| 16 | 15 | |
| 17 | 16 | pub const base_tag: Step.Tag = .update_source_files; |
| 18 | 17 | |
| 19 | pub const OutputSourceFile = struct { | |
| 20 | contents: Contents, | |
| 21 | sub_path: []const u8, | |
| 22 | }; | |
| 23 | ||
| 24 | pub const Contents = union(enum) { | |
| 25 | bytes: []const u8, | |
| 26 | copy: std.Build.LazyPath, | |
| 27 | }; | |
| 18 | pub const Embed = Step.WriteFile.Embed; | |
| 19 | pub const Copy = Step.WriteFile.Copy; | |
| 28 | 20 | |
| 29 | 21 | pub fn create(owner: *std.Build) *UpdateSourceFiles { |
| 30 | const usf = owner.allocator.create(UpdateSourceFiles) catch @panic("OOM"); | |
| 22 | const graph = owner.graph; | |
| 23 | const usf = graph.create(UpdateSourceFiles); | |
| 31 | 24 | usf.* = .{ |
| 32 | 25 | .step = .init(.{ |
| 33 | 26 | .tag = base_tag, |
| 34 | 27 | .name = "UpdateSourceFiles", |
| 35 | 28 | .owner = owner, |
| 36 | 29 | }), |
| 37 | .output_source_files = .empty, | |
| 38 | 30 | }; |
| 39 | 31 | return usf; |
| 40 | 32 | } |
| 41 | 33 | |
| 42 | /// A path relative to the package root. | |
| 34 | /// Overwrites a path relative to the build root with the contents of another file. | |
| 43 | 35 | /// |
| 44 | /// Be careful with this because it updates source files. This should not be | |
| 45 | /// used as part of the normal build process, but as a utility occasionally | |
| 46 | /// run by a developer with intent to modify source files and then commit | |
| 47 | /// those changes to version control. | |
| 48 | pub fn addCopyFileToSource(usf: *UpdateSourceFiles, source: std.Build.LazyPath, sub_path: []const u8) void { | |
| 49 | const b = usf.step.owner; | |
| 50 | usf.output_source_files.append(b.allocator, .{ | |
| 51 | .contents = .{ .copy = source }, | |
| 52 | .sub_path = sub_path, | |
| 36 | /// Because it updates source files, this should not be used as part of the | |
| 37 | /// normal build process, but as a utility occasionally run by a developer with | |
| 38 | /// intent to modify source files and then commit those changes to version | |
| 39 | /// control. | |
| 40 | pub fn addCopyFileToSource(usf: *UpdateSourceFiles, src_file: std.Build.LazyPath, sub_path: []const u8) void { | |
| 41 | const graph = usf.step.owner.graph; | |
| 42 | const wc = &graph.wip_configuration; | |
| 43 | const arena = graph.arena; | |
| 44 | ||
| 45 | usf.copies.append(arena, .{ | |
| 46 | .sub_path = wc.addString(sub_path) catch @panic("OOM"), | |
| 47 | .src_file = src_file.dupe(graph), | |
| 53 | 48 | }) catch @panic("OOM"); |
| 54 | source.addStepDependencies(&usf.step); | |
| 49 | ||
| 50 | src_file.addStepDependencies(&usf.step); | |
| 55 | 51 | } |
| 56 | 52 | |
| 57 | /// A path relative to the package root. | |
| 53 | /// Overwrites a path relative to the package root with the provided bytes. | |
| 58 | 54 | /// |
| 59 | /// Be careful with this because it updates source files. This should not be | |
| 60 | /// used as part of the normal build process, but as a utility occasionally | |
| 61 | /// run by a developer with intent to modify source files and then commit | |
| 62 | /// those changes to version control. | |
| 63 | pub fn addBytesToSource(usf: *UpdateSourceFiles, bytes: []const u8, sub_path: []const u8) void { | |
| 64 | const b = usf.step.owner; | |
| 65 | usf.output_source_files.append(b.allocator, .{ | |
| 66 | .contents = .{ .bytes = bytes }, | |
| 67 | .sub_path = sub_path, | |
| 55 | /// Because it updates source files, this should not be used as part of the | |
| 56 | /// normal build process, but as a utility occasionally run by a developer with | |
| 57 | /// intent to modify source files and then commit those changes to version | |
| 58 | /// control. | |
| 59 | pub fn addBytesToSource(usf: *UpdateSourceFiles, contents: []const u8, sub_path: []const u8) void { | |
| 60 | const graph = usf.step.owner.graph; | |
| 61 | const wc = &graph.wip_configuration; | |
| 62 | const arena = graph.arena; | |
| 63 | ||
| 64 | usf.embeds.append(arena, .{ | |
| 65 | .sub_path = wc.addString(sub_path) catch @panic("OOM"), | |
| 66 | .contents = wc.addBytes(contents) catch @panic("OOM"), | |
| 68 | 67 | }) catch @panic("OOM"); |
| 69 | 68 | } |
lib/std/Build/Step/WriteFile.zig-5| ... | ... | @@ -4,15 +4,10 @@ |
| 4 | 4 | const WriteFile = @This(); |
| 5 | 5 | |
| 6 | 6 | const std = @import("std"); |
| 7 | const Io = std.Io; | |
| 8 | const Dir = std.Io.Dir; | |
| 9 | 7 | const Step = std.Build.Step; |
| 10 | const ArrayList = std.ArrayList; | |
| 11 | const assert = std.debug.assert; | |
| 12 | 8 | const Configuration = std.Build.Configuration; |
| 13 | 9 | |
| 14 | 10 | step: Step, |
| 15 | ||
| 16 | 11 | embeds: std.ArrayList(Embed) = .empty, |
| 17 | 12 | copies: std.ArrayList(Copy) = .empty, |
| 18 | 13 | directories: std.ArrayList(Directory) = .empty, |