mirror of
https://github.com/NixOS/nix
synced 2025-06-28 09:31:16 +02:00
Merge branch 'no-stringly-typed-derivation-output' of github.com:Ericson2314/nix into validPathInfo-ca-proper-datatype
This commit is contained in:
commit
f4b89e11a4
15 changed files with 194 additions and 94 deletions
|
@ -8,22 +8,8 @@
|
|||
|
||||
namespace nix {
|
||||
|
||||
|
||||
void DerivationOutput::parseHashInfo(FileIngestionMethod & recursive, Hash & hash) const
|
||||
{
|
||||
recursive = FileIngestionMethod::Flat;
|
||||
string algo = hashAlgo;
|
||||
|
||||
if (string(algo, 0, 2) == "r:") {
|
||||
recursive = FileIngestionMethod::Recursive;
|
||||
algo = string(algo, 2);
|
||||
}
|
||||
|
||||
HashType hashType = parseHashType(algo);
|
||||
if (hashType == HashType::Unknown)
|
||||
throw Error("unknown hash algorithm '%s'", algo);
|
||||
|
||||
hash = Hash(this->hash, hashType);
|
||||
std::string FileSystemHash::printMethodAlgo() const {
|
||||
return makeFileIngestionPrefix(method) + printHashType(hash.type);
|
||||
}
|
||||
|
||||
|
||||
|
@ -35,7 +21,7 @@ BasicDerivation::BasicDerivation(const BasicDerivation & other)
|
|||
{
|
||||
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)));
|
||||
DerivationOutput(i.second.path.clone(), std::optional<FileSystemHash>(i.second.hash)));
|
||||
for (auto & i : other.inputSrcs)
|
||||
inputSrcs.insert(i.clone());
|
||||
}
|
||||
|
@ -142,6 +128,33 @@ static StringSet parseStrings(std::istream & str, bool arePaths)
|
|||
}
|
||||
|
||||
|
||||
static DerivationOutput parseDerivationOutput(const Store & store, istringstream_nocopy & str)
|
||||
{
|
||||
expect(str, ","); auto path = store.parseStorePath(parsePath(str));
|
||||
expect(str, ","); auto hashAlgo = parseString(str);
|
||||
expect(str, ","); const auto hash = parseString(str);
|
||||
expect(str, ")");
|
||||
|
||||
auto method = FileIngestionMethod::Flat;
|
||||
std::optional<FileSystemHash> fsh;
|
||||
if (hashAlgo != "") {
|
||||
if (string(hashAlgo, 0, 2) == "r:") {
|
||||
method = FileIngestionMethod::Recursive;
|
||||
hashAlgo = string(hashAlgo, 2);
|
||||
}
|
||||
const HashType hashType = parseHashType(hashAlgo);
|
||||
if (hashType == HashType::Unknown)
|
||||
throw Error("unknown hash hashAlgorithm '%s'", hashAlgo);
|
||||
fsh = FileSystemHash {
|
||||
std::move(method),
|
||||
Hash(hash, hashType),
|
||||
};
|
||||
}
|
||||
|
||||
return DerivationOutput(std::move(path), std::move(fsh));
|
||||
}
|
||||
|
||||
|
||||
static Derivation parseDerivation(const Store & store, const string & s)
|
||||
{
|
||||
Derivation drv;
|
||||
|
@ -151,11 +164,7 @@ static Derivation parseDerivation(const Store & store, const string & s)
|
|||
/* Parse the list of outputs. */
|
||||
while (!endOfList(str)) {
|
||||
expect(str, "("); std::string id = parseString(str);
|
||||
expect(str, ","); auto path = store.parseStorePath(parsePath(str));
|
||||
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, parseDerivationOutput(store, str));
|
||||
}
|
||||
|
||||
/* Parse the list of input derivations. */
|
||||
|
@ -275,8 +284,9 @@ string Derivation::unparse(const Store & store, bool maskOutputs,
|
|||
if (first) first = false; else s += ',';
|
||||
s += '('; printUnquotedString(s, i.first);
|
||||
s += ','; printUnquotedString(s, maskOutputs ? "" : store.printStorePath(i.second.path));
|
||||
s += ','; printUnquotedString(s, i.second.hashAlgo);
|
||||
s += ','; printUnquotedString(s, i.second.hash);
|
||||
s += ','; printUnquotedString(s, i.second.hash ? i.second.hash->printMethodAlgo() : "");
|
||||
s += ','; printUnquotedString(s,
|
||||
i.second.hash ? i.second.hash->hash.to_string(Base::Base16, false) : "");
|
||||
s += ')';
|
||||
}
|
||||
|
||||
|
@ -332,7 +342,7 @@ bool BasicDerivation::isFixedOutput() const
|
|||
{
|
||||
return outputs.size() == 1 &&
|
||||
outputs.begin()->first == "out" &&
|
||||
outputs.begin()->second.hash != "";
|
||||
outputs.begin()->second.hash;
|
||||
}
|
||||
|
||||
|
||||
|
@ -365,8 +375,8 @@ Hash hashDerivationModulo(Store & store, const Derivation & drv, bool maskOutput
|
|||
if (drv.isFixedOutput()) {
|
||||
DerivationOutputs::const_iterator i = drv.outputs.begin();
|
||||
return hashString(HashType::SHA256, "fixed:out:"
|
||||
+ i->second.hashAlgo + ":"
|
||||
+ i->second.hash + ":"
|
||||
+ i->second.hash->printMethodAlgo() + ":"
|
||||
+ i->second.hash->hash.to_string(Base::Base16, false) + ":"
|
||||
+ store.printStorePath(i->second.path));
|
||||
}
|
||||
|
||||
|
@ -409,6 +419,30 @@ StorePathSet BasicDerivation::outputPaths() const
|
|||
return paths;
|
||||
}
|
||||
|
||||
static DerivationOutput readDerivationOutput(Source & in, const Store & store)
|
||||
{
|
||||
auto path = store.parseStorePath(readString(in));
|
||||
auto hashAlgo = readString(in);
|
||||
const auto hash = readString(in);
|
||||
|
||||
auto method = FileIngestionMethod::Flat;
|
||||
std::optional<FileSystemHash> fsh;
|
||||
if (hashAlgo != "") {
|
||||
if (string(hashAlgo, 0, 2) == "r:") {
|
||||
method = FileIngestionMethod::Recursive;
|
||||
hashAlgo = string(hashAlgo, 2);
|
||||
}
|
||||
HashType hashType = parseHashType(hashAlgo);
|
||||
if (hashType == HashType::Unknown)
|
||||
throw Error("unknown hash hashAlgorithm '%s'", hashAlgo);
|
||||
fsh = FileSystemHash {
|
||||
std::move(method),
|
||||
Hash(hash, hashType),
|
||||
};
|
||||
}
|
||||
|
||||
return DerivationOutput(std::move(path), std::move(fsh));
|
||||
}
|
||||
|
||||
Source & readDerivation(Source & in, const Store & store, BasicDerivation & drv)
|
||||
{
|
||||
|
@ -416,10 +450,8 @@ Source & readDerivation(Source & in, const Store & store, BasicDerivation & drv)
|
|||
auto nr = readNum<size_t>(in);
|
||||
for (size_t n = 0; n < nr; n++) {
|
||||
auto name = readString(in);
|
||||
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)));
|
||||
auto output = readDerivationOutput(in, store);
|
||||
drv.outputs.emplace(name, output);
|
||||
}
|
||||
|
||||
drv.inputSrcs = readStorePaths<StorePathSet>(store, in);
|
||||
|
@ -441,7 +473,10 @@ void writeDerivation(Sink & out, const Store & store, const BasicDerivation & dr
|
|||
{
|
||||
out << drv.outputs.size();
|
||||
for (auto & i : drv.outputs)
|
||||
out << i.first << store.printStorePath(i.second.path) << i.second.hashAlgo << i.second.hash;
|
||||
out << i.first
|
||||
<< store.printStorePath(i.second.path)
|
||||
<< i.second.hash->printMethodAlgo()
|
||||
<< i.second.hash->hash.to_string(Base::Base16, false);
|
||||
writeStorePaths(store, out, drv.inputSrcs);
|
||||
out << drv.platform << drv.builder << drv.args;
|
||||
out << drv.env.size();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue