diff options
author | Maksim Denisov <denisov.maksim@huawei.com> | 2024-10-08 12:34:05 +0200 |
---|---|---|
committer | Maksim Denisov <denisov.maksim@huawei.com> | 2024-10-08 15:41:50 +0200 |
commit | ab9ff1405f9dd27addb6106e6d6e3ea45c730cc4 (patch) | |
tree | b7f2c3787752fb16f73b16e9e3343d2bf5e59d0f | |
parent | 6f03f36201fa79f3802f3235779ec5a451287e21 (diff) | |
download | justbuild-ab9ff1405f9dd27addb6106e6d6e3ea45c730cc4.tar.gz |
Name constexpr variables using kCamelCase.
-rw-r--r-- | .clang-tidy | 2 | ||||
-rw-r--r-- | src/buildtool/build_engine/base_maps/expression_map.hpp | 11 | ||||
-rw-r--r-- | src/buildtool/build_engine/base_maps/rule_map.hpp | 11 | ||||
-rw-r--r-- | src/buildtool/build_engine/base_maps/targets_file_map.hpp | 12 | ||||
-rw-r--r-- | src/buildtool/build_engine/expression/expression.cpp | 6 | ||||
-rw-r--r-- | src/other_tools/just_mr/setup.cpp | 4 | ||||
-rw-r--r-- | src/utils/cpp/type_safe_arithmetic.hpp | 14 | ||||
-rw-r--r-- | test/buildtool/file_system/git_repo.test.cpp | 4 | ||||
-rw-r--r-- | test/buildtool/file_system/resolve_symlinks_map.test.cpp | 8 | ||||
-rw-r--r-- | test/other_tools/git_operations/critical_git_ops.test.cpp | 10 | ||||
-rw-r--r-- | test/other_tools/git_operations/git_repo_remote.test.cpp | 4 |
11 files changed, 48 insertions, 38 deletions
diff --git a/.clang-tidy b/.clang-tidy index 5fe6d074..949174ae 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -54,5 +54,7 @@ CheckOptions: - { key: readability-identifier-naming.EnumCase, value: CamelCase } - { key: readability-identifier-naming.StructCase, value: CamelCase } - { key: readability-identifier-naming.TypeTemplateParameterCase, value: CamelCase } + - { key: readability-identifier-naming.ConstexprVariableCase, value: CamelCase } + - { key: readability-identifier-naming.ConstexprVariablePrefix, value: k } - { key: readability-identifier-naming.StaticConstantCase, value: CamelCase } - { key: readability-identifier-naming.StaticConstantPrefix, value: k } diff --git a/src/buildtool/build_engine/base_maps/expression_map.hpp b/src/buildtool/build_engine/base_maps/expression_map.hpp index ceb2cf2f..3acec531 100644 --- a/src/buildtool/build_engine/base_maps/expression_map.hpp +++ b/src/buildtool/build_engine/base_maps/expression_map.hpp @@ -33,10 +33,13 @@ namespace BuildMaps::Base { using ExpressionFileMap = AsyncMapConsumer<ModuleName, nlohmann::json>; -constexpr auto CreateExpressionFileMap = - CreateJsonFileMap<&RepositoryConfig::ExpressionRoot, - &RepositoryConfig::ExpressionFileName, - /*kMandatory=*/true>; +[[nodiscard]] static inline auto CreateExpressionFileMap( + gsl::not_null<const RepositoryConfig*> const& repo_config, + std::size_t jobs) -> JsonFileMap { + return CreateJsonFileMap<&RepositoryConfig::ExpressionRoot, + &RepositoryConfig::ExpressionFileName, + /*kMandatory=*/true>(repo_config, jobs); +} using ExpressionFunctionMap = AsyncMapConsumer<EntityName, ExpressionFunctionPtr>; diff --git a/src/buildtool/build_engine/base_maps/rule_map.hpp b/src/buildtool/build_engine/base_maps/rule_map.hpp index 867f4c38..d911317c 100644 --- a/src/buildtool/build_engine/base_maps/rule_map.hpp +++ b/src/buildtool/build_engine/base_maps/rule_map.hpp @@ -33,10 +33,13 @@ namespace BuildMaps::Base { using RuleFileMap = AsyncMapConsumer<ModuleName, nlohmann::json>; -constexpr auto CreateRuleFileMap = - CreateJsonFileMap<&RepositoryConfig::RuleRoot, - &RepositoryConfig::RuleFileName, - /*kMandatory=*/true>; +[[nodiscard]] static inline auto CreateRuleFileMap( + gsl::not_null<const RepositoryConfig*> const& repo_config, + std::size_t jobs) -> JsonFileMap { + return CreateJsonFileMap<&RepositoryConfig::RuleRoot, + &RepositoryConfig::RuleFileName, + /*kMandatory=*/true>(repo_config, jobs); +} using UserRuleMap = AsyncMapConsumer<EntityName, UserRulePtr>; diff --git a/src/buildtool/build_engine/base_maps/targets_file_map.hpp b/src/buildtool/build_engine/base_maps/targets_file_map.hpp index f14ea7f1..8ff5d76c 100644 --- a/src/buildtool/build_engine/base_maps/targets_file_map.hpp +++ b/src/buildtool/build_engine/base_maps/targets_file_map.hpp @@ -27,11 +27,13 @@ namespace BuildMaps::Base { using TargetsFileMap = AsyncMapConsumer<ModuleName, nlohmann::json>; -constexpr auto CreateTargetsFileMap = - CreateJsonFileMap<&RepositoryConfig::TargetRoot, - &RepositoryConfig::TargetFileName, - /*kMandatory=*/true>; - +[[nodiscard]] static inline auto CreateTargetsFileMap( + gsl::not_null<const RepositoryConfig*> const& repo_config, + std::size_t jobs) -> JsonFileMap { + return CreateJsonFileMap<&RepositoryConfig::TargetRoot, + &RepositoryConfig::TargetFileName, + /*kMandatory=*/true>(repo_config, jobs); +} } // namespace BuildMaps::Base #endif // INCLUDED_SRC_BUILDTOOL_BUILD_ENGINE_BASE_MAPS_TARGETS_FILE_MAP_HPP diff --git a/src/buildtool/build_engine/expression/expression.cpp b/src/buildtool/build_engine/expression/expression.cpp index 963f20f9..4dd61a2d 100644 --- a/src/buildtool/build_engine/expression/expression.cpp +++ b/src/buildtool/build_engine/expression/expression.cpp @@ -216,11 +216,11 @@ auto Expression::TypeStringForIndex() const noexcept -> std::string { if (kIndex == data_.index()) { return TypeToString<std::variant_alternative_t<kIndex, var_t>>(); } - constexpr auto size = std::variant_size_v<var_t>; - if constexpr (kIndex < size - 1) { + constexpr auto kSize = std::variant_size_v<var_t>; + if constexpr (kIndex < kSize - 1) { return TypeStringForIndex<kIndex + 1>(); } - return TypeToString<std::variant_alternative_t<size - 1, var_t>>(); + return TypeToString<std::variant_alternative_t<kSize - 1, var_t>>(); } auto Expression::TypeString() const noexcept -> std::string { diff --git a/src/other_tools/just_mr/setup.cpp b/src/other_tools/just_mr/setup.cpp index 0c884d86..1629402b 100644 --- a/src/other_tools/just_mr/setup.cpp +++ b/src/other_tools/just_mr/setup.cpp @@ -370,7 +370,7 @@ auto MultiRepoSetup(std::shared_ptr<Configuration> const& config, mr_repos[repo] = *values[i]; } // populate ALT_DIRS - constexpr auto err_msg_format = + constexpr auto kErrMsgFormat = "While performing {} {}:\nWhile populating fields for " "repository {}:\nExpected value for key \"{}\" to be a " "string, but found {}"; @@ -386,7 +386,7 @@ auto MultiRepoSetup(std::shared_ptr<Configuration> const& config, // we expect a string if (not val->IsString()) { Logger::Log(LogLevel::Error, - err_msg_format, + kErrMsgFormat, multi_repo_tool_name, interactive ? "setup-env" diff --git a/src/utils/cpp/type_safe_arithmetic.hpp b/src/utils/cpp/type_safe_arithmetic.hpp index 52efd81c..c647996a 100644 --- a/src/utils/cpp/type_safe_arithmetic.hpp +++ b/src/utils/cpp/type_safe_arithmetic.hpp @@ -39,9 +39,9 @@ struct TypeSafeArithmeticTag { using pointer_t = T*; using const_pointer_t = T const*; - static constexpr value_t max_value = MAX_VALUE; - static constexpr value_t min_value = MIN_VALUE; - static constexpr value_t smallest_value = SMALLEST_VALUE; + static constexpr value_t kMaxValue = MAX_VALUE; + static constexpr value_t kMinValue = MIN_VALUE; + static constexpr value_t kSmallestValue = SMALLEST_VALUE; }; /// \class TypeSafeArithmetic @@ -59,9 +59,9 @@ class TypeSafeArithmetic { using pointer_t = typename tag_t::pointer_t; using const_pointer_t = typename tag_t::const_pointer_t; - static constexpr value_t max_value = tag_t::max_value; - static constexpr value_t min_value = tag_t::min_value; - static constexpr value_t smallest_value = tag_t::smallest_value; + static constexpr value_t kMaxValue = tag_t::kMaxValue; + static constexpr value_t kMinValue = tag_t::kMinValue; + static constexpr value_t kSmallestValue = tag_t::kSmallestValue; constexpr TypeSafeArithmetic() = default; @@ -86,7 +86,7 @@ class TypeSafeArithmetic { constexpr auto get() const -> value_t { return m_value; } constexpr void set(value_t value) { - Expects(value >= min_value and value <= max_value and + Expects(value >= kMinValue and value <= kMaxValue and "value output of range"); m_value = value; } diff --git a/test/buildtool/file_system/git_repo.test.cpp b/test/buildtool/file_system/git_repo.test.cpp index fbe92a85..ae3ded41 100644 --- a/test/buildtool/file_system/git_repo.test.cpp +++ b/test/buildtool/file_system/git_repo.test.cpp @@ -611,7 +611,7 @@ TEST_CASE("Multi-threaded fake repository operations", "[git_repo]") { threads.reserve(kNumThreads); SECTION("Lookups in the same ODB") { - constexpr int NUM_CASES = 10; + constexpr int kNumCases = 10; for (int id{}; id < kNumThreads; ++id) { threads.emplace_back( [&storage_config, @@ -621,7 +621,7 @@ TEST_CASE("Multi-threaded fake repository operations", "[git_repo]") { &starting_signal](int tid) { starting_signal.wait(false); // cases based on thread number - switch (tid % NUM_CASES) { + switch (tid % kNumCases) { case 0: { auto remote_repo = GitRepo::Open(remote_cas); REQUIRE(remote_repo); diff --git a/test/buildtool/file_system/resolve_symlinks_map.test.cpp b/test/buildtool/file_system/resolve_symlinks_map.test.cpp index 01865f6d..5831aee1 100644 --- a/test/buildtool/file_system/resolve_symlinks_map.test.cpp +++ b/test/buildtool/file_system/resolve_symlinks_map.test.cpp @@ -120,7 +120,7 @@ TEST_CASE("Resolve symlinks", "[resolve_symlinks_map]") { auto resolve_symlinks_map = CreateResolveSymlinksMap(); SECTION("Source repo is target repo") { - constexpr auto NUM_CASES = 3; + constexpr auto kNumCases = 3; std::vector<ResolvedGitObject> expected = { {kFooId, ObjectType::File, "baz/foo"}, {kBazBarLinkId, ObjectType::Symlink, "bar_l"}, @@ -151,7 +151,7 @@ TEST_CASE("Resolve symlinks", "[resolve_symlinks_map]") { source_cas, source_cas)}, [&expected, &source_cas](auto const& values) { - for (auto i = 0; i < NUM_CASES; ++i) { + for (auto i = 0; i < kNumCases; ++i) { auto const& res = ResolvedGitObject{*values[i]}; CHECK(res.id == expected[i].id); CHECK(res.type == expected[i].type); @@ -176,7 +176,7 @@ TEST_CASE("Resolve symlinks", "[resolve_symlinks_map]") { auto target_cas = GitCAS::Open(*target_repo_path); REQUIRE(target_cas); - constexpr auto NUM_CASES = 3; + constexpr auto kNumCases = 3; std::vector<ResolvedGitObject> expected = { {kFooId, ObjectType::File, "baz/foo"}, {kBazBarLinkId, ObjectType::Symlink, "bar_l"}, @@ -207,7 +207,7 @@ TEST_CASE("Resolve symlinks", "[resolve_symlinks_map]") { source_cas, target_cas)}, [&expected, &target_cas](auto const& values) { - for (auto i = 0; i < NUM_CASES; ++i) { + for (auto i = 0; i < kNumCases; ++i) { auto const& res = ResolvedGitObject{*values[i]}; CHECK(res.id == expected[i].id); CHECK(res.type == expected[i].type); diff --git a/test/other_tools/git_operations/critical_git_ops.test.cpp b/test/other_tools/git_operations/critical_git_ops.test.cpp index c15842e7..aa93b391 100644 --- a/test/other_tools/git_operations/critical_git_ops.test.cpp +++ b/test/other_tools/git_operations/critical_git_ops.test.cpp @@ -152,21 +152,21 @@ TEST_CASE("Critical git operations", "[critical_git_op_map]") { // Add ops to the map. None should throw, as repeating the same operation // should retrieve the value from the map, not call the operation again. // helper lists - constexpr auto NUM_METHODS = 6; - std::vector<std::size_t> ops_all(NUM_METHODS); // indices of all ops tested + constexpr auto kNumMethods = 6; + std::vector<std::size_t> ops_all(kNumMethods); // indices of all ops tested std::iota(ops_all.begin(), ops_all.end(), 0); const std::vector<std::size_t> ops_with_result{ 0, 4}; // indices of ops that return a non-empty string // Add to the map all ops multiple times - constexpr auto REPEATS = 3; - for ([[maybe_unused]] auto k = REPEATS; k > 0; --k) { + constexpr auto kRepeats = 3; + for ([[maybe_unused]] auto k = kRepeats; k > 0; --k) { auto error = false; auto error_msg = std::string("NONE"); { TaskSystem ts; - for ([[maybe_unused]] auto j = REPEATS; j > 0; --j) { + for ([[maybe_unused]] auto j = kRepeats; j > 0; --j) { crit_op_map.ConsumeAfterKeysReady( &ts, {GitOpKey{.params = diff --git a/test/other_tools/git_operations/git_repo_remote.test.cpp b/test/other_tools/git_operations/git_repo_remote.test.cpp index a4f0daa6..d1efe97c 100644 --- a/test/other_tools/git_operations/git_repo_remote.test.cpp +++ b/test/other_tools/git_operations/git_repo_remote.test.cpp @@ -345,7 +345,7 @@ TEST_CASE("Multi-threaded fake repository operations", "[git_repo_remote]") { REQUIRE(target_repo); SECTION("Fetching into same repository from remote") { - constexpr int NUM_CASES = 4; + constexpr int kNumCases = 4; for (int id{}; id < kNumThreads; ++id) { threads.emplace_back( [&storage_config, @@ -355,7 +355,7 @@ TEST_CASE("Multi-threaded fake repository operations", "[git_repo_remote]") { &starting_signal](int tid) { starting_signal.wait(false); // cases based on thread number - switch (tid % NUM_CASES) { + switch (tid % kNumCases) { case 0: { auto result_containing = target_repo->CheckCommitExists(kRootCommit, |