aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/derivations.cc
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2020-06-18 21:58:27 +0000
committerJohn Ericson <John.Ericson@Obsidian.Systems>2020-06-18 22:11:19 +0000
commitbbbf3602a323538b8da38f1a2c7ce136a20f74c6 (patch)
treee783d838d8a75d854e0b72eea03784c5909040bc /src/libstore/derivations.cc
parent406dbb7fce32f7d80b02f560d91c956698b58d6e (diff)
parent40526fbea56a8006eb7f1758d461a5acbe9a1694 (diff)
Merge branch 'enum-class' into no-hash-type-unknown
Diffstat (limited to 'src/libstore/derivations.cc')
-rw-r--r--src/libstore/derivations.cc65
1 files changed, 33 insertions, 32 deletions
diff --git a/src/libstore/derivations.cc b/src/libstore/derivations.cc
index d7b677185..5dc8605df 100644
--- a/src/libstore/derivations.cc
+++ b/src/libstore/derivations.cc
@@ -25,28 +25,6 @@ void DerivationOutput::parseHashInfo(FileIngestionMethod & recursive, Hash & has
}
-BasicDerivation::BasicDerivation(const BasicDerivation & other)
- : platform(other.platform)
- , builder(other.builder)
- , args(other.args)
- , env(other.env)
-{
- for (auto & i : other.outputs)
- outputs.insert_or_assign(i.first,
- DerivationOutput(i.second.path.clone(), std::string(i.second.hashAlgo), std::string(i.second.hash)));
- for (auto & i : other.inputSrcs)
- inputSrcs.insert(i.clone());
-}
-
-
-Derivation::Derivation(const Derivation & other)
- : BasicDerivation(other)
-{
- for (auto & i : other.inputDrvs)
- inputDrvs.insert_or_assign(i.first.clone(), i.second);
-}
-
-
const StorePath & BasicDerivation::findOutput(const string & id) const
{
auto i = outputs.find(id);
@@ -65,9 +43,9 @@ bool BasicDerivation::isBuiltin() const
StorePath writeDerivation(ref<Store> store,
const Derivation & drv, std::string_view name, RepairFlag repair)
{
- auto references = cloneStorePathSet(drv.inputSrcs);
+ auto references = drv.inputSrcs;
for (auto & i : drv.inputDrvs)
- references.insert(i.first.clone());
+ references.insert(i.first);
/* Note that the outputs of a derivation are *not* references
(that can be missing (of course) and should not necessarily be
held during a garbage collection). */
@@ -85,7 +63,7 @@ static void expect(std::istream & str, const string & s)
char s2[s.size()];
str.read(s2, s.size());
if (string(s2, s.size()) != s)
- throw FormatError(format("expected string '%1%'") % s);
+ throw FormatError("expected string '%1%'", s);
}
@@ -112,7 +90,7 @@ static Path parsePath(std::istream & str)
{
string s = parseString(str);
if (s.size() == 0 || s[0] != '/')
- throw FormatError(format("bad path '%1%' in derivation") % s);
+ throw FormatError("bad path '%1%' in derivation", s);
return s;
}
@@ -153,7 +131,11 @@ static Derivation parseDerivation(const Store & store, const string & s)
expect(str, ","); auto hashAlgo = parseString(str);
expect(str, ","); auto hash = parseString(str);
expect(str, ")");
- drv.outputs.emplace(id, DerivationOutput(std::move(path), std::move(hashAlgo), std::move(hash)));
+ drv.outputs.emplace(id, DerivationOutput {
+ .path = std::move(path),
+ .hashAlgo = std::move(hashAlgo),
+ .hash = std::move(hash)
+ });
}
/* Parse the list of input derivations. */
@@ -194,7 +176,7 @@ Derivation readDerivation(const Store & store, const Path & drvPath)
try {
return parseDerivation(store, readFile(drvPath));
} catch (FormatError & e) {
- throw Error(format("error parsing derivation '%1%': %2%") % drvPath % e.msg());
+ throw Error("error parsing derivation '%1%': %2%", drvPath, e.msg());
}
}
@@ -202,6 +184,12 @@ Derivation readDerivation(const Store & store, const Path & drvPath)
Derivation Store::derivationFromPath(const StorePath & drvPath)
{
ensurePath(drvPath);
+ return readDerivation(drvPath);
+}
+
+
+Derivation Store::readDerivation(const StorePath & drvPath)
+{
auto accessor = getFSAccessor();
try {
return parseDerivation(*this, accessor->readFile(printStorePath(drvPath)));
@@ -375,8 +363,8 @@ Hash hashDerivationModulo(Store & store, const Derivation & drv, bool maskOutput
auto h = drvHashes.find(i.first);
if (h == drvHashes.end()) {
assert(store.isValidPath(i.first));
- h = drvHashes.insert_or_assign(i.first.clone(), hashDerivationModulo(store,
- readDerivation(store, store.toRealPath(i.first)), false)).first;
+ h = drvHashes.insert_or_assign(i.first, hashDerivationModulo(store,
+ store.readDerivation(i.first), false)).first;
}
inputs2.insert_or_assign(h->second.to_string(Base::Base16, false), i.second);
}
@@ -403,11 +391,20 @@ StorePathSet BasicDerivation::outputPaths() const
{
StorePathSet paths;
for (auto & i : outputs)
- paths.insert(i.second.path.clone());
+ paths.insert(i.second.path);
return paths;
}
+StringSet BasicDerivation::outputNames() const
+{
+ StringSet names;
+ for (auto & i : outputs)
+ names.insert(i.first);
+ return names;
+}
+
+
Source & readDerivation(Source & in, const Store & store, BasicDerivation & drv)
{
drv.outputs.clear();
@@ -417,7 +414,11 @@ Source & readDerivation(Source & in, const Store & store, BasicDerivation & drv)
auto path = store.parseStorePath(readString(in));
auto hashAlgo = readString(in);
auto hash = readString(in);
- drv.outputs.emplace(name, DerivationOutput(std::move(path), std::move(hashAlgo), std::move(hash)));
+ drv.outputs.emplace(name, DerivationOutput {
+ .path = std::move(path),
+ .hashAlgo = std::move(hashAlgo),
+ .hash = std::move(hash)
+ });
}
drv.inputSrcs = readStorePaths<StorePathSet>(store, in);