From 06d7b4aebd9e4a1a87f77fe59a8c08392318be5d Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Sun, 24 May 2020 01:36:11 +0100 Subject: refactor(3p/nix/libutil): Replace chomp() with absl::strings --- third_party/nix/meson.build | 1 + third_party/nix/src/build-remote/build-remote.cc | 7 +++++-- third_party/nix/src/libexpr/primops/fetchGit.cc | 8 ++++++-- third_party/nix/src/libexpr/primops/fetchMercurial.cc | 4 +++- third_party/nix/src/libstore/build.cc | 9 ++++++--- third_party/nix/src/libstore/download.cc | 6 +++++- third_party/nix/src/libstore/meson.build | 2 +- third_party/nix/src/libstore/remote-store.cc | 3 ++- third_party/nix/src/libstore/s3-binary-cache-store.cc | 3 ++- third_party/nix/src/libutil/util.cc | 5 ----- third_party/nix/src/libutil/util.hh | 3 --- third_party/nix/src/nix-build/nix-build.cc | 3 ++- third_party/nix/src/nix-channel/nix-channel.cc | 7 ++++--- third_party/nix/src/nix/meson.build | 2 +- third_party/nix/src/nix/repl.cc | 3 ++- 15 files changed, 40 insertions(+), 26 deletions(-) (limited to 'third_party/nix') diff --git a/third_party/nix/meson.build b/third_party/nix/meson.build index 8e845c20e281..ecf83f8f0ccb 100644 --- a/third_party/nix/meson.build +++ b/third_party/nix/meson.build @@ -381,6 +381,7 @@ absl_deps = [ absl.dependency('spinlock_wait'), absl.dependency('stacktrace'), absl.dependency('strings'), + absl.dependency('strings_internal'), absl.dependency('symbolize'), absl.dependency('synchronization'), absl.dependency('throw_delegate'), diff --git a/third_party/nix/src/build-remote/build-remote.cc b/third_party/nix/src/build-remote/build-remote.cc index 04fcf389705d..9403d3c35e99 100644 --- a/third_party/nix/src/build-remote/build-remote.cc +++ b/third_party/nix/src/build-remote/build-remote.cc @@ -6,6 +6,8 @@ #include #include +#include +#include #include #include "derivations.hh" @@ -199,9 +201,10 @@ static int _main(int argc, char* argv[]) { storeUri = bestMachine->storeUri; } catch (std::exception& e) { - auto msg = chomp(drainFD(5, false)); + auto msg = absl::StripTrailingAsciiWhitespace(drainFD(5, false)); LOG(ERROR) << "cannot build on '" << bestMachine->storeUri - << "': " << e.what() << (msg.empty() ? "" : ": " + msg); + << "': " << e.what() + << (msg.empty() ? "" : absl::StrCat(": ", msg)); bestMachine->enabled = false; continue; } diff --git a/third_party/nix/src/libexpr/primops/fetchGit.cc b/third_party/nix/src/libexpr/primops/fetchGit.cc index 67641258d518..c45090707749 100644 --- a/third_party/nix/src/libexpr/primops/fetchGit.cc +++ b/third_party/nix/src/libexpr/primops/fetchGit.cc @@ -1,6 +1,7 @@ #include #include +#include #include #include @@ -76,7 +77,8 @@ GitInfo exportGit(ref store, const std::string& uri, } // clean working tree, but no ref or rev specified. Use 'HEAD'. - rev = chomp(runProgram("git", true, {"-C", uri, "rev-parse", "HEAD"})); + rev = absl::StripTrailingAsciiWhitespace( + runProgram("git", true, {"-C", uri, "rev-parse", "HEAD"})); ref = "HEAD"s; } @@ -145,7 +147,9 @@ GitInfo exportGit(ref store, const std::string& uri, // FIXME: check whether rev is an ancestor of ref. GitInfo gitInfo; - gitInfo.rev = rev != "" ? rev : chomp(readFile(localRefFile)); + gitInfo.rev = + rev != "" ? rev + : absl::StripTrailingAsciiWhitespace(readFile(localRefFile)); gitInfo.shortRev = std::string(gitInfo.rev, 0, 7); DLOG(INFO) << "using revision " << gitInfo.rev << " of repo '" << uri << "'"; diff --git a/third_party/nix/src/libexpr/primops/fetchMercurial.cc b/third_party/nix/src/libexpr/primops/fetchMercurial.cc index 9223f1c3ca99..69ece06eacb9 100644 --- a/third_party/nix/src/libexpr/primops/fetchMercurial.cc +++ b/third_party/nix/src/libexpr/primops/fetchMercurial.cc @@ -1,6 +1,7 @@ #include #include +#include #include #include @@ -43,7 +44,8 @@ HgInfo exportMercurial(ref store, const std::string& uri, HgInfo hgInfo; hgInfo.rev = "0000000000000000000000000000000000000000"; - hgInfo.branch = chomp(runProgram("hg", true, {"branch", "-R", uri})); + hgInfo.branch = absl::StripTrailingAsciiWhitespace( + runProgram("hg", true, {"branch", "-R", uri})); auto files = tokenizeString>( runProgram("hg", true, diff --git a/third_party/nix/src/libstore/build.cc b/third_party/nix/src/libstore/build.cc index feac6fcbfddc..266cedc096ad 100644 --- a/third_party/nix/src/libstore/build.cc +++ b/third_party/nix/src/libstore/build.cc @@ -12,6 +12,7 @@ #include #include +#include #include #include #include @@ -461,7 +462,7 @@ void handleDiffHook(uid_t uid, uid_t gid, Path tryA, Path tryB, Path drvPath, } if (!diffRes.second.empty()) { - LOG(ERROR) << chomp(diffRes.second); + LOG(ERROR) << absl::StripTrailingAsciiWhitespace(diffRes.second); } } catch (Error& error) { LOG(ERROR) << "diff hook execution failed: " << error.what(); @@ -1640,7 +1641,8 @@ MakeError(NotDeterministic, BuildError) hookEnvironment.emplace("DRV_PATH", drvPath); hookEnvironment.emplace("OUT_PATHS", - chomp(concatStringsSep(" ", outputPaths))); + absl::StripTrailingAsciiWhitespace( + concatStringsSep(" ", outputPaths))); RunOptions opts(settings.postBuildHook, {}); opts.environment = hookEnvironment; @@ -1788,7 +1790,8 @@ HookReply DerivationGoal::tryBuildHook() { } catch (SysError& e) { if (e.errNo == EPIPE) { LOG(ERROR) << "build hook died unexpectedly: " - << chomp(drainFD(worker.hook->fromHook.readSide.get())); + << absl::StripTrailingAsciiWhitespace( + drainFD(worker.hook->fromHook.readSide.get())); worker.hook = nullptr; return rpDecline; } diff --git a/third_party/nix/src/libstore/download.cc b/third_party/nix/src/libstore/download.cc index 7476dd50b579..876734478785 100644 --- a/third_party/nix/src/libstore/download.cc +++ b/third_party/nix/src/libstore/download.cc @@ -1,5 +1,7 @@ #include "download.hh" +#include + #include "archive.hh" #include "compression.hh" #include "finally.hh" @@ -231,7 +233,9 @@ struct CurlDownloader : public Downloader { static int debugCallback(CURL* handle, curl_infotype type, char* data, size_t size, void* userptr) { if (type == CURLINFO_TEXT) { - DLOG(INFO) << "curl: " << chomp(std::string(data, size)); + DLOG(INFO) << "curl: " + << absl::StripTrailingAsciiWhitespace( + std::string(data, size)); } return 0; } diff --git a/third_party/nix/src/libstore/meson.build b/third_party/nix/src/libstore/meson.build index 47f6ddf25970..b8564f24f8b0 100644 --- a/third_party/nix/src/libstore/meson.build +++ b/third_party/nix/src/libstore/meson.build @@ -80,7 +80,7 @@ libstore_dep_list = [ pthread_dep, sqlite3_dep, libsodium_dep -] +] + absl_deps if sys_name.contains('linux') libstore_dep_list += libseccomp_dep diff --git a/third_party/nix/src/libstore/remote-store.cc b/third_party/nix/src/libstore/remote-store.cc index c4215800da8d..cc6f6ebae993 100644 --- a/third_party/nix/src/libstore/remote-store.cc +++ b/third_party/nix/src/libstore/remote-store.cc @@ -3,6 +3,7 @@ #include #include +#include #include #include #include @@ -715,7 +716,7 @@ std::exception_ptr RemoteStore::Connection::processStderr(Sink* sink, } else if (msg == STDERR_NEXT) { - LOG(ERROR) << chomp(readString(from)); + LOG(ERROR) << absl::StripTrailingAsciiWhitespace(readString(from)); } else if (msg == STDERR_START_ACTIVITY) { diff --git a/third_party/nix/src/libstore/s3-binary-cache-store.cc b/third_party/nix/src/libstore/s3-binary-cache-store.cc index 483ddc19a3aa..df3afab3cf32 100644 --- a/third_party/nix/src/libstore/s3-binary-cache-store.cc +++ b/third_party/nix/src/libstore/s3-binary-cache-store.cc @@ -2,6 +2,7 @@ #include "s3-binary-cache-store.hh" +#include #include #include #include @@ -50,7 +51,7 @@ class AwsLogger : public Aws::Utils::Logging::FormattedLogSystem { using Aws::Utils::Logging::FormattedLogSystem::FormattedLogSystem; void ProcessFormattedStatement(Aws::String&& statement) override { - debug("AWS: %s", chomp(statement)); + debug("AWS: %s", absl::StripTrailingAsciiWhitespace(statement)); } }; diff --git a/third_party/nix/src/libutil/util.cc b/third_party/nix/src/libutil/util.cc index 6076bdc3934b..53d037cf5801 100644 --- a/third_party/nix/src/libutil/util.cc +++ b/third_party/nix/src/libutil/util.cc @@ -1210,11 +1210,6 @@ string concatStringsSep(const string& sep, const StringSet& ss) { return s; } -string chomp(const string& s) { - size_t i = s.find_last_not_of(" \n\r\t"); - return i == string::npos ? "" : string(s, 0, i + 1); -} - string trim(const string& s, const string& whitespace) { auto i = s.find_first_not_of(whitespace); if (i == string::npos) { diff --git a/third_party/nix/src/libutil/util.hh b/third_party/nix/src/libutil/util.hh index 5ce12f2ede43..3c8d4bd70c06 100644 --- a/third_party/nix/src/libutil/util.hh +++ b/third_party/nix/src/libutil/util.hh @@ -324,9 +324,6 @@ MakeError(Interrupted, BaseError) string concatStringsSep(const string& sep, const Strings& ss); string concatStringsSep(const string& sep, const StringSet& ss); -/* Remove trailing whitespace from a string. */ -string chomp(const string& s); - /* Remove whitespace from the start and end of a string. */ string trim(const string& s, const string& whitespace = " \n\r\t"); diff --git a/third_party/nix/src/nix-build/nix-build.cc b/third_party/nix/src/nix-build/nix-build.cc index 66947051ba32..a98603f35109 100644 --- a/third_party/nix/src/nix-build/nix-build.cc +++ b/third_party/nix/src/nix-build/nix-build.cc @@ -5,6 +5,7 @@ #include #include +#include #include #include "affinity.hh" @@ -121,7 +122,7 @@ static void _main(int argc, char** argv) { } args.clear(); for (auto line : lines) { - line = chomp(line); + line = absl::StripTrailingAsciiWhitespace(line); std::smatch match; if (std::regex_match(line, match, std::regex("^#!\\s*nix-shell (.*)$"))) { diff --git a/third_party/nix/src/nix-channel/nix-channel.cc b/third_party/nix/src/nix-channel/nix-channel.cc index 00305151747a..1a094f8cdb35 100644 --- a/third_party/nix/src/nix-channel/nix-channel.cc +++ b/third_party/nix/src/nix-channel/nix-channel.cc @@ -1,5 +1,6 @@ #include +#include #include #include @@ -25,7 +26,7 @@ static void readChannels() { for (const auto& line : tokenizeString>(channelsFile, "\n")) { - chomp(line); + absl::StripTrailingAsciiWhitespace(line); if (std::regex_search(line, std::regex("^\\s*\\#"))) { continue; } @@ -99,7 +100,7 @@ static void update(const StringSet& channelNames) { auto dl = getDownloader(); auto result = dl->downloadCached(store, request); auto filename = result.path; - url = chomp(result.effectiveUri); + url = absl::StripTrailingAsciiWhitespace(result.effectiveUri); // If the URL contains a version number, append it to the name // attribute (so that "nix-env -q" on the channels profile @@ -136,7 +137,7 @@ static void update(const StringSet& channelNames) { CachedDownloadRequest(url + "/nixexprs.tar.bz2")) .path; } - chomp(filename); + absl::StripTrailingAsciiWhitespace(filename); } // Regardless of where it came from, add the expression representing this diff --git a/third_party/nix/src/nix/meson.build b/third_party/nix/src/nix/meson.build index 259de78e2476..f6049deae465 100644 --- a/third_party/nix/src/nix/meson.build +++ b/third_party/nix/src/nix/meson.build @@ -58,7 +58,7 @@ nix_dep_list = [ libdl_dep, libsodium_dep, pthread_dep, -] +] + absl_deps nix_link_list = [ libutil_lib, diff --git a/third_party/nix/src/nix/repl.cc b/third_party/nix/src/nix/repl.cc index 87caf9dd3fc2..5db9468fdc0a 100644 --- a/third_party/nix/src/nix/repl.cc +++ b/third_party/nix/src/nix/repl.cc @@ -5,6 +5,7 @@ #include #include +#include #include #ifdef READLINE @@ -122,7 +123,7 @@ void printHelp() { } string removeWhitespace(string s) { - s = chomp(s); + s = absl::StripTrailingAsciiWhitespace(s); size_t n = s.find_first_not_of(" \n\r\t"); if (n != string::npos) { s = string(s, n); -- cgit 1.4.1