Rename OutputPath -> ExtendedOutputPath

Do this prior to making a new more limitted `OutputPath` we will use in
more places.
This commit is contained in:
John Ericson 2023-01-11 02:00:44 -05:00
parent a8f45b5e5a
commit a7c0cff07f
9 changed files with 60 additions and 60 deletions

View file

@ -446,19 +446,19 @@ struct InstallableAttrPath : InstallableValue
SourceExprCommand & cmd; SourceExprCommand & cmd;
RootValue v; RootValue v;
std::string attrPath; std::string attrPath;
OutputsSpec outputsSpec; ExtendedOutputsSpec extendedOutputsSpec;
InstallableAttrPath( InstallableAttrPath(
ref<EvalState> state, ref<EvalState> state,
SourceExprCommand & cmd, SourceExprCommand & cmd,
Value * v, Value * v,
const std::string & attrPath, const std::string & attrPath,
OutputsSpec outputsSpec) ExtendedOutputsSpec extendedOutputsSpec)
: InstallableValue(state) : InstallableValue(state)
, cmd(cmd) , cmd(cmd)
, v(allocRootValue(v)) , v(allocRootValue(v))
, attrPath(attrPath) , attrPath(attrPath)
, outputsSpec(std::move(outputsSpec)) , extendedOutputsSpec(std::move(extendedOutputsSpec))
{ } { }
std::string what() const override { return attrPath; } std::string what() const override { return attrPath; }
@ -490,10 +490,10 @@ struct InstallableAttrPath : InstallableValue
std::set<std::string> outputsToInstall; std::set<std::string> outputsToInstall;
if (auto outputNames = std::get_if<OutputNames>(&outputsSpec)) if (auto outputNames = std::get_if<OutputNames>(&extendedOutputsSpec))
outputsToInstall = *outputNames; outputsToInstall = *outputNames;
else else
for (auto & output : drvInfo.queryOutputs(false, std::get_if<DefaultOutputs>(&outputsSpec))) for (auto & output : drvInfo.queryOutputs(false, std::get_if<DefaultOutputs>(&extendedOutputsSpec)))
outputsToInstall.insert(output.first); outputsToInstall.insert(output.first);
auto derivedPath = byDrvPath.emplace(*drvPath, DerivedPath::Built { .drvPath = *drvPath }).first; auto derivedPath = byDrvPath.emplace(*drvPath, DerivedPath::Built { .drvPath = *drvPath }).first;
@ -581,7 +581,7 @@ InstallableFlake::InstallableFlake(
ref<EvalState> state, ref<EvalState> state,
FlakeRef && flakeRef, FlakeRef && flakeRef,
std::string_view fragment, std::string_view fragment,
OutputsSpec outputsSpec, ExtendedOutputsSpec extendedOutputsSpec,
Strings attrPaths, Strings attrPaths,
Strings prefixes, Strings prefixes,
const flake::LockFlags & lockFlags) const flake::LockFlags & lockFlags)
@ -589,7 +589,7 @@ InstallableFlake::InstallableFlake(
flakeRef(flakeRef), flakeRef(flakeRef),
attrPaths(fragment == "" ? attrPaths : Strings{(std::string) fragment}), attrPaths(fragment == "" ? attrPaths : Strings{(std::string) fragment}),
prefixes(fragment == "" ? Strings{} : prefixes), prefixes(fragment == "" ? Strings{} : prefixes),
outputsSpec(std::move(outputsSpec)), extendedOutputsSpec(std::move(extendedOutputsSpec)),
lockFlags(lockFlags) lockFlags(lockFlags)
{ {
if (cmd && cmd->getAutoArgs(*state)->size()) if (cmd && cmd->getAutoArgs(*state)->size())
@ -657,7 +657,7 @@ DerivedPathsWithInfo InstallableFlake::toDerivedPaths()
priority = aPriority->getInt(); priority = aPriority->getInt();
} }
if (outputsToInstall.empty() || std::get_if<AllOutputs>(&outputsSpec)) { if (outputsToInstall.empty() || std::get_if<AllOutputs>(&extendedOutputsSpec)) {
outputsToInstall.clear(); outputsToInstall.clear();
if (auto aOutputs = attr->maybeGetAttr(state->sOutputs)) if (auto aOutputs = attr->maybeGetAttr(state->sOutputs))
for (auto & s : aOutputs->getListOfStrings()) for (auto & s : aOutputs->getListOfStrings())
@ -667,7 +667,7 @@ DerivedPathsWithInfo InstallableFlake::toDerivedPaths()
if (outputsToInstall.empty()) if (outputsToInstall.empty())
outputsToInstall.insert("out"); outputsToInstall.insert("out");
if (auto outputNames = std::get_if<OutputNames>(&outputsSpec)) if (auto outputNames = std::get_if<OutputNames>(&extendedOutputsSpec))
outputsToInstall = *outputNames; outputsToInstall = *outputNames;
return {{ return {{
@ -680,7 +680,7 @@ DerivedPathsWithInfo InstallableFlake::toDerivedPaths()
.originalRef = flakeRef, .originalRef = flakeRef,
.resolvedRef = getLockedFlake()->flake.lockedRef, .resolvedRef = getLockedFlake()->flake.lockedRef,
.attrPath = attrPath, .attrPath = attrPath,
.outputsSpec = outputsSpec, .extendedOutputsSpec = extendedOutputsSpec,
} }
}}; }};
} }
@ -797,12 +797,12 @@ std::vector<std::shared_ptr<Installable>> SourceExprCommand::parseInstallables(
} }
for (auto & s : ss) { for (auto & s : ss) {
auto [prefix, outputsSpec] = OutputsSpec::parse(s); auto [prefix, extendedOutputsSpec] = ExtendedOutputsSpec::parse(s);
result.push_back( result.push_back(
std::make_shared<InstallableAttrPath>( std::make_shared<InstallableAttrPath>(
state, *this, vFile, state, *this, vFile,
prefix == "." ? "" : prefix, prefix == "." ? "" : prefix,
outputsSpec)); extendedOutputsSpec));
} }
} else { } else {
@ -837,13 +837,13 @@ std::vector<std::shared_ptr<Installable>> SourceExprCommand::parseInstallables(
} }
try { try {
auto [flakeRef, fragment, outputsSpec] = parseFlakeRefWithFragmentAndOutputsSpec(s, absPath(".")); auto [flakeRef, fragment, extendedOutputsSpec] = parseFlakeRefWithFragmentAndExtendedOutputsSpec(s, absPath("."));
result.push_back(std::make_shared<InstallableFlake>( result.push_back(std::make_shared<InstallableFlake>(
this, this,
getEvalState(), getEvalState(),
std::move(flakeRef), std::move(flakeRef),
fragment, fragment,
outputsSpec, extendedOutputsSpec,
getDefaultFlakeAttrPaths(), getDefaultFlakeAttrPaths(),
getDefaultFlakeAttrPathPrefixes(), getDefaultFlakeAttrPathPrefixes(),
lockFlags)); lockFlags));

View file

@ -59,7 +59,7 @@ struct ExtraPathInfo
std::optional<FlakeRef> resolvedRef; std::optional<FlakeRef> resolvedRef;
std::optional<std::string> attrPath; std::optional<std::string> attrPath;
// FIXME: merge with DerivedPath's 'outputs' field? // FIXME: merge with DerivedPath's 'outputs' field?
std::optional<OutputsSpec> outputsSpec; std::optional<ExtendedOutputsSpec> extendedOutputsSpec;
}; };
/* A derived path with any additional info that commands might /* A derived path with any additional info that commands might
@ -169,7 +169,7 @@ struct InstallableFlake : InstallableValue
FlakeRef flakeRef; FlakeRef flakeRef;
Strings attrPaths; Strings attrPaths;
Strings prefixes; Strings prefixes;
OutputsSpec outputsSpec; ExtendedOutputsSpec extendedOutputsSpec;
const flake::LockFlags & lockFlags; const flake::LockFlags & lockFlags;
mutable std::shared_ptr<flake::LockedFlake> _lockedFlake; mutable std::shared_ptr<flake::LockedFlake> _lockedFlake;
@ -178,7 +178,7 @@ struct InstallableFlake : InstallableValue
ref<EvalState> state, ref<EvalState> state,
FlakeRef && flakeRef, FlakeRef && flakeRef,
std::string_view fragment, std::string_view fragment,
OutputsSpec outputsSpec, ExtendedOutputsSpec extendedOutputsSpec,
Strings attrPaths, Strings attrPaths,
Strings prefixes, Strings prefixes,
const flake::LockFlags & lockFlags); const flake::LockFlags & lockFlags);

View file

@ -238,15 +238,15 @@ std::pair<fetchers::Tree, FlakeRef> FlakeRef::fetchTree(ref<Store> store) const
return {std::move(tree), FlakeRef(std::move(lockedInput), subdir)}; return {std::move(tree), FlakeRef(std::move(lockedInput), subdir)};
} }
std::tuple<FlakeRef, std::string, OutputsSpec> parseFlakeRefWithFragmentAndOutputsSpec( std::tuple<FlakeRef, std::string, ExtendedOutputsSpec> parseFlakeRefWithFragmentAndExtendedOutputsSpec(
const std::string & url, const std::string & url,
const std::optional<Path> & baseDir, const std::optional<Path> & baseDir,
bool allowMissing, bool allowMissing,
bool isFlake) bool isFlake)
{ {
auto [prefix, outputsSpec] = OutputsSpec::parse(url); auto [prefix, extendedOutputsSpec] = ExtendedOutputsSpec::parse(url);
auto [flakeRef, fragment] = parseFlakeRefWithFragment(prefix, baseDir, allowMissing, isFlake); auto [flakeRef, fragment] = parseFlakeRefWithFragment(prefix, baseDir, allowMissing, isFlake);
return {std::move(flakeRef), fragment, outputsSpec}; return {std::move(flakeRef), fragment, extendedOutputsSpec};
} }
} }

View file

@ -80,7 +80,7 @@ std::pair<FlakeRef, std::string> parseFlakeRefWithFragment(
std::optional<std::pair<FlakeRef, std::string>> maybeParseFlakeRefWithFragment( std::optional<std::pair<FlakeRef, std::string>> maybeParseFlakeRefWithFragment(
const std::string & url, const std::optional<Path> & baseDir = {}); const std::string & url, const std::optional<Path> & baseDir = {});
std::tuple<FlakeRef, std::string, OutputsSpec> parseFlakeRefWithFragmentAndOutputsSpec( std::tuple<FlakeRef, std::string, ExtendedOutputsSpec> parseFlakeRefWithFragmentAndExtendedOutputsSpec(
const std::string & url, const std::string & url,
const std::optional<Path> & baseDir = {}, const std::optional<Path> & baseDir = {},
bool allowMissing = false, bool allowMissing = false,

View file

@ -6,7 +6,7 @@
namespace nix { namespace nix {
std::pair<std::string, OutputsSpec> OutputsSpec::parse(std::string s) std::pair<std::string, ExtendedOutputsSpec> ExtendedOutputsSpec::parse(std::string s)
{ {
static std::regex regex(R"((.*)\^((\*)|([a-z]+(,[a-z]+)*)))"); static std::regex regex(R"((.*)\^((\*)|([a-z]+(,[a-z]+)*)))");
@ -20,43 +20,43 @@ std::pair<std::string, OutputsSpec> OutputsSpec::parse(std::string s)
return {match[1], tokenizeString<OutputNames>(match[4].str(), ",")}; return {match[1], tokenizeString<OutputNames>(match[4].str(), ",")};
} }
std::string OutputsSpec::to_string() const std::string ExtendedOutputsSpec::to_string() const
{ {
return std::visit(overloaded { return std::visit(overloaded {
[&](const OutputsSpec::Default &) -> std::string { [&](const ExtendedOutputsSpec::Default &) -> std::string {
return ""; return "";
}, },
[&](const OutputsSpec::All &) -> std::string { [&](const ExtendedOutputsSpec::All &) -> std::string {
return "*"; return "*";
}, },
[&](const OutputsSpec::Names & outputNames) -> std::string { [&](const ExtendedOutputsSpec::Names & outputNames) -> std::string {
return "^" + concatStringsSep(",", outputNames); return "^" + concatStringsSep(",", outputNames);
}, },
}, raw()); }, raw());
} }
void to_json(nlohmann::json & json, const OutputsSpec & outputsSpec) void to_json(nlohmann::json & json, const ExtendedOutputsSpec & extendedOutputsSpec)
{ {
if (std::get_if<DefaultOutputs>(&outputsSpec)) if (std::get_if<DefaultOutputs>(&extendedOutputsSpec))
json = nullptr; json = nullptr;
else if (std::get_if<AllOutputs>(&outputsSpec)) else if (std::get_if<AllOutputs>(&extendedOutputsSpec))
json = std::vector<std::string>({"*"}); json = std::vector<std::string>({"*"});
else if (auto outputNames = std::get_if<OutputNames>(&outputsSpec)) else if (auto outputNames = std::get_if<OutputNames>(&extendedOutputsSpec))
json = *outputNames; json = *outputNames;
} }
void from_json(const nlohmann::json & json, OutputsSpec & outputsSpec) void from_json(const nlohmann::json & json, ExtendedOutputsSpec & extendedOutputsSpec)
{ {
if (json.is_null()) if (json.is_null())
outputsSpec = DefaultOutputs(); extendedOutputsSpec = DefaultOutputs();
else { else {
auto names = json.get<OutputNames>(); auto names = json.get<OutputNames>();
if (names == OutputNames({"*"})) if (names == OutputNames({"*"}))
outputsSpec = AllOutputs(); extendedOutputsSpec = AllOutputs();
else else
outputsSpec = names; extendedOutputsSpec = names;
} }
} }

View file

@ -17,10 +17,10 @@ struct DefaultOutputs {
bool operator < (const DefaultOutputs & _) const { return false; } bool operator < (const DefaultOutputs & _) const { return false; }
}; };
typedef std::variant<DefaultOutputs, AllOutputs, OutputNames> _OutputsSpecRaw; typedef std::variant<DefaultOutputs, AllOutputs, OutputNames> _ExtendedOutputsSpecRaw;
struct OutputsSpec : _OutputsSpecRaw { struct ExtendedOutputsSpec : _ExtendedOutputsSpecRaw {
using Raw = _OutputsSpecRaw; using Raw = _ExtendedOutputsSpecRaw;
using Raw::Raw; using Raw::Raw;
using Names = OutputNames; using Names = OutputNames;
@ -33,12 +33,12 @@ struct OutputsSpec : _OutputsSpecRaw {
/* Parse a string of the form 'prefix^output1,...outputN' or /* Parse a string of the form 'prefix^output1,...outputN' or
'prefix^*', returning the prefix and the outputs spec. */ 'prefix^*', returning the prefix and the outputs spec. */
static std::pair<std::string, OutputsSpec> parse(std::string s); static std::pair<std::string, ExtendedOutputsSpec> parse(std::string s);
std::string to_string() const; std::string to_string() const;
}; };
void to_json(nlohmann::json &, const OutputsSpec &); void to_json(nlohmann::json &, const ExtendedOutputsSpec &);
void from_json(const nlohmann::json &, OutputsSpec &); void from_json(const nlohmann::json &, ExtendedOutputsSpec &);
} }

View file

@ -4,42 +4,42 @@
namespace nix { 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_EQ(prefix, "foo");
ASSERT_TRUE(std::get_if<DefaultOutputs>(&outputsSpec)); ASSERT_TRUE(std::get_if<DefaultOutputs>(&extendedOutputsSpec));
} }
{ {
auto [prefix, outputsSpec] = OutputsSpec::parse("foo^*"); auto [prefix, extendedOutputsSpec] = ExtendedOutputsSpec::parse("foo^*");
ASSERT_EQ(prefix, "foo"); ASSERT_EQ(prefix, "foo");
ASSERT_TRUE(std::get_if<AllOutputs>(&outputsSpec)); ASSERT_TRUE(std::get_if<AllOutputs>(&extendedOutputsSpec));
} }
{ {
auto [prefix, outputsSpec] = OutputsSpec::parse("foo^out"); auto [prefix, extendedOutputsSpec] = ExtendedOutputsSpec::parse("foo^out");
ASSERT_EQ(prefix, "foo"); ASSERT_EQ(prefix, "foo");
ASSERT_TRUE(std::get<OutputNames>(outputsSpec) == OutputNames({"out"})); ASSERT_TRUE(std::get<OutputNames>(extendedOutputsSpec) == OutputNames({"out"}));
} }
{ {
auto [prefix, outputsSpec] = OutputsSpec::parse("foo^out,bin"); auto [prefix, extendedOutputsSpec] = ExtendedOutputsSpec::parse("foo^out,bin");
ASSERT_EQ(prefix, "foo"); ASSERT_EQ(prefix, "foo");
ASSERT_TRUE(std::get<OutputNames>(outputsSpec) == OutputNames({"out", "bin"})); ASSERT_TRUE(std::get<OutputNames>(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_EQ(prefix, "foo^bar");
ASSERT_TRUE(std::get<OutputNames>(outputsSpec) == OutputNames({"out", "bin"})); ASSERT_TRUE(std::get<OutputNames>(extendedOutputsSpec) == OutputNames({"out", "bin"}));
} }
{ {
auto [prefix, outputsSpec] = OutputsSpec::parse("foo^&*()"); auto [prefix, extendedOutputsSpec] = ExtendedOutputsSpec::parse("foo^&*()");
ASSERT_EQ(prefix, "foo^&*()"); ASSERT_EQ(prefix, "foo^&*()");
ASSERT_TRUE(std::get_if<DefaultOutputs>(&outputsSpec)); ASSERT_TRUE(std::get_if<DefaultOutputs>(&extendedOutputsSpec));
} }
} }

View file

@ -75,10 +75,10 @@ struct CmdBundle : InstallableCommand
auto val = installable->toValue(*evalState).first; 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 }; const flake::LockFlags lockFlags{ .writeLockFile = false };
InstallableFlake bundler{this, InstallableFlake bundler{this,
evalState, std::move(bundlerFlakeRef), bundlerName, outputsSpec, evalState, std::move(bundlerFlakeRef), bundlerName, extendedOutputsSpec,
{"bundlers." + settings.thisSystem.get() + ".default", {"bundlers." + settings.thisSystem.get() + ".default",
"defaultBundler." + settings.thisSystem.get() "defaultBundler." + settings.thisSystem.get()
}, },

View file

@ -22,7 +22,7 @@ struct ProfileElementSource
// FIXME: record original attrpath. // FIXME: record original attrpath.
FlakeRef resolvedRef; FlakeRef resolvedRef;
std::string attrPath; std::string attrPath;
OutputsSpec outputs; ExtendedOutputsSpec outputs;
bool operator < (const ProfileElementSource & other) const bool operator < (const ProfileElementSource & other) const
{ {
@ -126,7 +126,7 @@ struct ProfileManifest
parseFlakeRef(e[sOriginalUrl]), parseFlakeRef(e[sOriginalUrl]),
parseFlakeRef(e[sUrl]), parseFlakeRef(e[sUrl]),
e["attrPath"], e["attrPath"],
e["outputs"].get<OutputsSpec>() e["outputs"].get<ExtendedOutputsSpec>()
}; };
} }
elements.emplace_back(std::move(element)); elements.emplace_back(std::move(element));
@ -308,12 +308,12 @@ struct CmdProfileInstall : InstallablesCommand, MixDefaultProfile
auto & [res, info] = builtPaths[installable.get()]; 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 { element.source = ProfileElementSource {
.originalRef = *info.originalRef, .originalRef = *info.originalRef,
.resolvedRef = *info.resolvedRef, .resolvedRef = *info.resolvedRef,
.attrPath = *info.attrPath, .attrPath = *info.attrPath,
.outputs = *info.outputsSpec, .outputs = *info.extendedOutputsSpec,
}; };
} }
@ -497,7 +497,7 @@ struct CmdProfileUpgrade : virtual SourceExprCommand, MixDefaultProfile, MixProf
.originalRef = installable->flakeRef, .originalRef = installable->flakeRef,
.resolvedRef = *info.resolvedRef, .resolvedRef = *info.resolvedRef,
.attrPath = *info.attrPath, .attrPath = *info.attrPath,
.outputs = installable->outputsSpec, .outputs = installable->extendedOutputsSpec,
}; };
installables.push_back(installable); installables.push_back(installable);