forked from lix-project/lix
nix-build, nix-shell: Don't print error message if nix-store/nix-instantiate fails
This commit is contained in:
parent
c55bf085eb
commit
4546be1b3e
src
|
@ -927,7 +927,7 @@ string runProgram(Path program, bool searchPath, const Strings & args,
|
||||||
/* Wait for the child to finish. */
|
/* Wait for the child to finish. */
|
||||||
int status = pid.wait(true);
|
int status = pid.wait(true);
|
||||||
if (!statusOk(status))
|
if (!statusOk(status))
|
||||||
throw ExecError(format("program ‘%1%’ %2%")
|
throw ExecError(status, format("program ‘%1%’ %2%")
|
||||||
% program % statusToString(status));
|
% program % statusToString(status));
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -247,7 +247,16 @@ pid_t startProcess(std::function<void()> fun, const ProcessOptions & options = P
|
||||||
string runProgram(Path program, bool searchPath = false,
|
string runProgram(Path program, bool searchPath = false,
|
||||||
const Strings & args = Strings(), const string & input = "");
|
const Strings & args = Strings(), const string & input = "");
|
||||||
|
|
||||||
MakeError(ExecError, Error)
|
class ExecError : public Error
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
int status;
|
||||||
|
|
||||||
|
template<typename... Args>
|
||||||
|
ExecError(int status, Args... args)
|
||||||
|
: Error(args...), status(status)
|
||||||
|
{ }
|
||||||
|
};
|
||||||
|
|
||||||
/* Convert a list of strings to a null-terminated vector of char
|
/* Convert a list of strings to a null-terminated vector of char
|
||||||
*'s. The result must not be accessed beyond the lifetime of the
|
*'s. The result must not be accessed beyond the lifetime of the
|
||||||
|
|
|
@ -60,6 +60,14 @@ std::vector<string> shellwords(const string & s)
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void maybePrintExecError(ExecError & e)
|
||||||
|
{
|
||||||
|
if (WIFEXITED(e.status))
|
||||||
|
throw Exit(WEXITSTATUS(e.status));
|
||||||
|
else
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char ** argv)
|
int main(int argc, char ** argv)
|
||||||
{
|
{
|
||||||
return handleExceptions(argv[0], [&]() {
|
return handleExceptions(argv[0], [&]() {
|
||||||
|
@ -346,8 +354,12 @@ int main(int argc, char ** argv)
|
||||||
for (const auto & arg : instArgs)
|
for (const auto & arg : instArgs)
|
||||||
instantiateArgs.push_back(arg);
|
instantiateArgs.push_back(arg);
|
||||||
instantiateArgs.push_back(expr);
|
instantiateArgs.push_back(expr);
|
||||||
|
try {
|
||||||
auto instOutput = runProgram(settings.nixBinDir + "/nix-instantiate", false, instantiateArgs);
|
auto instOutput = runProgram(settings.nixBinDir + "/nix-instantiate", false, instantiateArgs);
|
||||||
drvPaths = tokenizeString<std::vector<string>>(instOutput);
|
drvPaths = tokenizeString<std::vector<string>>(instOutput);
|
||||||
|
} catch (ExecError & e) {
|
||||||
|
maybePrintExecError(e);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
drvPaths.push_back(expr);
|
drvPaths.push_back(expr);
|
||||||
}
|
}
|
||||||
|
@ -370,7 +382,12 @@ int main(int argc, char ** argv)
|
||||||
nixStoreArgs.push_back(input.first);
|
nixStoreArgs.push_back(input.first);
|
||||||
for (const auto & src : drv.inputSrcs)
|
for (const auto & src : drv.inputSrcs)
|
||||||
nixStoreArgs.push_back(src);
|
nixStoreArgs.push_back(src);
|
||||||
|
|
||||||
|
try {
|
||||||
runProgram(settings.nixBinDir + "/nix-store", false, nixStoreArgs);
|
runProgram(settings.nixBinDir + "/nix-store", false, nixStoreArgs);
|
||||||
|
} catch (ExecError & e) {
|
||||||
|
maybePrintExecError(e);
|
||||||
|
}
|
||||||
|
|
||||||
// Set the environment.
|
// Set the environment.
|
||||||
auto env = getEnv();
|
auto env = getEnv();
|
||||||
|
@ -471,7 +488,14 @@ int main(int argc, char ** argv)
|
||||||
nixStoreArgs.push_back(arg);
|
nixStoreArgs.push_back(arg);
|
||||||
for (const auto & path : drvPaths2)
|
for (const auto & path : drvPaths2)
|
||||||
nixStoreArgs.push_back(path);
|
nixStoreArgs.push_back(path);
|
||||||
auto nixStoreRes = runProgram(settings.nixBinDir + "/nix-store", false, nixStoreArgs);
|
|
||||||
|
std::string nixStoreRes;
|
||||||
|
try {
|
||||||
|
nixStoreRes = runProgram(settings.nixBinDir + "/nix-store", false, nixStoreArgs);
|
||||||
|
} catch (ExecError & e) {
|
||||||
|
maybePrintExecError(e);
|
||||||
|
}
|
||||||
|
|
||||||
for (const auto & outpath : tokenizeString<std::vector<string>>(nixStoreRes))
|
for (const auto & outpath : tokenizeString<std::vector<string>>(nixStoreRes))
|
||||||
outPaths.push_back(chomp(outpath));
|
outPaths.push_back(chomp(outpath));
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue