From 516c046ed984ba74da9a36f21e356dae9e227ca3 Mon Sep 17 00:00:00 2001 From: Kane York Date: Fri, 27 Nov 2020 16:31:10 -0800 Subject: refactor(tvix): remove all 'using namespace' from nix command clang-tidy: google-build-using-namespace Change-Id: I07ea10b03a6d9582c0508747698038f7106e8f63 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2181 Tested-by: BuildkiteCI Reviewed-by: glittershark --- third_party/nix/src/nix/add-to-store.cc | 6 ++-- third_party/nix/src/nix/build.cc | 6 ++-- third_party/nix/src/nix/cat.cc | 8 ++--- third_party/nix/src/nix/copy.cc | 6 ++-- third_party/nix/src/nix/doctor.cc | 8 ++--- third_party/nix/src/nix/dump-path.cc | 6 ++-- third_party/nix/src/nix/edit.cc | 6 ++-- third_party/nix/src/nix/eval.cc | 6 ++-- third_party/nix/src/nix/hash.cc | 4 +-- third_party/nix/src/nix/log.cc | 6 ++-- third_party/nix/src/nix/ls.cc | 8 ++--- third_party/nix/src/nix/optimise-store.cc | 6 ++-- third_party/nix/src/nix/path-info.cc | 6 ++-- third_party/nix/src/nix/ping-store.cc | 6 ++-- third_party/nix/src/nix/run.cc | 51 +++++++++++++++--------------- third_party/nix/src/nix/search.cc | 8 +++-- third_party/nix/src/nix/show-config.cc | 6 ++-- third_party/nix/src/nix/show-derivation.cc | 6 ++-- third_party/nix/src/nix/sigs.cc | 7 ++-- third_party/nix/src/nix/upgrade-nix.cc | 6 ++-- third_party/nix/src/nix/verify.cc | 6 ++-- third_party/nix/src/nix/why-depends.cc | 8 +++-- 22 files changed, 96 insertions(+), 90 deletions(-) diff --git a/third_party/nix/src/nix/add-to-store.cc b/third_party/nix/src/nix/add-to-store.cc index 34f6d03963c0..53641f120e8f 100644 --- a/third_party/nix/src/nix/add-to-store.cc +++ b/third_party/nix/src/nix/add-to-store.cc @@ -3,8 +3,7 @@ #include "libutil/archive.hh" #include "nix/command.hh" -using namespace nix; - +namespace nix { struct CmdAddToStore final : MixDryRun, StoreCommand { Path path; std::optional namePart; @@ -47,5 +46,6 @@ struct CmdAddToStore final : MixDryRun, StoreCommand { std::cout << fmt("%s\n", info.path); } }; +} // namespace nix -static RegisterCommand r1(make_ref()); +static nix::RegisterCommand r1(nix::make_ref()); diff --git a/third_party/nix/src/nix/build.cc b/third_party/nix/src/nix/build.cc index b0e8feefd33f..3fe74b7ffdba 100644 --- a/third_party/nix/src/nix/build.cc +++ b/third_party/nix/src/nix/build.cc @@ -3,8 +3,7 @@ #include "libstore/store-api.hh" #include "nix/command.hh" -using namespace nix; - +namespace nix { struct CmdBuild final : MixDryRun, InstallablesCommand { Path outLink = "result"; @@ -64,5 +63,6 @@ struct CmdBuild final : MixDryRun, InstallablesCommand { } } }; +} // namespace nix -static RegisterCommand r1(make_ref()); +static nix::RegisterCommand r1(nix::make_ref()); diff --git a/third_party/nix/src/nix/cat.cc b/third_party/nix/src/nix/cat.cc index 9ead9a6ff69d..7788707eae56 100644 --- a/third_party/nix/src/nix/cat.cc +++ b/third_party/nix/src/nix/cat.cc @@ -3,8 +3,7 @@ #include "libstore/store-api.hh" #include "nix/command.hh" -using namespace nix; - +namespace nix { struct MixCat : virtual Args { std::string path; @@ -51,6 +50,7 @@ struct CmdCatNar final : StoreCommand, MixCat { cat(makeNarAccessor(make_ref(readFile(narPath)))); } }; +} // namespace nix -static RegisterCommand r1(make_ref()); -static RegisterCommand r2(make_ref()); +static nix::RegisterCommand r1(nix::make_ref()); +static nix::RegisterCommand r2(nix::make_ref()); diff --git a/third_party/nix/src/nix/copy.cc b/third_party/nix/src/nix/copy.cc index ec25d0fc5a13..75c85698d11e 100644 --- a/third_party/nix/src/nix/copy.cc +++ b/third_party/nix/src/nix/copy.cc @@ -6,8 +6,7 @@ #include "libutil/thread-pool.hh" #include "nix/command.hh" -using namespace nix; - +namespace nix { struct CmdCopy final : StorePathsCommand { std::string srcUri, dstUri; @@ -82,5 +81,6 @@ struct CmdCopy final : StorePathsCommand { NoRepair, checkSigs, substitute); } }; +} // namespace nix -static RegisterCommand r1(make_ref()); +static nix::RegisterCommand r1(nix::make_ref()); diff --git a/third_party/nix/src/nix/doctor.cc b/third_party/nix/src/nix/doctor.cc index e65ca69f6bee..d0b4c2b58873 100644 --- a/third_party/nix/src/nix/doctor.cc +++ b/third_party/nix/src/nix/doctor.cc @@ -8,9 +8,8 @@ #include "libstore/worker-protocol.hh" #include "nix/command.hh" -using namespace nix; - -std::string formatProtocol(unsigned int proto) { +namespace nix { +static std::string formatProtocol(unsigned int proto) { if (proto != 0u) { auto major = GET_PROTOCOL_MAJOR(proto) >> 8; auto minor = GET_PROTOCOL_MINOR(proto); @@ -138,5 +137,6 @@ struct CmdDoctor final : StoreCommand { return true; } }; +} // namespace nix -static RegisterCommand r1(make_ref()); +static nix::RegisterCommand r1(nix::make_ref()); diff --git a/third_party/nix/src/nix/dump-path.cc b/third_party/nix/src/nix/dump-path.cc index 4ca5f1bc0277..1d0a996e561c 100644 --- a/third_party/nix/src/nix/dump-path.cc +++ b/third_party/nix/src/nix/dump-path.cc @@ -1,8 +1,7 @@ #include "libstore/store-api.hh" #include "nix/command.hh" -using namespace nix; - +namespace nix { struct CmdDumpPath final : StorePathCommand { std::string name() override { return "dump-path"; } @@ -24,5 +23,6 @@ struct CmdDumpPath final : StorePathCommand { sink.flush(); } }; +} // namespace nix -static RegisterCommand r1(make_ref()); +static nix::RegisterCommand r1(nix::make_ref()); diff --git a/third_party/nix/src/nix/edit.cc b/third_party/nix/src/nix/edit.cc index b5369e4a8a94..04c67acb94c6 100644 --- a/third_party/nix/src/nix/edit.cc +++ b/third_party/nix/src/nix/edit.cc @@ -7,8 +7,7 @@ #include "libmain/shared.hh" #include "nix/command.hh" -using namespace nix; - +namespace nix { struct CmdEdit final : InstallableCommand { std::string name() override { return "edit"; } @@ -71,5 +70,6 @@ struct CmdEdit final : InstallableCommand { throw SysError("cannot run editor '%s'", editor); } }; +} // namespace nix -static RegisterCommand r1(make_ref()); +static nix::RegisterCommand r1(nix::make_ref()); diff --git a/third_party/nix/src/nix/eval.cc b/third_party/nix/src/nix/eval.cc index a78f5b34faac..72fcbd82717d 100644 --- a/third_party/nix/src/nix/eval.cc +++ b/third_party/nix/src/nix/eval.cc @@ -7,8 +7,7 @@ #include "libutil/json.hh" #include "nix/command.hh" -using namespace nix; - +namespace nix { struct CmdEval final : MixJSON, InstallableCommand { bool raw = false; @@ -52,5 +51,6 @@ struct CmdEval final : MixJSON, InstallableCommand { } } }; +} // namespace nix -static RegisterCommand r1(make_ref()); +static nix::RegisterCommand r1(nix::make_ref()); diff --git a/third_party/nix/src/nix/hash.cc b/third_party/nix/src/nix/hash.cc index a40f7b4c859a..4fb262f1a8f0 100644 --- a/third_party/nix/src/nix/hash.cc +++ b/third_party/nix/src/nix/hash.cc @@ -4,8 +4,7 @@ #include "nix/command.hh" #include "nix/legacy.hh" -using namespace nix; - +namespace nix { struct CmdHash final : Command { enum Mode { mFile, mPath }; Mode mode; @@ -150,3 +149,4 @@ static int compatNixHash(int argc, char** argv) { } static RegisterLegacyCommand s1("nix-hash", compatNixHash); +} // namespace nix diff --git a/third_party/nix/src/nix/log.cc b/third_party/nix/src/nix/log.cc index 623d16e5d254..84207d8576ea 100644 --- a/third_party/nix/src/nix/log.cc +++ b/third_party/nix/src/nix/log.cc @@ -5,8 +5,7 @@ #include "libstore/store-api.hh" #include "nix/command.hh" -using namespace nix; - +namespace nix { struct CmdLog final : InstallableCommand { CmdLog() = default; @@ -59,5 +58,6 @@ struct CmdLog final : InstallableCommand { throw Error("build log of '%s' is not available", installable->what()); } }; +} // namespace nix -static RegisterCommand r1(make_ref()); +static nix::RegisterCommand r1(nix::make_ref()); diff --git a/third_party/nix/src/nix/ls.cc b/third_party/nix/src/nix/ls.cc index d6ff1aaf816a..1da722babbd3 100644 --- a/third_party/nix/src/nix/ls.cc +++ b/third_party/nix/src/nix/ls.cc @@ -5,8 +5,7 @@ #include "libutil/json.hh" #include "nix/command.hh" -using namespace nix; - +namespace nix { struct MixLs : virtual Args, MixJSON { std::string path; @@ -132,6 +131,7 @@ struct CmdLsNar final : Command, MixLs { list(makeNarAccessor(make_ref(readFile(narPath, true)))); } }; +} // namespace nix -static RegisterCommand r1(make_ref()); -static RegisterCommand r2(make_ref()); +static nix::RegisterCommand r1(nix::make_ref()); +static nix::RegisterCommand r2(nix::make_ref()); diff --git a/third_party/nix/src/nix/optimise-store.cc b/third_party/nix/src/nix/optimise-store.cc index 1b33ea3ec270..ceb53aa77b17 100644 --- a/third_party/nix/src/nix/optimise-store.cc +++ b/third_party/nix/src/nix/optimise-store.cc @@ -4,8 +4,7 @@ #include "libstore/store-api.hh" #include "nix/command.hh" -using namespace nix; - +namespace nix { struct CmdOptimiseStore final : StoreCommand { CmdOptimiseStore() = default; @@ -23,5 +22,6 @@ struct CmdOptimiseStore final : StoreCommand { void run(ref store) override { store->optimiseStore(); } }; +} // namespace nix -static RegisterCommand r1(make_ref()); +static nix::RegisterCommand r1(nix::make_ref()); diff --git a/third_party/nix/src/nix/path-info.cc b/third_party/nix/src/nix/path-info.cc index 300a588a2ef9..fcf060d50d08 100644 --- a/third_party/nix/src/nix/path-info.cc +++ b/third_party/nix/src/nix/path-info.cc @@ -7,8 +7,7 @@ #include "libutil/json.hh" #include "nix/command.hh" -using namespace nix; - +namespace nix { struct CmdPathInfo final : StorePathsCommand, MixJSON { bool showSize = false; bool showClosureSize = false; @@ -129,5 +128,6 @@ struct CmdPathInfo final : StorePathsCommand, MixJSON { } } }; +} // namespace nix -static RegisterCommand r1(make_ref()); +static nix::RegisterCommand r1(nix::make_ref()); diff --git a/third_party/nix/src/nix/ping-store.cc b/third_party/nix/src/nix/ping-store.cc index 78a79b037b43..4a33486bf8c6 100644 --- a/third_party/nix/src/nix/ping-store.cc +++ b/third_party/nix/src/nix/ping-store.cc @@ -2,8 +2,7 @@ #include "libstore/store-api.hh" #include "nix/command.hh" -using namespace nix; - +namespace nix { struct CmdPingStore final : StoreCommand { std::string name() override { return "ping-store"; } @@ -21,5 +20,6 @@ struct CmdPingStore final : StoreCommand { void run(ref store) override { store->connect(); } }; +} // namespace nix -static RegisterCommand r1(make_ref()); +static nix::RegisterCommand r1(nix::make_ref()); diff --git a/third_party/nix/src/nix/run.cc b/third_party/nix/src/nix/run.cc index 06c95f856f88..b3b54f300b4a 100644 --- a/third_party/nix/src/nix/run.cc +++ b/third_party/nix/src/nix/run.cc @@ -13,10 +13,10 @@ #include "libutil/finally.hh" #include "nix/command.hh" -using namespace nix; - +// note: exported in header file std::string chrootHelperName = "__run_in_chroot"; +namespace nix { struct CmdRun final : InstallablesCommand { std::vector command = {"bash"}; StringSet keep, unset; @@ -187,13 +187,14 @@ struct CmdRun final : InstallablesCommand { }; static RegisterCommand r1(make_ref()); +} // namespace nix void chrootHelper(int argc, char** argv) { int p = 1; std::string storeDir = argv[p++]; std::string realStoreDir = argv[p++]; std::string cmd = argv[p++]; - Strings args; + nix::Strings args; while (p < argc) { args.push_back(argv[p++]); } @@ -206,7 +207,7 @@ void chrootHelper(int argc, char** argv) { /* Try with just CLONE_NEWNS in case user namespaces are specifically disabled. */ if (unshare(CLONE_NEWNS) == -1) { - throw SysError("setting up a private mount namespace"); + throw nix::SysError("setting up a private mount namespace"); } } @@ -217,65 +218,65 @@ void chrootHelper(int argc, char** argv) { but that doesn't work in a user namespace yet (Ubuntu has a patch for this: https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1478578). */ - if (!pathExists(storeDir)) { + if (!nix::pathExists(storeDir)) { // FIXME: Use overlayfs? - Path tmpDir = createTempDir(); + nix::Path tmpDir = nix::createTempDir(); - createDirs(tmpDir + storeDir); + nix::createDirs(tmpDir + storeDir); if (mount(realStoreDir.c_str(), (tmpDir + storeDir).c_str(), "", MS_BIND, nullptr) == -1) { - throw SysError("mounting '%s' on '%s'", realStoreDir, storeDir); + throw nix::SysError("mounting '%s' on '%s'", realStoreDir, storeDir); } - for (const auto& entry : readDirectory("/")) { + for (const auto& entry : nix::readDirectory("/")) { auto src = "/" + entry.name; - auto st = lstat(src); + auto st = nix::lstat(src); if (!S_ISDIR(st.st_mode)) { continue; } - Path dst = tmpDir + "/" + entry.name; - if (pathExists(dst)) { + nix::Path dst = tmpDir + "/" + entry.name; + if (nix::pathExists(dst)) { continue; } if (mkdir(dst.c_str(), 0700) == -1) { - throw SysError("creating directory '%s'", dst); + throw nix::SysError("creating directory '%s'", dst); } if (mount(src.c_str(), dst.c_str(), "", MS_BIND | MS_REC, nullptr) == -1) { - throw SysError("mounting '%s' on '%s'", src, dst); + throw nix::SysError("mounting '%s' on '%s'", src, dst); } } char* cwd = getcwd(nullptr, 0); if (cwd == nullptr) { - throw SysError("getting current directory"); + throw nix::SysError("getting current directory"); } - Finally freeCwd([&]() { free(cwd); }); + ::Finally freeCwd([&]() { free(cwd); }); if (chroot(tmpDir.c_str()) == -1) { - throw SysError(format("chrooting into '%s'") % tmpDir); + throw nix::SysError(nix::format("chrooting into '%s'") % tmpDir); } if (chdir(cwd) == -1) { - throw SysError(format("chdir to '%s' in chroot") % cwd); + throw nix::SysError(nix::format("chdir to '%s' in chroot") % cwd); } } else if (mount(realStoreDir.c_str(), storeDir.c_str(), "", MS_BIND, nullptr) == -1) { - throw SysError("mounting '%s' on '%s'", realStoreDir, storeDir); + throw nix::SysError("mounting '%s' on '%s'", realStoreDir, storeDir); } - writeFile("/proc/self/setgroups", "deny"); - writeFile("/proc/self/uid_map", fmt("%d %d %d", uid, uid, 1)); - writeFile("/proc/self/gid_map", fmt("%d %d %d", gid, gid, 1)); + nix::writeFile("/proc/self/setgroups", "deny"); + nix::writeFile("/proc/self/uid_map", nix::fmt("%d %d %d", uid, uid, 1)); + nix::writeFile("/proc/self/gid_map", nix::fmt("%d %d %d", gid, gid, 1)); - execvp(cmd.c_str(), stringsToCharPtrs(args).data()); + execvp(cmd.c_str(), nix::stringsToCharPtrs(args).data()); - throw SysError("unable to exec '%s'", cmd); + throw nix::SysError("unable to exec '%s'", cmd); #else - throw Error( + throw nix::Error( "mounting the Nix store on '%s' is not supported on this platform", storeDir); #endif diff --git a/third_party/nix/src/nix/search.cc b/third_party/nix/src/nix/search.cc index 9db5b3d103f9..5a6bae6a1161 100644 --- a/third_party/nix/src/nix/search.cc +++ b/third_party/nix/src/nix/search.cc @@ -14,8 +14,7 @@ #include "libutil/json.hh" #include "nix/command.hh" -using namespace nix; - +namespace { std::string wrap(const std::string& prefix, const std::string& s) { return prefix + s + ANSI_NORMAL; } @@ -26,7 +25,9 @@ std::string hilite(const std::string& s, const std::smatch& m, : std::string(m.prefix()) + ANSI_RED + std::string(m.str()) + postfix + std::string(m.suffix()); } +} // namespace +namespace nix { struct CmdSearch final : SourceExprCommand, MixJSON { std::vector res; @@ -270,5 +271,6 @@ struct CmdSearch final : SourceExprCommand, MixJSON { } } }; +} // namespace nix -static RegisterCommand r1(make_ref()); +static nix::RegisterCommand r1(nix::make_ref()); diff --git a/third_party/nix/src/nix/show-config.cc b/third_party/nix/src/nix/show-config.cc index 56448f9d606b..fd92e481e89a 100644 --- a/third_party/nix/src/nix/show-config.cc +++ b/third_party/nix/src/nix/show-config.cc @@ -4,8 +4,7 @@ #include "libutil/json.hh" #include "nix/command.hh" -using namespace nix; - +namespace nix { struct CmdShowConfig final : Command, MixJSON { CmdShowConfig() = default; @@ -27,5 +26,6 @@ struct CmdShowConfig final : Command, MixJSON { } } }; +} // namespace nix -static RegisterCommand r1(make_ref()); +static nix::RegisterCommand r1(nix::make_ref()); diff --git a/third_party/nix/src/nix/show-derivation.cc b/third_party/nix/src/nix/show-derivation.cc index 51c7ba9c291a..efe554710ff8 100644 --- a/third_party/nix/src/nix/show-derivation.cc +++ b/third_party/nix/src/nix/show-derivation.cc @@ -7,8 +7,7 @@ #include "libutil/json.hh" #include "nix/command.hh" -using namespace nix; - +namespace nix { struct CmdShowDerivation final : InstallablesCommand { bool recursive = false; @@ -109,5 +108,6 @@ struct CmdShowDerivation final : InstallablesCommand { std::cout << "\n"; } }; +} // namespace nix -static RegisterCommand r1(make_ref()); +static nix::RegisterCommand r1(nix::make_ref()); diff --git a/third_party/nix/src/nix/sigs.cc b/third_party/nix/src/nix/sigs.cc index 21d14bfface9..cc42613d0713 100644 --- a/third_party/nix/src/nix/sigs.cc +++ b/third_party/nix/src/nix/sigs.cc @@ -7,8 +7,7 @@ #include "libutil/thread-pool.hh" #include "nix/command.hh" -using namespace nix; - +namespace nix { struct CmdCopySigs final : StorePathsCommand { Strings substituterUris; @@ -97,7 +96,7 @@ struct CmdCopySigs final : StorePathsCommand { } }; -static RegisterCommand r1(make_ref()); +static nix::RegisterCommand r1(make_ref()); struct CmdSignPaths final : StorePathsCommand { Path secretKeyFile; @@ -143,3 +142,5 @@ struct CmdSignPaths final : StorePathsCommand { }; static RegisterCommand r3(make_ref()); + +} // namespace nix diff --git a/third_party/nix/src/nix/upgrade-nix.cc b/third_party/nix/src/nix/upgrade-nix.cc index 77e284afba2c..c7f654d64884 100644 --- a/third_party/nix/src/nix/upgrade-nix.cc +++ b/third_party/nix/src/nix/upgrade-nix.cc @@ -11,8 +11,7 @@ #include "libstore/store-api.hh" #include "nix/command.hh" -using namespace nix; - +namespace nix { struct CmdUpgradeNix final : MixDryRun, StoreCommand { Path profileDir; std::string storePathsUrl = @@ -163,5 +162,6 @@ struct CmdUpgradeNix final : MixDryRun, StoreCommand { return state->forceString(*v2); } }; +} // namespace nix -static RegisterCommand r1(make_ref()); +static nix::RegisterCommand r1(nix::make_ref()); diff --git a/third_party/nix/src/nix/verify.cc b/third_party/nix/src/nix/verify.cc index 6552e3d1a7e0..7de46f2a9c01 100644 --- a/third_party/nix/src/nix/verify.cc +++ b/third_party/nix/src/nix/verify.cc @@ -8,8 +8,7 @@ #include "libutil/thread-pool.hh" #include "nix/command.hh" -using namespace nix; - +namespace nix { struct CmdVerify final : StorePathsCommand { bool noContents = false; bool noTrust = false; @@ -167,5 +166,6 @@ struct CmdVerify final : StorePathsCommand { (failed != 0u ? 4 : 0)); } }; +} // namespace nix -static RegisterCommand r1(make_ref()); +static nix::RegisterCommand r1(nix::make_ref()); diff --git a/third_party/nix/src/nix/why-depends.cc b/third_party/nix/src/nix/why-depends.cc index e18314e7fd01..954d619ef3ce 100644 --- a/third_party/nix/src/nix/why-depends.cc +++ b/third_party/nix/src/nix/why-depends.cc @@ -7,8 +7,7 @@ #include "libstore/store-api.hh" #include "nix/command.hh" -using namespace nix; - +namespace { static std::string hilite(const std::string& s, size_t pos, size_t len, const std::string& colour = ANSI_RED) { return std::string(s, 0, pos) + colour + std::string(s, pos, len) + @@ -22,7 +21,9 @@ static std::string filterPrintable(const std::string& s) { } return res; } +} // namespace +namespace nix { struct CmdWhyDepends final : SourceExprCommand { std::string _package, _dependency; bool all = false; @@ -263,5 +264,6 @@ struct CmdWhyDepends final : SourceExprCommand { } } }; +} // namespace nix -static RegisterCommand r1(make_ref()); +static nix::RegisterCommand r1(nix::make_ref()); -- cgit 1.4.1