aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/derivations.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstore/derivations.cc')
-rw-r--r--src/libstore/derivations.cc74
1 files changed, 37 insertions, 37 deletions
diff --git a/src/libstore/derivations.cc b/src/libstore/derivations.cc
index f05f8b9ac..826b336e0 100644
--- a/src/libstore/derivations.cc
+++ b/src/libstore/derivations.cc
@@ -13,28 +13,6 @@ std::string FileSystemHash::printMethodAlgo() const {
}
-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::optional<FileSystemHash>(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);
@@ -53,9 +31,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). */
@@ -73,7 +51,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);
}
@@ -100,7 +78,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;
}
@@ -135,9 +113,9 @@ static DerivationOutput parseDerivationOutput(const Store & store, istringstream
expect(str, ","); const auto hash = parseString(str);
expect(str, ")");
- auto method = FileIngestionMethod::Flat;
std::optional<FileSystemHash> fsh;
if (hashAlgo != "") {
+ auto method = FileIngestionMethod::Flat;
if (string(hashAlgo, 0, 2) == "r:") {
method = FileIngestionMethod::Recursive;
hashAlgo = string(hashAlgo, 2);
@@ -151,7 +129,10 @@ static DerivationOutput parseDerivationOutput(const Store & store, istringstream
};
}
- return DerivationOutput(std::move(path), std::move(fsh));
+ return DerivationOutput {
+ .path = std::move(path),
+ .hash = std::move(fsh),
+ };
}
@@ -164,7 +145,8 @@ static Derivation parseDerivation(const Store & store, const string & s)
/* Parse the list of outputs. */
while (!endOfList(str)) {
expect(str, "("); std::string id = parseString(str);
- drv.outputs.emplace(id, parseDerivationOutput(store, str));
+ auto output = parseDerivationOutput(store, str);
+ drv.outputs.emplace(std::move(id), std::move(output));
}
/* Parse the list of input derivations. */
@@ -205,7 +187,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());
}
}
@@ -213,6 +195,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)));
@@ -387,8 +375,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(Base16, false), i.second);
}
@@ -415,7 +403,7 @@ StorePathSet BasicDerivation::outputPaths() const
{
StorePathSet paths;
for (auto & i : outputs)
- paths.insert(i.second.path.clone());
+ paths.insert(i.second.path);
return paths;
}
@@ -425,14 +413,14 @@ static DerivationOutput readDerivationOutput(Source & in, const Store & store)
auto hashAlgo = readString(in);
const auto hash = readString(in);
- auto method = FileIngestionMethod::Flat;
std::optional<FileSystemHash> fsh;
if (hashAlgo != "") {
+ auto method = FileIngestionMethod::Flat;
if (string(hashAlgo, 0, 2) == "r:") {
method = FileIngestionMethod::Recursive;
hashAlgo = string(hashAlgo, 2);
}
- HashType hashType = parseHashType(hashAlgo);
+ const HashType hashType = parseHashType(hashAlgo);
if (hashType == htUnknown)
throw Error("unknown hash hashAlgorithm '%s'", hashAlgo);
fsh = FileSystemHash {
@@ -441,9 +429,21 @@ static DerivationOutput readDerivationOutput(Source & in, const Store & store)
};
}
- return DerivationOutput(std::move(path), std::move(fsh));
+ return DerivationOutput {
+ .path = std::move(path),
+ .hash = std::move(fsh),
+ };
}
+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();
@@ -451,7 +451,7 @@ Source & readDerivation(Source & in, const Store & store, BasicDerivation & drv)
for (size_t n = 0; n < nr; n++) {
auto name = readString(in);
auto output = readDerivationOutput(in, store);
- drv.outputs.emplace(name, output);
+ drv.outputs.emplace(std::move(name), std::move(output));
}
drv.inputSrcs = readStorePaths<StorePathSet>(store, in);