forked from lix-project/lix
If a .drv cannot be parsed, show its path
Otherwise you just get ‘expected string `Derive(['’ which isn't very helpful.
This commit is contained in:
parent
e0a947cde6
commit
dfa2f77d2e
|
@ -67,7 +67,7 @@ static void prim_import(EvalState & state, const Pos & pos, Value * * args, Valu
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isStorePath(path) && store->isValidPath(path) && isDerivation(path)) {
|
if (isStorePath(path) && store->isValidPath(path) && isDerivation(path)) {
|
||||||
Derivation drv = parseDerivation(readFile(path));
|
Derivation drv = readDerivation(path);
|
||||||
Value & w = *state.allocValue();
|
Value & w = *state.allocValue();
|
||||||
state.mkAttrs(w, 1 + drv.outputs.size());
|
state.mkAttrs(w, 1 + drv.outputs.size());
|
||||||
mkString(*state.allocAttr(w, state.sDrvPath), path, singleton<PathSet>("=" + path));
|
mkString(*state.allocAttr(w, state.sDrvPath), path, singleton<PathSet>("=" + path));
|
||||||
|
|
|
@ -48,7 +48,7 @@ static Path parsePath(std::istream & str)
|
||||||
{
|
{
|
||||||
string s = parseString(str);
|
string s = parseString(str);
|
||||||
if (s.size() == 0 || s[0] != '/')
|
if (s.size() == 0 || s[0] != '/')
|
||||||
throw Error(format("bad path `%1%' in derivation") % s);
|
throw FormatError(format("bad path `%1%' in derivation") % s);
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ static StringSet parseStrings(std::istream & str, bool arePaths)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Derivation parseDerivation(const string & s)
|
static Derivation parseDerivation(const string & s)
|
||||||
{
|
{
|
||||||
Derivation drv;
|
Derivation drv;
|
||||||
std::istringstream str(s);
|
std::istringstream str(s);
|
||||||
|
@ -112,6 +112,16 @@ Derivation parseDerivation(const string & s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Derivation readDerivation(const Path & drvPath)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
return parseDerivation(readFile(drvPath));
|
||||||
|
} catch (FormatError & e) {
|
||||||
|
throw Error(format("error parsing derivation `%1%': %2%") % drvPath % e.msg());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void printString(string & res, const string & s)
|
static void printString(string & res, const string & s)
|
||||||
{
|
{
|
||||||
res += '"';
|
res += '"';
|
||||||
|
@ -240,7 +250,7 @@ Hash hashDerivationModulo(StoreAPI & store, Derivation drv)
|
||||||
Hash h = drvHashes[i->first];
|
Hash h = drvHashes[i->first];
|
||||||
if (h.type == htUnknown) {
|
if (h.type == htUnknown) {
|
||||||
assert(store.isValidPath(i->first));
|
assert(store.isValidPath(i->first));
|
||||||
Derivation drv2 = parseDerivation(readFile(i->first));
|
Derivation drv2 = readDerivation(i->first);
|
||||||
h = hashDerivationModulo(store, drv2);
|
h = hashDerivationModulo(store, drv2);
|
||||||
drvHashes[i->first] = h;
|
drvHashes[i->first] = h;
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,8 +59,8 @@ class StoreAPI;
|
||||||
Path writeDerivation(StoreAPI & store,
|
Path writeDerivation(StoreAPI & store,
|
||||||
const Derivation & drv, const string & name, bool repair = false);
|
const Derivation & drv, const string & name, bool repair = false);
|
||||||
|
|
||||||
/* Parse a derivation. */
|
/* Read a derivation from a file. */
|
||||||
Derivation parseDerivation(const string & s);
|
Derivation readDerivation(const Path & drvPath);
|
||||||
|
|
||||||
/* Print a derivation. */
|
/* Print a derivation. */
|
||||||
string unparseDerivation(const Derivation & drv);
|
string unparseDerivation(const Derivation & drv);
|
||||||
|
|
|
@ -661,7 +661,7 @@ unsigned long long LocalStore::addValidPath(const ValidPathInfo & info, bool che
|
||||||
efficiently query whether a path is an output of some
|
efficiently query whether a path is an output of some
|
||||||
derivation. */
|
derivation. */
|
||||||
if (isDerivation(info.path)) {
|
if (isDerivation(info.path)) {
|
||||||
Derivation drv = parseDerivation(readFile(info.path));
|
Derivation drv = readDerivation(info.path);
|
||||||
|
|
||||||
/* Verify that the output paths in the derivation are correct
|
/* Verify that the output paths in the derivation are correct
|
||||||
(i.e., follow the scheme for computing output paths from
|
(i.e., follow the scheme for computing output paths from
|
||||||
|
@ -1290,7 +1290,7 @@ void LocalStore::registerValidPaths(const ValidPathInfos & infos)
|
||||||
if (isDerivation(i->path)) {
|
if (isDerivation(i->path)) {
|
||||||
// FIXME: inefficient; we already loaded the
|
// FIXME: inefficient; we already loaded the
|
||||||
// derivation in addValidPath().
|
// derivation in addValidPath().
|
||||||
Derivation drv = parseDerivation(readFile(i->path));
|
Derivation drv = readDerivation(i->path);
|
||||||
checkDerivationOutputs(i->path, drv);
|
checkDerivationOutputs(i->path, drv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ Derivation derivationFromPath(StoreAPI & store, const Path & drvPath)
|
||||||
{
|
{
|
||||||
assertStorePath(drvPath);
|
assertStorePath(drvPath);
|
||||||
store.ensurePath(drvPath);
|
store.ensurePath(drvPath);
|
||||||
return parseDerivation(readFile(drvPath));
|
return readDerivation(drvPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1041,7 +1041,7 @@ void expect(std::istream & str, const string & s)
|
||||||
char s2[s.size()];
|
char s2[s.size()];
|
||||||
str.read(s2, s.size());
|
str.read(s2, s.size());
|
||||||
if (string(s2, s.size()) != s)
|
if (string(s2, s.size()) != s)
|
||||||
throw Error(format("expected string `%1%'") % s);
|
throw FormatError(format("expected string `%1%'") % s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -326,6 +326,8 @@ bool hasSuffix(const string & s, const string & suffix);
|
||||||
/* Read string `s' from stream `str'. */
|
/* Read string `s' from stream `str'. */
|
||||||
void expect(std::istream & str, const string & s);
|
void expect(std::istream & str, const string & s);
|
||||||
|
|
||||||
|
MakeError(FormatError, Error)
|
||||||
|
|
||||||
|
|
||||||
/* Read a C-style string from stream `str'. */
|
/* Read a C-style string from stream `str'. */
|
||||||
string parseString(std::istream & str);
|
string parseString(std::istream & str);
|
||||||
|
|
Loading…
Reference in a new issue