diff options
author | John Ericson <John.Ericson@Obsidian.Systems> | 2021-02-27 03:53:22 +0000 |
---|---|---|
committer | John Ericson <John.Ericson@Obsidian.Systems> | 2021-02-27 03:53:22 +0000 |
commit | e547fe12d1a3b0a8b3c424629636f014a5778137 (patch) | |
tree | 3c4f57b1305110161d8ddd48f3a46110ec70a2ef /src/build-remote | |
parent | 7d703f2106faa3c879d0ec066a474e10981d8e56 (diff) | |
parent | 5b42e5b1771061de50575b33eeeda56f40f216f2 (diff) |
Merge branch 'restore-test-build-remote-ca-fixed' into trustless-remote-builder-simple
Diffstat (limited to 'src/build-remote')
-rw-r--r-- | src/build-remote/build-remote.cc | 51 |
1 files changed, 41 insertions, 10 deletions
diff --git a/src/build-remote/build-remote.cc b/src/build-remote/build-remote.cc index 3bd16e2fb..54844befc 100644 --- a/src/build-remote/build-remote.cc +++ b/src/build-remote/build-remote.cc @@ -254,7 +254,7 @@ connected: std::cerr << "# accept\n" << storeUri << "\n"; auto inputs = readStrings<PathSet>(source); - auto outputs = readStrings<PathSet>(source); + auto wantedOutputs = readStrings<StringSet>(source); AutoCloseFD uploadLock = openLockFile(currentLoad + "/" + escapeUri(storeUri) + ".upload-lock", true); @@ -282,28 +282,59 @@ connected: BasicDerivation drv = store->readDerivation(*drvPath); + std::optional<BuildResult> optResult; if (sshStore2->isTrusting || derivationIsCA(drv.type())) { drv.inputSrcs = store->parseStorePathSet(inputs); - auto result = sshStore2->buildDerivation(*drvPath, drv); + optResult = sshStore2->buildDerivation(*drvPath, drv); + auto & result = *optResult; if (!result.success()) throw Error("build of '%s' on '%s' failed: %s", store->printStorePath(*drvPath), storeUri, result.errorMsg); } else { - copyPaths(store, sshStore2, {*drvPath}, NoRepair, NoCheckSigs, substitute, copyStorePathImpl); + copyPaths(store, sshStore2, StorePathSet {*drvPath}, NoRepair, NoCheckSigs, substitute, copyStorePathImpl); sshStore2->buildPaths({{*drvPath}}); } - StorePathSet missing; - for (auto & path : outputs) - if (!store->isValidPath(store->parseStorePath(path))) missing.insert(store->parseStorePath(path)); + auto outputHashes = staticOutputHashes(*store, drv); + std::set<Realisation> missingRealisations; + StorePathSet missingPaths; + if (settings.isExperimentalFeatureEnabled("ca-derivations") && !derivationHasKnownOutputPaths(drv.type())) { + for (auto & outputName : wantedOutputs) { + auto thisOutputHash = outputHashes.at(outputName); + auto thisOutputId = DrvOutput{ thisOutputHash, outputName }; + if (!store->queryRealisation(thisOutputId)) { + debug("missing output %s", outputName); + assert(optResult); + auto & result = *optResult; + assert(result.builtOutputs.count(thisOutputId)); + auto newRealisation = result.builtOutputs.at(thisOutputId); + missingRealisations.insert(newRealisation); + missingPaths.insert(newRealisation.outPath); + } + } + } else { + auto outputPaths = drv.outputsAndOptPaths(*store); + for (auto & [outputName, hopefullyOutputPath] : outputPaths) { + assert(hopefullyOutputPath.second); + if (!store->isValidPath(*hopefullyOutputPath.second)) + missingPaths.insert(*hopefullyOutputPath.second); + } + } - if (!missing.empty()) { + if (!missingPaths.empty()) { Activity act(*logger, lvlTalkative, actUnknown, fmt("copying outputs from '%s'", storeUri)); if (auto localStore = store.dynamic_pointer_cast<LocalStore>()) - for (auto & i : missing) - localStore->locksHeld.insert(store->printStorePath(i)); /* FIXME: ugly */ + for (auto & path : missingPaths) + localStore->locksHeld.insert(store->printStorePath(path)); /* FIXME: ugly */ /* No `copyStorePathImpl` because we always trust ourselves. */ - copyPaths(ref<Store>(sshStore), store, missing, NoRepair, NoCheckSigs, NoSubstitute); + copyPaths(ref<Store>(sshStore), store, missingPaths, NoRepair, NoCheckSigs, NoSubstitute); + } + // XXX: Should be done as part of `copyPaths` + for (auto & realisation : missingRealisations) { + // Should hold, because if the feature isn't enabled the set + // of missing realisations should be empty + settings.requireExperimentalFeature("ca-derivations"); + store->registerDrvOutput(realisation); } return 0; |