* Derivation expressions now can specify arguments to be passed to the
builder. Note that this unfortunately causes all Fix-computed hashes to change.
This commit is contained in:
parent
e374dbf89b
commit
555347744d
33
src/exec.cc
33
src/exec.cc
|
@ -35,7 +35,8 @@ public:
|
||||||
|
|
||||||
|
|
||||||
/* Run a program. */
|
/* Run a program. */
|
||||||
void runProgram(const string & program, Environment env)
|
void runProgram(const string & program,
|
||||||
|
const Strings & args, const Environment & env)
|
||||||
{
|
{
|
||||||
/* Create a log file. */
|
/* Create a log file. */
|
||||||
string logFileName = nixLogDir + "/run.log";
|
string logFileName = nixLogDir + "/run.log";
|
||||||
|
@ -68,15 +69,25 @@ void runProgram(const string & program, Environment env)
|
||||||
if (chdir(tmpDir.c_str()) == -1)
|
if (chdir(tmpDir.c_str()) == -1)
|
||||||
throw SysError(format("changing into to `%1%'") % tmpDir);
|
throw SysError(format("changing into to `%1%'") % tmpDir);
|
||||||
|
|
||||||
/* Fill in the environment. We don't bother freeing
|
/* Fill in the arguments. */
|
||||||
the strings, since we'll exec or die soon
|
const char * argArr[args.size() + 2];
|
||||||
anyway. */
|
const char * * p = argArr;
|
||||||
const char * env2[env.size() + 1];
|
string progName = baseNameOf(program);
|
||||||
int i = 0;
|
*p++ = progName.c_str();
|
||||||
for (Environment::iterator it = env.begin();
|
for (Strings::const_iterator i = args.begin();
|
||||||
it != env.end(); it++, i++)
|
i != args.end(); i++)
|
||||||
env2[i] = (new string(it->first + "=" + it->second))->c_str();
|
*p++ = i->c_str();
|
||||||
env2[i] = 0;
|
*p = 0;
|
||||||
|
|
||||||
|
/* Fill in the environment. */
|
||||||
|
Strings envStrs;
|
||||||
|
const char * envArr[env.size() + 1];
|
||||||
|
p = envArr;
|
||||||
|
for (Environment::const_iterator i = env.begin();
|
||||||
|
i != env.end(); i++)
|
||||||
|
*p++ = envStrs.insert(envStrs.end(),
|
||||||
|
i->first + "=" + i->second)->c_str();
|
||||||
|
*p = 0;
|
||||||
|
|
||||||
/* Dup the log handle into stderr. */
|
/* Dup the log handle into stderr. */
|
||||||
if (dup2(fileno(logFile), STDERR_FILENO) == -1)
|
if (dup2(fileno(logFile), STDERR_FILENO) == -1)
|
||||||
|
@ -87,7 +98,7 @@ void runProgram(const string & program, Environment env)
|
||||||
throw SysError("cannot dup stderr into stdout");
|
throw SysError("cannot dup stderr into stdout");
|
||||||
|
|
||||||
/* Execute the program. This should not return. */
|
/* Execute the program. This should not return. */
|
||||||
execle(program.c_str(), baseNameOf(program).c_str(), 0, env2);
|
execve(program.c_str(), (char * *) argArr, (char * *) envArr);
|
||||||
|
|
||||||
throw SysError(format("unable to execute %1%") % program);
|
throw SysError(format("unable to execute %1%") % program);
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,8 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
|
#include "util.hh"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
|
||||||
|
@ -12,7 +14,8 @@ typedef map<string, string> Environment;
|
||||||
|
|
||||||
|
|
||||||
/* Run a program. */
|
/* Run a program. */
|
||||||
void runProgram(const string & program, Environment env);
|
void runProgram(const string & program,
|
||||||
|
const Strings & args, const Environment & env);
|
||||||
|
|
||||||
|
|
||||||
#endif /* !__EXEC_H */
|
#endif /* !__EXEC_H */
|
||||||
|
|
|
@ -120,13 +120,19 @@ static bool parseSlice(ATerm t, Slice & slice)
|
||||||
|
|
||||||
static bool parseDerive(ATerm t, Derive & derive)
|
static bool parseDerive(ATerm t, Derive & derive)
|
||||||
{
|
{
|
||||||
ATermList outs, ins, bnds;
|
ATermList outs, ins, args, bnds;
|
||||||
char * builder;
|
char * builder;
|
||||||
char * platform;
|
char * platform;
|
||||||
|
|
||||||
if (!ATmatch(t, "Derive([<list>], [<list>], <str>, <str>, [<list>])",
|
if (!ATmatch(t, "Derive([<list>], [<list>], <str>, <str>, [<list>], [<list>])",
|
||||||
&outs, &ins, &builder, &platform, &bnds))
|
&outs, &ins, &platform, &builder, &args, &bnds))
|
||||||
return false;
|
{
|
||||||
|
/* !!! compatibility -> remove eventually */
|
||||||
|
if (!ATmatch(t, "Derive([<list>], [<list>], <str>, <str>, [<list>])",
|
||||||
|
&outs, &ins, &builder, &platform, &bnds))
|
||||||
|
return false;
|
||||||
|
args = ATempty;
|
||||||
|
}
|
||||||
|
|
||||||
while (!ATisEmpty(outs)) {
|
while (!ATisEmpty(outs)) {
|
||||||
char * s1, * s2;
|
char * s1, * s2;
|
||||||
|
@ -142,6 +148,15 @@ static bool parseDerive(ATerm t, Derive & derive)
|
||||||
derive.builder = builder;
|
derive.builder = builder;
|
||||||
derive.platform = platform;
|
derive.platform = platform;
|
||||||
|
|
||||||
|
while (!ATisEmpty(args)) {
|
||||||
|
char * s;
|
||||||
|
ATerm arg = ATgetFirst(args);
|
||||||
|
if (!ATmatch(arg, "<str>", &s))
|
||||||
|
throw badTerm("string expected", arg);
|
||||||
|
derive.args.push_back(s);
|
||||||
|
args = ATgetNext(args);
|
||||||
|
}
|
||||||
|
|
||||||
while (!ATisEmpty(bnds)) {
|
while (!ATisEmpty(bnds)) {
|
||||||
char * s1, * s2;
|
char * s1, * s2;
|
||||||
ATerm bnd = ATgetFirst(bnds);
|
ATerm bnd = ATgetFirst(bnds);
|
||||||
|
@ -204,6 +219,11 @@ static ATerm unparseDerive(const Derive & derive)
|
||||||
ATmake("(<str>, <str>)",
|
ATmake("(<str>, <str>)",
|
||||||
i->first.c_str(), ((string) i->second).c_str()));
|
i->first.c_str(), ((string) i->second).c_str()));
|
||||||
|
|
||||||
|
ATermList args = ATempty;
|
||||||
|
for (Strings::const_iterator i = derive.args.begin();
|
||||||
|
i != derive.args.end(); i++)
|
||||||
|
args = ATinsert(args, ATmake("<str>", i->c_str()));
|
||||||
|
|
||||||
ATermList env = ATempty;
|
ATermList env = ATempty;
|
||||||
for (StringPairs::const_iterator i = derive.env.begin();
|
for (StringPairs::const_iterator i = derive.env.begin();
|
||||||
i != derive.env.end(); i++)
|
i != derive.env.end(); i++)
|
||||||
|
@ -211,11 +231,12 @@ static ATerm unparseDerive(const Derive & derive)
|
||||||
ATmake("(<str>, <str>)",
|
ATmake("(<str>, <str>)",
|
||||||
i->first.c_str(), i->second.c_str()));
|
i->first.c_str(), i->second.c_str()));
|
||||||
|
|
||||||
return ATmake("Derive(<term>, <term>, <str>, <str>, <term>)",
|
return ATmake("Derive(<term>, <term>, <str>, <str>, <term>, <term>)",
|
||||||
ATreverse(outs),
|
ATreverse(outs),
|
||||||
unparseIds(derive.inputs),
|
unparseIds(derive.inputs),
|
||||||
derive.builder.c_str(),
|
|
||||||
derive.platform.c_str(),
|
derive.platform.c_str(),
|
||||||
|
derive.builder.c_str(),
|
||||||
|
ATreverse(args),
|
||||||
ATreverse(env));
|
ATreverse(env));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,8 +36,9 @@ struct Derive
|
||||||
{
|
{
|
||||||
DeriveOutputs outputs;
|
DeriveOutputs outputs;
|
||||||
FSIds inputs;
|
FSIds inputs;
|
||||||
string builder;
|
|
||||||
string platform;
|
string platform;
|
||||||
|
string builder;
|
||||||
|
Strings args;
|
||||||
StringPairs env;
|
StringPairs env;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -169,7 +169,7 @@ FSId normaliseFState(FSId id, FSIdSet pending)
|
||||||
|
|
||||||
/* Run the builder. */
|
/* Run the builder. */
|
||||||
msg(lvlChatty, format("building..."));
|
msg(lvlChatty, format("building..."));
|
||||||
runProgram(fs.derive.builder, env);
|
runProgram(fs.derive.builder, fs.derive.args, env);
|
||||||
msg(lvlChatty, format("build completed"));
|
msg(lvlChatty, format("build completed"));
|
||||||
|
|
||||||
} else
|
} else
|
||||||
|
|
Loading…
Reference in a new issue