mirror of
https://github.com/NixOS/nix.git
synced 2024-11-21 22:32:26 +00:00
Merge pull request #11912 from DeterminateSystems/apply-rewrites
BasicDerivation: Add applyRewrites() method
This commit is contained in:
commit
a7e1f2d5a3
@ -1017,29 +1017,31 @@ std::string hashPlaceholder(const OutputNameView outputName)
|
||||
return "/" + hashString(HashAlgorithm::SHA256, concatStrings("nix-output:", outputName)).to_string(HashFormat::Nix32, false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
static void rewriteDerivation(Store & store, BasicDerivation & drv, const StringMap & rewrites)
|
||||
void BasicDerivation::applyRewrites(const StringMap & rewrites)
|
||||
{
|
||||
debug("Rewriting the derivation");
|
||||
if (rewrites.empty()) return;
|
||||
|
||||
for (auto & rewrite : rewrites) {
|
||||
debug("rewriting the derivation");
|
||||
|
||||
for (auto & rewrite : rewrites)
|
||||
debug("rewriting %s as %s", rewrite.first, rewrite.second);
|
||||
}
|
||||
|
||||
drv.builder = rewriteStrings(drv.builder, rewrites);
|
||||
for (auto & arg : drv.args) {
|
||||
builder = rewriteStrings(builder, rewrites);
|
||||
for (auto & arg : args)
|
||||
arg = rewriteStrings(arg, rewrites);
|
||||
}
|
||||
|
||||
StringPairs newEnv;
|
||||
for (auto & envVar : drv.env) {
|
||||
for (auto & envVar : env) {
|
||||
auto envName = rewriteStrings(envVar.first, rewrites);
|
||||
auto envValue = rewriteStrings(envVar.second, rewrites);
|
||||
newEnv.emplace(envName, envValue);
|
||||
}
|
||||
drv.env = newEnv;
|
||||
env = std::move(newEnv);
|
||||
}
|
||||
|
||||
static void rewriteDerivation(Store & store, BasicDerivation & drv, const StringMap & rewrites)
|
||||
{
|
||||
drv.applyRewrites(rewrites);
|
||||
|
||||
auto hashModulo = hashDerivationModulo(store, Derivation(drv), true);
|
||||
for (auto & [outputName, output] : drv.outputs) {
|
||||
|
@ -325,6 +325,12 @@ struct BasicDerivation
|
||||
|
||||
static std::string_view nameFromPath(const StorePath & storePath);
|
||||
|
||||
/**
|
||||
* Apply string rewrites to the `env`, `args` and `builder`
|
||||
* fields.
|
||||
*/
|
||||
void applyRewrites(const StringMap & rewrites);
|
||||
|
||||
bool operator == (const BasicDerivation &) const = default;
|
||||
// TODO libc++ 16 (used by darwin) missing `std::map::operator <=>`, can't do yet.
|
||||
//auto operator <=> (const BasicDerivation &) const = default;
|
||||
|
Loading…
Reference in New Issue
Block a user