mirror of
https://github.com/NixOS/nix
synced 2025-06-25 10:41:16 +02:00
Factor out MixOutLinkByDefault
This commit is contained in:
parent
3f811c2373
commit
9d1f00e31d
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);
|
||||
|
||||
/** `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;
|
||||
}
|
||||
|
||||
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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue