forked from lix-project/lix
* `nix-instantiate ... --arg NAME VALUE': allow arguments to be passed
to functions from the command line. * nix-build: started removing backticks.
This commit is contained in:
parent
c11839d7b2
commit
4661282fde
|
@ -77,6 +77,12 @@ EOF
|
||||||
push @instArgs, ("--attr", $ARGV[$n]);
|
push @instArgs, ("--attr", $ARGV[$n]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
elsif ($arg eq "--arg") {
|
||||||
|
die "$0: `--arg' requires two arguments\n" unless $n + 2 < scalar @ARGV;
|
||||||
|
push @instArgs, ("--arg", $ARGV[$n + 1], $ARGV[$n + 2]);
|
||||||
|
$n += 2;
|
||||||
|
}
|
||||||
|
|
||||||
elsif (substr($arg, 0, 1) eq "-") {
|
elsif (substr($arg, 0, 1) eq "-") {
|
||||||
push @buildArgs, $arg;
|
push @buildArgs, $arg;
|
||||||
}
|
}
|
||||||
|
@ -103,8 +109,10 @@ if (!defined $outLink) {
|
||||||
foreach my $expr (@exprs) {
|
foreach my $expr (@exprs) {
|
||||||
|
|
||||||
# Instantiate.
|
# Instantiate.
|
||||||
my $drvPaths = `@bindir@/nix-instantiate --add-root "$drvLink" --indirect @instArgs "$expr"`;
|
my @drvPaths;
|
||||||
my @drvPaths = split ' ', $drvPaths;
|
open DRVPATHS, "-|", "@bindir@/nix-instantiate", "--add-root", $drvLink, "--indirect", @instArgs, $expr;
|
||||||
|
while (<DRVPATHS>) {chomp; push @drvPaths, $_;}
|
||||||
|
close DRVPATHS;
|
||||||
|
|
||||||
foreach my $drvPath (@drvPaths) {
|
foreach my $drvPath (@drvPaths) {
|
||||||
my $target = readlink $drvPath;
|
my $target = readlink $drvPath;
|
||||||
|
|
|
@ -33,7 +33,7 @@ Expr findAlongAttrPath(EvalState & state, const string & attrPath, Expr e)
|
||||||
if (string2Int(attr, attrIndex)) apType = apIndex;
|
if (string2Int(attr, attrIndex)) apType = apIndex;
|
||||||
|
|
||||||
/* Evaluate the expression. */
|
/* Evaluate the expression. */
|
||||||
e = evalExpr(state, autoCallFunction(evalExpr(state, e)));
|
e = evalExpr(state, autoCallFunction(evalExpr(state, e), ATermMap(1)));
|
||||||
|
|
||||||
/* It should evaluate to either an attribute set or an
|
/* It should evaluate to either an attribute set or an
|
||||||
expression, according to what is specified in the
|
expression, according to what is specified in the
|
||||||
|
|
|
@ -287,20 +287,27 @@ static ATerm concatStrings(EvalState & state, const ATermVector & args)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Expr autoCallFunction(Expr e)
|
Expr autoCallFunction(Expr e, const ATermMap & args)
|
||||||
{
|
{
|
||||||
ATermList formals;
|
ATermList formals;
|
||||||
ATerm body, pos;
|
ATerm body, pos;
|
||||||
|
|
||||||
if (matchFunction(e, formals, body, pos)) {
|
if (matchFunction(e, formals, body, pos)) {
|
||||||
|
ATermMap actualArgs(128);
|
||||||
|
|
||||||
for (ATermIterator i(formals); i; ++i) {
|
for (ATermIterator i(formals); i; ++i) {
|
||||||
Expr name, def; ATerm values, def2;
|
Expr name, def, value; ATerm values, def2;
|
||||||
if (!matchFormal(*i, name, values, def2)) abort();
|
if (!matchFormal(*i, name, values, def2)) abort();
|
||||||
if (!matchDefaultValue(def2, def))
|
if ((value = args.get(name)))
|
||||||
|
actualArgs.set(name, makeAttrRHS(value, makeNoPos()));
|
||||||
|
else if (!matchDefaultValue(def2, def))
|
||||||
throw TypeError(format("cannot auto-call a function that has an argument without a default value (`%1%')")
|
throw TypeError(format("cannot auto-call a function that has an argument without a default value (`%1%')")
|
||||||
% aterm2String(name));
|
% aterm2String(name));
|
||||||
}
|
}
|
||||||
e = makeCall(e, makeAttrs(ATermMap(0)));
|
|
||||||
|
e = makeCall(e, makeAttrs(actualArgs));
|
||||||
}
|
}
|
||||||
|
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -60,9 +60,9 @@ string coerceToStringWithContext(EvalState & state,
|
||||||
Expr wrapInContext(ATermList context, Expr e);
|
Expr wrapInContext(ATermList context, Expr e);
|
||||||
|
|
||||||
/* Automatically call a function for which each argument has a default
|
/* Automatically call a function for which each argument has a default
|
||||||
value. Note: result is a call, not a normal form; it should be
|
value or has a binding in the `args' map. Note: result is a call,
|
||||||
evaluated by calling evalExpr(). */
|
not a normal form; it should be evaluated by calling evalExpr(). */
|
||||||
Expr autoCallFunction(Expr e);
|
Expr autoCallFunction(Expr e, const ATermMap & args);
|
||||||
|
|
||||||
/* Print statistics. */
|
/* Print statistics. */
|
||||||
void printEvalStats(EvalState & state);
|
void printEvalStats(EvalState & state);
|
||||||
|
|
|
@ -121,9 +121,10 @@ static string addToPath(const string & s1, const string & s2)
|
||||||
|
|
||||||
|
|
||||||
static void getDerivations(EvalState & state, Expr e,
|
static void getDerivations(EvalState & state, Expr e,
|
||||||
const string & pathPrefix, DrvInfos & drvs, Exprs & doneExprs)
|
const string & pathPrefix, const ATermMap & autoArgs,
|
||||||
|
DrvInfos & drvs, Exprs & doneExprs)
|
||||||
{
|
{
|
||||||
e = evalExpr(state, autoCallFunction(evalExpr(state, e)));
|
e = evalExpr(state, autoCallFunction(evalExpr(state, e), autoArgs));
|
||||||
|
|
||||||
/* Process the expression. */
|
/* Process the expression. */
|
||||||
ATermList es;
|
ATermList es;
|
||||||
|
@ -152,7 +153,7 @@ static void getDerivations(EvalState & state, Expr e,
|
||||||
queryAllAttrs(e, attrs, false);
|
queryAllAttrs(e, attrs, false);
|
||||||
Expr e2 = attrs.get(toATerm("recurseForDerivations"));
|
Expr e2 = attrs.get(toATerm("recurseForDerivations"));
|
||||||
if (e2 && evalBool(state, e2))
|
if (e2 && evalBool(state, e2))
|
||||||
getDerivations(state, e, pathPrefix2, drvs, doneExprs);
|
getDerivations(state, e, pathPrefix2, autoArgs, drvs, doneExprs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -167,7 +168,7 @@ static void getDerivations(EvalState & state, Expr e,
|
||||||
format("evaluating list element"));
|
format("evaluating list element"));
|
||||||
string pathPrefix2 = addToPath(pathPrefix, (format("%1%") % n).str());
|
string pathPrefix2 = addToPath(pathPrefix, (format("%1%") % n).str());
|
||||||
if (getDerivation(state, *i, pathPrefix2, drvs, doneExprs))
|
if (getDerivation(state, *i, pathPrefix2, drvs, doneExprs))
|
||||||
getDerivations(state, *i, pathPrefix2, drvs, doneExprs);
|
getDerivations(state, *i, pathPrefix2, autoArgs, drvs, doneExprs);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -177,8 +178,8 @@ static void getDerivations(EvalState & state, Expr e,
|
||||||
|
|
||||||
|
|
||||||
void getDerivations(EvalState & state, Expr e, const string & pathPrefix,
|
void getDerivations(EvalState & state, Expr e, const string & pathPrefix,
|
||||||
DrvInfos & drvs)
|
const ATermMap & autoArgs, DrvInfos & drvs)
|
||||||
{
|
{
|
||||||
Exprs doneExprs;
|
Exprs doneExprs;
|
||||||
getDerivations(state, e, pathPrefix, drvs, doneExprs);
|
getDerivations(state, e, pathPrefix, autoArgs, drvs, doneExprs);
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,7 @@ typedef list<DrvInfo> DrvInfos;
|
||||||
bool getDerivation(EvalState & state, Expr e, DrvInfo & drv);
|
bool getDerivation(EvalState & state, Expr e, DrvInfo & drv);
|
||||||
|
|
||||||
void getDerivations(EvalState & state, Expr e, const string & pathPrefix,
|
void getDerivations(EvalState & state, Expr e, const string & pathPrefix,
|
||||||
DrvInfos & drvs);
|
const ATermMap & autoArgs, DrvInfos & drvs);
|
||||||
|
|
||||||
|
|
||||||
#endif /* !__GET_DRVS_H */
|
#endif /* !__GET_DRVS_H */
|
||||||
|
|
|
@ -65,7 +65,7 @@ static void loadDerivations(EvalState & state, Path nixExprPath,
|
||||||
string systemFilter, DrvInfos & elems)
|
string systemFilter, DrvInfos & elems)
|
||||||
{
|
{
|
||||||
getDerivations(state,
|
getDerivations(state,
|
||||||
parseExprFromFile(state, absPath(nixExprPath)), "", elems);
|
parseExprFromFile(state, absPath(nixExprPath)), "", ATermMap(1), elems);
|
||||||
|
|
||||||
/* Filter out all derivations not applicable to the current
|
/* Filter out all derivations not applicable to the current
|
||||||
system. */
|
system. */
|
||||||
|
@ -119,7 +119,7 @@ static DrvInfos queryInstalled(EvalState & state, const Path & userEnv)
|
||||||
e = bottomupRewrite(addPos, e);
|
e = bottomupRewrite(addPos, e);
|
||||||
|
|
||||||
DrvInfos elems;
|
DrvInfos elems;
|
||||||
getDerivations(state, e, "", elems);
|
getDerivations(state, e, "", ATermMap(1), elems);
|
||||||
return elems;
|
return elems;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -334,7 +334,7 @@ static void queryInstSources(EvalState & state,
|
||||||
{
|
{
|
||||||
Expr e2 = parseExprFromString(state, *i, absPath("."));
|
Expr e2 = parseExprFromString(state, *i, absPath("."));
|
||||||
Expr call = makeCall(e2, e1);
|
Expr call = makeCall(e2, e1);
|
||||||
getDerivations(state, call, "", elems);
|
getDerivations(state, call, "", ATermMap(1), elems);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
@ -390,7 +390,7 @@ static void queryInstSources(EvalState & state,
|
||||||
getDerivations(state,
|
getDerivations(state,
|
||||||
findAlongAttrPath(state, *i,
|
findAlongAttrPath(state, *i,
|
||||||
parseExprFromFile(state, instSource.nixExprPath)),
|
parseExprFromFile(state, instSource.nixExprPath)),
|
||||||
"", elems);
|
"", ATermMap(1), elems);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ static bool indirectRoot = false;
|
||||||
|
|
||||||
|
|
||||||
static void printResult(EvalState & state, Expr e,
|
static void printResult(EvalState & state, Expr e,
|
||||||
bool evalOnly, bool printArgs)
|
bool evalOnly, bool printArgs, const ATermMap & autoArgs)
|
||||||
{
|
{
|
||||||
if (evalOnly)
|
if (evalOnly)
|
||||||
cout << format("%1%\n") % e;
|
cout << format("%1%\n") % e;
|
||||||
|
@ -62,7 +62,7 @@ static void printResult(EvalState & state, Expr e,
|
||||||
|
|
||||||
else {
|
else {
|
||||||
DrvInfos drvs;
|
DrvInfos drvs;
|
||||||
getDerivations(state, e, "", drvs);
|
getDerivations(state, e, "", autoArgs, drvs);
|
||||||
for (DrvInfos::iterator i = drvs.begin(); i != drvs.end(); ++i) {
|
for (DrvInfos::iterator i = drvs.begin(); i != drvs.end(); ++i) {
|
||||||
Path drvPath = i->queryDrvPath(state);
|
Path drvPath = i->queryDrvPath(state);
|
||||||
if (gcRoot == "")
|
if (gcRoot == "")
|
||||||
|
@ -86,6 +86,7 @@ void run(Strings args)
|
||||||
bool parseOnly = false;
|
bool parseOnly = false;
|
||||||
bool printArgs = false;
|
bool printArgs = false;
|
||||||
string attrPath;
|
string attrPath;
|
||||||
|
ATermMap autoArgs(128);
|
||||||
|
|
||||||
for (Strings::iterator i = args.begin();
|
for (Strings::iterator i = args.begin();
|
||||||
i != args.end(); )
|
i != args.end(); )
|
||||||
|
@ -106,20 +107,29 @@ void run(Strings args)
|
||||||
readOnlyMode = true;
|
readOnlyMode = true;
|
||||||
printArgs = true;
|
printArgs = true;
|
||||||
}
|
}
|
||||||
else if (arg == "--add-root") {
|
|
||||||
if (i == args.end())
|
|
||||||
throw UsageError("`--add-root requires an argument");
|
|
||||||
gcRoot = absPath(*i++);
|
|
||||||
}
|
|
||||||
else if (arg == "--attr" || arg == "-A") {
|
else if (arg == "--attr" || arg == "-A") {
|
||||||
if (i == args.end())
|
if (i == args.end())
|
||||||
throw UsageError("`--attr requires an argument");
|
throw UsageError("`--attr' requires an argument");
|
||||||
attrPath = *i++;
|
attrPath = *i++;
|
||||||
}
|
}
|
||||||
|
else if (arg == "--arg") {
|
||||||
|
if (i == args.end())
|
||||||
|
throw UsageError("`--arg' requires two arguments");
|
||||||
|
string name = *i++;
|
||||||
|
if (i == args.end())
|
||||||
|
throw UsageError("`--arg' requires two arguments");
|
||||||
|
Expr value = parseExprFromString(state, *i++, absPath("."));
|
||||||
|
autoArgs.set(toATerm(name), value);
|
||||||
|
}
|
||||||
|
else if (arg == "--add-root") {
|
||||||
|
if (i == args.end())
|
||||||
|
throw UsageError("`--add-root' requires an argument");
|
||||||
|
gcRoot = absPath(*i++);
|
||||||
|
}
|
||||||
else if (arg == "--indirect")
|
else if (arg == "--indirect")
|
||||||
indirectRoot = true;
|
indirectRoot = true;
|
||||||
else if (arg[0] == '-')
|
else if (arg[0] == '-')
|
||||||
throw UsageError(format("unknown flag `%1%`") % arg);
|
throw UsageError(format("unknown flag `%1%'") % arg);
|
||||||
else
|
else
|
||||||
files.push_back(arg);
|
files.push_back(arg);
|
||||||
}
|
}
|
||||||
|
@ -129,7 +139,7 @@ void run(Strings args)
|
||||||
if (readStdin) {
|
if (readStdin) {
|
||||||
Expr e = findAlongAttrPath(state, attrPath, parseStdin(state));
|
Expr e = findAlongAttrPath(state, attrPath, parseStdin(state));
|
||||||
if (!parseOnly) e = evalExpr(state, e);
|
if (!parseOnly) e = evalExpr(state, e);
|
||||||
printResult(state, e, evalOnly, printArgs);
|
printResult(state, e, evalOnly, printArgs, autoArgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Strings::iterator i = files.begin();
|
for (Strings::iterator i = files.begin();
|
||||||
|
@ -139,7 +149,7 @@ void run(Strings args)
|
||||||
Expr e = findAlongAttrPath(state, attrPath,
|
Expr e = findAlongAttrPath(state, attrPath,
|
||||||
parseExprFromFile(state, path));
|
parseExprFromFile(state, path));
|
||||||
if (!parseOnly) e = evalExpr(state, e);
|
if (!parseOnly) e = evalExpr(state, e);
|
||||||
printResult(state, e, evalOnly, printArgs);
|
printResult(state, e, evalOnly, printArgs, autoArgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
printEvalStats(state);
|
printEvalStats(state);
|
||||||
|
|
Loading…
Reference in a new issue