forked from lix-project/hydra
Improve parsing of hydra-build-products
This commit is contained in:
parent
e13477bdf2
commit
81abb6e166
|
@ -2,6 +2,7 @@
|
||||||
#include "store-api.hh"
|
#include "store-api.hh"
|
||||||
#include "misc.hh"
|
#include "misc.hh"
|
||||||
#include "util.hh"
|
#include "util.hh"
|
||||||
|
#include "regex.hh"
|
||||||
|
|
||||||
using namespace nix;
|
using namespace nix;
|
||||||
|
|
||||||
|
@ -26,6 +27,15 @@ BuildResult getBuildResult(std::shared_ptr<StoreAPI> store, const Derivation & d
|
||||||
/* Get build products. */
|
/* Get build products. */
|
||||||
bool explicitProducts = false;
|
bool explicitProducts = false;
|
||||||
|
|
||||||
|
Regex regex(
|
||||||
|
"(([a-zA-Z0-9_-]+)" // type (e.g. "doc")
|
||||||
|
"[[:space:]]+"
|
||||||
|
"([a-zA-Z0-9_-]+)" // subtype (e.g. "readme")
|
||||||
|
"[[:space:]]+"
|
||||||
|
"(\"[^\"]+\"|[^[:space:]\"]+))" // path (may be quoted)
|
||||||
|
"([[:space:]]+([^[:space:]]+))?" // entry point
|
||||||
|
, true);
|
||||||
|
|
||||||
for (auto & output : outputs) {
|
for (auto & output : outputs) {
|
||||||
Path failedFile = output + "/nix-support/failed";
|
Path failedFile = output + "/nix-support/failed";
|
||||||
if (pathExists(failedFile)) res.failed = true;
|
if (pathExists(failedFile)) res.failed = true;
|
||||||
|
@ -35,33 +45,33 @@ BuildResult getBuildResult(std::shared_ptr<StoreAPI> store, const Derivation & d
|
||||||
explicitProducts = true;
|
explicitProducts = true;
|
||||||
|
|
||||||
/* For security, resolve symlinks. */
|
/* For security, resolve symlinks. */
|
||||||
productsFile = canonPath(productsFile, true);
|
try {
|
||||||
|
productsFile = canonPath(productsFile, true);
|
||||||
|
} catch (Error & e) { continue; }
|
||||||
if (!isInStore(productsFile)) continue;
|
if (!isInStore(productsFile)) continue;
|
||||||
|
|
||||||
// FIXME: handle I/O errors
|
string contents;
|
||||||
|
try {
|
||||||
|
contents = readFile(productsFile);
|
||||||
|
} catch (Error & e) { continue; }
|
||||||
|
|
||||||
auto contents = readFile(productsFile);
|
for (auto & line : tokenizeString<Strings>(contents, "\n")) {
|
||||||
auto lines = tokenizeString<Strings>(contents, "\n");
|
|
||||||
|
|
||||||
for (auto & line : lines) {
|
|
||||||
BuildProduct product;
|
BuildProduct product;
|
||||||
|
|
||||||
auto words = tokenizeString<Strings>(line);
|
Regex::Subs subs;
|
||||||
if (words.size() < 3) continue;
|
if (!regex.matches(line, subs)) continue;
|
||||||
product.type = words.front(); words.pop_front();
|
|
||||||
product.subtype = words.front(); words.pop_front();
|
product.type = subs[1];
|
||||||
if (string(words.front(), 0, 1) == "\"") {
|
product.subtype = subs[2];
|
||||||
// FIXME:
|
product.path = subs[3][0] == '"' ? string(subs[3], 1, subs[3].size() - 2) : subs[3];
|
||||||
throw Error("FIXME");
|
product.defaultPath = subs[5];
|
||||||
} else {
|
|
||||||
product.path = words.front(); words.pop_front();
|
|
||||||
}
|
|
||||||
product.defaultPath = words.empty() ? "" : words.front();
|
|
||||||
|
|
||||||
/* Ensure that the path exists and points into the Nix
|
/* Ensure that the path exists and points into the Nix
|
||||||
store. */
|
store. */
|
||||||
if (product.path == "" || product.path[0] != '/') continue;
|
if (product.path == "" || product.path[0] != '/') continue;
|
||||||
product.path = canonPath(product.path, true);
|
try {
|
||||||
|
product.path = canonPath(product.path, true);
|
||||||
|
} catch (Error & e) { continue; }
|
||||||
if (!isInStore(product.path) || !pathExists(product.path)) continue;
|
if (!isInStore(product.path) || !pathExists(product.path)) continue;
|
||||||
|
|
||||||
/* FIXME: check that the path is in the input closure
|
/* FIXME: check that the path is in the input closure
|
||||||
|
@ -106,8 +116,9 @@ BuildResult getBuildResult(std::shared_ptr<StoreAPI> store, const Derivation & d
|
||||||
for (auto & output : outputs) {
|
for (auto & output : outputs) {
|
||||||
Path p = output + "/nix-support/hydra-release-name";
|
Path p = output + "/nix-support/hydra-release-name";
|
||||||
if (!pathExists(p)) continue;
|
if (!pathExists(p)) continue;
|
||||||
// FIXME: handle I/O error
|
try {
|
||||||
res.releaseName = trim(readFile(p));
|
res.releaseName = trim(readFile(p));
|
||||||
|
} catch (Error & e) { continue; }
|
||||||
// FIXME: validate release name
|
// FIXME: validate release name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue