Skip to content

Commit b1fe93f

Browse files
authored
Merge pull request #13015 from obsidiansystems/derivation-options
`ParsedDerivation`: don't take `drvPath`
2 parents 3f3fd2c + 0123640 commit b1fe93f

6 files changed

Lines changed: 35 additions & 19 deletions

File tree

src/libstore-tests/derivation-advanced-attrs.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ TEST_F(DerivationAdvancedAttrsTest, Derivation_advancedAttributes_defaults)
8181

8282
auto drvPath = writeDerivation(*store, got, NoRepair, true);
8383

84-
ParsedDerivation parsedDrv(drvPath, got);
84+
ParsedDerivation parsedDrv(got);
8585
DerivationOptions options = DerivationOptions::fromParsedDerivation(parsedDrv);
8686

8787
EXPECT_TRUE(!parsedDrv.hasStructuredAttrs());
@@ -116,7 +116,7 @@ TEST_F(DerivationAdvancedAttrsTest, Derivation_advancedAttributes)
116116

117117
auto drvPath = writeDerivation(*store, got, NoRepair, true);
118118

119-
ParsedDerivation parsedDrv(drvPath, got);
119+
ParsedDerivation parsedDrv(got);
120120
DerivationOptions options = DerivationOptions::fromParsedDerivation(parsedDrv);
121121

122122
StringSet systemFeatures{"rainbow", "uid-range"};
@@ -157,7 +157,7 @@ TEST_F(DerivationAdvancedAttrsTest, Derivation_advancedAttributes_structuredAttr
157157

158158
auto drvPath = writeDerivation(*store, got, NoRepair, true);
159159

160-
ParsedDerivation parsedDrv(drvPath, got);
160+
ParsedDerivation parsedDrv(got);
161161
DerivationOptions options = DerivationOptions::fromParsedDerivation(parsedDrv);
162162

163163
EXPECT_TRUE(parsedDrv.hasStructuredAttrs());
@@ -191,7 +191,7 @@ TEST_F(DerivationAdvancedAttrsTest, Derivation_advancedAttributes_structuredAttr
191191

192192
auto drvPath = writeDerivation(*store, got, NoRepair, true);
193193

194-
ParsedDerivation parsedDrv(drvPath, got);
194+
ParsedDerivation parsedDrv(got);
195195
DerivationOptions options = DerivationOptions::fromParsedDerivation(parsedDrv);
196196

197197
StringSet systemFeatures{"rainbow", "uid-range"};

src/libstore/build/derivation-goal.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,13 @@ Goal::Co DerivationGoal::haveDerivation()
180180
{
181181
trace("have derivation");
182182

183-
parsedDrv = std::make_unique<ParsedDerivation>(drvPath, *drv);
184-
drvOptions = std::make_unique<DerivationOptions>(DerivationOptions::fromParsedDerivation(*parsedDrv));
183+
parsedDrv = std::make_unique<ParsedDerivation>(*drv);
184+
try {
185+
drvOptions = std::make_unique<DerivationOptions>(DerivationOptions::fromParsedDerivation(*parsedDrv));
186+
} catch (Error & e) {
187+
e.addTrace({}, "while parsing derivation '%s'", worker.store.printStorePath(drvPath));
188+
throw;
189+
}
185190

186191
if (!drv->type().hasKnownOutputPaths())
187192
experimentalFeatureSettings.require(Xp::CaDerivations);

src/libstore/include/nix/store/parsed-derivations.hh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ struct DerivationOptions;
1212

1313
class ParsedDerivation
1414
{
15-
StorePath drvPath;
1615
BasicDerivation & drv;
1716
std::unique_ptr<nlohmann::json> structuredAttrs;
1817

@@ -34,7 +33,7 @@ class ParsedDerivation
3433

3534
public:
3635

37-
ParsedDerivation(const StorePath & drvPath, BasicDerivation & drv);
36+
ParsedDerivation(BasicDerivation & drv);
3837

3938
~ParsedDerivation();
4039

src/libstore/misc.cc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,14 @@ void Store::queryMissing(const std::vector<DerivedPath> & targets,
222222
if (knownOutputPaths && invalid.empty()) return;
223223

224224
auto drv = make_ref<Derivation>(derivationFromPath(drvPath));
225-
ParsedDerivation parsedDrv(StorePath(drvPath), *drv);
226-
DerivationOptions drvOptions = DerivationOptions::fromParsedDerivation(parsedDrv);
225+
ParsedDerivation parsedDrv(*drv);
226+
DerivationOptions drvOptions;
227+
try {
228+
drvOptions = DerivationOptions::fromParsedDerivation(parsedDrv);
229+
} catch (Error & e) {
230+
e.addTrace({}, "while parsing derivation '%s'", printStorePath(drvPath));
231+
throw;
232+
}
227233

228234
if (!knownOutputPaths && settings.useSubstitutes && drvOptions.substitutesAllowed()) {
229235
experimentalFeatureSettings.require(Xp::CaDerivations);

src/libstore/parsed-derivations.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55

66
namespace nix {
77

8-
ParsedDerivation::ParsedDerivation(const StorePath & drvPath, BasicDerivation & drv)
9-
: drvPath(drvPath), drv(drv)
8+
ParsedDerivation::ParsedDerivation(BasicDerivation & drv)
9+
: drv(drv)
1010
{
1111
/* Parse the __json attribute, if any. */
1212
auto jsonAttr = drv.env.find("__json");
1313
if (jsonAttr != drv.env.end()) {
1414
try {
1515
structuredAttrs = std::make_unique<nlohmann::json>(nlohmann::json::parse(jsonAttr->second));
1616
} catch (std::exception & e) {
17-
throw Error("cannot process __json attribute of '%s': %s", drvPath.to_string(), e.what());
17+
throw Error("cannot process __json attribute: %s", e.what());
1818
}
1919
}
2020
}
@@ -29,7 +29,7 @@ std::optional<std::string> ParsedDerivation::getStringAttr(const std::string & n
2929
return {};
3030
else {
3131
if (!i->is_string())
32-
throw Error("attribute '%s' of derivation '%s' must be a string", name, drvPath.to_string());
32+
throw Error("attribute '%s' of must be a string", name);
3333
return i->get<std::string>();
3434
}
3535
} else {
@@ -49,7 +49,7 @@ bool ParsedDerivation::getBoolAttr(const std::string & name, bool def) const
4949
return def;
5050
else {
5151
if (!i->is_boolean())
52-
throw Error("attribute '%s' of derivation '%s' must be a Boolean", name, drvPath.to_string());
52+
throw Error("attribute '%s' must be a Boolean", name);
5353
return i->get<bool>();
5454
}
5555
} else {
@@ -69,11 +69,11 @@ std::optional<Strings> ParsedDerivation::getStringsAttr(const std::string & name
6969
return {};
7070
else {
7171
if (!i->is_array())
72-
throw Error("attribute '%s' of derivation '%s' must be a list of strings", name, drvPath.to_string());
72+
throw Error("attribute '%s' must be a list of strings", name);
7373
Strings res;
7474
for (auto j = i->begin(); j != i->end(); ++j) {
7575
if (!j->is_string())
76-
throw Error("attribute '%s' of derivation '%s' must be a list of strings", name, drvPath.to_string());
76+
throw Error("attribute '%s' must be a list of strings", name);
7777
res.push_back(j->get<std::string>());
7878
}
7979
return res;

src/nix-build/nix-build.cc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -544,8 +544,14 @@ static void main_nix_build(int argc, char * * argv)
544544
env["NIX_STORE"] = store->storeDir;
545545
env["NIX_BUILD_CORES"] = std::to_string(settings.buildCores);
546546

547-
ParsedDerivation parsedDrv(packageInfo.requireDrvPath(), drv);
548-
DerivationOptions drvOptions = DerivationOptions::fromParsedDerivation(parsedDrv);
547+
ParsedDerivation parsedDrv(drv);
548+
DerivationOptions drvOptions;
549+
try {
550+
drvOptions = DerivationOptions::fromParsedDerivation(parsedDrv);
551+
} catch (Error & e) {
552+
e.addTrace({}, "while parsing derivation '%s'", store->printStorePath(packageInfo.requireDrvPath()));
553+
throw;
554+
}
549555

550556
int fileNr = 0;
551557

0 commit comments

Comments
 (0)