1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-25 02:21:16 +02:00

Merge pull request #13105 from roberth/refactor-cli-out-link

Factor out `MixOutLinkByDefault`
This commit is contained in:
Jörg Thalheim 2025-04-29 21:19:34 +02:00 committed by GitHub
commit 0e2dc8774c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 47 additions and 21 deletions

View file

@ -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);
}
}

View file

@ -374,4 +374,41 @@ void printClosureDiff(
*/
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

View file

@ -41,29 +41,13 @@ static nlohmann::json builtPathsWithResultToJSON(const std::vector<BuiltPathWith
return res;
}
struct CmdBuild : InstallablesCommand, MixDryRun, MixJSON, MixProfile
struct CmdBuild : InstallablesCommand, MixOutLinkByDefault, MixDryRun, MixJSON, MixProfile
{
Path outLink = "result";
bool printOutputPaths = false;
BuildMode buildMode = bmNormal;
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({
.longName = "print-out-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 (outLink != "")
if (auto store2 = store.dynamic_pointer_cast<LocalFSStore>())
createOutLinks(outLink, toBuiltPaths(buildables), *store2);
createOutLinksMaybe(buildables, store);
if (printOutputPaths) {
logger->stop();