From 689ef502f5b0655c9923ed77da2ae3504630f473 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Wed, 20 May 2020 22:27:37 +0100 Subject: refactor(3p/nix): Apply clang-tidy's readability-* fixes This applies the readability fixes listed here: https://clang.llvm.org/extra/clang-tidy/checks/list.html --- third_party/nix/src/nix-build/nix-build.cc | 103 +++++++++++++++-------------- 1 file changed, 53 insertions(+), 50 deletions(-) (limited to 'third_party/nix/src/nix-build') 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) { . */ auto shell = getEnv("NIX_BUILD_SHELL", ""); - if (shell == "") { + if (shell.empty()) { try { auto expr = state->parseExprFromString( "(import {}).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 drvPrefixes; - std::map resultSymlinks; - std::vector outPaths; + std::map drvPrefixes; + std::map resultSymlinks; + std::vector 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()) { - 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()) { + store2->addPermRoot(symlink.second, absPath(symlink.first), true); } } + + for (auto& path : outPaths) { + std::cout << path << '\n'; + } } static RegisterLegacyCommand s1("nix-build", _main); -- cgit 1.4.1