forked from lix-project/lix
* Argument support in Fix. Arguments can be passed through the
builder using the `args' binding: ("args", ["bla", True, IncludeFix("aterm/aterm.fix")]) Note that packages can also be declared as inputs by specifying them in the argument list.
This commit is contained in:
parent
555347744d
commit
96c7b98bf0
61
src/fix.cc
61
src/fix.cc
|
@ -150,6 +150,30 @@ static Hash hashPackage(EvalState & state, FState fs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static string processBinding(EvalState & state, Expr e, FState & fs)
|
||||||
|
{
|
||||||
|
char * s1;
|
||||||
|
|
||||||
|
if (ATmatch(e, "FSId(<str>)", &s1)) {
|
||||||
|
FSId id = parseHash(s1);
|
||||||
|
Strings paths = fstatePathsCached(state, id);
|
||||||
|
if (paths.size() != 1) abort();
|
||||||
|
string path = *(paths.begin());
|
||||||
|
fs.derive.inputs.push_back(id);
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ATmatch(e, "<str>", &s1))
|
||||||
|
return s1;
|
||||||
|
|
||||||
|
if (ATmatch(e, "True")) return "1";
|
||||||
|
|
||||||
|
if (ATmatch(e, "False")) return "";
|
||||||
|
|
||||||
|
throw badTerm("invalid package binding", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static Expr evalExpr2(EvalState & state, Expr e)
|
static Expr evalExpr2(EvalState & state, Expr e)
|
||||||
{
|
{
|
||||||
char * s1;
|
char * s1;
|
||||||
|
@ -274,30 +298,29 @@ static Expr evalExpr2(EvalState & state, Expr e)
|
||||||
string key = it->first;
|
string key = it->first;
|
||||||
ATerm value = it->second;
|
ATerm value = it->second;
|
||||||
|
|
||||||
if (ATmatch(value, "FSId(<str>)", &s1)) {
|
if (key == "args") {
|
||||||
FSId id = parseHash(s1);
|
ATermList args;
|
||||||
Strings paths = fstatePathsCached(state, id);
|
if (!ATmatch(value, "[<list>]", &args))
|
||||||
if (paths.size() != 1) abort();
|
throw badTerm("list expected", value);
|
||||||
string path = *(paths.begin());
|
|
||||||
fs.derive.inputs.push_back(id);
|
while (!ATisEmpty(args)) {
|
||||||
fs.derive.env.push_back(StringPair(key, path));
|
Expr arg = evalExpr(state, ATgetFirst(args));
|
||||||
if (key == "build") fs.derive.builder = path;
|
fs.derive.args.push_back(processBinding(state, arg, fs));
|
||||||
|
args = ATgetNext(args);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (ATmatch(value, "<str>", &s1)) {
|
|
||||||
if (key == "name") name = s1;
|
else {
|
||||||
|
string s = processBinding(state, value, fs);
|
||||||
|
fs.derive.env.push_back(StringPair(key, s));
|
||||||
|
|
||||||
|
if (key == "build") fs.derive.builder = s;
|
||||||
|
if (key == "name") name = s;
|
||||||
if (key == "id") {
|
if (key == "id") {
|
||||||
outId = parseHash(s1);
|
outId = parseHash(s);
|
||||||
outIdGiven = true;
|
outIdGiven = true;
|
||||||
}
|
}
|
||||||
fs.derive.env.push_back(StringPair(key, s1));
|
|
||||||
}
|
}
|
||||||
else if (ATmatch(value, "True")) {
|
|
||||||
fs.derive.env.push_back(StringPair(key, "1"));
|
|
||||||
}
|
|
||||||
else if (ATmatch(value, "False")) {
|
|
||||||
fs.derive.env.push_back(StringPair(key, ""));
|
|
||||||
}
|
|
||||||
else throw badTerm("invalid package argument", value);
|
|
||||||
|
|
||||||
bnds = ATinsert(bnds,
|
bnds = ATinsert(bnds,
|
||||||
ATmake("(<str>, <term>)", key.c_str(), value));
|
ATmake("(<str>, <term>)", key.c_str(), value));
|
||||||
|
|
11
testpkgs/args/args-build.sh
Executable file
11
testpkgs/args/args-build.sh
Executable file
|
@ -0,0 +1,11 @@
|
||||||
|
#! /bin/sh
|
||||||
|
|
||||||
|
IFS=
|
||||||
|
|
||||||
|
echo "printing list of args"
|
||||||
|
|
||||||
|
for i in $@; do
|
||||||
|
echo "arg: $i"
|
||||||
|
done
|
||||||
|
|
||||||
|
touch $out
|
7
testpkgs/args/args.fix
Normal file
7
testpkgs/args/args.fix
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
Package(
|
||||||
|
[ ("name", "args")
|
||||||
|
, ("build", Relative("args/args-build.sh"))
|
||||||
|
|
||||||
|
, ("args", ["1", "2", "3", IncludeFix("slow2/slow.fix")])
|
||||||
|
]
|
||||||
|
)
|
Loading…
Reference in a new issue