forked from lix-project/lix
Move exportReferencesGraph into a separate method
startBuilder() is getting rather obese.
This commit is contained in:
parent
49bcb18035
commit
4425a5c547
|
@ -864,6 +864,9 @@ private:
|
||||||
/* Start building a derivation. */
|
/* Start building a derivation. */
|
||||||
void startBuilder();
|
void startBuilder();
|
||||||
|
|
||||||
|
/* Handle the exportReferencesGraph attribute. */
|
||||||
|
void doExportReferencesGraph();
|
||||||
|
|
||||||
/* Run the builder's process. */
|
/* Run the builder's process. */
|
||||||
void runChild();
|
void runChild();
|
||||||
|
|
||||||
|
@ -1791,51 +1794,9 @@ void DerivationGoal::startBuilder()
|
||||||
for (auto & output : drv->outputs)
|
for (auto & output : drv->outputs)
|
||||||
inputRewrites[hashPlaceholder(output.first)] = output.second.path;
|
inputRewrites[hashPlaceholder(output.first)] = output.second.path;
|
||||||
|
|
||||||
/* The `exportReferencesGraph' feature allows the references graph
|
|
||||||
to be passed to a builder. This attribute should be a list of
|
|
||||||
pairs [name1 path1 name2 path2 ...]. The references graph of
|
|
||||||
each `pathN' will be stored in a text file `nameN' in the
|
|
||||||
temporary build directory. The text files have the format used
|
|
||||||
by `nix-store --register-validity'. However, the deriver
|
|
||||||
fields are left empty. */
|
|
||||||
string s = get(drv->env, "exportReferencesGraph");
|
|
||||||
Strings ss = tokenizeString<Strings>(s);
|
|
||||||
if (ss.size() % 2 != 0)
|
|
||||||
throw BuildError(format("odd number of tokens in ‘exportReferencesGraph’: ‘%1%’") % s);
|
|
||||||
for (Strings::iterator i = ss.begin(); i != ss.end(); ) {
|
|
||||||
string fileName = *i++;
|
|
||||||
checkStoreName(fileName); /* !!! abuse of this function */
|
|
||||||
|
|
||||||
/* Check that the store path is valid. */
|
/* Handle exportReferencesGraph(), if set. */
|
||||||
Path storePath = *i++;
|
doExportReferencesGraph();
|
||||||
if (!worker.store.isInStore(storePath))
|
|
||||||
throw BuildError(format("‘exportReferencesGraph’ contains a non-store path ‘%1%’")
|
|
||||||
% storePath);
|
|
||||||
storePath = worker.store.toStorePath(storePath);
|
|
||||||
if (!worker.store.isValidPath(storePath))
|
|
||||||
throw BuildError(format("‘exportReferencesGraph’ contains an invalid path ‘%1%’")
|
|
||||||
% storePath);
|
|
||||||
|
|
||||||
/* If there are derivations in the graph, then include their
|
|
||||||
outputs as well. This is useful if you want to do things
|
|
||||||
like passing all build-time dependencies of some path to a
|
|
||||||
derivation that builds a NixOS DVD image. */
|
|
||||||
PathSet paths, paths2;
|
|
||||||
worker.store.computeFSClosure(storePath, paths);
|
|
||||||
paths2 = paths;
|
|
||||||
|
|
||||||
for (auto & j : paths2) {
|
|
||||||
if (isDerivation(j)) {
|
|
||||||
Derivation drv = worker.store.derivationFromPath(j);
|
|
||||||
for (auto & k : drv.outputs)
|
|
||||||
worker.store.computeFSClosure(k.second.path, paths);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Write closure info to `fileName'. */
|
|
||||||
writeFile(tmpDir + "/" + fileName,
|
|
||||||
worker.store.makeValidityRegistration(paths, false, false));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* If `build-users-group' is not empty, then we have to build as
|
/* If `build-users-group' is not empty, then we have to build as
|
||||||
|
@ -2242,6 +2203,56 @@ void DerivationGoal::startBuilder()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void DerivationGoal::doExportReferencesGraph()
|
||||||
|
{
|
||||||
|
/* The `exportReferencesGraph' feature allows the references graph
|
||||||
|
to be passed to a builder. This attribute should be a list of
|
||||||
|
pairs [name1 path1 name2 path2 ...]. The references graph of
|
||||||
|
each `pathN' will be stored in a text file `nameN' in the
|
||||||
|
temporary build directory. The text files have the format used
|
||||||
|
by `nix-store --register-validity'. However, the deriver
|
||||||
|
fields are left empty. */
|
||||||
|
string s = get(drv->env, "exportReferencesGraph");
|
||||||
|
Strings ss = tokenizeString<Strings>(s);
|
||||||
|
if (ss.size() % 2 != 0)
|
||||||
|
throw BuildError(format("odd number of tokens in ‘exportReferencesGraph’: ‘%1%’") % s);
|
||||||
|
for (Strings::iterator i = ss.begin(); i != ss.end(); ) {
|
||||||
|
string fileName = *i++;
|
||||||
|
checkStoreName(fileName); /* !!! abuse of this function */
|
||||||
|
|
||||||
|
/* Check that the store path is valid. */
|
||||||
|
Path storePath = *i++;
|
||||||
|
if (!worker.store.isInStore(storePath))
|
||||||
|
throw BuildError(format("‘exportReferencesGraph’ contains a non-store path ‘%1%’")
|
||||||
|
% storePath);
|
||||||
|
storePath = worker.store.toStorePath(storePath);
|
||||||
|
if (!worker.store.isValidPath(storePath))
|
||||||
|
throw BuildError(format("‘exportReferencesGraph’ contains an invalid path ‘%1%’")
|
||||||
|
% storePath);
|
||||||
|
|
||||||
|
/* If there are derivations in the graph, then include their
|
||||||
|
outputs as well. This is useful if you want to do things
|
||||||
|
like passing all build-time dependencies of some path to a
|
||||||
|
derivation that builds a NixOS DVD image. */
|
||||||
|
PathSet paths, paths2;
|
||||||
|
worker.store.computeFSClosure(storePath, paths);
|
||||||
|
paths2 = paths;
|
||||||
|
|
||||||
|
for (auto & j : paths2) {
|
||||||
|
if (isDerivation(j)) {
|
||||||
|
Derivation drv = worker.store.derivationFromPath(j);
|
||||||
|
for (auto & k : drv.outputs)
|
||||||
|
worker.store.computeFSClosure(k.second.path, paths);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Write closure info to `fileName'. */
|
||||||
|
writeFile(tmpDir + "/" + fileName,
|
||||||
|
worker.store.makeValidityRegistration(paths, false, false));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void DerivationGoal::runChild()
|
void DerivationGoal::runChild()
|
||||||
{
|
{
|
||||||
/* Warning: in the child we should absolutely not make any SQLite
|
/* Warning: in the child we should absolutely not make any SQLite
|
||||||
|
|
Loading…
Reference in a new issue