aboutsummaryrefslogtreecommitdiff
path: root/src/libstore
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstore')
-rw-r--r--src/libstore/binary-cache-store.cc16
-rw-r--r--src/libstore/local-fs-store.cc15
-rw-r--r--src/libstore/store-api.cc28
-rw-r--r--src/libstore/store-api.hh7
4 files changed, 43 insertions, 23 deletions
diff --git a/src/libstore/binary-cache-store.cc b/src/libstore/binary-cache-store.cc
index 12d0c32fb..14584f0a2 100644
--- a/src/libstore/binary-cache-store.cc
+++ b/src/libstore/binary-cache-store.cc
@@ -504,18 +504,10 @@ void BinaryCacheStore::addSignatures(const StorePath & storePath, const StringSe
std::optional<std::string> BinaryCacheStore::getBuildLog(const StorePath & path)
{
- auto drvPath = path;
-
- if (!path.isDerivation()) {
- try {
- auto info = queryPathInfo(path);
- // FIXME: add a "Log" field to .narinfo
- if (!info->deriver) return std::nullopt;
- drvPath = *info->deriver;
- } catch (InvalidPath &) {
- return std::nullopt;
- }
- }
+ auto maybePath = getBuildDerivationPath(path);
+ if (!maybePath)
+ return std::nullopt;
+ auto drvPath = maybePath.value();
auto logPath = "log/" + std::string(baseNameOf(printStorePath(drvPath)));
diff --git a/src/libstore/local-fs-store.cc b/src/libstore/local-fs-store.cc
index c5ae7536f..3a0585b15 100644
--- a/src/libstore/local-fs-store.cc
+++ b/src/libstore/local-fs-store.cc
@@ -89,17 +89,10 @@ const std::string LocalFSStore::drvsLogDir = "drvs";
std::optional<std::string> LocalFSStore::getBuildLog(const StorePath & path_)
{
- auto path = path_;
-
- if (!path.isDerivation()) {
- try {
- auto info = queryPathInfo(path);
- if (!info->deriver) return std::nullopt;
- path = *info->deriver;
- } catch (InvalidPath &) {
- return std::nullopt;
- }
- }
+ auto maybePath = getBuildDerivationPath(path_);
+ if (!maybePath)
+ return std::nullopt;
+ auto path = maybePath.value();
auto baseName = path.to_string();
diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc
index 8811ab578..ebd641aa4 100644
--- a/src/libstore/store-api.cc
+++ b/src/libstore/store-api.cc
@@ -1300,6 +1300,34 @@ Derivation readDerivationCommon(Store& store, const StorePath& drvPath, bool req
}
}
+std::optional<StorePath> Store::getBuildDerivationPath(const StorePath & path)
+{
+
+ if (!path.isDerivation()) {
+ try {
+ auto info = queryPathInfo(path);
+ if (!info->deriver) return std::nullopt;
+ return *info->deriver;
+ } catch (InvalidPath &) {
+ return std::nullopt;
+ }
+ }
+
+ if (!settings.isExperimentalFeatureEnabled(Xp::CaDerivations) || !isValidPath(path))
+ return path;
+
+ auto drv = readDerivation(path);
+ if (!derivationHasKnownOutputPaths(drv.type())) {
+ // The build log is actually attached to the corresponding
+ // resolved derivation, so we need to get it first
+ auto resolvedDrv = drv.tryResolve(*this);
+ if (resolvedDrv)
+ return writeDerivation(*this, *resolvedDrv, NoRepair, true);
+ }
+
+ return path;
+}
+
Derivation Store::readDerivation(const StorePath & drvPath)
{ return readDerivationCommon(*this, drvPath, true); }
diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh
index 151ec10d6..88a11d953 100644
--- a/src/libstore/store-api.hh
+++ b/src/libstore/store-api.hh
@@ -618,6 +618,13 @@ public:
*/
StorePathSet exportReferences(const StorePathSet & storePaths, const StorePathSet & inputPaths);
+ /**
+ * Given a store path, return the realisation actually used in the realisation of this path:
+ * - If the path is a content-addressed derivation, try to resolve it
+ * - Otherwise, find one of its derivers
+ */
+ std::optional<StorePath> getBuildDerivationPath(const StorePath &);
+
/* Hack to allow long-running processes like hydra-queue-runner to
occasionally flush their path info cache. */
void clearPathInfoCache()