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 {
156156 column: usize,
157157 byte_offset: usize,
158158 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 }
159168 };
160169
161170 pub fn deinit(self: *AllErrors, gpa: *Allocator) void {
......@@ -693,6 +702,12 @@ pub fn update(self: *Compilation) !void {
693702 }
694703 }
695704
705 if (self.totalErrorCount() != 0) {
706 // Skip flushing.
707 self.link_error_flags = .{};
708 return;
709 }
710
696711 // This is needed before reading the error flags.
697712 try self.bin_file.flush(self);
698713
......@@ -957,12 +972,14 @@ fn updateCObject(comp: *Compilation, c_object: *CObject) !void {
957972 mem.split(c_source_basename, ".").next().?;
958973 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: {
961976 var argv = std.ArrayList([]const u8).init(comp.gpa);
962977 defer argv.deinit();
963978
964979 // We can't know the digest until we do the C compiler invocation, so we need a temporary filename.
965980 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
967984 try argv.appendSlice(&[_][]const u8{ self_exe_path, "clang", "-c" });
968985
......@@ -1042,25 +1059,23 @@ fn updateCObject(comp: *Compilation, c_object: *CObject) !void {
10421059
10431060 // Rename into place.
10441061 const digest = ch.final();
1045 const full_object_path = if (comp.zig_cache_directory.path) |p|
1046 try std.fs.path.join(arena, &[_][]const u8{ p, "o", &digest, o_basename })
1047 else
1048 try std.fs.path.join(arena, &[_][]const u8{ "o", &digest, o_basename });
1049 try std.fs.rename(out_obj_path, full_object_path);
1062 const o_sub_path = try std.fs.path.join(arena, &[_][]const u8{ "o", &digest });
1063 var o_dir = try comp.zig_cache_directory.handle.makeOpenPath(o_sub_path, .{});
1064 defer o_dir.close();
1065 // TODO Add renameat capabilities to the std lib in a higher layer than the posix layer.
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
10511069 ch.writeManifest() catch |err| {
10521070 std.log.warn("failed to write cache manifest when compiling '{}': {}", .{ c_object.src_path, @errorName(err) });
10531071 };
1054 break :blk full_object_path;
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;
1072 break :blk digest;
10621073 };
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 });
10641079 c_object.status = .{
10651080 .success = .{
10661081 .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
619619 .c_source_files = &[1]Compilation.CSourceFile{c_source_file},
620620 .debug_cc = comp.debug_cc,
621621 .debug_link = comp.bin_file.options.debug_link,
622 .clang_passthrough_mode = comp.clang_passthrough_mode,
622623 });
623624 defer sub_compilation.destroy();
624625
625626 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
627644 try comp.crt_files.ensureCapacity(comp.gpa, comp.crt_files.count() + 1);
628645 const artifact_path = if (sub_compilation.bin_file.options.directory.path) |p|
629646 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 {
12651265 try ch.addOptionalFile(self.base.options.linker_script);
12661266 try ch.addOptionalFile(self.base.options.version_script);
12671267 try ch.addListOfFiles(self.base.options.objects);
1268 for (comp.c_object_table.items()) |entry| switch (entry.key.status) {
1269 .new => unreachable,
1270 .failure => return error.NotAllCSourceFilesAvailableToLink,
1271 .success => |success| _ = try ch.addFile(success.object_path, null),
1272 };
1268 for (comp.c_object_table.items()) |entry| {
1269 _ = try ch.addFile(entry.key.status.success.object_path, null);
1270 }
12731271 try ch.addOptionalFile(module_obj_path);
12741272 // We can skip hashing libc and libc++ components that we are in charge of building from Zig
12751273 // 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 {
14941492 // Positional arguments to the linker such as object files.
14951493 try argv.appendSlice(self.base.options.objects);
14961494
1497 for (comp.c_object_table.items()) |entry| switch (entry.key.status) {
1498 .new => unreachable,
1499 .failure => unreachable, // Checked during cache hashing.
1500 .success => |success| try argv.append(success.object_path),
1501 };
1495 for (comp.c_object_table.items()) |entry| {
1496 try argv.append(entry.key.status.success.object_path);
1497 }
15021498
15031499 if (module_obj_path) |p| {
15041500 try argv.append(p);
src-self-hosted/main.zig+3-27
......@@ -228,12 +228,8 @@ const usage_build_generic =
228228 \\
229229 \\Debug Options (Zig Compiler Development):
230230 \\ -ftime-report Print timing diagnostics
231 \\ --debug-tokenize verbose tokenization
232 \\ --debug-ast-tree verbose parsing into an AST (tree view)
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
231 \\ --debug-link Verbose linker invocation
232 \\ --debug-cc Verbose C compiler invocation
237233 \\
238234;
239235
......@@ -272,12 +268,7 @@ pub fn buildOutputType(
272268 var strip = false;
273269 var single_threaded = false;
274270 var watch = false;
275 var debug_tokenize = false;
276 var debug_ast_tree = false;
277 var debug_ast_fmt = false;
278271 var debug_link = false;
279 var debug_ir = false;
280 var debug_codegen = false;
281272 var debug_cc = false;
282273 var time_report = false;
283274 var emit_bin: Emit = .yes_default_path;
......@@ -531,18 +522,8 @@ pub fn buildOutputType(
531522 link_eh_frame_hdr = true;
532523 } else if (mem.eql(u8, arg, "-Bsymbolic")) {
533524 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;
540525 } else if (mem.eql(u8, arg, "--debug-link")) {
541526 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;
546527 } else if (mem.eql(u8, arg, "--debug-cc")) {
547528 debug_cc = true;
548529 } else if (mem.startsWith(u8, arg, "-T")) {
......@@ -1222,12 +1203,7 @@ fn updateModule(gpa: *Allocator, comp: *Compilation, zir_out_path: ?[]const u8)
12221203
12231204 if (errors.list.len != 0) {
12241205 for (errors.list) |full_err_msg| {
1225 std.debug.print("{}:{}:{}: error: {}\n", .{
1226 full_err_msg.src_path,
1227 full_err_msg.line + 1,
1228 full_err_msg.column + 1,
1229 full_err_msg.msg,
1230 });
1206 full_err_msg.renderToStdErr();
12311207 }
12321208 }
12331209