mirror of
https://github.com/NixOS/nix
synced 2025-06-25 14:51:16 +02:00
Merge pull request #13105 from roberth/refactor-cli-out-link
Factor out `MixOutLinkByDefault`
This commit is contained in:
commit
0e2dc8774c
3 changed files with 47 additions and 21 deletions
|
@ -397,4 +397,11 @@ void createOutLinks(const std::filesystem::path & outLink, const BuiltPaths & bu
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MixOutLinkBase::createOutLinksMaybe(const std::vector<BuiltPathWithResult> & buildables, ref<Store> & store)
|
||||||
|
{
|
||||||
|
if (outLink != "")
|
||||||
|
if (auto store2 = store.dynamic_pointer_cast<LocalFSStore>())
|
||||||
|
createOutLinks(outLink, toBuiltPaths(buildables), *store2);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -374,4 +374,41 @@ void printClosureDiff(
|
||||||
*/
|
*/
|
||||||
void createOutLinks(const std::filesystem::path & outLink, const BuiltPaths & buildables, LocalFSStore & store);
|
void createOutLinks(const std::filesystem::path & outLink, const BuiltPaths & buildables, LocalFSStore & store);
|
||||||
|
|
||||||
}
|
/** `outLink` parameter, `createOutLinksMaybe` method. See `MixOutLinkByDefault`. */
|
||||||
|
struct MixOutLinkBase : virtual Args
|
||||||
|
{
|
||||||
|
/** Prefix for any output symlinks. Empty means do not write an output symlink. */
|
||||||
|
Path outLink;
|
||||||
|
|
||||||
|
MixOutLinkBase(const std::string & defaultOutLink)
|
||||||
|
: outLink(defaultOutLink)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void createOutLinksMaybe(const std::vector<BuiltPathWithResult> & buildables, ref<Store> & store);
|
||||||
|
};
|
||||||
|
|
||||||
|
/** `--out-link`, `--no-link`, `createOutLinksMaybe` */
|
||||||
|
struct MixOutLinkByDefault : MixOutLinkBase, virtual Args
|
||||||
|
{
|
||||||
|
MixOutLinkByDefault()
|
||||||
|
: MixOutLinkBase("result")
|
||||||
|
{
|
||||||
|
addFlag({
|
||||||
|
.longName = "out-link",
|
||||||
|
.shortName = 'o',
|
||||||
|
.description = "Use *path* as prefix for the symlinks to the build results. It defaults to `result`.",
|
||||||
|
.labels = {"path"},
|
||||||
|
.handler = {&outLink},
|
||||||
|
.completer = completePath,
|
||||||
|
});
|
||||||
|
|
||||||
|
addFlag({
|
||||||
|
.longName = "no-link",
|
||||||
|
.description = "Do not create symlinks to the build results.",
|
||||||
|
.handler = {&outLink, Path("")},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace nix
|
||||||
|
|
|
@ -41,29 +41,13 @@ static nlohmann::json builtPathsWithResultToJSON(const std::vector<BuiltPathWith
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct CmdBuild : InstallablesCommand, MixDryRun, MixJSON, MixProfile
|
struct CmdBuild : InstallablesCommand, MixOutLinkByDefault, MixDryRun, MixJSON, MixProfile
|
||||||
{
|
{
|
||||||
Path outLink = "result";
|
|
||||||
bool printOutputPaths = false;
|
bool printOutputPaths = false;
|
||||||
BuildMode buildMode = bmNormal;
|
BuildMode buildMode = bmNormal;
|
||||||
|
|
||||||
CmdBuild()
|
CmdBuild()
|
||||||
{
|
{
|
||||||
addFlag({
|
|
||||||
.longName = "out-link",
|
|
||||||
.shortName = 'o',
|
|
||||||
.description = "Use *path* as prefix for the symlinks to the build results. It defaults to `result`.",
|
|
||||||
.labels = {"path"},
|
|
||||||
.handler = {&outLink},
|
|
||||||
.completer = completePath,
|
|
||||||
});
|
|
||||||
|
|
||||||
addFlag({
|
|
||||||
.longName = "no-link",
|
|
||||||
.description = "Do not create symlinks to the build results.",
|
|
||||||
.handler = {&outLink, Path("")},
|
|
||||||
});
|
|
||||||
|
|
||||||
addFlag({
|
addFlag({
|
||||||
.longName = "print-out-paths",
|
.longName = "print-out-paths",
|
||||||
.description = "Print the resulting output paths",
|
.description = "Print the resulting output paths",
|
||||||
|
@ -114,9 +98,7 @@ struct CmdBuild : InstallablesCommand, MixDryRun, MixJSON, MixProfile
|
||||||
|
|
||||||
if (json) logger->cout("%s", builtPathsWithResultToJSON(buildables, *store).dump());
|
if (json) logger->cout("%s", builtPathsWithResultToJSON(buildables, *store).dump());
|
||||||
|
|
||||||
if (outLink != "")
|
createOutLinksMaybe(buildables, store);
|
||||||
if (auto store2 = store.dynamic_pointer_cast<LocalFSStore>())
|
|
||||||
createOutLinks(outLink, toBuiltPaths(buildables), *store2);
|
|
||||||
|
|
||||||
if (printOutputPaths) {
|
if (printOutputPaths) {
|
||||||
logger->stop();
|
logger->stop();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue