Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DerivationInfo -> PackageInfo #9786

Merged
merged 2 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/libcmd/installable-attr-path.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,22 @@ DerivedPathsWithInfo InstallableAttrPath::toDerivedPaths()

Bindings & autoArgs = *cmd.getAutoArgs(*state);

DrvInfos drvInfos;
getDerivations(*state, *v, "", autoArgs, drvInfos, false);
PackageInfos packageInfos;
getDerivations(*state, *v, "", autoArgs, packageInfos, false);

// Backward compatibility hack: group results by drvPath. This
// helps keep .all output together.
std::map<StorePath, OutputsSpec> byDrvPath;

for (auto & drvInfo : drvInfos) {
auto drvPath = drvInfo.queryDrvPath();
for (auto & packageInfo : packageInfos) {
auto drvPath = packageInfo.queryDrvPath();
if (!drvPath)
throw Error("'%s' is not a derivation", what());

auto newOutputs = std::visit(overloaded {
[&](const ExtendedOutputsSpec::Default & d) -> OutputsSpec {
std::set<std::string> outputsToInstall;
for (auto & output : drvInfo.queryOutputs(false, true))
for (auto & output : packageInfo.queryOutputs(false, true))
outputsToInstall.insert(output.first);
return OutputsSpec::Names { std::move(outputsToInstall) };
},
Expand Down
2 changes: 1 addition & 1 deletion src/libcmd/installable-value.hh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace nix {

struct DrvInfo;
struct PackageInfo;
struct SourceExprCommand;

namespace eval_cache { class EvalCache; class AttrCursor; }
Expand Down
2 changes: 1 addition & 1 deletion src/libcmd/installables.hh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace nix {

struct DrvInfo;
struct PackageInfo;

enum class Realise {
/**
Expand Down
6 changes: 3 additions & 3 deletions src/libcmd/repl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -450,10 +450,10 @@ static bool isVarName(std::string_view s)


StorePath NixRepl::getDerivationPath(Value & v) {
auto drvInfo = getDerivation(*state, v, false);
if (!drvInfo)
auto packageInfo = getDerivation(*state, v, false);
if (!packageInfo)
throw Error("expression does not evaluate to a derivation, so I can't build it");
auto drvPath = drvInfo->queryDrvPath();
auto drvPath = packageInfo->queryDrvPath();
if (!drvPath)
throw Error("expression did not evaluate to a valid derivation (no 'drvPath' attribute)");
if (!state->store->isValidPath(*drvPath))
Expand Down
48 changes: 24 additions & 24 deletions src/libexpr/get-drvs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
namespace nix {


DrvInfo::DrvInfo(EvalState & state, std::string attrPath, Bindings * attrs)
PackageInfo::PackageInfo(EvalState & state, std::string attrPath, Bindings * attrs)
: state(&state), attrs(attrs), attrPath(std::move(attrPath))
{
}


DrvInfo::DrvInfo(EvalState & state, ref<Store> store, const std::string & drvPathWithOutputs)
PackageInfo::PackageInfo(EvalState & state, ref<Store> store, const std::string & drvPathWithOutputs)
: state(&state), attrs(nullptr), attrPath("")
{
auto [drvPath, selectedOutputs] = parsePathWithOutputs(*store, drvPathWithOutputs);
Expand Down Expand Up @@ -45,7 +45,7 @@ DrvInfo::DrvInfo(EvalState & state, ref<Store> store, const std::string & drvPat
}


std::string DrvInfo::queryName() const
std::string PackageInfo::queryName() const
{
if (name == "" && attrs) {
auto i = attrs->find(state->sName);
Expand All @@ -56,7 +56,7 @@ std::string DrvInfo::queryName() const
}


std::string DrvInfo::querySystem() const
std::string PackageInfo::querySystem() const
{
if (system == "" && attrs) {
auto i = attrs->find(state->sSystem);
Expand All @@ -66,7 +66,7 @@ std::string DrvInfo::querySystem() const
}


std::optional<StorePath> DrvInfo::queryDrvPath() const
std::optional<StorePath> PackageInfo::queryDrvPath() const
{
if (!drvPath && attrs) {
Bindings::iterator i = attrs->find(state->sDrvPath);
Expand All @@ -80,15 +80,15 @@ std::optional<StorePath> DrvInfo::queryDrvPath() const
}


StorePath DrvInfo::requireDrvPath() const
StorePath PackageInfo::requireDrvPath() const
{
if (auto drvPath = queryDrvPath())
return *drvPath;
throw Error("derivation does not contain a 'drvPath' attribute");
}


StorePath DrvInfo::queryOutPath() const
StorePath PackageInfo::queryOutPath() const
{
if (!outPath && attrs) {
Bindings::iterator i = attrs->find(state->sOutPath);
Expand All @@ -102,7 +102,7 @@ StorePath DrvInfo::queryOutPath() const
}


DrvInfo::Outputs DrvInfo::queryOutputs(bool withPaths, bool onlyOutputsToInstall)
PackageInfo::Outputs PackageInfo::queryOutputs(bool withPaths, bool onlyOutputsToInstall)
{
if (outputs.empty()) {
/* Get the ‘outputs’ list. */
Expand Down Expand Up @@ -164,7 +164,7 @@ DrvInfo::Outputs DrvInfo::queryOutputs(bool withPaths, bool onlyOutputsToInstall
}


std::string DrvInfo::queryOutputName() const
std::string PackageInfo::queryOutputName() const
{
if (outputName == "" && attrs) {
Bindings::iterator i = attrs->find(state->sOutputName);
Expand All @@ -174,7 +174,7 @@ std::string DrvInfo::queryOutputName() const
}


Bindings * DrvInfo::getMeta()
Bindings * PackageInfo::getMeta()
{
if (meta) return meta;
if (!attrs) return 0;
Expand All @@ -186,7 +186,7 @@ Bindings * DrvInfo::getMeta()
}


StringSet DrvInfo::queryMetaNames()
StringSet PackageInfo::queryMetaNames()
{
StringSet res;
if (!getMeta()) return res;
Expand All @@ -196,7 +196,7 @@ StringSet DrvInfo::queryMetaNames()
}


bool DrvInfo::checkMeta(Value & v)
bool PackageInfo::checkMeta(Value & v)
{
state->forceValue(v, v.determinePos(noPos));
if (v.type() == nList) {
Expand All @@ -216,7 +216,7 @@ bool DrvInfo::checkMeta(Value & v)
}


Value * DrvInfo::queryMeta(const std::string & name)
Value * PackageInfo::queryMeta(const std::string & name)
{
if (!getMeta()) return 0;
Bindings::iterator a = meta->find(state->symbols.create(name));
Expand All @@ -225,15 +225,15 @@ Value * DrvInfo::queryMeta(const std::string & name)
}


std::string DrvInfo::queryMetaString(const std::string & name)
std::string PackageInfo::queryMetaString(const std::string & name)
{
Value * v = queryMeta(name);
if (!v || v->type() != nString) return "";
return v->c_str();
}


NixInt DrvInfo::queryMetaInt(const std::string & name, NixInt def)
NixInt PackageInfo::queryMetaInt(const std::string & name, NixInt def)
{
Value * v = queryMeta(name);
if (!v) return def;
Expand All @@ -247,7 +247,7 @@ NixInt DrvInfo::queryMetaInt(const std::string & name, NixInt def)
return def;
}

NixFloat DrvInfo::queryMetaFloat(const std::string & name, NixFloat def)
NixFloat PackageInfo::queryMetaFloat(const std::string & name, NixFloat def)
{
Value * v = queryMeta(name);
if (!v) return def;
Expand All @@ -262,7 +262,7 @@ NixFloat DrvInfo::queryMetaFloat(const std::string & name, NixFloat def)
}


bool DrvInfo::queryMetaBool(const std::string & name, bool def)
bool PackageInfo::queryMetaBool(const std::string & name, bool def)
{
Value * v = queryMeta(name);
if (!v) return def;
Expand All @@ -277,7 +277,7 @@ bool DrvInfo::queryMetaBool(const std::string & name, bool def)
}


void DrvInfo::setMeta(const std::string & name, Value * v)
void PackageInfo::setMeta(const std::string & name, Value * v)
{
getMeta();
auto attrs = state->buildBindings(1 + (meta ? meta->size() : 0));
Expand All @@ -300,7 +300,7 @@ typedef std::set<Bindings *> Done;
The result boolean indicates whether it makes sense
for the caller to recursively search for derivations in `v'. */
static bool getDerivation(EvalState & state, Value & v,
const std::string & attrPath, DrvInfos & drvs, Done & done,
const std::string & attrPath, PackageInfos & drvs, Done & done,
bool ignoreAssertionFailures)
{
try {
Expand All @@ -311,7 +311,7 @@ static bool getDerivation(EvalState & state, Value & v,
derivation {...}; y = x;}'. */
if (!done.insert(v.attrs).second) return false;

DrvInfo drv(state, attrPath, v.attrs);
PackageInfo drv(state, attrPath, v.attrs);

drv.queryName();

Expand All @@ -326,11 +326,11 @@ static bool getDerivation(EvalState & state, Value & v,
}


std::optional<DrvInfo> getDerivation(EvalState & state, Value & v,
std::optional<PackageInfo> getDerivation(EvalState & state, Value & v,
bool ignoreAssertionFailures)
{
Done done;
DrvInfos drvs;
PackageInfos drvs;
getDerivation(state, v, "", drvs, done, ignoreAssertionFailures);
if (drvs.size() != 1) return {};
return std::move(drvs.front());
Expand All @@ -348,7 +348,7 @@ static std::regex attrRegex("[A-Za-z_][A-Za-z0-9-_+]*");

static void getDerivations(EvalState & state, Value & vIn,
const std::string & pathPrefix, Bindings & autoArgs,
DrvInfos & drvs, Done & done,
PackageInfos & drvs, Done & done,
bool ignoreAssertionFailures)
{
Value v;
Expand Down Expand Up @@ -401,7 +401,7 @@ static void getDerivations(EvalState & state, Value & vIn,


void getDerivations(EvalState & state, Value & v, const std::string & pathPrefix,
Bindings & autoArgs, DrvInfos & drvs, bool ignoreAssertionFailures)
Bindings & autoArgs, PackageInfos & drvs, bool ignoreAssertionFailures)
{
Done done;
getDerivations(state, v, pathPrefix, autoArgs, drvs, done, ignoreAssertionFailures);
Expand Down
22 changes: 12 additions & 10 deletions src/libexpr/get-drvs.hh
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@

namespace nix {


struct DrvInfo
/**
* A "parsed" package attribute set.
*/
struct PackageInfo
{
public:
typedef std::map<std::string, std::optional<StorePath>> Outputs;
Expand Down Expand Up @@ -43,9 +45,9 @@ public:
*/
std::string attrPath;

DrvInfo(EvalState & state) : state(&state) { };
DrvInfo(EvalState & state, std::string attrPath, Bindings * attrs);
DrvInfo(EvalState & state, ref<Store> store, const std::string & drvPathWithOutputs);
PackageInfo(EvalState & state) : state(&state) { };
PackageInfo(EvalState & state, std::string attrPath, Bindings * attrs);
PackageInfo(EvalState & state, ref<Store> store, const std::string & drvPathWithOutputs);

std::string queryName() const;
std::string querySystem() const;
Expand Down Expand Up @@ -82,21 +84,21 @@ public:


#if HAVE_BOEHMGC
typedef std::list<DrvInfo, traceable_allocator<DrvInfo>> DrvInfos;
typedef std::list<PackageInfo, traceable_allocator<PackageInfo>> PackageInfos;
#else
typedef std::list<DrvInfo> DrvInfos;
typedef std::list<PackageInfo> PackageInfos;
#endif


/**
* If value `v` denotes a derivation, return a DrvInfo object
* If value `v` denotes a derivation, return a PackageInfo object
* describing it. Otherwise return nothing.
*/
std::optional<DrvInfo> getDerivation(EvalState & state,
std::optional<PackageInfo> getDerivation(EvalState & state,
Value & v, bool ignoreAssertionFailures);

void getDerivations(EvalState & state, Value & v, const std::string & pathPrefix,
Bindings & autoArgs, DrvInfos & drvs,
Bindings & autoArgs, PackageInfos & drvs,
bool ignoreAssertionFailures);


Expand Down
3 changes: 3 additions & 0 deletions src/libstore/builtins/buildenv.hh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

namespace nix {

/**
* Think of this as a "store level package attrset", but stripped down to no more than the needs of buildenv.
*/
struct Package {
Path path;
bool active;
Expand Down
16 changes: 8 additions & 8 deletions src/nix-build/nix-build.cc
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ static void main_nix_build(int argc, char * * argv)
if (runEnv)
setenv("IN_NIX_SHELL", pure ? "pure" : "impure", 1);

DrvInfos drvs;
PackageInfos drvs;

/* Parse the expressions. */
std::vector<Expr *> exprs;
Expand All @@ -307,7 +307,7 @@ static void main_nix_build(int argc, char * * argv)
} catch (Error & e) {};
auto [path, outputNames] = parsePathWithOutputs(absolute);
if (evalStore->isStorePath(path) && hasSuffix(path, ".drv"))
drvs.push_back(DrvInfo(*state, evalStore, absolute));
drvs.push_back(PackageInfo(*state, evalStore, absolute));
else
/* If we're in a #! script, interpret filenames
relative to the script. */
Expand Down Expand Up @@ -383,8 +383,8 @@ static void main_nix_build(int argc, char * * argv)
if (drvs.size() != 1)
throw UsageError("nix-shell requires a single derivation");

auto & drvInfo = drvs.front();
auto drv = evalStore->derivationFromPath(drvInfo.requireDrvPath());
auto & packageInfo = drvs.front();
auto drv = evalStore->derivationFromPath(packageInfo.requireDrvPath());

std::vector<DerivedPath> pathsToBuild;
RealisedPath::Set pathsToCopy;
Expand Down Expand Up @@ -527,7 +527,7 @@ static void main_nix_build(int argc, char * * argv)
for (const auto & [inputDrv, inputNode] : drv.inputDrvs.map)
accumInputClosure(inputDrv, inputNode);

ParsedDerivation parsedDrv(drvInfo.requireDrvPath(), drv);
ParsedDerivation parsedDrv(packageInfo.requireDrvPath(), drv);

if (auto structAttrs = parsedDrv.prepareStructuredAttrs(*store, inputs)) {
auto json = structAttrs.value();
Expand Down Expand Up @@ -620,10 +620,10 @@ static void main_nix_build(int argc, char * * argv)

std::map<StorePath, std::pair<size_t, StringSet>> drvMap;

for (auto & drvInfo : drvs) {
auto drvPath = drvInfo.requireDrvPath();
for (auto & packageInfo : drvs) {
auto drvPath = packageInfo.requireDrvPath();

auto outputName = drvInfo.queryOutputName();
auto outputName = packageInfo.queryOutputName();
if (outputName == "")
throw Error("derivation '%s' lacks an 'outputName' attribute", store->printStorePath(drvPath));

Expand Down
Loading
Loading