about summary refs log tree commit diff
path: root/third_party/nix/src/nix-build
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@google.com>2020-05-20T21·27+0100
committerVincent Ambo <tazjin@google.com>2020-05-20T21·27+0100
commit689ef502f5b0655c9923ed77da2ae3504630f473 (patch)
tree3e331c153646f136875f047cc3b9f0aad8c86341 /third_party/nix/src/nix-build
parentd331d3a0b5c497a46e2636f308234be66566c04c (diff)
refactor(3p/nix): Apply clang-tidy's readability-* fixes r/788
This applies the readability fixes listed here:

https://clang.llvm.org/extra/clang-tidy/checks/list.html
Diffstat (limited to 'third_party/nix/src/nix-build')
-rw-r--r--third_party/nix/src/nix-build/nix-build.cc103
1 files changed, 53 insertions, 50 deletions
diff --git a/third_party/nix/src/nix-build/nix-build.cc b/third_party/nix/src/nix-build/nix-build.cc
index b2cc303ba816..5090cbe51370 100644
--- a/third_party/nix/src/nix-build/nix-build.cc
+++ b/third_party/nix/src/nix-build/nix-build.cc
@@ -23,7 +23,7 @@
 using namespace nix;
 using namespace std::string_literals;
 
-extern char** environ __attribute__((weak));
+__attribute__((weak));
 
 /* Recreate the effect of the perl shellwords function, breaking up a
  * string into arguments like a shell word, including escapes
@@ -75,7 +75,8 @@ static void _main(int argc, char** argv) {
   auto fromArgs = false;
   auto packages = false;
   // Same condition as bash uses for interactive shells
-  auto interactive = isatty(STDIN_FILENO) && isatty(STDERR_FILENO);
+  auto interactive =
+      (isatty(STDIN_FILENO) != 0) && (isatty(STDERR_FILENO) != 0);
   Strings attrPaths;
   Strings left;
   RepairFlag repair = NoRepair;
@@ -344,8 +345,11 @@ static void _main(int argc, char** argv) {
   auto buildPaths = [&](const PathSet& paths) {
     /* Note: we do this even when !printMissing to efficiently
        fetch binary cache data. */
-    unsigned long long downloadSize, narSize;
-    PathSet willBuild, willSubstitute, unknown;
+    unsigned long long downloadSize;
+    unsigned long long narSize;
+    PathSet willBuild;
+    PathSet willSubstitute;
+    PathSet unknown;
     store->queryMissing(paths, willBuild, willSubstitute, unknown, downloadSize,
                         narSize);
 
@@ -374,7 +378,7 @@ static void _main(int argc, char** argv) {
        <nixpkgs>. */
     auto shell = getEnv("NIX_BUILD_SHELL", "");
 
-    if (shell == "") {
+    if (shell.empty()) {
       try {
         auto expr = state->parseExprFromString(
             "(import <nixpkgs> {}).bashInteractive", absPath("."));
@@ -427,7 +431,7 @@ static void _main(int argc, char** argv) {
     if (pure) {
       decltype(env) newEnv;
       for (auto& i : env) {
-        if (keepVars.count(i.first)) {
+        if (keepVars.count(i.first) != 0u) {
           newEnv.emplace(i);
         }
       }
@@ -447,7 +451,7 @@ static void _main(int argc, char** argv) {
     int fileNr = 0;
 
     for (auto& var : drv.env) {
-      if (passAsFile.count(var.first)) {
+      if (passAsFile.count(var.first) != 0u) {
         keepTmp = true;
         string fn = ".attr-" + std::to_string(fileNr++);
         Path p = (Path)tmpDir + "/" + fn;
@@ -485,8 +489,9 @@ static void _main(int argc, char** argv) {
                 "%7%",
             (Path)tmpDir, (pure ? "" : "p=$PATH; "),
             (pure ? "" : "PATH=$PATH:$p; unset p; "), dirOf(shell), shell,
-            (getenv("TZ") ? (string("export TZ='") + getenv("TZ") + "'; ")
-                          : ""),
+            (getenv("TZ") != nullptr
+                 ? (string("export TZ='") + getenv("TZ") + "'; ")
+                 : ""),
             envCommand));
 
     Strings envStrs;
@@ -510,61 +515,59 @@ static void _main(int argc, char** argv) {
     throw SysError("executing shell '%s'", shell);
   }
 
-  else {
-    PathSet pathsToBuild;
+  PathSet pathsToBuild;
 
-    std::map<Path, Path> drvPrefixes;
-    std::map<Path, Path> resultSymlinks;
-    std::vector<Path> outPaths;
+  std::map<Path, Path> drvPrefixes;
+  std::map<Path, Path> resultSymlinks;
+  std::vector<Path> outPaths;
 
-    for (auto& drvInfo : drvs) {
-      auto drvPath = drvInfo.queryDrvPath();
-      auto outPath = drvInfo.queryOutPath();
+  for (auto& drvInfo : drvs) {
+    auto drvPath = drvInfo.queryDrvPath();
+    auto outPath = drvInfo.queryOutPath();
 
-      auto outputName = drvInfo.queryOutputName();
-      if (outputName == "") {
-        throw Error("derivation '%s' lacks an 'outputName' attribute", drvPath);
-      }
+    auto outputName = drvInfo.queryOutputName();
+    if (outputName.empty()) {
+      throw Error("derivation '%s' lacks an 'outputName' attribute", drvPath);
+    }
 
-      pathsToBuild.insert(drvPath + "!" + outputName);
+    pathsToBuild.insert(drvPath + "!" + outputName);
 
-      std::string drvPrefix;
-      auto i = drvPrefixes.find(drvPath);
-      if (i != drvPrefixes.end()) {
-        drvPrefix = i->second;
-      } else {
-        drvPrefix = outLink;
-        if (drvPrefixes.size()) {
-          drvPrefix += fmt("-%d", drvPrefixes.size() + 1);
-        }
-        drvPrefixes[drvPath] = drvPrefix;
-      }
-
-      std::string symlink = drvPrefix;
-      if (outputName != "out") {
-        symlink += "-" + outputName;
+    std::string drvPrefix;
+    auto i = drvPrefixes.find(drvPath);
+    if (i != drvPrefixes.end()) {
+      drvPrefix = i->second;
+    } else {
+      drvPrefix = outLink;
+      if (!drvPrefixes.empty() != 0u) {
+        drvPrefix += fmt("-%d", drvPrefixes.size() + 1);
       }
+      drvPrefixes[drvPath] = drvPrefix;
+    }
 
-      resultSymlinks[symlink] = outPath;
-      outPaths.push_back(outPath);
+    std::string symlink = drvPrefix;
+    if (outputName != "out") {
+      symlink += "-" + outputName;
     }
 
-    buildPaths(pathsToBuild);
+    resultSymlinks[symlink] = outPath;
+    outPaths.push_back(outPath);
+  }
 
-    if (dryRun) {
-      return;
-    }
+  buildPaths(pathsToBuild);
 
-    for (auto& symlink : resultSymlinks) {
-      if (auto store2 = store.dynamic_pointer_cast<LocalFSStore>()) {
-        store2->addPermRoot(symlink.second, absPath(symlink.first), true);
-      }
-    }
+  if (dryRun) {
+    return;
+  }
 
-    for (auto& path : outPaths) {
-      std::cout << path << '\n';
+  for (auto& symlink : resultSymlinks) {
+    if (auto store2 = store.dynamic_pointer_cast<LocalFSStore>()) {
+      store2->addPermRoot(symlink.second, absPath(symlink.first), true);
     }
   }
+
+  for (auto& path : outPaths) {
+    std::cout << path << '\n';
+  }
 }
 
 static RegisterLegacyCommand s1("nix-build", _main);