mirror of
https://github.com/NixOS/nix
synced 2025-06-25 10:41:16 +02:00
ParsedDerivation
: don't take drvPath
It is just use for adding context to errors, but we have `addTrace` to do that. Let the callers do that instead. The callers doing so is a bit duplicated, yes, but this will get better once `DerivationOptions` is included in `Derivation`.
This commit is contained in:
parent
71567373b6
commit
0123640009
6 changed files with 35 additions and 19 deletions
|
@ -81,7 +81,7 @@ TEST_F(DerivationAdvancedAttrsTest, Derivation_advancedAttributes_defaults)
|
||||||
|
|
||||||
auto drvPath = writeDerivation(*store, got, NoRepair, true);
|
auto drvPath = writeDerivation(*store, got, NoRepair, true);
|
||||||
|
|
||||||
ParsedDerivation parsedDrv(drvPath, got);
|
ParsedDerivation parsedDrv(got);
|
||||||
DerivationOptions options = DerivationOptions::fromParsedDerivation(parsedDrv);
|
DerivationOptions options = DerivationOptions::fromParsedDerivation(parsedDrv);
|
||||||
|
|
||||||
EXPECT_TRUE(!parsedDrv.hasStructuredAttrs());
|
EXPECT_TRUE(!parsedDrv.hasStructuredAttrs());
|
||||||
|
@ -116,7 +116,7 @@ TEST_F(DerivationAdvancedAttrsTest, Derivation_advancedAttributes)
|
||||||
|
|
||||||
auto drvPath = writeDerivation(*store, got, NoRepair, true);
|
auto drvPath = writeDerivation(*store, got, NoRepair, true);
|
||||||
|
|
||||||
ParsedDerivation parsedDrv(drvPath, got);
|
ParsedDerivation parsedDrv(got);
|
||||||
DerivationOptions options = DerivationOptions::fromParsedDerivation(parsedDrv);
|
DerivationOptions options = DerivationOptions::fromParsedDerivation(parsedDrv);
|
||||||
|
|
||||||
StringSet systemFeatures{"rainbow", "uid-range"};
|
StringSet systemFeatures{"rainbow", "uid-range"};
|
||||||
|
@ -157,7 +157,7 @@ TEST_F(DerivationAdvancedAttrsTest, Derivation_advancedAttributes_structuredAttr
|
||||||
|
|
||||||
auto drvPath = writeDerivation(*store, got, NoRepair, true);
|
auto drvPath = writeDerivation(*store, got, NoRepair, true);
|
||||||
|
|
||||||
ParsedDerivation parsedDrv(drvPath, got);
|
ParsedDerivation parsedDrv(got);
|
||||||
DerivationOptions options = DerivationOptions::fromParsedDerivation(parsedDrv);
|
DerivationOptions options = DerivationOptions::fromParsedDerivation(parsedDrv);
|
||||||
|
|
||||||
EXPECT_TRUE(parsedDrv.hasStructuredAttrs());
|
EXPECT_TRUE(parsedDrv.hasStructuredAttrs());
|
||||||
|
@ -191,7 +191,7 @@ TEST_F(DerivationAdvancedAttrsTest, Derivation_advancedAttributes_structuredAttr
|
||||||
|
|
||||||
auto drvPath = writeDerivation(*store, got, NoRepair, true);
|
auto drvPath = writeDerivation(*store, got, NoRepair, true);
|
||||||
|
|
||||||
ParsedDerivation parsedDrv(drvPath, got);
|
ParsedDerivation parsedDrv(got);
|
||||||
DerivationOptions options = DerivationOptions::fromParsedDerivation(parsedDrv);
|
DerivationOptions options = DerivationOptions::fromParsedDerivation(parsedDrv);
|
||||||
|
|
||||||
StringSet systemFeatures{"rainbow", "uid-range"};
|
StringSet systemFeatures{"rainbow", "uid-range"};
|
||||||
|
|
|
@ -180,8 +180,13 @@ Goal::Co DerivationGoal::haveDerivation()
|
||||||
{
|
{
|
||||||
trace("have derivation");
|
trace("have derivation");
|
||||||
|
|
||||||
parsedDrv = std::make_unique<ParsedDerivation>(drvPath, *drv);
|
parsedDrv = std::make_unique<ParsedDerivation>(*drv);
|
||||||
drvOptions = std::make_unique<DerivationOptions>(DerivationOptions::fromParsedDerivation(*parsedDrv));
|
try {
|
||||||
|
drvOptions = std::make_unique<DerivationOptions>(DerivationOptions::fromParsedDerivation(*parsedDrv));
|
||||||
|
} catch (Error & e) {
|
||||||
|
e.addTrace({}, "while parsing derivation '%s'", worker.store.printStorePath(drvPath));
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
if (!drv->type().hasKnownOutputPaths())
|
if (!drv->type().hasKnownOutputPaths())
|
||||||
experimentalFeatureSettings.require(Xp::CaDerivations);
|
experimentalFeatureSettings.require(Xp::CaDerivations);
|
||||||
|
|
|
@ -12,7 +12,6 @@ struct DerivationOptions;
|
||||||
|
|
||||||
class ParsedDerivation
|
class ParsedDerivation
|
||||||
{
|
{
|
||||||
StorePath drvPath;
|
|
||||||
BasicDerivation & drv;
|
BasicDerivation & drv;
|
||||||
std::unique_ptr<nlohmann::json> structuredAttrs;
|
std::unique_ptr<nlohmann::json> structuredAttrs;
|
||||||
|
|
||||||
|
@ -34,7 +33,7 @@ class ParsedDerivation
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
ParsedDerivation(const StorePath & drvPath, BasicDerivation & drv);
|
ParsedDerivation(BasicDerivation & drv);
|
||||||
|
|
||||||
~ParsedDerivation();
|
~ParsedDerivation();
|
||||||
|
|
||||||
|
|
|
@ -222,8 +222,14 @@ void Store::queryMissing(const std::vector<DerivedPath> & targets,
|
||||||
if (knownOutputPaths && invalid.empty()) return;
|
if (knownOutputPaths && invalid.empty()) return;
|
||||||
|
|
||||||
auto drv = make_ref<Derivation>(derivationFromPath(drvPath));
|
auto drv = make_ref<Derivation>(derivationFromPath(drvPath));
|
||||||
ParsedDerivation parsedDrv(StorePath(drvPath), *drv);
|
ParsedDerivation parsedDrv(*drv);
|
||||||
DerivationOptions drvOptions = DerivationOptions::fromParsedDerivation(parsedDrv);
|
DerivationOptions drvOptions;
|
||||||
|
try {
|
||||||
|
drvOptions = DerivationOptions::fromParsedDerivation(parsedDrv);
|
||||||
|
} catch (Error & e) {
|
||||||
|
e.addTrace({}, "while parsing derivation '%s'", printStorePath(drvPath));
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
if (!knownOutputPaths && settings.useSubstitutes && drvOptions.substitutesAllowed()) {
|
if (!knownOutputPaths && settings.useSubstitutes && drvOptions.substitutesAllowed()) {
|
||||||
experimentalFeatureSettings.require(Xp::CaDerivations);
|
experimentalFeatureSettings.require(Xp::CaDerivations);
|
||||||
|
|
|
@ -5,8 +5,8 @@
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
ParsedDerivation::ParsedDerivation(const StorePath & drvPath, BasicDerivation & drv)
|
ParsedDerivation::ParsedDerivation(BasicDerivation & drv)
|
||||||
: drvPath(drvPath), drv(drv)
|
: drv(drv)
|
||||||
{
|
{
|
||||||
/* Parse the __json attribute, if any. */
|
/* Parse the __json attribute, if any. */
|
||||||
auto jsonAttr = drv.env.find("__json");
|
auto jsonAttr = drv.env.find("__json");
|
||||||
|
@ -14,7 +14,7 @@ ParsedDerivation::ParsedDerivation(const StorePath & drvPath, BasicDerivation &
|
||||||
try {
|
try {
|
||||||
structuredAttrs = std::make_unique<nlohmann::json>(nlohmann::json::parse(jsonAttr->second));
|
structuredAttrs = std::make_unique<nlohmann::json>(nlohmann::json::parse(jsonAttr->second));
|
||||||
} catch (std::exception & e) {
|
} catch (std::exception & e) {
|
||||||
throw Error("cannot process __json attribute of '%s': %s", drvPath.to_string(), e.what());
|
throw Error("cannot process __json attribute: %s", e.what());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ std::optional<std::string> ParsedDerivation::getStringAttr(const std::string & n
|
||||||
return {};
|
return {};
|
||||||
else {
|
else {
|
||||||
if (!i->is_string())
|
if (!i->is_string())
|
||||||
throw Error("attribute '%s' of derivation '%s' must be a string", name, drvPath.to_string());
|
throw Error("attribute '%s' of must be a string", name);
|
||||||
return i->get<std::string>();
|
return i->get<std::string>();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -49,7 +49,7 @@ bool ParsedDerivation::getBoolAttr(const std::string & name, bool def) const
|
||||||
return def;
|
return def;
|
||||||
else {
|
else {
|
||||||
if (!i->is_boolean())
|
if (!i->is_boolean())
|
||||||
throw Error("attribute '%s' of derivation '%s' must be a Boolean", name, drvPath.to_string());
|
throw Error("attribute '%s' must be a Boolean", name);
|
||||||
return i->get<bool>();
|
return i->get<bool>();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -69,11 +69,11 @@ std::optional<Strings> ParsedDerivation::getStringsAttr(const std::string & name
|
||||||
return {};
|
return {};
|
||||||
else {
|
else {
|
||||||
if (!i->is_array())
|
if (!i->is_array())
|
||||||
throw Error("attribute '%s' of derivation '%s' must be a list of strings", name, drvPath.to_string());
|
throw Error("attribute '%s' must be a list of strings", name);
|
||||||
Strings res;
|
Strings res;
|
||||||
for (auto j = i->begin(); j != i->end(); ++j) {
|
for (auto j = i->begin(); j != i->end(); ++j) {
|
||||||
if (!j->is_string())
|
if (!j->is_string())
|
||||||
throw Error("attribute '%s' of derivation '%s' must be a list of strings", name, drvPath.to_string());
|
throw Error("attribute '%s' must be a list of strings", name);
|
||||||
res.push_back(j->get<std::string>());
|
res.push_back(j->get<std::string>());
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
|
|
|
@ -544,8 +544,14 @@ static void main_nix_build(int argc, char * * argv)
|
||||||
env["NIX_STORE"] = store->storeDir;
|
env["NIX_STORE"] = store->storeDir;
|
||||||
env["NIX_BUILD_CORES"] = std::to_string(settings.buildCores);
|
env["NIX_BUILD_CORES"] = std::to_string(settings.buildCores);
|
||||||
|
|
||||||
ParsedDerivation parsedDrv(packageInfo.requireDrvPath(), drv);
|
ParsedDerivation parsedDrv(drv);
|
||||||
DerivationOptions drvOptions = DerivationOptions::fromParsedDerivation(parsedDrv);
|
DerivationOptions drvOptions;
|
||||||
|
try {
|
||||||
|
drvOptions = DerivationOptions::fromParsedDerivation(parsedDrv);
|
||||||
|
} catch (Error & e) {
|
||||||
|
e.addTrace({}, "while parsing derivation '%s'", store->printStorePath(packageInfo.requireDrvPath()));
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
int fileNr = 0;
|
int fileNr = 0;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue