authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-09-13 21:13:24-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-09-13 21:13:24-07:00
log046dce9cefa221e46f59d3f2f3132556dec6432c
tree9787c75ba1bc1556ba0944ecb8a4d5d9057a3530
parent2456df5f4ebf9fef147d86736974e95403e2d40d

stage2: fix not creating cache o dir before writing to it

also remove non-working debug CLI options

4 files changed, 55 insertions(+), 51 deletions(-)

src-self-hosted/Compilation.zig+29-14
...@@ -156,6 +156,15 @@ pub const AllErrors = struct {...@@ -156,6 +156,15 @@ pub const AllErrors = struct {
156 column: usize,156 column: usize,
157 byte_offset: usize,157 byte_offset: usize,
158 msg: []const u8,158 msg: []const u8,
159
160 pub fn renderToStdErr(self: Message) void {
161 std.debug.print("{}:{}:{}: error: {}\n", .{
162 self.src_path,
163 self.line + 1,
164 self.column + 1,
165 self.msg,
166 });
167 }
159 };168 };
160169
161 pub fn deinit(self: *AllErrors, gpa: *Allocator) void {170 pub fn deinit(self: *AllErrors, gpa: *Allocator) void {
...@@ -693,6 +702,12 @@ pub fn update(self: *Compilation) !void {...@@ -693,6 +702,12 @@ pub fn update(self: *Compilation) !void {
693 }702 }
694 }703 }
695704
705 if (self.totalErrorCount() != 0) {
706 // Skip flushing.
707 self.link_error_flags = .{};
708 return;
709 }
710
696 // This is needed before reading the error flags.711 // This is needed before reading the error flags.
697 try self.bin_file.flush(self);712 try self.bin_file.flush(self);
698713
...@@ -957,12 +972,14 @@ fn updateCObject(comp: *Compilation, c_object: *CObject) !void {...@@ -957,12 +972,14 @@ fn updateCObject(comp: *Compilation, c_object: *CObject) !void {
957 mem.split(c_source_basename, ".").next().?;972 mem.split(c_source_basename, ".").next().?;
958 const o_basename = try std.fmt.allocPrint(arena, "{}{}", .{ o_basename_noext, comp.getTarget().oFileExt() });973 const o_basename = try std.fmt.allocPrint(arena, "{}{}", .{ o_basename_noext, comp.getTarget().oFileExt() });
959974
960 const full_object_path = if (!(try ch.hit()) or comp.disable_c_depfile) blk: {975 const digest = if ((try ch.hit()) and !comp.disable_c_depfile) ch.final() else blk: {
961 var argv = std.ArrayList([]const u8).init(comp.gpa);976 var argv = std.ArrayList([]const u8).init(comp.gpa);
962 defer argv.deinit();977 defer argv.deinit();
963978
964 // We can't know the digest until we do the C compiler invocation, so we need a temporary filename.979 // We can't know the digest until we do the C compiler invocation, so we need a temporary filename.
965 const out_obj_path = try comp.tmpFilePath(arena, o_basename);980 const out_obj_path = try comp.tmpFilePath(arena, o_basename);
981 var zig_cache_tmp_dir = try comp.zig_cache_directory.handle.makeOpenPath("tmp", .{});
982 defer zig_cache_tmp_dir.close();
966983
967 try argv.appendSlice(&[_][]const u8{ self_exe_path, "clang", "-c" });984 try argv.appendSlice(&[_][]const u8{ self_exe_path, "clang", "-c" });
968985
...@@ -1042,25 +1059,23 @@ fn updateCObject(comp: *Compilation, c_object: *CObject) !void {...@@ -1042,25 +1059,23 @@ fn updateCObject(comp: *Compilation, c_object: *CObject) !void {
10421059
1043 // Rename into place.1060 // Rename into place.
1044 const digest = ch.final();1061 const digest = ch.final();
1045 const full_object_path = if (comp.zig_cache_directory.path) |p|1062 const o_sub_path = try std.fs.path.join(arena, &[_][]const u8{ "o", &digest });
1046 try std.fs.path.join(arena, &[_][]const u8{ p, "o", &digest, o_basename })1063 var o_dir = try comp.zig_cache_directory.handle.makeOpenPath(o_sub_path, .{});
1047 else1064 defer o_dir.close();
1048 try std.fs.path.join(arena, &[_][]const u8{ "o", &digest, o_basename });1065 // TODO Add renameat capabilities to the std lib in a higher layer than the posix layer.
1049 try std.fs.rename(out_obj_path, full_object_path);1066 const tmp_basename = std.fs.path.basename(out_obj_path);
1067 try std.os.renameat(zig_cache_tmp_dir.fd, tmp_basename, o_dir.fd, o_basename);
10501068
1051 ch.writeManifest() catch |err| {1069 ch.writeManifest() catch |err| {
1052 std.log.warn("failed to write cache manifest when compiling '{}': {}", .{ c_object.src_path, @errorName(err) });1070 std.log.warn("failed to write cache manifest when compiling '{}': {}", .{ c_object.src_path, @errorName(err) });
1053 };1071 };
1054 break :blk full_object_path;1072 break :blk digest;
1055 } else blk: {
1056 const digest = ch.final();
1057 const full_object_path = if (comp.zig_cache_directory.path) |p|
1058 try std.fs.path.join(arena, &[_][]const u8{ p, "o", &digest, o_basename })
1059 else
1060 try std.fs.path.join(arena, &[_][]const u8{ "o", &digest, o_basename });
1061 break :blk full_object_path;
1062 };1073 };
10631074
1075 const full_object_path = if (comp.zig_cache_directory.path) |p|
1076 try std.fs.path.join(comp.gpa, &[_][]const u8{ p, "o", &digest, o_basename })
1077 else
1078 try std.fs.path.join(comp.gpa, &[_][]const u8{ "o", &digest, o_basename });
1064 c_object.status = .{1079 c_object.status = .{
1065 .success = .{1080 .success = .{
1066 .object_path = full_object_path,1081 .object_path = full_object_path,
src-self-hosted/glibc.zig+17
...@@ -619,11 +619,28 @@ fn build_libc_object(comp: *Compilation, basename: []const u8, c_source_file: Co...@@ -619,11 +619,28 @@ fn build_libc_object(comp: *Compilation, basename: []const u8, c_source_file: Co
619 .c_source_files = &[1]Compilation.CSourceFile{c_source_file},619 .c_source_files = &[1]Compilation.CSourceFile{c_source_file},
620 .debug_cc = comp.debug_cc,620 .debug_cc = comp.debug_cc,
621 .debug_link = comp.bin_file.options.debug_link,621 .debug_link = comp.bin_file.options.debug_link,
622 .clang_passthrough_mode = comp.clang_passthrough_mode,
622 });623 });
623 defer sub_compilation.destroy();624 defer sub_compilation.destroy();
624625
625 try sub_compilation.update();626 try sub_compilation.update();
626627
628 // Look for compilation errors in this sub_compilation
629 var errors = try sub_compilation.getAllErrorsAlloc();
630 defer errors.deinit(sub_compilation.gpa);
631
632 if (errors.list.len != 0) {
633 for (errors.list) |full_err_msg| {
634 std.log.err("{}:{}:{}: error: {}\n", .{
635 full_err_msg.src_path,
636 full_err_msg.line + 1,
637 full_err_msg.column + 1,
638 full_err_msg.msg,
639 });
640 }
641 return error.BuildingLibCObjectFailed;
642 }
643
627 try comp.crt_files.ensureCapacity(comp.gpa, comp.crt_files.count() + 1);644 try comp.crt_files.ensureCapacity(comp.gpa, comp.crt_files.count() + 1);
628 const artifact_path = if (sub_compilation.bin_file.options.directory.path) |p|645 const artifact_path = if (sub_compilation.bin_file.options.directory.path) |p|
629 try std.fs.path.join(comp.gpa, &[_][]const u8{ p, basename })646 try std.fs.path.join(comp.gpa, &[_][]const u8{ p, basename })
src-self-hosted/link/Elf.zig+6-10
...@@ -1265,11 +1265,9 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {...@@ -1265,11 +1265,9 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {
1265 try ch.addOptionalFile(self.base.options.linker_script);1265 try ch.addOptionalFile(self.base.options.linker_script);
1266 try ch.addOptionalFile(self.base.options.version_script);1266 try ch.addOptionalFile(self.base.options.version_script);
1267 try ch.addListOfFiles(self.base.options.objects);1267 try ch.addListOfFiles(self.base.options.objects);
1268 for (comp.c_object_table.items()) |entry| switch (entry.key.status) {1268 for (comp.c_object_table.items()) |entry| {
1269 .new => unreachable,1269 _ = try ch.addFile(entry.key.status.success.object_path, null);
1270 .failure => return error.NotAllCSourceFilesAvailableToLink,1270 }
1271 .success => |success| _ = try ch.addFile(success.object_path, null),
1272 };
1273 try ch.addOptionalFile(module_obj_path);1271 try ch.addOptionalFile(module_obj_path);
1274 // We can skip hashing libc and libc++ components that we are in charge of building from Zig1272 // We can skip hashing libc and libc++ components that we are in charge of building from Zig
1275 // installation sources because they are always a product of the compiler version + target information.1273 // installation sources because they are always a product of the compiler version + target information.
...@@ -1494,11 +1492,9 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {...@@ -1494,11 +1492,9 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {
1494 // Positional arguments to the linker such as object files.1492 // Positional arguments to the linker such as object files.
1495 try argv.appendSlice(self.base.options.objects);1493 try argv.appendSlice(self.base.options.objects);
14961494
1497 for (comp.c_object_table.items()) |entry| switch (entry.key.status) {1495 for (comp.c_object_table.items()) |entry| {
1498 .new => unreachable,1496 try argv.append(entry.key.status.success.object_path);
1499 .failure => unreachable, // Checked during cache hashing.1497 }
1500 .success => |success| try argv.append(success.object_path),
1501 };
15021498
1503 if (module_obj_path) |p| {1499 if (module_obj_path) |p| {
1504 try argv.append(p);1500 try argv.append(p);
src-self-hosted/main.zig+3-27
...@@ -228,12 +228,8 @@ const usage_build_generic =...@@ -228,12 +228,8 @@ const usage_build_generic =
228 \\228 \\
229 \\Debug Options (Zig Compiler Development):229 \\Debug Options (Zig Compiler Development):
230 \\ -ftime-report Print timing diagnostics230 \\ -ftime-report Print timing diagnostics
231 \\ --debug-tokenize verbose tokenization231 \\ --debug-link Verbose linker invocation
232 \\ --debug-ast-tree verbose parsing into an AST (tree view)232 \\ --debug-cc Verbose C compiler invocation
233 \\ --debug-ast-fmt verbose parsing into an AST (render source)
234 \\ --debug-ir verbose Zig IR
235 \\ --debug-link verbose linking
236 \\ --debug-codegen verbose machine code generation
237 \\233 \\
238;234;
239235
...@@ -272,12 +268,7 @@ pub fn buildOutputType(...@@ -272,12 +268,7 @@ pub fn buildOutputType(
272 var strip = false;268 var strip = false;
273 var single_threaded = false;269 var single_threaded = false;
274 var watch = false;270 var watch = false;
275 var debug_tokenize = false;
276 var debug_ast_tree = false;
277 var debug_ast_fmt = false;
278 var debug_link = false;271 var debug_link = false;
279 var debug_ir = false;
280 var debug_codegen = false;
281 var debug_cc = false;272 var debug_cc = false;
282 var time_report = false;273 var time_report = false;
283 var emit_bin: Emit = .yes_default_path;274 var emit_bin: Emit = .yes_default_path;
...@@ -531,18 +522,8 @@ pub fn buildOutputType(...@@ -531,18 +522,8 @@ pub fn buildOutputType(
531 link_eh_frame_hdr = true;522 link_eh_frame_hdr = true;
532 } else if (mem.eql(u8, arg, "-Bsymbolic")) {523 } else if (mem.eql(u8, arg, "-Bsymbolic")) {
533 linker_bind_global_refs_locally = true;524 linker_bind_global_refs_locally = true;
534 } else if (mem.eql(u8, arg, "--debug-tokenize")) {
535 debug_tokenize = true;
536 } else if (mem.eql(u8, arg, "--debug-ast-tree")) {
537 debug_ast_tree = true;
538 } else if (mem.eql(u8, arg, "--debug-ast-fmt")) {
539 debug_ast_fmt = true;
540 } else if (mem.eql(u8, arg, "--debug-link")) {525 } else if (mem.eql(u8, arg, "--debug-link")) {
541 debug_link = true;526 debug_link = true;
542 } else if (mem.eql(u8, arg, "--debug-ir")) {
543 debug_ir = true;
544 } else if (mem.eql(u8, arg, "--debug-codegen")) {
545 debug_codegen = true;
546 } else if (mem.eql(u8, arg, "--debug-cc")) {527 } else if (mem.eql(u8, arg, "--debug-cc")) {
547 debug_cc = true;528 debug_cc = true;
548 } else if (mem.startsWith(u8, arg, "-T")) {529 } else if (mem.startsWith(u8, arg, "-T")) {
...@@ -1222,12 +1203,7 @@ fn updateModule(gpa: *Allocator, comp: *Compilation, zir_out_path: ?[]const u8)...@@ -1222,12 +1203,7 @@ fn updateModule(gpa: *Allocator, comp: *Compilation, zir_out_path: ?[]const u8)
12221203
1223 if (errors.list.len != 0) {1204 if (errors.list.len != 0) {
1224 for (errors.list) |full_err_msg| {1205 for (errors.list) |full_err_msg| {
1225 std.debug.print("{}:{}:{}: error: {}\n", .{1206 full_err_msg.renderToStdErr();
1226 full_err_msg.src_path,
1227 full_err_msg.line + 1,
1228 full_err_msg.column + 1,
1229 full_err_msg.msg,
1230 });
1231 }1207 }
1232 }1208 }
12331209