refactor(3p/nix): Replace tokenizeStrings with absl::StrSplit
This function was a custom (and inefficient in the case of single-character delimiters) string splitter which was used all over the codebase. Abseil provides an appropriate replacement function.
This commit is contained in:
parent
b99b368d17
commit
bf452cbc2a
29 changed files with 146 additions and 145 deletions
3
third_party/nix/src/libexpr/primops.cc
vendored
3
third_party/nix/src/libexpr/primops.cc
vendored
|
@ -4,6 +4,7 @@
|
|||
#include <cstring>
|
||||
#include <regex>
|
||||
|
||||
#include <absl/strings/str_split.h>
|
||||
#include <dlfcn.h>
|
||||
#include <glog/logging.h>
|
||||
#include <sys/stat.h>
|
||||
|
@ -712,7 +713,7 @@ static void prim_derivationStrict(EvalState& state, const Pos& pos,
|
|||
} else if (i->name == state.sOutputHashMode) {
|
||||
handleHashMode(s);
|
||||
} else if (i->name == state.sOutputs) {
|
||||
handleOutputs(tokenizeString<Strings>(s));
|
||||
handleOutputs(absl::StrSplit(s, absl::ByAnyChar(" \t\n\r")));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include <absl/strings/ascii.h>
|
||||
#include <absl/strings/match.h>
|
||||
#include <absl/strings/str_split.h>
|
||||
#include <glog/logging.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
|
@ -54,8 +55,9 @@ GitInfo exportGit(ref<Store> store, const std::string& uri,
|
|||
gitInfo.rev = "0000000000000000000000000000000000000000";
|
||||
gitInfo.shortRev = std::string(gitInfo.rev, 0, 7);
|
||||
|
||||
auto files = tokenizeString<std::set<std::string>>(
|
||||
runProgram("git", true, {"-C", uri, "ls-files", "-z"}), "\0"s);
|
||||
std::set<std::string> files =
|
||||
absl::StrSplit(runProgram("git", true, {"-C", uri, "ls-files", "-z"}),
|
||||
absl::ByChar('\0'));
|
||||
|
||||
PathFilter filter = [&](const Path& p) -> bool {
|
||||
assert(absl::StartsWith(p, uri));
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include <absl/strings/ascii.h>
|
||||
#include <absl/strings/match.h>
|
||||
#include <absl/strings/str_split.h>
|
||||
#include <glog/logging.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
|
@ -48,11 +49,11 @@ HgInfo exportMercurial(ref<Store> store, const std::string& uri,
|
|||
hgInfo.branch = absl::StripTrailingAsciiWhitespace(
|
||||
runProgram("hg", true, {"branch", "-R", uri}));
|
||||
|
||||
auto files = tokenizeString<std::set<std::string>>(
|
||||
std::set<std::string> files = absl::StrSplit(
|
||||
runProgram("hg", true,
|
||||
{"status", "-R", uri, "--clean", "--modified", "--added",
|
||||
"--no-status", "--print0"}),
|
||||
"\0"s);
|
||||
absl::ByChar('\0'));
|
||||
|
||||
PathFilter filter = [&](const Path& p) -> bool {
|
||||
assert(absl::StartsWith(p, uri));
|
||||
|
@ -124,10 +125,11 @@ HgInfo exportMercurial(ref<Store> store, const std::string& uri,
|
|||
writeFile(stampFile, "");
|
||||
}
|
||||
|
||||
auto tokens = tokenizeString<std::vector<std::string>>(
|
||||
runProgram("hg", true,
|
||||
{"log", "-R", cacheDir, "-r", rev, "--template",
|
||||
"{node} {rev} {branch}"}));
|
||||
std::vector<std::string> tokens =
|
||||
absl::StrSplit(runProgram("hg", true,
|
||||
{"log", "-R", cacheDir, "-r", rev, "--template",
|
||||
"{node} {rev} {branch}"}),
|
||||
absl::ByAnyChar(" \t\n\r"));
|
||||
assert(tokens.size() == 3);
|
||||
|
||||
HgInfo hgInfo;
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include <absl/strings/ascii.h>
|
||||
#include <absl/strings/numbers.h>
|
||||
#include <absl/strings/str_split.h>
|
||||
|
||||
#include "archive.hh"
|
||||
#include "compression.hh"
|
||||
|
@ -41,7 +42,7 @@ void BinaryCacheStore::init() {
|
|||
upsertFile(cacheInfoFile, "StoreDir: " + storeDir + "\n",
|
||||
"text/x-nix-cache-info");
|
||||
} else {
|
||||
for (auto& line : tokenizeString<Strings>(*cacheInfo, "\n")) {
|
||||
for (auto& line : absl::StrSplit(*cacheInfo, absl::ByChar('\n'))) {
|
||||
size_t colon = line.find(':');
|
||||
if (colon == std::string::npos) {
|
||||
continue;
|
||||
|
|
7
third_party/nix/src/libstore/build.cc
vendored
7
third_party/nix/src/libstore/build.cc
vendored
|
@ -10,10 +10,12 @@
|
|||
#include <queue>
|
||||
#include <regex>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
||||
#include <absl/strings/ascii.h>
|
||||
#include <absl/strings/numbers.h>
|
||||
#include <absl/strings/str_split.h>
|
||||
#include <fcntl.h>
|
||||
#include <grp.h>
|
||||
#include <netdb.h>
|
||||
|
@ -1968,7 +1970,7 @@ void DerivationGoal::startBuilder() {
|
|||
by `nix-store --register-validity'. However, the deriver
|
||||
fields are left empty. */
|
||||
std::string s = get(drv->env, "exportReferencesGraph");
|
||||
auto ss = tokenizeString<Strings>(s);
|
||||
std::vector<std::string> ss = absl::StrSplit(s, absl::ByAnyChar(" \t\n\r"));
|
||||
if (ss.size() % 2 != 0) {
|
||||
throw BuildError(
|
||||
format("odd number of tokens in 'exportReferencesGraph': '%1%'") % s);
|
||||
|
@ -2481,7 +2483,8 @@ void DerivationGoal::initTmpDir() {
|
|||
needed (attributes are not passed through the environment, so
|
||||
there is no size constraint). */
|
||||
if (!parsedDrv->getStructuredAttrs()) {
|
||||
auto passAsFile = tokenizeString<StringSet>(get(drv->env, "passAsFile"));
|
||||
std::set<std::string> passAsFile =
|
||||
absl::StrSplit(get(drv->env, "passAsFile"), absl::ByAnyChar(" \t\n\r"));
|
||||
int fileNr = 0;
|
||||
for (auto& i : drv->env) {
|
||||
if (passAsFile.find(i.first) == passAsFile.end()) {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include <algorithm>
|
||||
|
||||
#include <absl/strings/match.h>
|
||||
#include <absl/strings/str_split.h>
|
||||
#include <fcntl.h>
|
||||
#include <glog/logging.h>
|
||||
#include <sys/stat.h>
|
||||
|
@ -134,12 +135,14 @@ static void addPkg(const Path& pkgDir, int priority) {
|
|||
createLinks(pkgDir, out, priority);
|
||||
|
||||
try {
|
||||
for (const auto& p : tokenizeString<std::vector<std::string>>(
|
||||
for (auto p : absl::StrSplit(
|
||||
readFile(pkgDir + "/nix-support/propagated-user-env-packages"),
|
||||
" \n"))
|
||||
if (!done.count(p)) {
|
||||
postponed.insert(p);
|
||||
absl::ByAnyChar(" \n"))) {
|
||||
auto pkg = std::string(p);
|
||||
if (!done.count(pkg)) {
|
||||
postponed.insert(pkg);
|
||||
}
|
||||
}
|
||||
} catch (SysError& e) {
|
||||
if (e.errNo != ENOENT && e.errNo != ENOTDIR) {
|
||||
throw;
|
||||
|
@ -172,7 +175,8 @@ void builtinBuildenv(const BasicDerivation& drv) {
|
|||
/* Convert the stuff we get from the environment back into a
|
||||
* coherent data type. */
|
||||
Packages pkgs;
|
||||
auto derivations = tokenizeString<Strings>(getAttr("derivations"));
|
||||
Strings derivations =
|
||||
absl::StrSplit(getAttr("derivations"), absl::ByAnyChar(" \t\n\r"));
|
||||
while (!derivations.empty()) {
|
||||
/* !!! We're trusting the caller to structure derivations env var correctly
|
||||
*/
|
||||
|
|
18
third_party/nix/src/libstore/derivations.cc
vendored
18
third_party/nix/src/libstore/derivations.cc
vendored
|
@ -1,6 +1,8 @@
|
|||
#include "derivations.hh"
|
||||
|
||||
#include <absl/strings/match.h>
|
||||
#include <absl/strings/str_split.h>
|
||||
#include <absl/strings/string_view.h>
|
||||
|
||||
#include "fs-accessor.hh"
|
||||
#include "globals.hh"
|
||||
|
@ -357,13 +359,15 @@ Hash hashDerivationModulo(Store& store, Derivation drv) {
|
|||
return hashString(htSHA256, drv.unparse());
|
||||
}
|
||||
|
||||
DrvPathWithOutputs parseDrvPathWithOutputs(const std::string& s) {
|
||||
size_t n = s.find('!');
|
||||
return n == std::string::npos
|
||||
? DrvPathWithOutputs(s, std::set<std::string>())
|
||||
: DrvPathWithOutputs(std::string(s, 0, n),
|
||||
tokenizeString<std::set<std::string> >(
|
||||
std::string(s, n + 1), ","));
|
||||
// TODO(tazjin): doc comment?
|
||||
DrvPathWithOutputs parseDrvPathWithOutputs(absl::string_view path) {
|
||||
auto pos = path.find('!');
|
||||
if (pos == absl::string_view::npos) {
|
||||
return DrvPathWithOutputs(path, std::set<std::string>());
|
||||
}
|
||||
|
||||
return DrvPathWithOutputs(path.substr(pos + 1),
|
||||
absl::StrSplit(path, absl::ByChar(',')));
|
||||
}
|
||||
|
||||
Path makeDrvPathWithOutputs(const Path& drvPath,
|
||||
|
|
2
third_party/nix/src/libstore/derivations.hh
vendored
2
third_party/nix/src/libstore/derivations.hh
vendored
|
@ -88,7 +88,7 @@ extern DrvHashes drvHashes; // FIXME: global, not thread-safe
|
|||
(/nix/store/hash-foo!out1,out2,...) into the derivation path and
|
||||
the outputs. */
|
||||
typedef std::pair<std::string, std::set<std::string> > DrvPathWithOutputs;
|
||||
DrvPathWithOutputs parseDrvPathWithOutputs(const std::string& s);
|
||||
DrvPathWithOutputs parseDrvPathWithOutputs(absl::string_view path);
|
||||
|
||||
Path makeDrvPathWithOutputs(const Path& drvPath,
|
||||
const std::set<std::string>& outputs);
|
||||
|
|
7
third_party/nix/src/libstore/download.cc
vendored
7
third_party/nix/src/libstore/download.cc
vendored
|
@ -3,6 +3,7 @@
|
|||
#include <absl/strings/ascii.h>
|
||||
#include <absl/strings/match.h>
|
||||
#include <absl/strings/numbers.h>
|
||||
#include <absl/strings/str_split.h>
|
||||
|
||||
#include "archive.hh"
|
||||
#include "compression.hh"
|
||||
|
@ -180,7 +181,7 @@ struct CurlDownloader : public Downloader {
|
|||
<< "': " << absl::StripAsciiWhitespace(line);
|
||||
if (line.compare(0, 5, "HTTP/") == 0) { // new response starts
|
||||
result.etag = "";
|
||||
auto ss = tokenizeString<std::vector<std::string>>(line, " ");
|
||||
std::vector<std::string> ss = absl::StrSplit(line, absl::ByChar(' '));
|
||||
status = ss.size() >= 2 ? ss[1] : "";
|
||||
result.data = std::make_shared<std::string>();
|
||||
result.bodySize = 0;
|
||||
|
@ -894,8 +895,8 @@ CachedDownloadResult Downloader::downloadCached(
|
|||
storePath = readLink(fileLink);
|
||||
store->addTempRoot(storePath);
|
||||
if (store->isValidPath(storePath)) {
|
||||
auto ss =
|
||||
tokenizeString<std::vector<std::string>>(readFile(dataFile), "\n");
|
||||
std::vector<std::string> ss =
|
||||
absl::StrSplit(readFile(dataFile), absl::ByChar('\n'));
|
||||
if (ss.size() >= 3 && ss[0] == url) {
|
||||
time_t lastChecked;
|
||||
if (absl::SimpleAtoi(ss[2], &lastChecked) &&
|
||||
|
|
27
third_party/nix/src/libstore/gc.cc
vendored
27
third_party/nix/src/libstore/gc.cc
vendored
|
@ -7,6 +7,7 @@
|
|||
#include <regex>
|
||||
|
||||
#include <absl/strings/match.h>
|
||||
#include <absl/strings/str_split.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/statvfs.h>
|
||||
|
@ -422,8 +423,8 @@ void LocalStore::findRuntimeRoots(Roots& roots, bool censor) {
|
|||
|
||||
try {
|
||||
auto mapFile = fmt("/proc/%s/maps", ent->d_name);
|
||||
auto mapLines = tokenizeString<std::vector<std::string>>(
|
||||
readFile(mapFile, true), "\n");
|
||||
std::vector<std::string> mapLines =
|
||||
absl::StrSplit(readFile(mapFile, true), absl::ByChar('\n'));
|
||||
for (const auto& line : mapLines) {
|
||||
auto match = std::smatch{};
|
||||
if (std::regex_match(line, match, mapRegex)) {
|
||||
|
@ -452,31 +453,9 @@ void LocalStore::findRuntimeRoots(Roots& roots, bool censor) {
|
|||
}
|
||||
}
|
||||
|
||||
#if !defined(__linux__)
|
||||
// lsof is really slow on OS X. This actually causes the gc-concurrent.sh test
|
||||
// to fail. See: https://github.com/NixOS/nix/issues/3011 Because of this we
|
||||
// disable lsof when running the tests.
|
||||
if (getEnv("_NIX_TEST_NO_LSOF") == "") {
|
||||
try {
|
||||
std::regex lsofRegex(R"(^n(/.*)$)");
|
||||
auto lsofLines = tokenizeString<std::vector<std::string>>(
|
||||
runProgram(LSOF, true, {"-n", "-w", "-F", "n"}), "\n");
|
||||
for (const auto& line : lsofLines) {
|
||||
std::smatch match;
|
||||
if (std::regex_match(line, match, lsofRegex))
|
||||
unchecked[match[1]].emplace("{lsof}");
|
||||
}
|
||||
} catch (ExecError& e) {
|
||||
/* lsof not installed, lsof failed */
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(__linux__)
|
||||
readFileRoots("/proc/sys/kernel/modprobe", unchecked);
|
||||
readFileRoots("/proc/sys/kernel/fbsplash", unchecked);
|
||||
readFileRoots("/proc/sys/kernel/poweroff_cmd", unchecked);
|
||||
#endif
|
||||
|
||||
for (auto& [target, links] : unchecked) {
|
||||
if (isInStore(target)) {
|
||||
|
|
18
third_party/nix/src/libstore/globals.cc
vendored
18
third_party/nix/src/libstore/globals.cc
vendored
|
@ -5,6 +5,8 @@
|
|||
#include <thread>
|
||||
|
||||
#include <absl/strings/numbers.h>
|
||||
#include <absl/strings/str_cat.h>
|
||||
#include <absl/strings/str_split.h>
|
||||
#include <dlfcn.h>
|
||||
|
||||
#include "archive.hh"
|
||||
|
@ -20,9 +22,6 @@ namespace nix {
|
|||
must be deleted and recreated on startup.) */
|
||||
#define DEFAULT_SOCKET_PATH "/daemon-socket/socket"
|
||||
|
||||
// TODO(tazjin): this was __APPLE__ specific, still needed?
|
||||
#define DEFAULT_ALLOWED_IMPURE_PREFIXES ""
|
||||
|
||||
Settings settings;
|
||||
|
||||
static GlobalConfig::Register r1(&settings);
|
||||
|
@ -55,21 +54,18 @@ Settings::Settings()
|
|||
}
|
||||
|
||||
/* Backwards compatibility. */
|
||||
// TODO(tazjin): still?
|
||||
auto s = getEnv("NIX_REMOTE_SYSTEMS");
|
||||
if (!s.empty()) {
|
||||
Strings ss;
|
||||
for (auto& p : tokenizeString<Strings>(s, ":")) {
|
||||
ss.push_back("@" + p);
|
||||
for (auto p : absl::StrSplit(s, absl::ByChar(':'))) {
|
||||
ss.push_back(absl::StrCat("@", p));
|
||||
}
|
||||
builders = concatStringsSep(" ", ss);
|
||||
}
|
||||
|
||||
#if defined(__linux__) && defined(SANDBOX_SHELL)
|
||||
sandboxPaths = tokenizeString<StringSet>("/bin/sh=" SANDBOX_SHELL);
|
||||
#endif
|
||||
|
||||
allowedImpureHostPrefixes =
|
||||
tokenizeString<StringSet>(DEFAULT_ALLOWED_IMPURE_PREFIXES);
|
||||
sandboxPaths =
|
||||
absl::StrSplit("/bin/sh=" SANDBOX_SHELL, absl::ByAnyChar(" \t\n\r"));
|
||||
}
|
||||
|
||||
void loadConfFile() {
|
||||
|
|
10
third_party/nix/src/libstore/local-store.cc
vendored
10
third_party/nix/src/libstore/local-store.cc
vendored
|
@ -8,6 +8,7 @@
|
|||
#include <iostream>
|
||||
|
||||
#include <absl/strings/numbers.h>
|
||||
#include <absl/strings/str_split.h>
|
||||
#include <fcntl.h>
|
||||
#include <glog/logging.h>
|
||||
#include <grp.h>
|
||||
|
@ -477,14 +478,15 @@ static void canonicalisePathMetaData_(const Path& path, uid_t fromUid,
|
|||
throw SysError("querying extended attributes of '%s'", path);
|
||||
}
|
||||
|
||||
for (auto& eaName : tokenizeString<Strings>(
|
||||
std::string(eaBuf.data(), eaSize), std::string("\000", 1))) {
|
||||
for (auto& eaName :
|
||||
absl::StrSplit(std::string(eaBuf.data(), eaSize),
|
||||
absl::ByString(std::string("\000", 1)))) {
|
||||
/* Ignore SELinux security labels since these cannot be
|
||||
removed even by root. */
|
||||
if (eaName == "security.selinux") {
|
||||
continue;
|
||||
}
|
||||
if (lremovexattr(path.c_str(), eaName.c_str()) == -1) {
|
||||
if (lremovexattr(path.c_str(), std::string(eaName).c_str()) == -1) {
|
||||
throw SysError("removing extended attribute '%s' from '%s'", eaName,
|
||||
path);
|
||||
}
|
||||
|
@ -702,7 +704,7 @@ void LocalStore::queryPathInfoUncached(
|
|||
|
||||
s = (const char*)sqlite3_column_text(state->stmtQueryPathInfo, 6);
|
||||
if (s != nullptr) {
|
||||
info->sigs = tokenizeString<StringSet>(s, " ");
|
||||
info->sigs = absl::StrSplit(s, absl::ByChar(' '));
|
||||
}
|
||||
|
||||
s = (const char*)sqlite3_column_text(state->stmtQueryPathInfo, 7);
|
||||
|
|
6
third_party/nix/src/libstore/local-store.hh
vendored
6
third_party/nix/src/libstore/local-store.hh
vendored
|
@ -5,6 +5,8 @@
|
|||
#include <string>
|
||||
#include <unordered_set>
|
||||
|
||||
#include <absl/strings/str_split.h>
|
||||
|
||||
#include "pathlocks.hh"
|
||||
#include "sqlite.hh"
|
||||
#include "store-api.hh"
|
||||
|
@ -94,7 +96,9 @@ class LocalStore : public LocalFSStore {
|
|||
|
||||
public:
|
||||
// Hack for build-remote.cc.
|
||||
PathSet locksHeld = tokenizeString<PathSet>(getEnv("NIX_HELD_LOCKS"));
|
||||
// TODO(tazjin): remove this when we've got gRPC
|
||||
PathSet locksHeld =
|
||||
absl::StrSplit(getEnv("NIX_HELD_LOCKS"), absl::ByAnyChar(" \t\n\r"));
|
||||
|
||||
/* Initialise the local store, upgrading the schema if
|
||||
necessary. */
|
||||
|
|
20
third_party/nix/src/libstore/machines.cc
vendored
20
third_party/nix/src/libstore/machines.cc
vendored
|
@ -4,6 +4,7 @@
|
|||
|
||||
#include <absl/strings/ascii.h>
|
||||
#include <absl/strings/match.h>
|
||||
#include <absl/strings/str_split.h>
|
||||
#include <absl/strings/string_view.h>
|
||||
#include <glog/logging.h>
|
||||
|
||||
|
@ -51,14 +52,15 @@ bool Machine::mandatoryMet(const std::set<std::string>& features) const {
|
|||
}
|
||||
|
||||
void parseMachines(const std::string& s, Machines& machines) {
|
||||
for (auto line : tokenizeString<std::vector<std::string>>(s, "\n;")) {
|
||||
line.erase(std::find(line.begin(), line.end(), '#'), line.end());
|
||||
if (line.empty()) {
|
||||
for (auto line : absl::StrSplit(s, absl::ByAnyChar("\n;"))) {
|
||||
// Skip empty lines & comments
|
||||
line = absl::StripAsciiWhitespace(line);
|
||||
if (line.empty() || line[line.find_first_not_of(" \t")] == '#') {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (line[0] == '@') {
|
||||
auto file = absl::StripAsciiWhitespace(std::string(line, 1));
|
||||
auto file = absl::StripAsciiWhitespace(line.substr(1));
|
||||
try {
|
||||
parseMachines(readFile(file), machines);
|
||||
} catch (const SysError& e) {
|
||||
|
@ -70,7 +72,8 @@ void parseMachines(const std::string& s, Machines& machines) {
|
|||
continue;
|
||||
}
|
||||
|
||||
auto tokens = tokenizeString<std::vector<std::string>>(line);
|
||||
std::vector<std::string> tokens =
|
||||
absl::StrSplit(line, absl::ByAnyChar(" \t\n\r"));
|
||||
auto sz = tokens.size();
|
||||
if (sz < 1) {
|
||||
throw FormatError("bad machine specification '%s'", line);
|
||||
|
@ -80,15 +83,16 @@ void parseMachines(const std::string& s, Machines& machines) {
|
|||
return tokens.size() > n && !tokens[n].empty() && tokens[n] != "-";
|
||||
};
|
||||
|
||||
// TODO(tazjin): what???
|
||||
machines.emplace_back(
|
||||
tokens[0],
|
||||
isSet(1) ? tokenizeString<std::vector<std::string>>(tokens[1], ",")
|
||||
isSet(1) ? absl::StrSplit(tokens[1], absl::ByChar(','))
|
||||
: std::vector<std::string>{settings.thisSystem},
|
||||
isSet(2) ? tokens[2] : "", isSet(3) ? std::stoull(tokens[3]) : 1LL,
|
||||
isSet(4) ? std::stoull(tokens[4]) : 1LL,
|
||||
isSet(5) ? tokenizeString<std::set<std::string>>(tokens[5], ",")
|
||||
isSet(5) ? absl::StrSplit(tokens[5], absl::ByChar(','))
|
||||
: std::set<std::string>{},
|
||||
isSet(6) ? tokenizeString<std::set<std::string>>(tokens[6], ",")
|
||||
isSet(6) ? absl::StrSplit(tokens[6], absl::ByChar(','))
|
||||
: std::set<std::string>{},
|
||||
isSet(7) ? tokens[7] : "");
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#include "nar-info-disk-cache.hh"
|
||||
|
||||
#include <absl/strings/str_cat.h>
|
||||
#include <absl/strings/str_split.h>
|
||||
#include <glog/logging.h>
|
||||
#include <sqlite3.h>
|
||||
|
||||
|
@ -227,14 +229,15 @@ class NarInfoDiskCacheImpl : public NarInfoDiskCache {
|
|||
narInfo->fileSize = queryNAR.getInt(5);
|
||||
narInfo->narHash = Hash(queryNAR.getStr(6));
|
||||
narInfo->narSize = queryNAR.getInt(7);
|
||||
for (auto& r : tokenizeString<Strings>(queryNAR.getStr(8), " ")) {
|
||||
narInfo->references.insert(cache.storeDir + "/" + r);
|
||||
for (auto r : absl::StrSplit(queryNAR.getStr(8), absl::ByChar(' '))) {
|
||||
narInfo->references.insert(absl::StrCat(cache.storeDir, "/", r));
|
||||
}
|
||||
if (!queryNAR.isNull(9)) {
|
||||
narInfo->deriver = cache.storeDir + "/" + queryNAR.getStr(9);
|
||||
}
|
||||
for (auto& sig : tokenizeString<Strings>(queryNAR.getStr(10), " ")) {
|
||||
narInfo->sigs.insert(sig);
|
||||
for (auto& sig :
|
||||
absl::StrSplit(queryNAR.getStr(10), absl::ByChar(' '))) {
|
||||
narInfo->sigs.insert(std::string(sig));
|
||||
}
|
||||
narInfo->ca = queryNAR.getStr(11);
|
||||
|
||||
|
|
3
third_party/nix/src/libstore/nar-info.cc
vendored
3
third_party/nix/src/libstore/nar-info.cc
vendored
|
@ -1,6 +1,7 @@
|
|||
#include "nar-info.hh"
|
||||
|
||||
#include <absl/strings/numbers.h>
|
||||
#include <absl/strings/str_split.h>
|
||||
|
||||
#include "globals.hh"
|
||||
|
||||
|
@ -59,7 +60,7 @@ NarInfo::NarInfo(const Store& store, const std::string& s,
|
|||
corrupt();
|
||||
}
|
||||
} else if (name == "References") {
|
||||
auto refs = tokenizeString<Strings>(value, " ");
|
||||
std::vector<std::string> refs = absl::StrSplit(value, absl::ByChar(' '));
|
||||
if (!references.empty()) {
|
||||
corrupt();
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#include "parsed-derivations.hh"
|
||||
|
||||
#include <absl/strings/str_split.h>
|
||||
|
||||
namespace nix {
|
||||
|
||||
ParsedDerivation::ParsedDerivation(const Path& drvPath, BasicDerivation& drv)
|
||||
|
@ -86,7 +88,7 @@ std::optional<Strings> ParsedDerivation::getStringsAttr(
|
|||
if (i == drv.env.end()) {
|
||||
return {};
|
||||
}
|
||||
return tokenizeString<Strings>(i->second);
|
||||
return absl::StrSplit(i->second, absl::ByAnyChar(" \t\n\r"));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
6
third_party/nix/src/libstore/ssh.cc
vendored
6
third_party/nix/src/libstore/ssh.cc
vendored
|
@ -3,6 +3,7 @@
|
|||
#include <utility>
|
||||
|
||||
#include <absl/strings/match.h>
|
||||
#include <absl/strings/str_split.h>
|
||||
|
||||
namespace nix {
|
||||
|
||||
|
@ -20,8 +21,9 @@ SSHMaster::SSHMaster(const std::string& host, std::string keyFile,
|
|||
}
|
||||
|
||||
void SSHMaster::addCommonSSHOpts(Strings& args) {
|
||||
for (auto& i : tokenizeString<Strings>(getEnv("NIX_SSHOPTS"))) {
|
||||
args.push_back(i);
|
||||
for (auto& i :
|
||||
absl::StrSplit(getEnv("NIX_SSHOPTS"), absl::ByAnyChar(" \t\n\r"))) {
|
||||
args.push_back(std::string(i));
|
||||
}
|
||||
if (!keyFile.empty()) {
|
||||
args.insert(args.end(), {"-i", keyFile});
|
||||
|
|
4
third_party/nix/src/libstore/store-api.cc
vendored
4
third_party/nix/src/libstore/store-api.cc
vendored
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include <absl/strings/match.h>
|
||||
#include <absl/strings/numbers.h>
|
||||
#include <absl/strings/str_split.h>
|
||||
#include <glog/logging.h>
|
||||
|
||||
#include "crypto.hh"
|
||||
|
@ -858,7 +859,8 @@ std::pair<std::string, Store::Params> splitUriAndParams(
|
|||
Store::Params params;
|
||||
auto q = uri.find('?');
|
||||
if (q != std::string::npos) {
|
||||
for (const auto& s : tokenizeString<Strings>(uri.substr(q + 1), "&")) {
|
||||
Strings parts = absl::StrSplit(uri.substr(q + 1), absl::ByChar('&'));
|
||||
for (const auto& s : parts) {
|
||||
auto e = s.find('=');
|
||||
if (e != std::string::npos) {
|
||||
auto value = s.substr(e + 1);
|
||||
|
|
14
third_party/nix/src/libutil/config.cc
vendored
14
third_party/nix/src/libutil/config.cc
vendored
|
@ -1,14 +1,16 @@
|
|||
#define GOOGLE_STRIP_LOG 0
|
||||
#include "config.hh"
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include <absl/strings/numbers.h>
|
||||
#include <absl/strings/str_split.h>
|
||||
#include <absl/strings/string_view.h>
|
||||
#include <glog/logging.h>
|
||||
|
||||
#include "args.hh"
|
||||
#include "json.hh"
|
||||
// #include <glog/log_severity.h>
|
||||
|
||||
namespace nix {
|
||||
|
||||
|
@ -99,7 +101,9 @@ void AbstractConfig::applyConfigFile(const Path& path) {
|
|||
line = std::string(line, 0, hash);
|
||||
}
|
||||
|
||||
auto tokens = tokenizeString<std::vector<std::string> >(line);
|
||||
// TODO(tazjin): absl::string_view after path functions are fixed.
|
||||
std::vector<std::string> tokens =
|
||||
absl::StrSplit(line, absl::ByAnyChar(" \t\n\r"));
|
||||
if (tokens.empty()) {
|
||||
continue;
|
||||
}
|
||||
|
@ -258,7 +262,7 @@ void BaseSetting<bool>::convertToArg(Args& args, const std::string& category) {
|
|||
|
||||
template <>
|
||||
void BaseSetting<Strings>::set(const std::string& str) {
|
||||
value = tokenizeString<Strings>(str);
|
||||
value = absl::StrSplit(str, absl::ByAnyChar(" \t\n\r"));
|
||||
}
|
||||
|
||||
template <>
|
||||
|
@ -276,7 +280,7 @@ void BaseSetting<Strings>::toJSON(JSONPlaceholder& out) {
|
|||
|
||||
template <>
|
||||
void BaseSetting<StringSet>::set(const std::string& str) {
|
||||
value = tokenizeString<StringSet>(str);
|
||||
value = absl::StrSplit(str, absl::ByAnyChar(" \t\n\r"));
|
||||
}
|
||||
|
||||
template <>
|
||||
|
|
29
third_party/nix/src/libutil/util.cc
vendored
29
third_party/nix/src/libutil/util.cc
vendored
|
@ -12,6 +12,7 @@
|
|||
#include <thread>
|
||||
#include <utility>
|
||||
|
||||
#include <absl/strings/str_split.h>
|
||||
#include <absl/strings/string_view.h>
|
||||
#include <fcntl.h>
|
||||
#include <grp.h>
|
||||
|
@ -165,7 +166,7 @@ Path canonPath(const Path& path, bool resolveSymlinks) {
|
|||
return s.empty() ? "/" : s;
|
||||
}
|
||||
|
||||
Path dirOf(const Path& path) {
|
||||
Path dirOf(absl::string_view path) {
|
||||
Path::size_type pos = path.rfind('/');
|
||||
if (pos == std::string::npos) {
|
||||
return ".";
|
||||
|
@ -542,7 +543,8 @@ Path getConfigDir() {
|
|||
std::vector<Path> getConfigDirs() {
|
||||
Path configHome = getConfigDir();
|
||||
std::string configDirs = getEnv("XDG_CONFIG_DIRS");
|
||||
auto result = tokenizeString<std::vector<std::string>>(configDirs, ":");
|
||||
std::vector<std::string> result =
|
||||
absl::StrSplit(configDirs, absl::ByChar(':'));
|
||||
result.insert(result.begin(), configHome);
|
||||
return result;
|
||||
}
|
||||
|
@ -1170,29 +1172,6 @@ void _interrupted() {
|
|||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
template <class C>
|
||||
C tokenizeString(const std::string& s, const std::string& separators) {
|
||||
C result;
|
||||
std::string::size_type pos = s.find_first_not_of(separators, 0);
|
||||
while (pos != std::string::npos) {
|
||||
std::string::size_type end = s.find_first_of(separators, pos + 1);
|
||||
if (end == std::string::npos) {
|
||||
end = s.size();
|
||||
}
|
||||
std::string token(s, pos, end - pos);
|
||||
result.insert(result.end(), token);
|
||||
pos = s.find_first_not_of(separators, end);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
template Strings tokenizeString(const std::string& s,
|
||||
const std::string& separators);
|
||||
template StringSet tokenizeString(const std::string& s,
|
||||
const std::string& separators);
|
||||
template std::vector<std::string> tokenizeString(const std::string& s,
|
||||
const std::string& separators);
|
||||
|
||||
std::string concatStringsSep(const std::string& sep, const Strings& ss) {
|
||||
std::string s;
|
||||
for (auto& i : ss) {
|
||||
|
|
7
third_party/nix/src/libutil/util.hh
vendored
7
third_party/nix/src/libutil/util.hh
vendored
|
@ -56,7 +56,7 @@ Path canonPath(const Path& path, bool resolveSymlinks = false);
|
|||
everything before the final `/'. If the path is the root or an
|
||||
immediate child thereof (e.g., `/foo'), this means an empty string
|
||||
is returned. */
|
||||
Path dirOf(const Path& path);
|
||||
Path dirOf(absl::string_view path);
|
||||
|
||||
/* Return the base name of the given canonical path, i.e., everything
|
||||
following the final `/'. */
|
||||
|
@ -316,11 +316,6 @@ MakeError(Interrupted, BaseError);
|
|||
|
||||
MakeError(FormatError, Error);
|
||||
|
||||
/* String tokenizer. */
|
||||
template <class C>
|
||||
C tokenizeString(const std::string& s,
|
||||
const std::string& separators = " \t\n\r");
|
||||
|
||||
/* Concatenate the given strings with a separator between the
|
||||
elements. */
|
||||
std::string concatStringsSep(const std::string& sep, const Strings& ss);
|
||||
|
|
6
third_party/nix/src/nix-build/nix-build.cc
vendored
6
third_party/nix/src/nix-build/nix-build.cc
vendored
|
@ -6,6 +6,7 @@
|
|||
#include <vector>
|
||||
|
||||
#include <absl/strings/ascii.h>
|
||||
#include <absl/strings/str_split.h>
|
||||
#include <glog/logging.h>
|
||||
|
||||
#include "affinity.hh"
|
||||
|
@ -113,7 +114,7 @@ static void _main(int argc, char** argv) {
|
|||
!std::regex_search(argv[1], std::regex("nix-shell"))) {
|
||||
script = argv[1];
|
||||
try {
|
||||
auto lines = tokenizeString<Strings>(readFile(script), "\n");
|
||||
Strings lines = absl::StrSplit(readFile(script), absl::ByChar('\n'));
|
||||
if (std::regex_search(lines.front(), std::regex("^#!"))) {
|
||||
lines.pop_front();
|
||||
inShebang = true;
|
||||
|
@ -444,7 +445,8 @@ static void _main(int argc, char** argv) {
|
|||
env["NIX_STORE"] = store->storeDir;
|
||||
env["NIX_BUILD_CORES"] = std::to_string(settings.buildCores);
|
||||
|
||||
auto passAsFile = tokenizeString<StringSet>(get(drv.env, "passAsFile", ""));
|
||||
StringSet passAsFile = absl::StrSplit(get(drv.env, "passAsFile", ""),
|
||||
absl::ByAnyChar(" \t\n\r"));
|
||||
|
||||
bool keepTmp = false;
|
||||
int fileNr = 0;
|
||||
|
|
11
third_party/nix/src/nix-channel/nix-channel.cc
vendored
11
third_party/nix/src/nix-channel/nix-channel.cc
vendored
|
@ -1,6 +1,7 @@
|
|||
#include <regex>
|
||||
|
||||
#include <absl/strings/ascii.h>
|
||||
#include <absl/strings/str_split.h>
|
||||
#include <fcntl.h>
|
||||
#include <pwd.h>
|
||||
|
||||
|
@ -24,13 +25,15 @@ static void readChannels() {
|
|||
}
|
||||
auto channelsFile = readFile(channelsList);
|
||||
|
||||
for (const auto& line :
|
||||
tokenizeString<std::vector<std::string>>(channelsFile, "\n")) {
|
||||
absl::StripTrailingAsciiWhitespace(line);
|
||||
std::vector<std::string> lines =
|
||||
absl::StrSplit(channelsFile, absl::ByChar('\n'));
|
||||
|
||||
for (auto& line : lines) {
|
||||
line = absl::StripTrailingAsciiWhitespace(line);
|
||||
if (std::regex_search(line, std::regex("^\\s*\\#"))) {
|
||||
continue;
|
||||
}
|
||||
auto split = tokenizeString<std::vector<std::string>>(line, " ");
|
||||
std::vector<std::string> split = absl::StrSplit(line, absl::ByChar(' '));
|
||||
auto url = std::regex_replace(split[0], std::regex("/*$"), "");
|
||||
auto name = split.size() > 1 ? split[1] : baseNameOf(url);
|
||||
channels[name] = url;
|
||||
|
|
2
third_party/nix/src/nix-daemon/nix-daemon.cc
vendored
2
third_party/nix/src/nix-daemon/nix-daemon.cc
vendored
|
@ -526,7 +526,7 @@ static void performOp(TunnelLogger* logger, const ref<Store>& store,
|
|||
trusted.insert(s);
|
||||
}
|
||||
Strings subs;
|
||||
auto ss = tokenizeString<Strings>(value);
|
||||
Strings ss = absl::StrSplit(value, absl::ByAnyChar(" \t\n\r"));
|
||||
for (auto& s : ss) {
|
||||
if (trusted.count(s) != 0u) {
|
||||
subs.push_back(s);
|
||||
|
|
12
third_party/nix/src/nix/doctor.cc
vendored
12
third_party/nix/src/nix/doctor.cc
vendored
|
@ -1,4 +1,6 @@
|
|||
#include <absl/strings/match.h>
|
||||
#include <absl/strings/str_cat.h>
|
||||
#include <absl/strings/str_split.h>
|
||||
|
||||
#include "command.hh"
|
||||
#include "serve-protocol.hh"
|
||||
|
@ -46,9 +48,9 @@ struct CmdDoctor : StoreCommand {
|
|||
static bool checkNixInPath() {
|
||||
PathSet dirs;
|
||||
|
||||
for (auto& dir : tokenizeString<Strings>(getEnv("PATH"), ":")) {
|
||||
if (pathExists(dir + "/nix-env")) {
|
||||
dirs.insert(dirOf(canonPath(dir + "/nix-env", true)));
|
||||
for (auto& dir : absl::StrSplit(getEnv("PATH"), absl::ByChar(':'))) {
|
||||
if (pathExists(absl::StrCat(dir, "/nix-env"))) {
|
||||
dirs.insert(dirOf(canonPath(absl::StrCat(dir, "/nix-env"), true)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -69,7 +71,7 @@ struct CmdDoctor : StoreCommand {
|
|||
static bool checkProfileRoots(const ref<Store>& store) {
|
||||
PathSet dirs;
|
||||
|
||||
for (auto& dir : tokenizeString<Strings>(getEnv("PATH"), ":")) {
|
||||
for (auto dir : absl::StrSplit(getEnv("PATH"), absl::ByChar(':'))) {
|
||||
Path profileDir = dirOf(dir);
|
||||
try {
|
||||
Path userEnv = canonPath(profileDir, true);
|
||||
|
@ -82,7 +84,7 @@ struct CmdDoctor : StoreCommand {
|
|||
}
|
||||
|
||||
if (profileDir.find("/profiles/") == std::string::npos) {
|
||||
dirs.insert(dir);
|
||||
dirs.insert(std::string(dir));
|
||||
}
|
||||
}
|
||||
} catch (SysError&) {
|
||||
|
|
3
third_party/nix/src/nix/edit.cc
vendored
3
third_party/nix/src/nix/edit.cc
vendored
|
@ -1,3 +1,4 @@
|
|||
#include <absl/strings/str_split.h>
|
||||
#include <glog/logging.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
@ -54,7 +55,7 @@ struct CmdEdit : InstallableCommand {
|
|||
|
||||
auto editor = getEnv("EDITOR", "cat");
|
||||
|
||||
auto args = tokenizeString<Strings>(editor);
|
||||
Strings args = absl::StrSplit(editor, absl::ByAnyChar(" \t\n\r"));
|
||||
|
||||
if (editor.find("emacs") != std::string::npos ||
|
||||
editor.find("nano") != std::string::npos ||
|
||||
|
|
18
third_party/nix/src/nix/run.cc
vendored
18
third_party/nix/src/nix/run.cc
vendored
|
@ -1,3 +1,8 @@
|
|||
#include <queue>
|
||||
|
||||
#include <absl/strings/str_split.h>
|
||||
#include <sys/mount.h>
|
||||
|
||||
#include "affinity.hh"
|
||||
#include "command.hh"
|
||||
#include "common-args.hh"
|
||||
|
@ -8,12 +13,6 @@
|
|||
#include "shared.hh"
|
||||
#include "store-api.hh"
|
||||
|
||||
#if __linux__
|
||||
#include <sys/mount.h>
|
||||
#endif
|
||||
|
||||
#include <queue>
|
||||
|
||||
using namespace nix;
|
||||
|
||||
std::string chrootHelperName = "__run_in_chroot";
|
||||
|
@ -124,7 +123,7 @@ struct CmdRun : InstallablesCommand {
|
|||
todo.push(path);
|
||||
}
|
||||
|
||||
auto unixPath = tokenizeString<Strings>(getEnv("PATH"), ":");
|
||||
Strings unixPath = absl::StrSplit(getEnv("PATH"), absl::ByChar(':'));
|
||||
|
||||
while (!todo.empty()) {
|
||||
Path path = todo.front();
|
||||
|
@ -137,8 +136,9 @@ struct CmdRun : InstallablesCommand {
|
|||
|
||||
auto propPath = path + "/nix-support/propagated-user-env-packages";
|
||||
if (accessor->stat(propPath).type == FSAccessor::tRegular) {
|
||||
for (auto& p : tokenizeString<Paths>(readFile(propPath))) {
|
||||
todo.push(p);
|
||||
for (auto p :
|
||||
absl::StrSplit(readFile(propPath), absl::ByAnyChar(" \t\n\r"))) {
|
||||
todo.push(std::string(p));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
6
third_party/nix/src/nix/upgrade-nix.cc
vendored
6
third_party/nix/src/nix/upgrade-nix.cc
vendored
|
@ -1,4 +1,6 @@
|
|||
#include <absl/strings/match.h>
|
||||
#include <absl/strings/str_cat.h>
|
||||
#include <absl/strings/str_split.h>
|
||||
#include <glog/logging.h>
|
||||
|
||||
#include "attr-path.hh"
|
||||
|
@ -101,8 +103,8 @@ struct CmdUpgradeNix : MixDryRun, StoreCommand {
|
|||
static Path getProfileDir(const ref<Store>& store) {
|
||||
Path where;
|
||||
|
||||
for (auto& dir : tokenizeString<Strings>(getEnv("PATH"), ":")) {
|
||||
if (pathExists(dir + "/nix-env")) {
|
||||
for (auto& dir : absl::StrSplit(getEnv("PATH"), absl::ByChar(':'))) {
|
||||
if (pathExists(absl::StrCat(dir, "/nix-env"))) {
|
||||
where = dir;
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue