* Substitute fixes.

This commit is contained in:
Eelco Dolstra 2003-07-16 20:00:51 +00:00
parent b9ecadee6e
commit 9d56ca219f
8 changed files with 86 additions and 36 deletions

View file

@ -4,7 +4,9 @@ echo "downloading $url into $out..."
wget "$url" -O "$out" || exit 1 wget "$url" -O "$out" || exit 1
actual=$(md5sum -b $out | cut -c1-32) actual=$(md5sum -b $out | cut -c1-32)
if ! test "$md5" == "ignore"; then
if ! test "$actual" == "$md5"; then if ! test "$actual" == "$md5"; then
echo "hash is $actual, expected $md5" echo "hash is $actual, expected $md5"
exit 1 exit 1
fi fi
fi

View file

@ -1,3 +1,3 @@
#! /bin/sh #! /bin/sh
/tmp/nix/bin/nix --dump --file "$path" | bzip2 > $out || exit 1 /nix/bin/nix --dump --file "$path" | bzip2 > $out || exit 1

View file

@ -38,7 +38,7 @@ while (<CONFFILE>) {
# Nix archive from the network. # Nix archive from the network.
my $fetch = my $fetch =
"App(IncludeFix(\"fetchurl/fetchurl.fix\"), " . "App(IncludeFix(\"fetchurl/fetchurl.fix\"), " .
"[(\"url\", \"$url/$fn\"), (\"hash\", \"\")])"; "[(\"url\", \"$url/$fn\"), (\"md5\", \"ignore\")])";
my $fixexpr = my $fixexpr =
"App(IncludeFix(\"nar/unnar.fix\"), " . "App(IncludeFix(\"nar/unnar.fix\"), " .
"[ (\"nar\", $fetch)" . "[ (\"nar\", $fetch)" .

View file

@ -2,14 +2,14 @@
my @pushlist; my @pushlist;
foreach my $hash (@ARGV) { foreach my $id (@ARGV) {
die unless $hash =~ /^([0-9a-z]{32})$/; die unless $id =~ /^([0-9a-z]{32})$/;
# Get all paths referenced by the normalisation of the given # Get all paths referenced by the normalisation of the given
# fstate expression. # fstate expression.
my @paths; my @paths;
open PATHS, "nix -qrh $hash 2> /dev/null |" or die "nix -qrh"; open PATHS, "nix -qrh $id 2> /dev/null |" or die "nix -qrh";
while (<PATHS>) { while (<PATHS>) {
chomp; chomp;
next unless /^\//; next unless /^\//;
@ -21,15 +21,12 @@ foreach my $hash (@ARGV) {
# a Nix archive. # a Nix archive.
foreach my $path (@paths) { foreach my $path (@paths) {
# Hash the path. next unless ($path =~ /\/([0-9a-z]{32})[^\/]*/);
my $phash = `nix-hash $path`; my $pathid = $1;
$? and die "nix-hash";
chomp $phash;
die unless $phash =~ /^([0-9a-z]{32})$/;
# Construct a name for the Nix archive. If the file is an # Construct a name for the Nix archive. If the file is an
# fstate successor, encode this into the name. # fstate successor, encode this into the name.
my $name = $phash; my $name = $pathid;
if ($path =~ /-s-([0-9a-z]{32}).nix$/) { if ($path =~ /-s-([0-9a-z]{32}).nix$/) {
$name = "$name-s-$1"; $name = "$name-s-$1";
} }
@ -38,7 +35,7 @@ foreach my $hash (@ARGV) {
# Construct a Fix expression that creates a Nix archive. # Construct a Fix expression that creates a Nix archive.
my $fixexpr = my $fixexpr =
"App(IncludeFix(\"nar/nar.fix\"), " . "App(IncludeFix(\"nar/nar.fix\"), " .
"[ (\"path\", Path(\"$path\", Hash(\"$phash\"), [Include(\"$hash\")]))" . "[ (\"path\", Slice([\"$pathid\"], [(\"$path\", \"$pathid\", [])]))" .
", (\"name\", \"$name\")" . ", (\"name\", \"$name\")" .
"])"; "])";
@ -48,13 +45,13 @@ foreach my $hash (@ARGV) {
close FIX; close FIX;
# Instantiate a Nix expression from the Fix expression. # Instantiate a Nix expression from the Fix expression.
my $nhash = `fix $fixfile`; my $nid = `fix $fixfile`;
$? and die "instantiating Nix archive expression"; $? and die "instantiating Nix archive expression";
chomp $nhash; chomp $nid;
die unless $nhash =~ /^([0-9a-z]{32})$/; die unless $nid =~ /^([0-9a-z]{32})$/;
# Realise the Nix expression. # Realise the Nix expression.
my $npath = `nix -qph $nhash 2> /dev/null`; my $npath = `nix -qph $nid 2> /dev/null`;
$? and die "creating Nix archive"; $? and die "creating Nix archive";
chomp $npath; chomp $npath;

View file

@ -65,6 +65,9 @@ bool queryDB(const string & filename, const string & dbname,
err = db->get(0, &kt, &dt, 0); err = db->get(0, &kt, &dt, 0);
if (err) return false; if (err) return false;
if (!dt.get_data())
data = "";
else
data = string((char *) dt.get_data(), dt.get_size()); data = string((char *) dt.get_data(), dt.get_size());
} catch (DbException e) { rethrow(e); } } catch (DbException e) { rethrow(e); }

View file

@ -111,6 +111,14 @@ static Expr evalExpr(Expr e)
ATmatch(e, "FSId(<str>)", &s1)) ATmatch(e, "FSId(<str>)", &s1))
return e; 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. */ /* Application. */
if (ATmatch(e, "App(<term>, [<list>])", &e1, &e2)) { if (ATmatch(e, "App(<term>, [<list>])", &e1, &e2)) {
e1 = evalExpr(e1); e1 = evalExpr(e1);

View file

@ -21,15 +21,22 @@ typedef map<string, string> Environment;
class AutoDelete class AutoDelete
{ {
string path; string path;
bool del;
public: public:
AutoDelete(const string & p) : path(p) AutoDelete(const string & p) : path(p)
{ {
del = true;
} }
~AutoDelete() ~AutoDelete()
{ {
deletePath(path); if (del) deletePath(path);
}
void cancel()
{
del = false;
} }
}; };
@ -114,9 +121,11 @@ static void runProgram(const string & program, Environment env)
if (waitpid(pid, &status, 0) != pid) if (waitpid(pid, &status, 0) != pid)
throw Error("unable to wait for child"); 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"); throw Error("unable to build package");
} }
}
/* Throw an exception if the given platform string is not supported by /* Throw an exception if the given platform string is not supported by
@ -336,7 +345,7 @@ static Slice normaliseFState2(FSId id, StringSet & usedPaths)
bnds = ATgetNext(bnds); bnds = ATgetNext(bnds);
} }
/* Check that none of the output paths exist. */ /* Parse the outputs. */
typedef map<string, FSId> OutPaths; typedef map<string, FSId> OutPaths;
OutPaths outPaths; OutPaths outPaths;
while (!ATisEmpty(outs)) { while (!ATisEmpty(outs)) {
@ -349,6 +358,25 @@ static Slice normaliseFState2(FSId id, StringSet & usedPaths)
outs = ATgetNext(outs); 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++)
{
try {
expandId(i->second, i->first);
} catch (...) {
fastBuild = false;
break;
}
}
#endif
if (!fastBuild) {
/* Check that none of the outputs exist. */
for (OutPaths::iterator i = outPaths.begin(); for (OutPaths::iterator i = outPaths.begin();
i != outPaths.end(); i++) i != outPaths.end(); i++)
if (pathExists(i->first)) if (pathExists(i->first))
@ -357,6 +385,9 @@ static Slice normaliseFState2(FSId id, StringSet & usedPaths)
/* Run the builder. */ /* Run the builder. */
runProgram(builder, env); runProgram(builder, env);
} else
debug(format("skipping build"));
Slice slice; Slice slice;
/* Check whether the output paths were created, and register each /* Check whether the output paths were created, and register each

View file

@ -86,6 +86,7 @@ void copyPath(string src, string dst)
void registerSubstitute(const FSId & srcId, const FSId & subId) void registerSubstitute(const FSId & srcId, const FSId & subId)
{ {
#if 0
Strings subs; Strings subs;
queryListDB(nixDB, dbSubstitutes, srcId, subs); /* non-existence = ok */ queryListDB(nixDB, dbSubstitutes, srcId, subs); /* non-existence = ok */
@ -94,6 +95,12 @@ void registerSubstitute(const FSId & srcId, const FSId & subId)
subs.push_back(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); setListDB(nixDB, dbSubstitutes, srcId, subs);
} }
@ -126,6 +133,8 @@ void unregisterPath(const string & _path)
return; return;
FSId id(parseHash(_id)); FSId id(parseHash(_id));
delDB(nixDB, dbPath2Id, path);
/* begin transaction */ /* begin transaction */
Strings paths, paths2; Strings paths, paths2;
@ -140,6 +149,7 @@ void unregisterPath(const string & _path)
setListDB(nixDB, dbId2Paths, id, paths2); setListDB(nixDB, dbId2Paths, id, paths2);
/* end transaction */ /* end transaction */
} }
@ -189,32 +199,31 @@ string expandId(const FSId & id, const string & target,
} }
} }
#if 0
/* Try to realise the substitutes. */ /* Try to realise the substitutes. */
Strings subs; Strings subs;
queryListDB(nixDB, dbSubstitutes, id, subs); /* non-existence = ok */ queryListDB(nixDB, dbSubstitutes, id, subs); /* non-existence = ok */
for (Strings::iterator it = subs.begin(); it != subs.end(); it++) { 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); Strings paths = fstatePaths(subId, true);
string path = fstatePath(nf); if (paths.size() != 1)
throw Error("substitute created more than 1 path");
if (hashPath(path) != hash) string path = *(paths.begin());
throw Error(format("bad substitute in `%1%'") % (string) path);
if (target.empty()) if (target.empty())
return path; /* !!! prefix */ return path; /* !!! prefix */
else { else {
if (path != target) { if (path != target) {
copyPath(path, target); copyPath(path, target);
registerPath(target, hash); registerPath(target, id);
} }
return target; return target;
} }
} }
#endif
throw Error(format("cannot expand id `%1%'") % (string) id); throw Error(format("cannot expand id `%1%'") % (string) id);
} }