fix(3p/nix): pass SkipEmpty to StrSplit("", ...)

When tokenizeString was changed to absl::StrSplit, there was a behavior
change because tokenizeString on an empty string returned an empty
vector - which the derivation builder (and likely a bunch of other
stuff) was depending on. The canonical way of fixing this is by passing
absl::SkipEmpty() to the function - there may be other places we need to
fix this as well.

This commit also includes some opportunistic absl::StrFormats and
StrCats, because I was here anyway, but those have no semantic
difference.

Change-Id: Ibf9bb602284f793fa55728481f63b838fb7a41db
Reviewed-on: https://cl.tvl.fyi/c/depot/+/1631
Reviewed-by: tazjin <mail@tazj.in>
Tested-by: BuildkiteCI
This commit is contained in:
Griffin Smith 2020-08-03 19:45:38 -04:00 committed by glittershark
parent 2344f8e528
commit 26a59482d2

View file

@ -15,6 +15,8 @@
#include <absl/strings/ascii.h>
#include <absl/strings/numbers.h>
#include <absl/strings/str_cat.h>
#include <absl/strings/str_format.h>
#include <absl/strings/str_split.h>
#include <fcntl.h>
#include <glog/logging.h>
@ -1970,10 +1972,12 @@ void DerivationGoal::startBuilder() {
by `nix-store --register-validity'. However, the deriver
fields are left empty. */
std::string s = get(drv->env, "exportReferencesGraph");
std::vector<std::string> ss = absl::StrSplit(s, absl::ByAnyChar(" \t\n\r"));
std::vector<std::string> ss =
absl::StrSplit(s, absl::ByAnyChar(" \t\n\r"), absl::SkipEmpty());
if (ss.size() % 2 != 0) {
throw BuildError(
format("odd number of tokens in 'exportReferencesGraph': '%1%'") % s);
throw BuildError(absl::StrFormat(
"odd number of tokens %d in 'exportReferencesGraph': '%s'", ss.size(),
s));
}
for (auto i = ss.begin(); i != ss.end();) {
std::string fileName = *i++;
@ -3959,7 +3963,7 @@ SubstitutionGoal::SubstitutionGoal(const Path& storePath, Worker& worker,
: Goal(worker), repair(repair) {
this->storePath = storePath;
state = &SubstitutionGoal::init;
name = (format("substitution of '%1%'") % storePath).str();
name = absl::StrCat("substitution of ", storePath);
trace("created");
maintainExpectedSubstitutions =
std::make_unique<MaintainCount<uint64_t>>(worker.expectedSubstitutions);