mirror of
https://github.com/NixOS/nix
synced 2025-06-28 17:51:15 +02:00
nix-store -l: Fetch build logs from the Internet
If a build log is not available locally, then ‘nix-store -l’ will now try to download it from the servers listed in the ‘log-servers’ option in nix.conf. For instance, if you have: log-servers = http://hydra.nixos.org/log then it will try to get logs from http://hydra.nixos.org/log/<base name of the store path>. So you can do things like: $ nix-store -l $(which xterm) and get a log even if xterm wasn't built locally.
This commit is contained in:
parent
eac5841970
commit
9f9080e2c0
9 changed files with 144 additions and 93 deletions
|
@ -7,3 +7,5 @@ nix-store_SOURCES := $(wildcard $(d)/*.cc)
|
|||
nix-store_LIBS = libmain libstore libutil libformat
|
||||
|
||||
nix-store_LDFLAGS = -lbz2
|
||||
|
||||
nix-store_CXXFLAGS = -DCURL=\"$(curl)\"
|
||||
|
|
|
@ -467,10 +467,11 @@ static void opReadLog(Strings opFlags, Strings opArgs)
|
|||
foreach (Strings::iterator, i, opArgs) {
|
||||
Path path = useDeriver(followLinksToStorePath(*i));
|
||||
|
||||
for (int j = 0; j <= 2; j++) {
|
||||
if (j == 2) throw Error(format("build log of derivation `%1%' is not available") % path);
|
||||
string baseName = baseNameOf(path);
|
||||
bool found = false;
|
||||
|
||||
for (int j = 0; j < 2; j++) {
|
||||
|
||||
string baseName = baseNameOf(path);
|
||||
Path logPath =
|
||||
j == 0
|
||||
? (format("%1%/%2%/%3%/%4%") % settings.nixLogDir % drvsLogDir % string(baseName, 0, 2) % string(baseName, 2)).str()
|
||||
|
@ -481,6 +482,7 @@ static void opReadLog(Strings opFlags, Strings opArgs)
|
|||
/* !!! Make this run in O(1) memory. */
|
||||
string log = readFile(logPath);
|
||||
writeFull(STDOUT_FILENO, (const unsigned char *) log.data(), log.size());
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -500,9 +502,30 @@ static void opReadLog(Strings opFlags, Strings opArgs)
|
|||
writeFull(STDOUT_FILENO, buf, n);
|
||||
} while (err != BZ_STREAM_END);
|
||||
BZ2_bzReadClose(&err, bz);
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
for (auto & i : settings.logServers) {
|
||||
string prefix = i;
|
||||
if (!prefix.empty() && prefix.back() != '/') prefix += '/';
|
||||
string url = prefix + baseName;
|
||||
try {
|
||||
string log = runProgram(CURL, true, {"--fail", "--location", "--silent", "--", url});
|
||||
std::cout << "(using build log from " << url << ")" << std::endl;
|
||||
std::cout << log;
|
||||
found = true;
|
||||
break;
|
||||
} catch (ExecError & e) {
|
||||
/* Ignore errors from curl. FIXME: actually, might be
|
||||
nice to print a warning on HTTP status != 404. */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) throw Error(format("build log of derivation `%1%' is not available") % path);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue