stage2: linkAsArchive: respect disable_lld_caching

Closes #7274
Closes #6943
This commit is contained in:
Andrew Kelley 2020-12-02 16:37:32 -07:00
parent 6d91ebce45
commit 41387e1822

View File

@ -485,21 +485,27 @@ pub const File = struct {
const id_symlink_basename = "llvm-ar.id"; const id_symlink_basename = "llvm-ar.id";
var man: Cache.Manifest = undefined;
defer if (!base.options.disable_lld_caching) man.deinit();
var digest: [Cache.hex_digest_len]u8 = undefined;
if (!base.options.disable_lld_caching) {
man = comp.cache_parent.obtain();
// We are about to obtain this lock, so here we give other processes a chance first.
base.releaseLock(); base.releaseLock();
var ch = comp.cache_parent.obtain(); try man.addListOfFiles(base.options.objects);
defer ch.deinit();
try ch.addListOfFiles(base.options.objects);
for (comp.c_object_table.items()) |entry| { for (comp.c_object_table.items()) |entry| {
_ = try ch.addFile(entry.key.status.success.object_path, null); _ = try man.addFile(entry.key.status.success.object_path, null);
} }
try ch.addOptionalFile(module_obj_path); try man.addOptionalFile(module_obj_path);
try ch.addOptionalFile(compiler_rt_path); try man.addOptionalFile(compiler_rt_path);
// We don't actually care whether it's a cache hit or miss; we just need the digest and the lock. // We don't actually care whether it's a cache hit or miss; we just need the digest and the lock.
_ = try ch.hit(); _ = try man.hit();
const digest = ch.final(); digest = man.final();
var prev_digest_buf: [digest.len]u8 = undefined; var prev_digest_buf: [digest.len]u8 = undefined;
const prev_digest: []u8 = Cache.readSmallFile( const prev_digest: []u8 = Cache.readSmallFile(
@ -512,7 +518,7 @@ pub const File = struct {
}; };
if (mem.eql(u8, prev_digest, &digest)) { if (mem.eql(u8, prev_digest, &digest)) {
log.debug("archive digest={} match - skipping invocation", .{digest}); log.debug("archive digest={} match - skipping invocation", .{digest});
base.lock = ch.toOwnedLock(); base.lock = man.toOwnedLock();
return; return;
} }
@ -521,6 +527,7 @@ pub const File = struct {
error.FileNotFound => {}, error.FileNotFound => {},
else => |e| return e, else => |e| return e,
}; };
}
var object_files = std.ArrayList([*:0]const u8).init(base.allocator); var object_files = std.ArrayList([*:0]const u8).init(base.allocator);
defer object_files.deinit(); defer object_files.deinit();
@ -555,15 +562,17 @@ pub const File = struct {
const bad = llvm.WriteArchive(full_out_path_z, object_files.items.ptr, object_files.items.len, os_type); const bad = llvm.WriteArchive(full_out_path_z, object_files.items.ptr, object_files.items.len, os_type);
if (bad) return error.UnableToWriteArchive; if (bad) return error.UnableToWriteArchive;
if (!base.options.disable_lld_caching) {
Cache.writeSmallFile(directory.handle, id_symlink_basename, &digest) catch |err| { Cache.writeSmallFile(directory.handle, id_symlink_basename, &digest) catch |err| {
std.log.warn("failed to save archive hash digest file: {}", .{@errorName(err)}); std.log.warn("failed to save archive hash digest file: {}", .{@errorName(err)});
}; };
ch.writeManifest() catch |err| { man.writeManifest() catch |err| {
std.log.warn("failed to write cache manifest when archiving: {}", .{@errorName(err)}); std.log.warn("failed to write cache manifest when archiving: {}", .{@errorName(err)});
}; };
base.lock = ch.toOwnedLock(); base.lock = man.toOwnedLock();
}
} }
pub const Tag = enum { pub const Tag = enum {