From f15651303f8596bf34c67fc8d536b1e9e7843a87 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 28 Aug 2020 19:24:29 +0200 Subject: [PATCH] nix develop: Add convenience flags for running specific phases For example, for building the Nix flake, you would do: $ nix develop --configure $ nix develop --install $ nix develop --installcheck --- src/nix/develop.cc | 55 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 2 deletions(-) diff --git a/src/nix/develop.cc b/src/nix/develop.cc index 20316c477..516e7bda9 100644 --- a/src/nix/develop.cc +++ b/src/nix/develop.cc @@ -264,6 +264,7 @@ struct Common : InstallableCommand, MixProfile struct CmdDevelop : Common, MixEnvironment { std::vector command; + std::optional phase; CmdDevelop() { @@ -277,6 +278,43 @@ struct CmdDevelop : Common, MixEnvironment command = ss; }} }); + + addFlag({ + .longName = "phase", + .description = "phase to run (e.g. `build` or `configure`)", + .labels = {"phase-name"}, + .handler = {&phase}, + }); + + addFlag({ + .longName = "configure", + .description = "run the configure phase", + .handler = {&phase, {"configure"}}, + }); + + addFlag({ + .longName = "build", + .description = "run the build phase", + .handler = {&phase, {"build"}}, + }); + + addFlag({ + .longName = "check", + .description = "run the check phase", + .handler = {&phase, {"check"}}, + }); + + addFlag({ + .longName = "install", + .description = "run the install phase", + .handler = {&phase, {"install"}}, + }); + + addFlag({ + .longName = "installcheck", + .description = "run the installcheck phase", + .handler = {&phase, {"installCheck"}}, + }); } std::string description() override @@ -314,9 +352,22 @@ struct CmdDevelop : Common, MixEnvironment auto script = makeRcScript(buildEnvironment); - script += fmt("rm -f '%s'\n", rcFilePath); + if (verbosity >= lvlDebug) + script += "set -x\n"; - if (!command.empty()) { + script += fmt("rm -f '%s'\n", rcFilePath); + + if (phase) { + if (!command.empty()) + throw UsageError("you cannot use both '--command' and '--phase'"); + // FIXME: foundMakefile is set by buildPhase, need to get + // rid of that. + script += fmt("foundMakefile=1\n"); + script += fmt("runHook %1%Phase\n", *phase); + script += fmt("exit 0\n", *phase); + } + + else if (!command.empty()) { std::vector args; for (auto s : command) args.push_back(shellEscape(s));