| author | |
| committer | |
| log | 5744ceedb8ea4b3e5906175033f634b17287f3ca |
| tree | 5e5178c8f53a7bf6ffadfc713051661e04220de8 |
| parent | c9dffc842e5b9875066f012daaa0888d073ba584 |
| signature |
8 files changed, 26 insertions(+), 32 deletions(-)
lib/std/Build.zig+1-1| ... | ... | @@ -759,7 +759,7 @@ pub fn dupePath(self: *Build, bytes: []const u8) []u8 { |
| 759 | 759 | |
| 760 | 760 | pub fn addWriteFile(self: *Build, file_path: []const u8, data: []const u8) *Step.WriteFile { |
| 761 | 761 | const write_file_step = self.addWriteFiles(); |
| 762 | write_file_step.add(file_path, data); | |
| 762 | _ = write_file_step.add(file_path, data); | |
| 763 | 763 | return write_file_step; |
| 764 | 764 | } |
| 765 | 765 |
lib/std/Build/Step/WriteFile.zig+9-14| ... | ... | @@ -27,6 +27,10 @@ pub const File = struct { |
| 27 | 27 | generated_file: std.Build.GeneratedFile, |
| 28 | 28 | sub_path: []const u8, |
| 29 | 29 | contents: Contents, |
| 30 | ||
| 31 | pub fn getFileSource(self: *File) std.Build.FileSource { | |
| 32 | return .{ .generated = &self.generated_file }; | |
| 33 | } | |
| 30 | 34 | }; |
| 31 | 35 | |
| 32 | 36 | pub const OutputSourceFile = struct { |
| ... | ... | @@ -55,7 +59,7 @@ pub fn create(owner: *std.Build) *WriteFile { |
| 55 | 59 | return wf; |
| 56 | 60 | } |
| 57 | 61 | |
| 58 | pub fn add(wf: *WriteFile, sub_path: []const u8, bytes: []const u8) void { | |
| 62 | pub fn add(wf: *WriteFile, sub_path: []const u8, bytes: []const u8) std.Build.FileSource { | |
| 59 | 63 | const b = wf.step.owner; |
| 60 | 64 | const gpa = b.allocator; |
| 61 | 65 | const file = gpa.create(File) catch @panic("OOM"); |
| ... | ... | @@ -65,8 +69,8 @@ pub fn add(wf: *WriteFile, sub_path: []const u8, bytes: []const u8) void { |
| 65 | 69 | .contents = .{ .bytes = b.dupe(bytes) }, |
| 66 | 70 | }; |
| 67 | 71 | wf.files.append(gpa, file) catch @panic("OOM"); |
| 68 | ||
| 69 | 72 | wf.maybeUpdateName(); |
| 73 | return file.getFileSource(); | |
| 70 | 74 | } |
| 71 | 75 | |
| 72 | 76 | /// Place the file into the generated directory within the local cache, |
| ... | ... | @@ -76,7 +80,7 @@ pub fn add(wf: *WriteFile, sub_path: []const u8, bytes: []const u8) void { |
| 76 | 80 | /// include sub-directories, in which case this step will ensure the |
| 77 | 81 | /// required sub-path exists. |
| 78 | 82 | /// This is the option expected to be used most commonly with `addCopyFile`. |
| 79 | pub fn addCopyFile(wf: *WriteFile, source: std.Build.FileSource, sub_path: []const u8) void { | |
| 83 | pub fn addCopyFile(wf: *WriteFile, source: std.Build.FileSource, sub_path: []const u8) std.Build.FileSource { | |
| 80 | 84 | const b = wf.step.owner; |
| 81 | 85 | const gpa = b.allocator; |
| 82 | 86 | const file = gpa.create(File) catch @panic("OOM"); |
| ... | ... | @@ -89,6 +93,7 @@ pub fn addCopyFile(wf: *WriteFile, source: std.Build.FileSource, sub_path: []con |
| 89 | 93 | |
| 90 | 94 | wf.maybeUpdateName(); |
| 91 | 95 | source.addStepDependencies(&wf.step); |
| 96 | return file.getFileSource(); | |
| 92 | 97 | } |
| 93 | 98 | |
| 94 | 99 | /// A path relative to the package root. |
| ... | ... | @@ -96,7 +101,6 @@ pub fn addCopyFile(wf: *WriteFile, source: std.Build.FileSource, sub_path: []con |
| 96 | 101 | /// used as part of the normal build process, but as a utility occasionally |
| 97 | 102 | /// run by a developer with intent to modify source files and then commit |
| 98 | 103 | /// those changes to version control. |
| 99 | /// A file added this way is not available with `getFileSource`. | |
| 100 | 104 | pub fn addCopyFileToSource(wf: *WriteFile, source: std.Build.FileSource, sub_path: []const u8) void { |
| 101 | 105 | const b = wf.step.owner; |
| 102 | 106 | wf.output_source_files.append(b.allocator, .{ |
| ... | ... | @@ -111,7 +115,6 @@ pub fn addCopyFileToSource(wf: *WriteFile, source: std.Build.FileSource, sub_pat |
| 111 | 115 | /// used as part of the normal build process, but as a utility occasionally |
| 112 | 116 | /// run by a developer with intent to modify source files and then commit |
| 113 | 117 | /// those changes to version control. |
| 114 | /// A file added this way is not available with `getFileSource`. | |
| 115 | 118 | pub fn addBytesToSource(wf: *WriteFile, bytes: []const u8, sub_path: []const u8) void { |
| 116 | 119 | const b = wf.step.owner; |
| 117 | 120 | wf.output_source_files.append(b.allocator, .{ |
| ... | ... | @@ -120,15 +123,7 @@ pub fn addBytesToSource(wf: *WriteFile, bytes: []const u8, sub_path: []const u8) |
| 120 | 123 | }) catch @panic("OOM"); |
| 121 | 124 | } |
| 122 | 125 | |
| 123 | /// Gets a file source for the given sub_path. If the file does not exist, returns `null`. | |
| 124 | pub fn getFileSource(wf: *WriteFile, sub_path: []const u8) ?std.Build.FileSource { | |
| 125 | for (wf.files.items) |file| { | |
| 126 | if (std.mem.eql(u8, file.sub_path, sub_path)) { | |
| 127 | return .{ .generated = &file.generated_file }; | |
| 128 | } | |
| 129 | } | |
| 130 | return null; | |
| 131 | } | |
| 126 | pub const getFileSource = @compileError("Deprecated; use the return value from add()/addCopyFile(), or use files[i].getFileSource()"); | |
| 132 | 127 | |
| 133 | 128 | /// Returns a `FileSource` representing the base directory that contains all the |
| 134 | 129 | /// files from this `WriteFile`. |
test/src/Cases.zig+5-3| ... | ... | @@ -494,10 +494,12 @@ pub fn lowerToBuildSteps( |
| 494 | 494 | } |
| 495 | 495 | |
| 496 | 496 | const writefiles = b.addWriteFiles(); |
| 497 | var file_sources = std.StringHashMap(std.Build.FileSource).init(b.allocator); | |
| 498 | defer file_sources.deinit(); | |
| 497 | 499 | for (update.files.items) |file| { |
| 498 | writefiles.add(file.path, file.src); | |
| 500 | file_sources.put(file.path, writefiles.add(file.path, file.src)) catch @panic("OOM"); | |
| 499 | 501 | } |
| 500 | const root_source_file = writefiles.getFileSource(update.files.items[0].path).?; | |
| 502 | const root_source_file = writefiles.files.items[0].getFileSource(); | |
| 501 | 503 | |
| 502 | 504 | const artifact = if (case.is_test) b.addTest(.{ |
| 503 | 505 | .root_source_file = root_source_file, |
| ... | ... | @@ -540,7 +542,7 @@ pub fn lowerToBuildSteps( |
| 540 | 542 | |
| 541 | 543 | for (case.deps.items) |dep| { |
| 542 | 544 | artifact.addAnonymousModule(dep.name, .{ |
| 543 | .source_file = writefiles.getFileSource(dep.path).?, | |
| 545 | .source_file = file_sources.get(dep.path).?, | |
| 544 | 546 | }); |
| 545 | 547 | } |
| 546 | 548 |
test/src/CompareOutput.zig+4-6| ... | ... | @@ -82,7 +82,7 @@ pub fn addCase(self: *CompareOutput, case: TestCase) void { |
| 82 | 82 | |
| 83 | 83 | const write_src = b.addWriteFiles(); |
| 84 | 84 | for (case.sources.items) |src_file| { |
| 85 | write_src.add(src_file.filename, src_file.source); | |
| 85 | _ = write_src.add(src_file.filename, src_file.source); | |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | switch (case.special) { |
| ... | ... | @@ -99,7 +99,7 @@ pub fn addCase(self: *CompareOutput, case: TestCase) void { |
| 99 | 99 | .target = .{}, |
| 100 | 100 | .optimize = .Debug, |
| 101 | 101 | }); |
| 102 | exe.addAssemblyFileSource(write_src.getFileSource(case.sources.items[0].filename).?); | |
| 102 | exe.addAssemblyFileSource(write_src.files.items[0].getFileSource()); | |
| 103 | 103 | |
| 104 | 104 | const run = b.addRunArtifact(exe); |
| 105 | 105 | run.setName(annotated_case_name); |
| ... | ... | @@ -117,10 +117,9 @@ pub fn addCase(self: *CompareOutput, case: TestCase) void { |
| 117 | 117 | if (mem.indexOf(u8, annotated_case_name, filter) == null) continue; |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | const basename = case.sources.items[0].filename; | |
| 121 | 120 | const exe = b.addExecutable(.{ |
| 122 | 121 | .name = "test", |
| 123 | .root_source_file = write_src.getFileSource(basename).?, | |
| 122 | .root_source_file = write_src.files.items[0].getFileSource(), | |
| 124 | 123 | .optimize = optimize, |
| 125 | 124 | .target = .{}, |
| 126 | 125 | }); |
| ... | ... | @@ -144,10 +143,9 @@ pub fn addCase(self: *CompareOutput, case: TestCase) void { |
| 144 | 143 | if (mem.indexOf(u8, annotated_case_name, filter) == null) return; |
| 145 | 144 | } |
| 146 | 145 | |
| 147 | const basename = case.sources.items[0].filename; | |
| 148 | 146 | const exe = b.addExecutable(.{ |
| 149 | 147 | .name = "test", |
| 150 | .root_source_file = write_src.getFileSource(basename).?, | |
| 148 | .root_source_file = write_src.files.items[0].getFileSource(), | |
| 151 | 149 | .target = .{}, |
| 152 | 150 | .optimize = .Debug, |
| 153 | 151 | }); |
test/src/StackTrace.zig+2-3| ... | ... | @@ -72,11 +72,10 @@ fn addExpect( |
| 72 | 72 | if (mem.indexOf(u8, annotated_case_name, filter) == null) return; |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | const src_basename = "source.zig"; | |
| 76 | const write_src = b.addWriteFile(src_basename, source); | |
| 75 | const write_src = b.addWriteFile("source.zig", source); | |
| 77 | 76 | const exe = b.addExecutable(.{ |
| 78 | 77 | .name = "test", |
| 79 | .root_source_file = write_src.getFileSource(src_basename).?, | |
| 78 | .root_source_file = write_src.files.items[0].getFileSource(), | |
| 80 | 79 | .optimize = optimize_mode, |
| 81 | 80 | .target = .{}, |
| 82 | 81 | }); |
test/src/run_translated_c.zig+2-2| ... | ... | @@ -82,10 +82,10 @@ pub const RunTranslatedCContext = struct { |
| 82 | 82 | |
| 83 | 83 | const write_src = b.addWriteFiles(); |
| 84 | 84 | for (case.sources.items) |src_file| { |
| 85 | write_src.add(src_file.filename, src_file.source); | |
| 85 | _ = write_src.add(src_file.filename, src_file.source); | |
| 86 | 86 | } |
| 87 | 87 | const translate_c = b.addTranslateC(.{ |
| 88 | .source_file = write_src.getFileSource(case.sources.items[0].filename).?, | |
| 88 | .source_file = write_src.files.items[0].getFileSource(), | |
| 89 | 89 | .target = .{}, |
| 90 | 90 | .optimize = .Debug, |
| 91 | 91 | }); |
test/src/translate_c.zig+2-2| ... | ... | @@ -104,11 +104,11 @@ pub const TranslateCContext = struct { |
| 104 | 104 | |
| 105 | 105 | const write_src = b.addWriteFiles(); |
| 106 | 106 | for (case.sources.items) |src_file| { |
| 107 | write_src.add(src_file.filename, src_file.source); | |
| 107 | _ = write_src.add(src_file.filename, src_file.source); | |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | const translate_c = b.addTranslateC(.{ |
| 111 | .source_file = write_src.getFileSource(case.sources.items[0].filename).?, | |
| 111 | .source_file = write_src.files.items[0].getFileSource(), | |
| 112 | 112 | .target = case.target, |
| 113 | 113 | .optimize = .Debug, |
| 114 | 114 | }); |
test/tests.zig+1-1| ... | ... | @@ -759,7 +759,7 @@ pub fn addCliTests(b: *std.Build) *Step { |
| 759 | 759 | "-fno-emit-bin", "-fno-emit-h", |
| 760 | 760 | "-fstrip", "-OReleaseFast", |
| 761 | 761 | }); |
| 762 | run.addFileSourceArg(writefile.getFileSource("example.zig").?); | |
| 762 | run.addFileSourceArg(writefile.files.items[0].getFileSource()); | |
| 763 | 763 | const example_s = run.addPrefixedOutputFileArg("-femit-asm=", "example.s"); |
| 764 | 764 | |
| 765 | 765 | const checkfile = b.addCheckFile(example_s, .{ |