aboutsummaryrefslogtreecommitdiff
path: root/lib/std/Build/Step/WriteFile.zig
diff options
context:
space:
mode:
authorJonathan Marler <johnnymarler@gmail.com>2024-07-02 06:15:29 -0600
committerAndrew Kelley <andrew@ziglang.org>2024-07-04 13:34:17 -0400
commitd9f1a952b8b0e19aafcf568b35cc220adbb4a7b5 (patch)
treed7333d6953a0fe37ac11b12a2456efebffd2a4c0 /lib/std/Build/Step/WriteFile.zig
parentb67caf72e31eefe08fe2dc8b17b4bca16e0e3cc6 (diff)
downloadzig-d9f1a952b8b0e19aafcf568b35cc220adbb4a7b5.tar.gz
zig-d9f1a952b8b0e19aafcf568b35cc220adbb4a7b5.zip
build: fix WriteFile and addCSourceFiles not adding LazyPath deps
Adds a missing call to addLazyPathDependenciesOnly in std.Build.Module.addCSourceFiles. Also fixes an issue in std.Build.Step.WriteFile where it wasn't updating all the GeneratedFile instances for every directory. To fix the second issue, I removed all the GeneratedFile instances and now all files/directories reference the steps main GeneratedFile via sub paths.
Diffstat (limited to 'lib/std/Build/Step/WriteFile.zig')
-rw-r--r--lib/std/Build/Step/WriteFile.zig56
1 files changed, 23 insertions, 33 deletions
diff --git a/lib/std/Build/Step/WriteFile.zig b/lib/std/Build/Step/WriteFile.zig
index 0639573b8f..013c58890a 100644
--- a/lib/std/Build/Step/WriteFile.zig
+++ b/lib/std/Build/Step/WriteFile.zig
@@ -17,8 +17,8 @@ const WriteFile = @This();
step: Step,
// The elements here are pointers because we need stable pointers for the GeneratedFile field.
-files: std.ArrayListUnmanaged(*File),
-directories: std.ArrayListUnmanaged(*Directory),
+files: std.ArrayListUnmanaged(File),
+directories: std.ArrayListUnmanaged(Directory),
output_source_files: std.ArrayListUnmanaged(OutputSourceFile),
generated_directory: std.Build.GeneratedFile,
@@ -26,20 +26,14 @@ generated_directory: std.Build.GeneratedFile,
pub const base_id: Step.Id = .write_file;
pub const File = struct {
- generated_file: std.Build.GeneratedFile,
sub_path: []const u8,
contents: Contents,
-
- pub fn getPath(file: *File) std.Build.LazyPath {
- return .{ .generated = .{ .file = &file.generated_file } };
- }
};
pub const Directory = struct {
source: std.Build.LazyPath,
sub_path: []const u8,
options: Options,
- generated_dir: std.Build.GeneratedFile,
pub const Options = struct {
/// File paths that end in any of these suffixes will be excluded from copying.
@@ -56,10 +50,6 @@ pub const Directory = struct {
};
}
};
-
- pub fn getPath(dir: *Directory) std.Build.LazyPath {
- return .{ .generated = .{ .file = &dir.generated_dir } };
- }
};
pub const OutputSourceFile = struct {
@@ -92,15 +82,18 @@ pub fn create(owner: *std.Build) *WriteFile {
pub fn add(write_file: *WriteFile, sub_path: []const u8, bytes: []const u8) std.Build.LazyPath {
const b = write_file.step.owner;
const gpa = b.allocator;
- const file = gpa.create(File) catch @panic("OOM");
- file.* = .{
- .generated_file = .{ .step = &write_file.step },
+ const file = File{
.sub_path = b.dupePath(sub_path),
.contents = .{ .bytes = b.dupe(bytes) },
};
write_file.files.append(gpa, file) catch @panic("OOM");
write_file.maybeUpdateName();
- return file.getPath();
+ return .{
+ .generated = .{
+ .file = &write_file.generated_directory,
+ .sub_path = file.sub_path,
+ },
+ };
}
/// Place the file into the generated directory within the local cache,
@@ -113,9 +106,7 @@ pub fn add(write_file: *WriteFile, sub_path: []const u8, bytes: []const u8) std.
pub fn addCopyFile(write_file: *WriteFile, source: std.Build.LazyPath, sub_path: []const u8) std.Build.LazyPath {
const b = write_file.step.owner;
const gpa = b.allocator;
- const file = gpa.create(File) catch @panic("OOM");
- file.* = .{
- .generated_file = .{ .step = &write_file.step },
+ const file = File{
.sub_path = b.dupePath(sub_path),
.contents = .{ .copy = source },
};
@@ -123,7 +114,12 @@ pub fn addCopyFile(write_file: *WriteFile, source: std.Build.LazyPath, sub_path:
write_file.maybeUpdateName();
source.addStepDependencies(&write_file.step);
- return file.getPath();
+ return .{
+ .generated = .{
+ .file = &write_file.generated_directory,
+ .sub_path = file.sub_path,
+ },
+ };
}
/// Copy files matching the specified exclude/include patterns to the specified subdirectory
@@ -137,18 +133,21 @@ pub fn addCopyDirectory(
) std.Build.LazyPath {
const b = write_file.step.owner;
const gpa = b.allocator;
- const dir = gpa.create(Directory) catch @panic("OOM");
- dir.* = .{
+ const dir = Directory{
.source = source.dupe(b),
.sub_path = b.dupePath(sub_path),
.options = options.dupe(b),
- .generated_dir = .{ .step = &write_file.step },
};
write_file.directories.append(gpa, dir) catch @panic("OOM");
write_file.maybeUpdateName();
source.addStepDependencies(&write_file.step);
- return dir.getPath();
+ return .{
+ .generated = .{
+ .file = &write_file.generated_directory,
+ .sub_path = dir.sub_path,
+ },
+ };
}
/// A path relative to the package root.
@@ -278,11 +277,6 @@ fn make(step: *Step, prog_node: std.Progress.Node) !void {
if (try step.cacheHit(&man)) {
const digest = man.final();
- for (write_file.files.items) |file| {
- file.generated_file.path = try b.cache_root.join(b.allocator, &.{
- "o", &digest, file.sub_path,
- });
- }
write_file.generated_directory.path = try b.cache_root.join(b.allocator, &.{ "o", &digest });
return;
}
@@ -342,10 +336,6 @@ fn make(step: *Step, prog_node: std.Progress.Node) !void {
_ = prev_status;
},
}
-
- file.generated_file.path = try b.cache_root.join(b.allocator, &.{
- cache_path, file.sub_path,
- });
}
for (write_file.directories.items) |dir| {
const full_src_dir_path = dir.source.getPath2(b, step);