mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 05:44:20 +00:00
Fixes WriteFile.getFileSource failure on Windows (#15730)
This commit is contained in:
parent
c9dffc842e
commit
5744ceedb8
8 changed files with 26 additions and 32 deletions
|
|
@ -759,7 +759,7 @@ pub fn dupePath(self: *Build, bytes: []const u8) []u8 {
|
|||
|
||||
pub fn addWriteFile(self: *Build, file_path: []const u8, data: []const u8) *Step.WriteFile {
|
||||
const write_file_step = self.addWriteFiles();
|
||||
write_file_step.add(file_path, data);
|
||||
_ = write_file_step.add(file_path, data);
|
||||
return write_file_step;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,6 +27,10 @@ pub const File = struct {
|
|||
generated_file: std.Build.GeneratedFile,
|
||||
sub_path: []const u8,
|
||||
contents: Contents,
|
||||
|
||||
pub fn getFileSource(self: *File) std.Build.FileSource {
|
||||
return .{ .generated = &self.generated_file };
|
||||
}
|
||||
};
|
||||
|
||||
pub const OutputSourceFile = struct {
|
||||
|
|
@ -55,7 +59,7 @@ pub fn create(owner: *std.Build) *WriteFile {
|
|||
return wf;
|
||||
}
|
||||
|
||||
pub fn add(wf: *WriteFile, sub_path: []const u8, bytes: []const u8) void {
|
||||
pub fn add(wf: *WriteFile, sub_path: []const u8, bytes: []const u8) std.Build.FileSource {
|
||||
const b = wf.step.owner;
|
||||
const gpa = b.allocator;
|
||||
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 {
|
|||
.contents = .{ .bytes = b.dupe(bytes) },
|
||||
};
|
||||
wf.files.append(gpa, file) catch @panic("OOM");
|
||||
|
||||
wf.maybeUpdateName();
|
||||
return file.getFileSource();
|
||||
}
|
||||
|
||||
/// 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 {
|
|||
/// include sub-directories, in which case this step will ensure the
|
||||
/// required sub-path exists.
|
||||
/// This is the option expected to be used most commonly with `addCopyFile`.
|
||||
pub fn addCopyFile(wf: *WriteFile, source: std.Build.FileSource, sub_path: []const u8) void {
|
||||
pub fn addCopyFile(wf: *WriteFile, source: std.Build.FileSource, sub_path: []const u8) std.Build.FileSource {
|
||||
const b = wf.step.owner;
|
||||
const gpa = b.allocator;
|
||||
const file = gpa.create(File) catch @panic("OOM");
|
||||
|
|
@ -89,6 +93,7 @@ pub fn addCopyFile(wf: *WriteFile, source: std.Build.FileSource, sub_path: []con
|
|||
|
||||
wf.maybeUpdateName();
|
||||
source.addStepDependencies(&wf.step);
|
||||
return file.getFileSource();
|
||||
}
|
||||
|
||||
/// A path relative to the package root.
|
||||
|
|
@ -96,7 +101,6 @@ pub fn addCopyFile(wf: *WriteFile, source: std.Build.FileSource, sub_path: []con
|
|||
/// used as part of the normal build process, but as a utility occasionally
|
||||
/// run by a developer with intent to modify source files and then commit
|
||||
/// those changes to version control.
|
||||
/// A file added this way is not available with `getFileSource`.
|
||||
pub fn addCopyFileToSource(wf: *WriteFile, source: std.Build.FileSource, sub_path: []const u8) void {
|
||||
const b = wf.step.owner;
|
||||
wf.output_source_files.append(b.allocator, .{
|
||||
|
|
@ -111,7 +115,6 @@ pub fn addCopyFileToSource(wf: *WriteFile, source: std.Build.FileSource, sub_pat
|
|||
/// used as part of the normal build process, but as a utility occasionally
|
||||
/// run by a developer with intent to modify source files and then commit
|
||||
/// those changes to version control.
|
||||
/// A file added this way is not available with `getFileSource`.
|
||||
pub fn addBytesToSource(wf: *WriteFile, bytes: []const u8, sub_path: []const u8) void {
|
||||
const b = wf.step.owner;
|
||||
wf.output_source_files.append(b.allocator, .{
|
||||
|
|
@ -120,15 +123,7 @@ pub fn addBytesToSource(wf: *WriteFile, bytes: []const u8, sub_path: []const u8)
|
|||
}) catch @panic("OOM");
|
||||
}
|
||||
|
||||
/// Gets a file source for the given sub_path. If the file does not exist, returns `null`.
|
||||
pub fn getFileSource(wf: *WriteFile, sub_path: []const u8) ?std.Build.FileSource {
|
||||
for (wf.files.items) |file| {
|
||||
if (std.mem.eql(u8, file.sub_path, sub_path)) {
|
||||
return .{ .generated = &file.generated_file };
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
pub const getFileSource = @compileError("Deprecated; use the return value from add()/addCopyFile(), or use files[i].getFileSource()");
|
||||
|
||||
/// Returns a `FileSource` representing the base directory that contains all the
|
||||
/// files from this `WriteFile`.
|
||||
|
|
|
|||
|
|
@ -494,10 +494,12 @@ pub fn lowerToBuildSteps(
|
|||
}
|
||||
|
||||
const writefiles = b.addWriteFiles();
|
||||
var file_sources = std.StringHashMap(std.Build.FileSource).init(b.allocator);
|
||||
defer file_sources.deinit();
|
||||
for (update.files.items) |file| {
|
||||
writefiles.add(file.path, file.src);
|
||||
file_sources.put(file.path, writefiles.add(file.path, file.src)) catch @panic("OOM");
|
||||
}
|
||||
const root_source_file = writefiles.getFileSource(update.files.items[0].path).?;
|
||||
const root_source_file = writefiles.files.items[0].getFileSource();
|
||||
|
||||
const artifact = if (case.is_test) b.addTest(.{
|
||||
.root_source_file = root_source_file,
|
||||
|
|
@ -540,7 +542,7 @@ pub fn lowerToBuildSteps(
|
|||
|
||||
for (case.deps.items) |dep| {
|
||||
artifact.addAnonymousModule(dep.name, .{
|
||||
.source_file = writefiles.getFileSource(dep.path).?,
|
||||
.source_file = file_sources.get(dep.path).?,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ pub fn addCase(self: *CompareOutput, case: TestCase) void {
|
|||
|
||||
const write_src = b.addWriteFiles();
|
||||
for (case.sources.items) |src_file| {
|
||||
write_src.add(src_file.filename, src_file.source);
|
||||
_ = write_src.add(src_file.filename, src_file.source);
|
||||
}
|
||||
|
||||
switch (case.special) {
|
||||
|
|
@ -99,7 +99,7 @@ pub fn addCase(self: *CompareOutput, case: TestCase) void {
|
|||
.target = .{},
|
||||
.optimize = .Debug,
|
||||
});
|
||||
exe.addAssemblyFileSource(write_src.getFileSource(case.sources.items[0].filename).?);
|
||||
exe.addAssemblyFileSource(write_src.files.items[0].getFileSource());
|
||||
|
||||
const run = b.addRunArtifact(exe);
|
||||
run.setName(annotated_case_name);
|
||||
|
|
@ -117,10 +117,9 @@ pub fn addCase(self: *CompareOutput, case: TestCase) void {
|
|||
if (mem.indexOf(u8, annotated_case_name, filter) == null) continue;
|
||||
}
|
||||
|
||||
const basename = case.sources.items[0].filename;
|
||||
const exe = b.addExecutable(.{
|
||||
.name = "test",
|
||||
.root_source_file = write_src.getFileSource(basename).?,
|
||||
.root_source_file = write_src.files.items[0].getFileSource(),
|
||||
.optimize = optimize,
|
||||
.target = .{},
|
||||
});
|
||||
|
|
@ -144,10 +143,9 @@ pub fn addCase(self: *CompareOutput, case: TestCase) void {
|
|||
if (mem.indexOf(u8, annotated_case_name, filter) == null) return;
|
||||
}
|
||||
|
||||
const basename = case.sources.items[0].filename;
|
||||
const exe = b.addExecutable(.{
|
||||
.name = "test",
|
||||
.root_source_file = write_src.getFileSource(basename).?,
|
||||
.root_source_file = write_src.files.items[0].getFileSource(),
|
||||
.target = .{},
|
||||
.optimize = .Debug,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -72,11 +72,10 @@ fn addExpect(
|
|||
if (mem.indexOf(u8, annotated_case_name, filter) == null) return;
|
||||
}
|
||||
|
||||
const src_basename = "source.zig";
|
||||
const write_src = b.addWriteFile(src_basename, source);
|
||||
const write_src = b.addWriteFile("source.zig", source);
|
||||
const exe = b.addExecutable(.{
|
||||
.name = "test",
|
||||
.root_source_file = write_src.getFileSource(src_basename).?,
|
||||
.root_source_file = write_src.files.items[0].getFileSource(),
|
||||
.optimize = optimize_mode,
|
||||
.target = .{},
|
||||
});
|
||||
|
|
|
|||
|
|
@ -82,10 +82,10 @@ pub const RunTranslatedCContext = struct {
|
|||
|
||||
const write_src = b.addWriteFiles();
|
||||
for (case.sources.items) |src_file| {
|
||||
write_src.add(src_file.filename, src_file.source);
|
||||
_ = write_src.add(src_file.filename, src_file.source);
|
||||
}
|
||||
const translate_c = b.addTranslateC(.{
|
||||
.source_file = write_src.getFileSource(case.sources.items[0].filename).?,
|
||||
.source_file = write_src.files.items[0].getFileSource(),
|
||||
.target = .{},
|
||||
.optimize = .Debug,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -104,11 +104,11 @@ pub const TranslateCContext = struct {
|
|||
|
||||
const write_src = b.addWriteFiles();
|
||||
for (case.sources.items) |src_file| {
|
||||
write_src.add(src_file.filename, src_file.source);
|
||||
_ = write_src.add(src_file.filename, src_file.source);
|
||||
}
|
||||
|
||||
const translate_c = b.addTranslateC(.{
|
||||
.source_file = write_src.getFileSource(case.sources.items[0].filename).?,
|
||||
.source_file = write_src.files.items[0].getFileSource(),
|
||||
.target = case.target,
|
||||
.optimize = .Debug,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -759,7 +759,7 @@ pub fn addCliTests(b: *std.Build) *Step {
|
|||
"-fno-emit-bin", "-fno-emit-h",
|
||||
"-fstrip", "-OReleaseFast",
|
||||
});
|
||||
run.addFileSourceArg(writefile.getFileSource("example.zig").?);
|
||||
run.addFileSourceArg(writefile.files.items[0].getFileSource());
|
||||
const example_s = run.addPrefixedOutputFileArg("-femit-asm=", "example.s");
|
||||
|
||||
const checkfile = b.addCheckFile(example_s, .{
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue