mirror of
https://github.com/NixOS/nix
synced 2025-06-25 14:51:16 +02:00
Merge pull request #12896 from Mic92/no-dangling-reference
Fix -Wdangling-reference
This commit is contained in:
commit
2ace512a70
2 changed files with 14 additions and 12 deletions
|
@ -1228,13 +1228,13 @@ DerivationOutput DerivationOutput::fromJSON(
|
||||||
keys.insert(key);
|
keys.insert(key);
|
||||||
|
|
||||||
auto methodAlgo = [&]() -> std::pair<ContentAddressMethod, HashAlgorithm> {
|
auto methodAlgo = [&]() -> std::pair<ContentAddressMethod, HashAlgorithm> {
|
||||||
auto & method_ = getString(valueAt(json, "method"));
|
ContentAddressMethod method = ContentAddressMethod::parse(
|
||||||
ContentAddressMethod method = ContentAddressMethod::parse(method_);
|
getString(valueAt(json, "method")));
|
||||||
if (method == ContentAddressMethod::Raw::Text)
|
if (method == ContentAddressMethod::Raw::Text)
|
||||||
xpSettings.require(Xp::DynamicDerivations);
|
xpSettings.require(Xp::DynamicDerivations);
|
||||||
|
|
||||||
auto & hashAlgo_ = getString(valueAt(json, "hashAlgo"));
|
auto hashAlgo = parseHashAlgo(
|
||||||
auto hashAlgo = parseHashAlgo(hashAlgo_);
|
getString(valueAt(json, "hashAlgo")));
|
||||||
return { std::move(method), std::move(hashAlgo) };
|
return { std::move(method), std::move(hashAlgo) };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1351,7 +1351,8 @@ Derivation Derivation::fromJSON(
|
||||||
res.name = getString(valueAt(json, "name"));
|
res.name = getString(valueAt(json, "name"));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
for (auto & [outputName, output] : getObject(valueAt(json, "outputs"))) {
|
auto outputs = getObject(valueAt(json, "outputs"));
|
||||||
|
for (auto & [outputName, output] : outputs) {
|
||||||
res.outputs.insert_or_assign(
|
res.outputs.insert_or_assign(
|
||||||
outputName,
|
outputName,
|
||||||
DerivationOutput::fromJSON(store, res.name, outputName, output));
|
DerivationOutput::fromJSON(store, res.name, outputName, output));
|
||||||
|
@ -1362,7 +1363,8 @@ Derivation Derivation::fromJSON(
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
for (auto & input : getArray(valueAt(json, "inputSrcs")))
|
auto inputSrcs = getArray(valueAt(json, "inputSrcs"));
|
||||||
|
for (auto & input : inputSrcs)
|
||||||
res.inputSrcs.insert(store.parseStorePath(static_cast<const std::string &>(input)));
|
res.inputSrcs.insert(store.parseStorePath(static_cast<const std::string &>(input)));
|
||||||
} catch (Error & e) {
|
} catch (Error & e) {
|
||||||
e.addTrace({}, "while reading key 'inputSrcs'");
|
e.addTrace({}, "while reading key 'inputSrcs'");
|
||||||
|
@ -1375,13 +1377,15 @@ Derivation Derivation::fromJSON(
|
||||||
auto & json = getObject(_json);
|
auto & json = getObject(_json);
|
||||||
DerivedPathMap<StringSet>::ChildNode node;
|
DerivedPathMap<StringSet>::ChildNode node;
|
||||||
node.value = getStringSet(valueAt(json, "outputs"));
|
node.value = getStringSet(valueAt(json, "outputs"));
|
||||||
for (auto & [outputId, childNode] : getObject(valueAt(json, "dynamicOutputs"))) {
|
auto drvs = getObject(valueAt(json, "dynamicOutputs"));
|
||||||
|
for (auto & [outputId, childNode] : drvs) {
|
||||||
xpSettings.require(Xp::DynamicDerivations);
|
xpSettings.require(Xp::DynamicDerivations);
|
||||||
node.childMap[outputId] = doInput(childNode);
|
node.childMap[outputId] = doInput(childNode);
|
||||||
}
|
}
|
||||||
return node;
|
return node;
|
||||||
};
|
};
|
||||||
for (auto & [inputDrvPath, inputOutputs] : getObject(valueAt(json, "inputDrvs")))
|
auto drvs = getObject(valueAt(json, "inputDrvs"));
|
||||||
|
for (auto & [inputDrvPath, inputOutputs] : drvs)
|
||||||
res.inputDrvs.map[store.parseStorePath(inputDrvPath)] =
|
res.inputDrvs.map[store.parseStorePath(inputDrvPath)] =
|
||||||
doInput(inputOutputs);
|
doInput(inputOutputs);
|
||||||
} catch (Error & e) {
|
} catch (Error & e) {
|
||||||
|
|
|
@ -63,9 +63,7 @@ TEST(valueAt, simpleObject) {
|
||||||
|
|
||||||
auto nested = R"({ "hello": { "world": "" } })"_json;
|
auto nested = R"({ "hello": { "world": "" } })"_json;
|
||||||
|
|
||||||
auto & nestedObject = valueAt(getObject(nested), "hello");
|
ASSERT_EQ(valueAt(valueAt(getObject(nested), "hello"), "world"), "");
|
||||||
|
|
||||||
ASSERT_EQ(valueAt(nestedObject, "world"), "");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(valueAt, missingKey) {
|
TEST(valueAt, missingKey) {
|
||||||
|
@ -83,7 +81,7 @@ TEST(getObject, rightAssertions) {
|
||||||
|
|
||||||
auto nested = R"({ "object": { "object": {} } })"_json;
|
auto nested = R"({ "object": { "object": {} } })"_json;
|
||||||
|
|
||||||
auto & nestedObject = getObject(valueAt(getObject(nested), "object"));
|
auto nestedObject = getObject(valueAt(getObject(nested), "object"));
|
||||||
|
|
||||||
ASSERT_EQ(nestedObject, getObject(nlohmann::json::parse(R"({ "object": {} })")));
|
ASSERT_EQ(nestedObject, getObject(nlohmann::json::parse(R"({ "object": {} })")));
|
||||||
ASSERT_EQ(getObject(valueAt(getObject(nestedObject), "object")), (nlohmann::json::object_t {}));
|
ASSERT_EQ(getObject(valueAt(getObject(nestedObject), "object")), (nlohmann::json::object_t {}));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue