Clean up RealiseMode
This commit is contained in:
parent
e3c2b00237
commit
94eb5fad76
|
@ -53,7 +53,7 @@ struct CmdBuild : InstallablesCommand, MixDryRun, MixProfile
|
|||
|
||||
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;
|
||||
|
||||
|
|
|
@ -80,7 +80,7 @@ void StorePathsCommand::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)
|
||||
throw UsageError("this command requires exactly one store path");
|
||||
|
|
|
@ -70,7 +70,16 @@ struct SourceExprCommand : virtual Args, MixFlakeOptions
|
|||
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
|
||||
store paths, attribute paths, Nix expressions, etc. */
|
||||
|
@ -120,7 +129,7 @@ private:
|
|||
|
||||
protected:
|
||||
|
||||
RealiseMode realiseMode = NoBuild;
|
||||
Realise realiseMode = Realise::Derivation;
|
||||
|
||||
public:
|
||||
|
||||
|
@ -164,13 +173,13 @@ static RegisterCommand registerCommand(const std::string & name)
|
|||
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::set<StorePath> toStorePaths(ref<Store> store, RealiseMode mode,
|
||||
std::set<StorePath> toStorePaths(ref<Store> store, Realise mode,
|
||||
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::set<StorePath> toDerivations(ref<Store> store,
|
||||
|
|
|
@ -46,7 +46,7 @@ struct CmdCopy : StorePathsCommand
|
|||
.handler = {&substitute, Substitute},
|
||||
});
|
||||
|
||||
realiseMode = Build;
|
||||
realiseMode = Realise::Outputs;
|
||||
}
|
||||
|
||||
std::string description() override
|
||||
|
|
|
@ -321,7 +321,7 @@ struct CmdDevelop : Common, MixEnvironment
|
|||
Strings{"legacyPackages." + settings.thisSystem.get() + "."},
|
||||
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 &) {
|
||||
ignoreException();
|
||||
}
|
||||
|
|
|
@ -635,10 +635,10 @@ std::shared_ptr<Installable> SourceExprCommand::parseInstallable(
|
|||
return installables.front();
|
||||
}
|
||||
|
||||
Buildables build(ref<Store> store, RealiseMode mode,
|
||||
Buildables build(ref<Store> store, Realise mode,
|
||||
std::vector<std::shared_ptr<Installable>> installables)
|
||||
{
|
||||
if (mode != Build)
|
||||
if (mode == Realise::Nothing)
|
||||
settings.readOnlyMode = true;
|
||||
|
||||
Buildables buildables;
|
||||
|
@ -659,15 +659,15 @@ Buildables build(ref<Store> store, RealiseMode mode,
|
|||
}
|
||||
}
|
||||
|
||||
if (mode == DryRun)
|
||||
if (mode == Realise::Nothing)
|
||||
printMissing(store, pathsToBuild, lvlError);
|
||||
else if (mode == Build)
|
||||
else if (mode == Realise::Outputs)
|
||||
store->buildPaths(pathsToBuild);
|
||||
|
||||
return buildables;
|
||||
}
|
||||
|
||||
StorePathSet toStorePaths(ref<Store> store, RealiseMode mode,
|
||||
StorePathSet toStorePaths(ref<Store> store, Realise mode,
|
||||
std::vector<std::shared_ptr<Installable>> installables)
|
||||
{
|
||||
StorePathSet outPaths;
|
||||
|
@ -679,7 +679,7 @@ StorePathSet toStorePaths(ref<Store> store, RealiseMode mode,
|
|||
return outPaths;
|
||||
}
|
||||
|
||||
StorePath toStorePath(ref<Store> store, RealiseMode mode,
|
||||
StorePath toStorePath(ref<Store> store, Realise mode,
|
||||
std::shared_ptr<Installable> installable)
|
||||
{
|
||||
auto paths = toStorePaths(store, mode, {installable});
|
||||
|
|
|
@ -10,7 +10,7 @@ struct CmdMakeContentAddressable : StorePathsCommand, MixJSON
|
|||
{
|
||||
CmdMakeContentAddressable()
|
||||
{
|
||||
realiseMode = Build;
|
||||
realiseMode = Realise::Outputs;
|
||||
}
|
||||
|
||||
std::string description() override
|
||||
|
|
|
@ -104,7 +104,7 @@ struct CmdShell : InstallablesCommand, RunCommon, MixEnvironment
|
|||
|
||||
void run(ref<Store> store) override
|
||||
{
|
||||
auto outPaths = toStorePaths(store, Build, installables);
|
||||
auto outPaths = toStorePaths(store, Realise::Outputs, installables);
|
||||
|
||||
auto accessor = store->getFSAccessor();
|
||||
|
||||
|
|
|
@ -73,9 +73,9 @@ struct CmdWhyDepends : SourceExprCommand
|
|||
void run(ref<Store> store) override
|
||||
{
|
||||
auto package = parseInstallable(store, _package);
|
||||
auto packagePath = toStorePath(store, Build, package);
|
||||
auto packagePath = toStorePath(store, Realise::Outputs, package);
|
||||
auto dependency = parseInstallable(store, _dependency);
|
||||
auto dependencyPath = toStorePath(store, NoBuild, dependency);
|
||||
auto dependencyPath = toStorePath(store, Realise::Derivation, dependency);
|
||||
auto dependencyPathHash = dependencyPath.hashPart();
|
||||
|
||||
StorePathSet closure;
|
||||
|
|
Loading…
Reference in a new issue