| ... | @@ -4,7 +4,6 @@ const fs = std.fs; | ... | @@ -4,7 +4,6 @@ const fs = std.fs; |
| 4 | const Step = std.Build.Step; | 4 | const Step = std.Build.Step; |
| 5 | const InstallDir = std.Build.InstallDir; | 5 | const InstallDir = std.Build.InstallDir; |
| 6 | const InstallDirStep = @This(); | 6 | const InstallDirStep = @This(); |
| 7 | const log = std.log; | | |
| 8 | | 7 | |
| 9 | step: Step, | 8 | step: Step, |
| 10 | options: Options, | 9 | options: 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 | } |
| 77 | | 76 | |
| 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(); |
| 80 | | 81 | |
| 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 | } |
| 90 | | 91 | |
| 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 | } |