mirror of
https://github.com/NixOS/nix.git
synced 2024-11-25 08:12:29 +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);
|
return "/" + hashString(HashAlgorithm::SHA256, concatStrings("nix-output:", outputName)).to_string(HashFormat::Nix32, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BasicDerivation::applyRewrites(const StringMap & rewrites)
|
||||||
|
|
||||||
|
|
||||||
static void rewriteDerivation(Store & store, BasicDerivation & drv, 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);
|
debug("rewriting %s as %s", rewrite.first, rewrite.second);
|
||||||
}
|
|
||||||
|
|
||||||
drv.builder = rewriteStrings(drv.builder, rewrites);
|
builder = rewriteStrings(builder, rewrites);
|
||||||
for (auto & arg : drv.args) {
|
for (auto & arg : args)
|
||||||
arg = rewriteStrings(arg, rewrites);
|
arg = rewriteStrings(arg, rewrites);
|
||||||
}
|
|
||||||
|
|
||||||
StringPairs newEnv;
|
StringPairs newEnv;
|
||||||
for (auto & envVar : drv.env) {
|
for (auto & envVar : env) {
|
||||||
auto envName = rewriteStrings(envVar.first, rewrites);
|
auto envName = rewriteStrings(envVar.first, rewrites);
|
||||||
auto envValue = rewriteStrings(envVar.second, rewrites);
|
auto envValue = rewriteStrings(envVar.second, rewrites);
|
||||||
newEnv.emplace(envName, envValue);
|
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);
|
auto hashModulo = hashDerivationModulo(store, Derivation(drv), true);
|
||||||
for (auto & [outputName, output] : drv.outputs) {
|
for (auto & [outputName, output] : drv.outputs) {
|
||||||
|
@ -325,6 +325,12 @@ struct BasicDerivation
|
|||||||
|
|
||||||
static std::string_view nameFromPath(const StorePath & storePath);
|
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;
|
bool operator == (const BasicDerivation &) const = default;
|
||||||
// TODO libc++ 16 (used by darwin) missing `std::map::operator <=>`, can't do yet.
|
// TODO libc++ 16 (used by darwin) missing `std::map::operator <=>`, can't do yet.
|
||||||
//auto operator <=> (const BasicDerivation &) const = default;
|
//auto operator <=> (const BasicDerivation &) const = default;
|
||||||
|
Loading…
Reference in New Issue
Block a user