| author | |
| committer | |
| log | a4c35a62454a3970dd44ac8b842be91a46bb896c |
| tree | d71aee352f75881373aa1658d031ff6ef765163a |
| parent | 1e63573d359f15042ebdcc9b0c32d7ce4662899f |
* remove std.Build.updateFile. I noticed some people use it from
build.zig (declare phase) when it is intended only for use in the
make phase.
- This also was incorrectly reporting errors with std.log.
* std.Build.InstallArtifactStep
- report better errors on failure
- report whether the step was cached or not
* std.Build.InstallDirStep: report better error on failure
* std.Build.InstallFileStep: report better error on failure5 files changed, 60 insertions(+), 27 deletions(-)
lib/std/Build.zig-12| ... | ... | @@ -1235,18 +1235,6 @@ pub fn pushInstalledFile(self: *Build, dir: InstallDir, dest_rel_path: []const u |
| 1235 | 1235 | self.installed_files.append(file.dupe(self)) catch @panic("OOM"); |
| 1236 | 1236 | } |
| 1237 | 1237 | |
| 1238 | pub fn updateFile(self: *Build, source_path: []const u8, dest_path: []const u8) !void { | |
| 1239 | if (self.verbose) { | |
| 1240 | log.info("cp {s} {s} ", .{ source_path, dest_path }); | |
| 1241 | } | |
| 1242 | const cwd = fs.cwd(); | |
| 1243 | const prev_status = try fs.Dir.updateFile(cwd, source_path, cwd, dest_path, .{}); | |
| 1244 | if (self.verbose) switch (prev_status) { | |
| 1245 | .stale => log.info("# installed", .{}), | |
| 1246 | .fresh => log.info("# up-to-date", .{}), | |
| 1247 | }; | |
| 1248 | } | |
| 1249 | ||
| 1250 | 1238 | pub fn truncateFile(self: *Build, dest_path: []const u8) !void { |
| 1251 | 1239 | if (self.verbose) { |
| 1252 | 1240 | log.info("truncate {s}", .{dest_path}); |
lib/std/Build/CompileStep.zig+3-3| ... | ... | @@ -1910,13 +1910,13 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 1910 | 1910 | const build_output_dir = fs.path.dirname(output_bin_path).?; |
| 1911 | 1911 | |
| 1912 | 1912 | if (self.output_dir) |output_dir| { |
| 1913 | var src_dir = try std.fs.cwd().openIterableDir(build_output_dir, .{}); | |
| 1913 | var src_dir = try fs.cwd().openIterableDir(build_output_dir, .{}); | |
| 1914 | 1914 | defer src_dir.close(); |
| 1915 | 1915 | |
| 1916 | 1916 | // Create the output directory if it doesn't exist. |
| 1917 | try std.fs.cwd().makePath(output_dir); | |
| 1917 | try fs.cwd().makePath(output_dir); | |
| 1918 | 1918 | |
| 1919 | var dest_dir = try std.fs.cwd().openDir(output_dir, .{}); | |
| 1919 | var dest_dir = try fs.cwd().openDir(output_dir, .{}); | |
| 1920 | 1920 | defer dest_dir.close(); |
| 1921 | 1921 | |
| 1922 | 1922 | var it = src_dir.iterate(); |
lib/std/Build/InstallArtifactStep.zig+44-9| ... | ... | @@ -3,6 +3,7 @@ const Step = std.Build.Step; |
| 3 | 3 | const CompileStep = std.Build.CompileStep; |
| 4 | 4 | const InstallDir = std.Build.InstallDir; |
| 5 | 5 | const InstallArtifactStep = @This(); |
| 6 | const fs = std.fs; | |
| 6 | 7 | |
| 7 | 8 | pub const base_id = .install_artifact; |
| 8 | 9 | |
| ... | ... | @@ -77,25 +78,59 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 77 | 78 | |
| 78 | 79 | const dest_sub_path = if (self.dest_sub_path) |sub_path| sub_path else self.artifact.out_filename; |
| 79 | 80 | const full_dest_path = dest_builder.getInstallPath(self.dest_dir, dest_sub_path); |
| 81 | const cwd = fs.cwd(); | |
| 80 | 82 | |
| 81 | try src_builder.updateFile( | |
| 82 | self.artifact.getOutputSource().getPath(src_builder), | |
| 83 | full_dest_path, | |
| 84 | ); | |
| 85 | if (self.artifact.isDynamicLibrary() and self.artifact.version != null and self.artifact.target.wantSharedLibSymLinks()) { | |
| 83 | var all_cached = true; | |
| 84 | ||
| 85 | { | |
| 86 | const full_src_path = self.artifact.getOutputSource().getPath(src_builder); | |
| 87 | const p = fs.Dir.updateFile(cwd, full_src_path, cwd, full_dest_path, .{}) catch |err| { | |
| 88 | return step.fail("unable to update file from '{s}' to '{s}': {s}", .{ | |
| 89 | full_src_path, full_dest_path, @errorName(err), | |
| 90 | }); | |
| 91 | }; | |
| 92 | all_cached = all_cached and p == .fresh; | |
| 93 | } | |
| 94 | ||
| 95 | if (self.artifact.isDynamicLibrary() and | |
| 96 | self.artifact.version != null and | |
| 97 | self.artifact.target.wantSharedLibSymLinks()) | |
| 98 | { | |
| 86 | 99 | try CompileStep.doAtomicSymLinks(step, full_dest_path, self.artifact.major_only_filename.?, self.artifact.name_only_filename.?); |
| 87 | 100 | } |
| 88 | if (self.artifact.isDynamicLibrary() and self.artifact.target.isWindows() and self.artifact.emit_implib != .no_emit) { | |
| 101 | if (self.artifact.isDynamicLibrary() and | |
| 102 | self.artifact.target.isWindows() and | |
| 103 | self.artifact.emit_implib != .no_emit) | |
| 104 | { | |
| 105 | const full_src_path = self.artifact.getOutputLibSource().getPath(src_builder); | |
| 89 | 106 | const full_implib_path = dest_builder.getInstallPath(self.dest_dir, self.artifact.out_lib_filename); |
| 90 | try src_builder.updateFile(self.artifact.getOutputLibSource().getPath(src_builder), full_implib_path); | |
| 107 | const p = fs.Dir.updateFile(cwd, full_src_path, cwd, full_implib_path, .{}) catch |err| { | |
| 108 | return step.fail("unable to update file from '{s}' to '{s}': {s}", .{ | |
| 109 | full_src_path, full_implib_path, @errorName(err), | |
| 110 | }); | |
| 111 | }; | |
| 112 | all_cached = all_cached and p == .fresh; | |
| 91 | 113 | } |
| 92 | 114 | if (self.pdb_dir) |pdb_dir| { |
| 115 | const full_src_path = self.artifact.getOutputPdbSource().getPath(src_builder); | |
| 93 | 116 | const full_pdb_path = dest_builder.getInstallPath(pdb_dir, self.artifact.out_pdb_filename); |
| 94 | try src_builder.updateFile(self.artifact.getOutputPdbSource().getPath(src_builder), full_pdb_path); | |
| 117 | const p = fs.Dir.updateFile(cwd, full_src_path, cwd, full_pdb_path, .{}) catch |err| { | |
| 118 | return step.fail("unable to update file from '{s}' to '{s}': {s}", .{ | |
| 119 | full_src_path, full_pdb_path, @errorName(err), | |
| 120 | }); | |
| 121 | }; | |
| 122 | all_cached = all_cached and p == .fresh; | |
| 95 | 123 | } |
| 96 | 124 | if (self.h_dir) |h_dir| { |
| 125 | const full_src_path = self.artifact.getOutputHSource().getPath(src_builder); | |
| 97 | 126 | const full_h_path = dest_builder.getInstallPath(h_dir, self.artifact.out_h_filename); |
| 98 | try src_builder.updateFile(self.artifact.getOutputHSource().getPath(src_builder), full_h_path); | |
| 127 | const p = fs.Dir.updateFile(cwd, full_src_path, cwd, full_h_path, .{}) catch |err| { | |
| 128 | return step.fail("unable to update file from '{s}' to '{s}': {s}", .{ | |
| 129 | full_src_path, full_h_path, @errorName(err), | |
| 130 | }); | |
| 131 | }; | |
| 132 | all_cached = all_cached and p == .fresh; | |
| 99 | 133 | } |
| 100 | 134 | self.artifact.installed_path = full_dest_path; |
| 135 | step.result_cached = all_cached; | |
| 101 | 136 | } |
lib/std/Build/InstallDirStep.zig+6-2| ... | ... | @@ -89,13 +89,17 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 89 | 89 | } |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | const prev_status = try fs.Dir.updateFile( | |
| 92 | const prev_status = fs.Dir.updateFile( | |
| 93 | 93 | src_builder.build_root.handle, |
| 94 | 94 | src_sub_path, |
| 95 | 95 | cwd, |
| 96 | 96 | dest_path, |
| 97 | 97 | .{}, |
| 98 | ); | |
| 98 | ) catch |err| { | |
| 99 | return step.fail("unable to update file from '{}{s}' to '{s}': {s}", .{ | |
| 100 | src_builder.build_root, src_sub_path, dest_path, @errorName(err), | |
| 101 | }); | |
| 102 | }; | |
| 99 | 103 | all_cached = all_cached and prev_status == .fresh; |
| 100 | 104 | }, |
| 101 | 105 | else => continue, |
lib/std/Build/InstallFileStep.zig+7-1| ... | ... | @@ -42,5 +42,11 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 42 | 42 | const dest_builder = self.dest_builder; |
| 43 | 43 | const full_src_path = self.source.getPath2(src_builder, step); |
| 44 | 44 | const full_dest_path = dest_builder.getInstallPath(self.dir, self.dest_rel_path); |
| 45 | try dest_builder.updateFile(full_src_path, full_dest_path); | |
| 45 | const cwd = std.fs.cwd(); | |
| 46 | const prev = std.fs.Dir.updateFile(cwd, full_src_path, cwd, full_dest_path, .{}) catch |err| { | |
| 47 | return step.fail("unable to update file from '{s}' to '{s}': {s}", .{ | |
| 48 | full_src_path, full_dest_path, @errorName(err), | |
| 49 | }); | |
| 50 | }; | |
| 51 | step.result_cached = prev == .fresh; | |
| 46 | 52 | } |