authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-03-03 17:49:14-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-03-15 10:48:13-07:00
logbb1960c2a4ae3257fab3eedd7fdf2293fde59cec
tree62131bdf9d6c245ba9af8af109a4dbe93637560c
parent405bf1b091bd1dba3a2c904c70aa562f41a6b3a3

std.Build.InstallDirStep: avoid std.log

And better make use of open directory handles.

1 files changed, 21 insertions(+), 11 deletions(-)

lib/std/Build/InstallDirStep.zig+21-11
......@@ -4,7 +4,6 @@ const fs = std.fs;
44const Step = std.Build.Step;
55const InstallDir = std.Build.InstallDir;
66const InstallDirStep = @This();
7const log = std.log;
87
98step: Step,
109options: Options,
......@@ -57,17 +56,17 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
5756 _ = prog_node;
5857 const self = @fieldParentPtr(InstallDirStep, "step", step);
5958 const dest_builder = self.dest_builder;
59 const arena = dest_builder.allocator;
6060 const dest_prefix = dest_builder.getInstallPath(self.options.install_dir, self.options.install_subdir);
6161 const src_builder = self.step.owner;
62 const full_src_dir = src_builder.pathFromRoot(self.options.source_dir);
63 var src_dir = std.fs.cwd().openIterableDir(full_src_dir, .{}) catch |err| {
64 log.err("InstallDirStep: unable to open source directory '{s}': {s}", .{
65 full_src_dir, @errorName(err),
62 var src_dir = src_builder.build_root.handle.openIterableDir(self.options.source_dir, .{}) catch |err| {
63 return step.fail("unable to open source directory '{}{s}': {s}", .{
64 src_builder.build_root, self.options.source_dir, @errorName(err),
6665 });
67 return error.StepFailed;
6866 };
6967 defer src_dir.close();
70 var it = try src_dir.walk(dest_builder.allocator);
68 var it = try src_dir.walk(arena);
69 var all_cached = true;
7170 next_entry: while (try it.next()) |entry| {
7271 for (self.options.exclude_extensions) |ext| {
7372 if (mem.endsWith(u8, entry.path, ext)) {
......@@ -75,11 +74,13 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
7574 }
7675 }
7776
78 const full_path = dest_builder.pathJoin(&.{ full_src_dir, entry.path });
79 const dest_path = dest_builder.pathJoin(&.{ dest_prefix, entry.path });
77 // relative to src build root
78 const src_sub_path = try fs.path.join(arena, &.{ self.options.source_dir, entry.path });
79 const dest_path = try fs.path.join(arena, &.{ dest_prefix, entry.path });
80 const cwd = fs.cwd();
8081
8182 switch (entry.kind) {
82 .Directory => try fs.cwd().makePath(dest_path),
83 .Directory => try cwd.makePath(dest_path),
8384 .File => {
8485 for (self.options.blank_extensions) |ext| {
8586 if (mem.endsWith(u8, entry.path, ext)) {
......@@ -88,9 +89,18 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
8889 }
8990 }
9091
91 try dest_builder.updateFile(full_path, dest_path);
92 const prev_status = try fs.Dir.updateFile(
93 src_builder.build_root.handle,
94 src_sub_path,
95 cwd,
96 dest_path,
97 .{},
98 );
99 all_cached = all_cached and prev_status == .fresh;
92100 },
93101 else => continue,
94102 }
95103 }
104
105 step.result_cached = all_cached;
96106}