mirror of
https://github.com/NixOS/nix
synced 2025-07-03 02:01:48 +02:00
* Substitute fixes.
This commit is contained in:
parent
b9ecadee6e
commit
9d56ca219f
8 changed files with 86 additions and 36 deletions
|
@ -65,7 +65,10 @@ bool queryDB(const string & filename, const string & dbname,
|
|||
err = db->get(0, &kt, &dt, 0);
|
||||
if (err) return false;
|
||||
|
||||
data = string((char *) dt.get_data(), dt.get_size());
|
||||
if (!dt.get_data())
|
||||
data = "";
|
||||
else
|
||||
data = string((char *) dt.get_data(), dt.get_size());
|
||||
|
||||
} catch (DbException e) { rethrow(e); }
|
||||
|
||||
|
|
|
@ -111,6 +111,14 @@ static Expr evalExpr(Expr e)
|
|||
ATmatch(e, "FSId(<str>)", &s1))
|
||||
return e;
|
||||
|
||||
if (ATgetType(e) == AT_APPL &&
|
||||
((string) ATgetName(ATgetAFun(e)) == "Slice" ||
|
||||
(string) ATgetName(ATgetAFun(e)) == "Derive"))
|
||||
{
|
||||
return ATmake("FSId(<str>)",
|
||||
((string) writeTerm(e, "", 0)).c_str());
|
||||
}
|
||||
|
||||
/* Application. */
|
||||
if (ATmatch(e, "App(<term>, [<list>])", &e1, &e2)) {
|
||||
e1 = evalExpr(e1);
|
||||
|
|
|
@ -21,15 +21,22 @@ typedef map<string, string> Environment;
|
|||
class AutoDelete
|
||||
{
|
||||
string path;
|
||||
bool del;
|
||||
public:
|
||||
|
||||
AutoDelete(const string & p) : path(p)
|
||||
{
|
||||
del = true;
|
||||
}
|
||||
|
||||
~AutoDelete()
|
||||
{
|
||||
deletePath(path);
|
||||
if (del) deletePath(path);
|
||||
}
|
||||
|
||||
void cancel()
|
||||
{
|
||||
del = false;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -114,8 +121,10 @@ static void runProgram(const string & program, Environment env)
|
|||
if (waitpid(pid, &status, 0) != pid)
|
||||
throw Error("unable to wait for child");
|
||||
|
||||
if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
|
||||
if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
|
||||
delTmpDir.cancel();
|
||||
throw Error("unable to build package");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -336,7 +345,7 @@ static Slice normaliseFState2(FSId id, StringSet & usedPaths)
|
|||
bnds = ATgetNext(bnds);
|
||||
}
|
||||
|
||||
/* Check that none of the output paths exist. */
|
||||
/* Parse the outputs. */
|
||||
typedef map<string, FSId> OutPaths;
|
||||
OutPaths outPaths;
|
||||
while (!ATisEmpty(outs)) {
|
||||
|
@ -349,14 +358,36 @@ static Slice normaliseFState2(FSId id, StringSet & usedPaths)
|
|||
outs = ATgetNext(outs);
|
||||
}
|
||||
|
||||
/* We can skip running the builder if we can expand all output
|
||||
paths from their ids. */
|
||||
bool fastBuild = false;
|
||||
#if 0
|
||||
for (OutPaths::iterator i = outPaths.begin();
|
||||
i != outPaths.end(); i++)
|
||||
if (pathExists(i->first))
|
||||
throw Error(format("path `%1%' exists") % i->first);
|
||||
{
|
||||
try {
|
||||
expandId(i->second, i->first);
|
||||
} catch (...) {
|
||||
fastBuild = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Run the builder. */
|
||||
runProgram(builder, env);
|
||||
if (!fastBuild) {
|
||||
|
||||
/* Check that none of the outputs exist. */
|
||||
for (OutPaths::iterator i = outPaths.begin();
|
||||
i != outPaths.end(); i++)
|
||||
if (pathExists(i->first))
|
||||
throw Error(format("path `%1%' exists") % i->first);
|
||||
|
||||
/* Run the builder. */
|
||||
runProgram(builder, env);
|
||||
|
||||
} else
|
||||
debug(format("skipping build"));
|
||||
|
||||
Slice slice;
|
||||
|
||||
/* Check whether the output paths were created, and register each
|
||||
|
|
27
src/store.cc
27
src/store.cc
|
@ -86,6 +86,7 @@ void copyPath(string src, string dst)
|
|||
|
||||
void registerSubstitute(const FSId & srcId, const FSId & subId)
|
||||
{
|
||||
#if 0
|
||||
Strings subs;
|
||||
queryListDB(nixDB, dbSubstitutes, srcId, subs); /* non-existence = ok */
|
||||
|
||||
|
@ -94,6 +95,12 @@ void registerSubstitute(const FSId & srcId, const FSId & subId)
|
|||
|
||||
subs.push_back(subId);
|
||||
|
||||
setListDB(nixDB, dbSubstitutes, srcId, subs);
|
||||
#endif
|
||||
|
||||
/* For now, accept only one substitute per id. */
|
||||
Strings subs;
|
||||
subs.push_back(subId);
|
||||
setListDB(nixDB, dbSubstitutes, srcId, subs);
|
||||
}
|
||||
|
||||
|
@ -126,6 +133,8 @@ void unregisterPath(const string & _path)
|
|||
return;
|
||||
FSId id(parseHash(_id));
|
||||
|
||||
delDB(nixDB, dbPath2Id, path);
|
||||
|
||||
/* begin transaction */
|
||||
|
||||
Strings paths, paths2;
|
||||
|
@ -140,6 +149,7 @@ void unregisterPath(const string & _path)
|
|||
setListDB(nixDB, dbId2Paths, id, paths2);
|
||||
|
||||
/* end transaction */
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -189,32 +199,31 @@ string expandId(const FSId & id, const string & target,
|
|||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
/* Try to realise the substitutes. */
|
||||
|
||||
Strings subs;
|
||||
queryListDB(nixDB, dbSubstitutes, id, subs); /* non-existence = ok */
|
||||
|
||||
for (Strings::iterator it = subs.begin(); it != subs.end(); it++) {
|
||||
realiseSlice(normaliseFState(*it));
|
||||
FSId subId = parseHash(*it);
|
||||
Slice slice = normaliseFState(subId);
|
||||
realiseSlice(slice);
|
||||
|
||||
FState nf = realiseFState(hash2fstate(parseHash(*it)), dummy);
|
||||
string path = fstatePath(nf);
|
||||
|
||||
if (hashPath(path) != hash)
|
||||
throw Error(format("bad substitute in `%1%'") % (string) path);
|
||||
Strings paths = fstatePaths(subId, true);
|
||||
if (paths.size() != 1)
|
||||
throw Error("substitute created more than 1 path");
|
||||
string path = *(paths.begin());
|
||||
|
||||
if (target.empty())
|
||||
return path; /* !!! prefix */
|
||||
else {
|
||||
if (path != target) {
|
||||
copyPath(path, target);
|
||||
registerPath(target, hash);
|
||||
registerPath(target, id);
|
||||
}
|
||||
return target;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
throw Error(format("cannot expand id `%1%'") % (string) id);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue