Clean up RealiseMode

This commit is contained in:
Eelco Dolstra 2020-07-15 20:05:42 +02:00
parent e3c2b00237
commit 94eb5fad76
9 changed files with 28 additions and 19 deletions

View file

@ -53,7 +53,7 @@ struct CmdBuild : InstallablesCommand, MixDryRun, MixProfile
void run(ref<Store> store) override void run(ref<Store> store) override
{ {
auto buildables = build(store, dryRun ? DryRun : Build, installables); auto buildables = build(store, dryRun ? Realise::Nothing : Realise::Outputs, installables);
if (dryRun) return; if (dryRun) return;

View file

@ -80,7 +80,7 @@ void StorePathsCommand::run(ref<Store> store)
void StorePathCommand::run(ref<Store> store) void StorePathCommand::run(ref<Store> store)
{ {
auto storePaths = toStorePaths(store, NoBuild, installables); auto storePaths = toStorePaths(store, Realise::Nothing, installables);
if (storePaths.size() != 1) if (storePaths.size() != 1)
throw UsageError("this command requires exactly one store path"); throw UsageError("this command requires exactly one store path");

View file

@ -70,7 +70,16 @@ struct SourceExprCommand : virtual Args, MixFlakeOptions
void completeInstallable(std::string_view prefix); void completeInstallable(std::string_view prefix);
}; };
enum RealiseMode { Build, NoBuild, DryRun }; enum class Realise {
/* Build the derivation. Postcondition: the
derivation outputs exist. */
Outputs,
/* Don't build the derivation. Postcondition: the store derivation
exists. */
Derivation,
/* Evaluate in dry-run mode. Postcondition: nothing. */
Nothing
};
/* A command that operates on a list of "installables", which can be /* A command that operates on a list of "installables", which can be
store paths, attribute paths, Nix expressions, etc. */ store paths, attribute paths, Nix expressions, etc. */
@ -120,7 +129,7 @@ private:
protected: protected:
RealiseMode realiseMode = NoBuild; Realise realiseMode = Realise::Derivation;
public: public:
@ -164,13 +173,13 @@ static RegisterCommand registerCommand(const std::string & name)
return RegisterCommand(name, [](){ return make_ref<T>(); }); return RegisterCommand(name, [](){ return make_ref<T>(); });
} }
Buildables build(ref<Store> store, RealiseMode mode, Buildables build(ref<Store> store, Realise mode,
std::vector<std::shared_ptr<Installable>> installables); std::vector<std::shared_ptr<Installable>> installables);
std::set<StorePath> toStorePaths(ref<Store> store, RealiseMode mode, std::set<StorePath> toStorePaths(ref<Store> store, Realise mode,
std::vector<std::shared_ptr<Installable>> installables); std::vector<std::shared_ptr<Installable>> installables);
StorePath toStorePath(ref<Store> store, RealiseMode mode, StorePath toStorePath(ref<Store> store, Realise mode,
std::shared_ptr<Installable> installable); std::shared_ptr<Installable> installable);
std::set<StorePath> toDerivations(ref<Store> store, std::set<StorePath> toDerivations(ref<Store> store,

View file

@ -46,7 +46,7 @@ struct CmdCopy : StorePathsCommand
.handler = {&substitute, Substitute}, .handler = {&substitute, Substitute},
}); });
realiseMode = Build; realiseMode = Realise::Outputs;
} }
std::string description() override std::string description() override

View file

@ -321,7 +321,7 @@ struct CmdDevelop : Common, MixEnvironment
Strings{"legacyPackages." + settings.thisSystem.get() + "."}, Strings{"legacyPackages." + settings.thisSystem.get() + "."},
lockFlags); lockFlags);
shell = state->store->printStorePath(toStorePath(state->store, Build, bashInstallable)) + "/bin/bash"; shell = state->store->printStorePath(toStorePath(state->store, Realise::Outputs, bashInstallable)) + "/bin/bash";
} catch (Error &) { } catch (Error &) {
ignoreException(); ignoreException();
} }

View file

@ -635,10 +635,10 @@ std::shared_ptr<Installable> SourceExprCommand::parseInstallable(
return installables.front(); return installables.front();
} }
Buildables build(ref<Store> store, RealiseMode mode, Buildables build(ref<Store> store, Realise mode,
std::vector<std::shared_ptr<Installable>> installables) std::vector<std::shared_ptr<Installable>> installables)
{ {
if (mode != Build) if (mode == Realise::Nothing)
settings.readOnlyMode = true; settings.readOnlyMode = true;
Buildables buildables; Buildables buildables;
@ -659,15 +659,15 @@ Buildables build(ref<Store> store, RealiseMode mode,
} }
} }
if (mode == DryRun) if (mode == Realise::Nothing)
printMissing(store, pathsToBuild, lvlError); printMissing(store, pathsToBuild, lvlError);
else if (mode == Build) else if (mode == Realise::Outputs)
store->buildPaths(pathsToBuild); store->buildPaths(pathsToBuild);
return buildables; return buildables;
} }
StorePathSet toStorePaths(ref<Store> store, RealiseMode mode, StorePathSet toStorePaths(ref<Store> store, Realise mode,
std::vector<std::shared_ptr<Installable>> installables) std::vector<std::shared_ptr<Installable>> installables)
{ {
StorePathSet outPaths; StorePathSet outPaths;
@ -679,7 +679,7 @@ StorePathSet toStorePaths(ref<Store> store, RealiseMode mode,
return outPaths; return outPaths;
} }
StorePath toStorePath(ref<Store> store, RealiseMode mode, StorePath toStorePath(ref<Store> store, Realise mode,
std::shared_ptr<Installable> installable) std::shared_ptr<Installable> installable)
{ {
auto paths = toStorePaths(store, mode, {installable}); auto paths = toStorePaths(store, mode, {installable});

View file

@ -10,7 +10,7 @@ struct CmdMakeContentAddressable : StorePathsCommand, MixJSON
{ {
CmdMakeContentAddressable() CmdMakeContentAddressable()
{ {
realiseMode = Build; realiseMode = Realise::Outputs;
} }
std::string description() override std::string description() override

View file

@ -104,7 +104,7 @@ struct CmdShell : InstallablesCommand, RunCommon, MixEnvironment
void run(ref<Store> store) override void run(ref<Store> store) override
{ {
auto outPaths = toStorePaths(store, Build, installables); auto outPaths = toStorePaths(store, Realise::Outputs, installables);
auto accessor = store->getFSAccessor(); auto accessor = store->getFSAccessor();

View file

@ -73,9 +73,9 @@ struct CmdWhyDepends : SourceExprCommand
void run(ref<Store> store) override void run(ref<Store> store) override
{ {
auto package = parseInstallable(store, _package); auto package = parseInstallable(store, _package);
auto packagePath = toStorePath(store, Build, package); auto packagePath = toStorePath(store, Realise::Outputs, package);
auto dependency = parseInstallable(store, _dependency); auto dependency = parseInstallable(store, _dependency);
auto dependencyPath = toStorePath(store, NoBuild, dependency); auto dependencyPath = toStorePath(store, Realise::Derivation, dependency);
auto dependencyPathHash = dependencyPath.hashPart(); auto dependencyPathHash = dependencyPath.hashPart();
StorePathSet closure; StorePathSet closure;