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;...@@ -4,7 +4,6 @@ const fs = std.fs;
4const Step = std.Build.Step;4const Step = std.Build.Step;
5const InstallDir = std.Build.InstallDir;5const InstallDir = std.Build.InstallDir;
6const InstallDirStep = @This();6const InstallDirStep = @This();
7const log = std.log;
87
9step: Step,8step: Step,
10options: Options,9options: Options,
...@@ -57,17 +56,17 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {...@@ -57,17 +56,17 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
57 _ = prog_node;56 _ = prog_node;
58 const self = @fieldParentPtr(InstallDirStep, "step", step);57 const self = @fieldParentPtr(InstallDirStep, "step", step);
59 const dest_builder = self.dest_builder;58 const dest_builder = self.dest_builder;
59 const arena = dest_builder.allocator;
60 const dest_prefix = dest_builder.getInstallPath(self.options.install_dir, self.options.install_subdir);60 const dest_prefix = dest_builder.getInstallPath(self.options.install_dir, self.options.install_subdir);
61 const src_builder = self.step.owner;61 const src_builder = self.step.owner;
62 const full_src_dir = src_builder.pathFromRoot(self.options.source_dir);62 var src_dir = src_builder.build_root.handle.openIterableDir(self.options.source_dir, .{}) catch |err| {
63 var src_dir = std.fs.cwd().openIterableDir(full_src_dir, .{}) catch |err| {63 return step.fail("unable to open source directory '{}{s}': {s}", .{
64 log.err("InstallDirStep: unable to open source directory '{s}': {s}", .{64 src_builder.build_root, self.options.source_dir, @errorName(err),
65 full_src_dir, @errorName(err),
66 });65 });
67 return error.StepFailed;
68 };66 };
69 defer src_dir.close();67 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;
71 next_entry: while (try it.next()) |entry| {70 next_entry: while (try it.next()) |entry| {
72 for (self.options.exclude_extensions) |ext| {71 for (self.options.exclude_extensions) |ext| {
73 if (mem.endsWith(u8, entry.path, ext)) {72 if (mem.endsWith(u8, entry.path, ext)) {
...@@ -75,11 +74,13 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {...@@ -75,11 +74,13 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
75 }74 }
76 }75 }
7776
78 const full_path = dest_builder.pathJoin(&.{ full_src_dir, entry.path });77 // relative to src build root
79 const dest_path = dest_builder.pathJoin(&.{ dest_prefix, entry.path });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
81 switch (entry.kind) {82 switch (entry.kind) {
82 .Directory => try fs.cwd().makePath(dest_path),83 .Directory => try cwd.makePath(dest_path),
83 .File => {84 .File => {
84 for (self.options.blank_extensions) |ext| {85 for (self.options.blank_extensions) |ext| {
85 if (mem.endsWith(u8, entry.path, ext)) {86 if (mem.endsWith(u8, entry.path, ext)) {
...@@ -88,9 +89,18 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {...@@ -88,9 +89,18 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
88 }89 }
89 }90 }
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;
92 },100 },
93 else => continue,101 else => continue,
94 }102 }
95 }103 }
104
105 step.result_cached = all_cached;
96}106}