authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-11-25 17:42:27-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-11-25 17:43:27-07:00
log7b78b4fff02e5f59da3034ee739c0eae99a01de5
tree22d29adc7469faae3c7c119aad0acc1e0b136657
parent2006add8496c47804ee3b6c562f420871cb4ea0a

stage2: better error message when copying artifacts fails


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

src/Compilation.zig+11-4
...@@ -1885,7 +1885,7 @@ pub fn update(self: *Compilation) !void {...@@ -1885,7 +1885,7 @@ pub fn update(self: *Compilation) !void {
18851885
1886 // Flush takes care of -femit-bin, but we still have -femit-llvm-ir, -femit-llvm-bc, and1886 // Flush takes care of -femit-bin, but we still have -femit-llvm-ir, -femit-llvm-bc, and
1887 // -femit-asm to handle, in the case of C objects.1887 // -femit-asm to handle, in the case of C objects.
1888 try self.emitOthers();1888 self.emitOthers();
18891889
1890 // If there are any errors, we anticipate the source files being loaded1890 // If there are any errors, we anticipate the source files being loaded
1891 // to report error messages. Otherwise we unload all source files to save memory.1891 // to report error messages. Otherwise we unload all source files to save memory.
...@@ -1902,7 +1902,7 @@ pub fn update(self: *Compilation) !void {...@@ -1902,7 +1902,7 @@ pub fn update(self: *Compilation) !void {
1902 }1902 }
1903}1903}
19041904
1905fn emitOthers(comp: *Compilation) !void {1905fn emitOthers(comp: *Compilation) void {
1906 if (comp.bin_file.options.output_mode != .Obj or comp.bin_file.options.module != null or1906 if (comp.bin_file.options.output_mode != .Obj or comp.bin_file.options.module != null or
1907 comp.c_object_table.count() == 0)1907 comp.c_object_table.count() == 0)
1908 {1908 {
...@@ -1925,9 +1925,16 @@ fn emitOthers(comp: *Compilation) !void {...@@ -1925,9 +1925,16 @@ fn emitOthers(comp: *Compilation) !void {
1925 for (outs) |out| {1925 for (outs) |out| {
1926 if (out.emit) |loc| {1926 if (out.emit) |loc| {
1927 if (loc.directory) |directory| {1927 if (loc.directory) |directory| {
1928 const src_path = try std.fmt.allocPrint(comp.gpa, "{s}{s}", .{ basename, out.ext });1928 const src_path = std.fmt.allocPrint(comp.gpa, "{s}{s}", .{
1929 basename, out.ext,
1930 }) catch |err| {
1931 log.err("unable to copy {s}{s}: {s}", .{ basename, out.ext, @errorName(err) });
1932 continue;
1933 };
1929 defer comp.gpa.free(src_path);1934 defer comp.gpa.free(src_path);
1930 try cwd.copyFile(src_path, directory.handle, loc.basename, .{});1935 cwd.copyFile(src_path, directory.handle, loc.basename, .{}) catch |err| {
1936 log.err("unable to copy {s}: {s}", .{ src_path, @errorName(err) });
1937 };
1931 }1938 }
1932 }1939 }
1933 }1940 }