diff options
author | Vincent Ambo <tazjin@google.com> | 2020-05-24T00·36+0100 |
---|---|---|
committer | Vincent Ambo <tazjin@google.com> | 2020-05-24T01·13+0100 |
commit | 06d7b4aebd9e4a1a87f77fe59a8c08392318be5d (patch) | |
tree | 264bfbef18b5b93596d6eb805fc9e5647ddadb4b | |
parent | 10481d25861f1c25b53cfbd8119199ef2e918f9f (diff) |
refactor(3p/nix/libutil): Replace chomp() with absl::strings r/835
-rw-r--r-- | third_party/nix/meson.build | 1 | ||||
-rw-r--r-- | third_party/nix/src/build-remote/build-remote.cc | 7 | ||||
-rw-r--r-- | third_party/nix/src/libexpr/primops/fetchGit.cc | 8 | ||||
-rw-r--r-- | third_party/nix/src/libexpr/primops/fetchMercurial.cc | 4 | ||||
-rw-r--r-- | third_party/nix/src/libstore/build.cc | 9 | ||||
-rw-r--r-- | third_party/nix/src/libstore/download.cc | 6 | ||||
-rw-r--r-- | third_party/nix/src/libstore/meson.build | 2 | ||||
-rw-r--r-- | third_party/nix/src/libstore/remote-store.cc | 3 | ||||
-rw-r--r-- | third_party/nix/src/libstore/s3-binary-cache-store.cc | 3 | ||||
-rw-r--r-- | third_party/nix/src/libutil/util.cc | 5 | ||||
-rw-r--r-- | third_party/nix/src/libutil/util.hh | 3 | ||||
-rw-r--r-- | third_party/nix/src/nix-build/nix-build.cc | 3 | ||||
-rw-r--r-- | third_party/nix/src/nix-channel/nix-channel.cc | 7 | ||||
-rw-r--r-- | third_party/nix/src/nix/meson.build | 2 | ||||
-rw-r--r-- | third_party/nix/src/nix/repl.cc | 3 |
15 files changed, 40 insertions, 26 deletions
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 <set> #include <tuple> +#include <absl/strings/ascii.h> +#include <absl/strings/str_cat.h> #include <glog/logging.h> #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 <nlohmann/json.hpp> #include <regex> +#include <absl/strings/ascii.h> #include <glog/logging.h> #include <sys/time.h> @@ -76,7 +77,8 @@ GitInfo exportGit(ref<Store> 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> 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 <nlohmann/json.hpp> #include <regex> +#include <absl/strings/ascii.h> #include <glog/logging.h> #include <sys/time.h> @@ -43,7 +44,8 @@ HgInfo exportMercurial(ref<Store> 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<std::set<std::string>>( 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 <sstream> #include <thread> +#include <absl/strings/ascii.h> #include <fcntl.h> #include <grp.h> #include <netdb.h> @@ -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 <absl/strings/ascii.h> + #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 <cerrno> #include <cstring> +#include <absl/strings/ascii.h> #include <fcntl.h> #include <glog/logging.h> #include <sys/socket.h> @@ -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 <absl/strings/ascii.h> #include <aws/core/Aws.h> #include <aws/core/VersionConfig.h> #include <aws/core/auth/AWSCredentialsProvider.h> @@ -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 <sstream> #include <vector> +#include <absl/strings/ascii.h> #include <glog/logging.h> #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 <regex> +#include <absl/strings/ascii.h> #include <fcntl.h> #include <pwd.h> @@ -25,7 +26,7 @@ static void readChannels() { for (const auto& line : tokenizeString<std::vector<string>>(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 <iostream> #include <utility> +#include <absl/strings/ascii.h> #include <glog/logging.h> #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); |