about summary refs log tree commit diff
path: root/third_party/nix/src/nix
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@google.com>2020-05-25T14·54+0100
committerVincent Ambo <tazjin@google.com>2020-05-25T14·54+0100
commitbf452cbc2ae2b209ec262ce858deca470d086f24 (patch)
tree198e98902be569301ecb9a821b0c9512b128f930 /third_party/nix/src/nix
parentb99b368d17f2e806a61f7abb83c6d3a9e4bbdc38 (diff)
refactor(3p/nix): Replace tokenizeStrings with absl::StrSplit r/846
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.
Diffstat (limited to 'third_party/nix/src/nix')
-rw-r--r--third_party/nix/src/nix/doctor.cc12
-rw-r--r--third_party/nix/src/nix/edit.cc3
-rw-r--r--third_party/nix/src/nix/run.cc18
-rw-r--r--third_party/nix/src/nix/upgrade-nix.cc6
4 files changed, 22 insertions, 17 deletions
diff --git a/third_party/nix/src/nix/doctor.cc b/third_party/nix/src/nix/doctor.cc
index 79e9eb5394..c7d133fdac 100644
--- a/third_party/nix/src/nix/doctor.cc
+++ b/third_party/nix/src/nix/doctor.cc
@@ -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&) {
diff --git a/third_party/nix/src/nix/edit.cc b/third_party/nix/src/nix/edit.cc
index 330a845dc5..4d5cb382bc 100644
--- a/third_party/nix/src/nix/edit.cc
+++ b/third_party/nix/src/nix/edit.cc
@@ -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 ||
diff --git a/third_party/nix/src/nix/run.cc b/third_party/nix/src/nix/run.cc
index fa471bd542..47103e8db3 100644
--- a/third_party/nix/src/nix/run.cc
+++ b/third_party/nix/src/nix/run.cc
@@ -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));
         }
       }
     }
diff --git a/third_party/nix/src/nix/upgrade-nix.cc b/third_party/nix/src/nix/upgrade-nix.cc
index 7098e0eb90..174cc1f1fc 100644
--- a/third_party/nix/src/nix/upgrade-nix.cc
+++ b/third_party/nix/src/nix/upgrade-nix.cc
@@ -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;
       }