From a7c0cff07f3e1af60bdbcd5bf7e13f8ae768da90 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Wed, 11 Jan 2023 02:00:44 -0500 Subject: [PATCH] Rename `OutputPath` -> `ExtendedOutputPath` Do this prior to making a new more limitted `OutputPath` we will use in more places. --- src/libcmd/installables.cc | 28 ++++++++++++++-------------- src/libcmd/installables.hh | 6 +++--- src/libexpr/flake/flakeref.cc | 6 +++--- src/libexpr/flake/flakeref.hh | 2 +- src/libstore/outputs-spec.cc | 26 +++++++++++++------------- src/libstore/outputs-spec.hh | 12 ++++++------ src/libstore/tests/outputs-spec.cc | 26 +++++++++++++------------- src/nix/bundle.cc | 4 ++-- src/nix/profile.cc | 10 +++++----- 9 files changed, 60 insertions(+), 60 deletions(-) diff --git a/src/libcmd/installables.cc b/src/libcmd/installables.cc index ce40986d0..b80ae4df1 100644 --- a/src/libcmd/installables.cc +++ b/src/libcmd/installables.cc @@ -446,19 +446,19 @@ struct InstallableAttrPath : InstallableValue SourceExprCommand & cmd; RootValue v; std::string attrPath; - OutputsSpec outputsSpec; + ExtendedOutputsSpec extendedOutputsSpec; InstallableAttrPath( ref state, SourceExprCommand & cmd, Value * v, const std::string & attrPath, - OutputsSpec outputsSpec) + ExtendedOutputsSpec extendedOutputsSpec) : InstallableValue(state) , cmd(cmd) , v(allocRootValue(v)) , attrPath(attrPath) - , outputsSpec(std::move(outputsSpec)) + , extendedOutputsSpec(std::move(extendedOutputsSpec)) { } std::string what() const override { return attrPath; } @@ -490,10 +490,10 @@ struct InstallableAttrPath : InstallableValue std::set outputsToInstall; - if (auto outputNames = std::get_if(&outputsSpec)) + if (auto outputNames = std::get_if(&extendedOutputsSpec)) outputsToInstall = *outputNames; else - for (auto & output : drvInfo.queryOutputs(false, std::get_if(&outputsSpec))) + for (auto & output : drvInfo.queryOutputs(false, std::get_if(&extendedOutputsSpec))) outputsToInstall.insert(output.first); auto derivedPath = byDrvPath.emplace(*drvPath, DerivedPath::Built { .drvPath = *drvPath }).first; @@ -581,7 +581,7 @@ InstallableFlake::InstallableFlake( ref state, FlakeRef && flakeRef, std::string_view fragment, - OutputsSpec outputsSpec, + ExtendedOutputsSpec extendedOutputsSpec, Strings attrPaths, Strings prefixes, const flake::LockFlags & lockFlags) @@ -589,7 +589,7 @@ InstallableFlake::InstallableFlake( flakeRef(flakeRef), attrPaths(fragment == "" ? attrPaths : Strings{(std::string) fragment}), prefixes(fragment == "" ? Strings{} : prefixes), - outputsSpec(std::move(outputsSpec)), + extendedOutputsSpec(std::move(extendedOutputsSpec)), lockFlags(lockFlags) { if (cmd && cmd->getAutoArgs(*state)->size()) @@ -657,7 +657,7 @@ DerivedPathsWithInfo InstallableFlake::toDerivedPaths() priority = aPriority->getInt(); } - if (outputsToInstall.empty() || std::get_if(&outputsSpec)) { + if (outputsToInstall.empty() || std::get_if(&extendedOutputsSpec)) { outputsToInstall.clear(); if (auto aOutputs = attr->maybeGetAttr(state->sOutputs)) for (auto & s : aOutputs->getListOfStrings()) @@ -667,7 +667,7 @@ DerivedPathsWithInfo InstallableFlake::toDerivedPaths() if (outputsToInstall.empty()) outputsToInstall.insert("out"); - if (auto outputNames = std::get_if(&outputsSpec)) + if (auto outputNames = std::get_if(&extendedOutputsSpec)) outputsToInstall = *outputNames; return {{ @@ -680,7 +680,7 @@ DerivedPathsWithInfo InstallableFlake::toDerivedPaths() .originalRef = flakeRef, .resolvedRef = getLockedFlake()->flake.lockedRef, .attrPath = attrPath, - .outputsSpec = outputsSpec, + .extendedOutputsSpec = extendedOutputsSpec, } }}; } @@ -797,12 +797,12 @@ std::vector> SourceExprCommand::parseInstallables( } for (auto & s : ss) { - auto [prefix, outputsSpec] = OutputsSpec::parse(s); + auto [prefix, extendedOutputsSpec] = ExtendedOutputsSpec::parse(s); result.push_back( std::make_shared( state, *this, vFile, prefix == "." ? "" : prefix, - outputsSpec)); + extendedOutputsSpec)); } } else { @@ -837,13 +837,13 @@ std::vector> SourceExprCommand::parseInstallables( } try { - auto [flakeRef, fragment, outputsSpec] = parseFlakeRefWithFragmentAndOutputsSpec(s, absPath(".")); + auto [flakeRef, fragment, extendedOutputsSpec] = parseFlakeRefWithFragmentAndExtendedOutputsSpec(s, absPath(".")); result.push_back(std::make_shared( this, getEvalState(), std::move(flakeRef), fragment, - outputsSpec, + extendedOutputsSpec, getDefaultFlakeAttrPaths(), getDefaultFlakeAttrPathPrefixes(), lockFlags)); diff --git a/src/libcmd/installables.hh b/src/libcmd/installables.hh index 9b92cc4be..3d12639b0 100644 --- a/src/libcmd/installables.hh +++ b/src/libcmd/installables.hh @@ -59,7 +59,7 @@ struct ExtraPathInfo std::optional resolvedRef; std::optional attrPath; // FIXME: merge with DerivedPath's 'outputs' field? - std::optional outputsSpec; + std::optional extendedOutputsSpec; }; /* A derived path with any additional info that commands might @@ -169,7 +169,7 @@ struct InstallableFlake : InstallableValue FlakeRef flakeRef; Strings attrPaths; Strings prefixes; - OutputsSpec outputsSpec; + ExtendedOutputsSpec extendedOutputsSpec; const flake::LockFlags & lockFlags; mutable std::shared_ptr _lockedFlake; @@ -178,7 +178,7 @@ struct InstallableFlake : InstallableValue ref state, FlakeRef && flakeRef, std::string_view fragment, - OutputsSpec outputsSpec, + ExtendedOutputsSpec extendedOutputsSpec, Strings attrPaths, Strings prefixes, const flake::LockFlags & lockFlags); diff --git a/src/libexpr/flake/flakeref.cc b/src/libexpr/flake/flakeref.cc index cfa279fb4..bc61e2c9a 100644 --- a/src/libexpr/flake/flakeref.cc +++ b/src/libexpr/flake/flakeref.cc @@ -238,15 +238,15 @@ std::pair FlakeRef::fetchTree(ref store) const return {std::move(tree), FlakeRef(std::move(lockedInput), subdir)}; } -std::tuple parseFlakeRefWithFragmentAndOutputsSpec( +std::tuple parseFlakeRefWithFragmentAndExtendedOutputsSpec( const std::string & url, const std::optional & baseDir, bool allowMissing, bool isFlake) { - auto [prefix, outputsSpec] = OutputsSpec::parse(url); + auto [prefix, extendedOutputsSpec] = ExtendedOutputsSpec::parse(url); auto [flakeRef, fragment] = parseFlakeRefWithFragment(prefix, baseDir, allowMissing, isFlake); - return {std::move(flakeRef), fragment, outputsSpec}; + return {std::move(flakeRef), fragment, extendedOutputsSpec}; } } diff --git a/src/libexpr/flake/flakeref.hh b/src/libexpr/flake/flakeref.hh index 4ec79fb73..c4142fc20 100644 --- a/src/libexpr/flake/flakeref.hh +++ b/src/libexpr/flake/flakeref.hh @@ -80,7 +80,7 @@ std::pair parseFlakeRefWithFragment( std::optional> maybeParseFlakeRefWithFragment( const std::string & url, const std::optional & baseDir = {}); -std::tuple parseFlakeRefWithFragmentAndOutputsSpec( +std::tuple parseFlakeRefWithFragmentAndExtendedOutputsSpec( const std::string & url, const std::optional & baseDir = {}, bool allowMissing = false, diff --git a/src/libstore/outputs-spec.cc b/src/libstore/outputs-spec.cc index b5ea7e325..c446976bc 100644 --- a/src/libstore/outputs-spec.cc +++ b/src/libstore/outputs-spec.cc @@ -6,7 +6,7 @@ namespace nix { -std::pair OutputsSpec::parse(std::string s) +std::pair ExtendedOutputsSpec::parse(std::string s) { static std::regex regex(R"((.*)\^((\*)|([a-z]+(,[a-z]+)*)))"); @@ -20,43 +20,43 @@ std::pair OutputsSpec::parse(std::string s) return {match[1], tokenizeString(match[4].str(), ",")}; } -std::string OutputsSpec::to_string() const +std::string ExtendedOutputsSpec::to_string() const { return std::visit(overloaded { - [&](const OutputsSpec::Default &) -> std::string { + [&](const ExtendedOutputsSpec::Default &) -> std::string { return ""; }, - [&](const OutputsSpec::All &) -> std::string { + [&](const ExtendedOutputsSpec::All &) -> std::string { return "*"; }, - [&](const OutputsSpec::Names & outputNames) -> std::string { + [&](const ExtendedOutputsSpec::Names & outputNames) -> std::string { return "^" + concatStringsSep(",", outputNames); }, }, raw()); } -void to_json(nlohmann::json & json, const OutputsSpec & outputsSpec) +void to_json(nlohmann::json & json, const ExtendedOutputsSpec & extendedOutputsSpec) { - if (std::get_if(&outputsSpec)) + if (std::get_if(&extendedOutputsSpec)) json = nullptr; - else if (std::get_if(&outputsSpec)) + else if (std::get_if(&extendedOutputsSpec)) json = std::vector({"*"}); - else if (auto outputNames = std::get_if(&outputsSpec)) + else if (auto outputNames = std::get_if(&extendedOutputsSpec)) json = *outputNames; } -void from_json(const nlohmann::json & json, OutputsSpec & outputsSpec) +void from_json(const nlohmann::json & json, ExtendedOutputsSpec & extendedOutputsSpec) { if (json.is_null()) - outputsSpec = DefaultOutputs(); + extendedOutputsSpec = DefaultOutputs(); else { auto names = json.get(); if (names == OutputNames({"*"})) - outputsSpec = AllOutputs(); + extendedOutputsSpec = AllOutputs(); else - outputsSpec = names; + extendedOutputsSpec = names; } } diff --git a/src/libstore/outputs-spec.hh b/src/libstore/outputs-spec.hh index 6f886ccb6..5ed711a62 100644 --- a/src/libstore/outputs-spec.hh +++ b/src/libstore/outputs-spec.hh @@ -17,10 +17,10 @@ struct DefaultOutputs { bool operator < (const DefaultOutputs & _) const { return false; } }; -typedef std::variant _OutputsSpecRaw; +typedef std::variant _ExtendedOutputsSpecRaw; -struct OutputsSpec : _OutputsSpecRaw { - using Raw = _OutputsSpecRaw; +struct ExtendedOutputsSpec : _ExtendedOutputsSpecRaw { + using Raw = _ExtendedOutputsSpecRaw; using Raw::Raw; using Names = OutputNames; @@ -33,12 +33,12 @@ struct OutputsSpec : _OutputsSpecRaw { /* Parse a string of the form 'prefix^output1,...outputN' or 'prefix^*', returning the prefix and the outputs spec. */ - static std::pair parse(std::string s); + static std::pair parse(std::string s); std::string to_string() const; }; -void to_json(nlohmann::json &, const OutputsSpec &); -void from_json(const nlohmann::json &, OutputsSpec &); +void to_json(nlohmann::json &, const ExtendedOutputsSpec &); +void from_json(const nlohmann::json &, ExtendedOutputsSpec &); } diff --git a/src/libstore/tests/outputs-spec.cc b/src/libstore/tests/outputs-spec.cc index 552380837..a3dd42341 100644 --- a/src/libstore/tests/outputs-spec.cc +++ b/src/libstore/tests/outputs-spec.cc @@ -4,42 +4,42 @@ namespace nix { -TEST(OutputsSpec_parse, basic) +TEST(ExtendedOutputsSpec_parse, basic) { { - auto [prefix, outputsSpec] = OutputsSpec::parse("foo"); + auto [prefix, extendedOutputsSpec] = ExtendedOutputsSpec::parse("foo"); ASSERT_EQ(prefix, "foo"); - ASSERT_TRUE(std::get_if(&outputsSpec)); + ASSERT_TRUE(std::get_if(&extendedOutputsSpec)); } { - auto [prefix, outputsSpec] = OutputsSpec::parse("foo^*"); + auto [prefix, extendedOutputsSpec] = ExtendedOutputsSpec::parse("foo^*"); ASSERT_EQ(prefix, "foo"); - ASSERT_TRUE(std::get_if(&outputsSpec)); + ASSERT_TRUE(std::get_if(&extendedOutputsSpec)); } { - auto [prefix, outputsSpec] = OutputsSpec::parse("foo^out"); + auto [prefix, extendedOutputsSpec] = ExtendedOutputsSpec::parse("foo^out"); ASSERT_EQ(prefix, "foo"); - ASSERT_TRUE(std::get(outputsSpec) == OutputNames({"out"})); + ASSERT_TRUE(std::get(extendedOutputsSpec) == OutputNames({"out"})); } { - auto [prefix, outputsSpec] = OutputsSpec::parse("foo^out,bin"); + auto [prefix, extendedOutputsSpec] = ExtendedOutputsSpec::parse("foo^out,bin"); ASSERT_EQ(prefix, "foo"); - ASSERT_TRUE(std::get(outputsSpec) == OutputNames({"out", "bin"})); + ASSERT_TRUE(std::get(extendedOutputsSpec) == OutputNames({"out", "bin"})); } { - auto [prefix, outputsSpec] = OutputsSpec::parse("foo^bar^out,bin"); + auto [prefix, extendedOutputsSpec] = ExtendedOutputsSpec::parse("foo^bar^out,bin"); ASSERT_EQ(prefix, "foo^bar"); - ASSERT_TRUE(std::get(outputsSpec) == OutputNames({"out", "bin"})); + ASSERT_TRUE(std::get(extendedOutputsSpec) == OutputNames({"out", "bin"})); } { - auto [prefix, outputsSpec] = OutputsSpec::parse("foo^&*()"); + auto [prefix, extendedOutputsSpec] = ExtendedOutputsSpec::parse("foo^&*()"); ASSERT_EQ(prefix, "foo^&*()"); - ASSERT_TRUE(std::get_if(&outputsSpec)); + ASSERT_TRUE(std::get_if(&extendedOutputsSpec)); } } diff --git a/src/nix/bundle.cc b/src/nix/bundle.cc index 74a7973b0..a09dadff4 100644 --- a/src/nix/bundle.cc +++ b/src/nix/bundle.cc @@ -75,10 +75,10 @@ struct CmdBundle : InstallableCommand auto val = installable->toValue(*evalState).first; - auto [bundlerFlakeRef, bundlerName, outputsSpec] = parseFlakeRefWithFragmentAndOutputsSpec(bundler, absPath(".")); + auto [bundlerFlakeRef, bundlerName, extendedOutputsSpec] = parseFlakeRefWithFragmentAndExtendedOutputsSpec(bundler, absPath(".")); const flake::LockFlags lockFlags{ .writeLockFile = false }; InstallableFlake bundler{this, - evalState, std::move(bundlerFlakeRef), bundlerName, outputsSpec, + evalState, std::move(bundlerFlakeRef), bundlerName, extendedOutputsSpec, {"bundlers." + settings.thisSystem.get() + ".default", "defaultBundler." + settings.thisSystem.get() }, diff --git a/src/nix/profile.cc b/src/nix/profile.cc index 346c4e117..32364e720 100644 --- a/src/nix/profile.cc +++ b/src/nix/profile.cc @@ -22,7 +22,7 @@ struct ProfileElementSource // FIXME: record original attrpath. FlakeRef resolvedRef; std::string attrPath; - OutputsSpec outputs; + ExtendedOutputsSpec outputs; bool operator < (const ProfileElementSource & other) const { @@ -126,7 +126,7 @@ struct ProfileManifest parseFlakeRef(e[sOriginalUrl]), parseFlakeRef(e[sUrl]), e["attrPath"], - e["outputs"].get() + e["outputs"].get() }; } elements.emplace_back(std::move(element)); @@ -308,12 +308,12 @@ struct CmdProfileInstall : InstallablesCommand, MixDefaultProfile auto & [res, info] = builtPaths[installable.get()]; - if (info.originalRef && info.resolvedRef && info.attrPath && info.outputsSpec) { + if (info.originalRef && info.resolvedRef && info.attrPath && info.extendedOutputsSpec) { element.source = ProfileElementSource { .originalRef = *info.originalRef, .resolvedRef = *info.resolvedRef, .attrPath = *info.attrPath, - .outputs = *info.outputsSpec, + .outputs = *info.extendedOutputsSpec, }; } @@ -497,7 +497,7 @@ struct CmdProfileUpgrade : virtual SourceExprCommand, MixDefaultProfile, MixProf .originalRef = installable->flakeRef, .resolvedRef = *info.resolvedRef, .attrPath = *info.attrPath, - .outputs = installable->outputsSpec, + .outputs = installable->extendedOutputsSpec, }; installables.push_back(installable);