diff options
author | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2023-05-25 16:11:11 +0200 |
---|---|---|
committer | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2023-05-31 15:21:02 +0200 |
commit | 9d30f04f8fb16643b470248b252654846a7126f7 (patch) | |
tree | a0d216e17a88bcf0f1f44340dfeca92e53e1d433 /src | |
parent | 26e7149fe8cc1be820ab35ebb6b92a683f9809bb (diff) | |
download | justbuild-9d30f04f8fb16643b470248b252654846a7126f7.tar.gz |
utils: Relocate the std::filesystem::hash_value libc fix...
...and make the use of std::hash consistent.
This will make it easier to remove the fix once the libc
implementation we use catches up with the C++ standard.
Diffstat (limited to 'src')
-rw-r--r-- | src/buildtool/build_engine/target_map/TARGETS | 1 | ||||
-rw-r--r-- | src/buildtool/build_engine/target_map/utils.cpp | 3 | ||||
-rw-r--r-- | src/other_tools/ops_maps/TARGETS | 2 | ||||
-rw-r--r-- | src/other_tools/ops_maps/critical_git_op_map.hpp | 9 | ||||
-rw-r--r-- | src/other_tools/ops_maps/import_to_git_map.hpp | 5 | ||||
-rw-r--r-- | src/other_tools/root_maps/TARGETS | 1 | ||||
-rw-r--r-- | src/other_tools/root_maps/fpath_git_map.hpp | 17 | ||||
-rw-r--r-- | src/utils/cpp/TARGETS | 6 | ||||
-rw-r--r-- | src/utils/cpp/path_hash.hpp | 36 |
9 files changed, 54 insertions, 26 deletions
diff --git a/src/buildtool/build_engine/target_map/TARGETS b/src/buildtool/build_engine/target_map/TARGETS index 92c55cbd..e2c76c8e 100644 --- a/src/buildtool/build_engine/target_map/TARGETS +++ b/src/buildtool/build_engine/target_map/TARGETS @@ -61,6 +61,7 @@ , ["src/buildtool/logging", "logging"] , ["src/utils/cpp", "hash_combine"] , ["src/utils/cpp", "path"] + , ["src/utils/cpp", "path_hash"] , ["src/utils/cpp", "vector"] ] } diff --git a/src/buildtool/build_engine/target_map/utils.cpp b/src/buildtool/build_engine/target_map/utils.cpp index 24e0e8a7..050749de 100644 --- a/src/buildtool/build_engine/target_map/utils.cpp +++ b/src/buildtool/build_engine/target_map/utils.cpp @@ -20,6 +20,7 @@ #include <vector> #include "src/utils/cpp/path.hpp" +#include "src/utils/cpp/path_hash.hpp" auto BuildMaps::Target::Utils::obtainTargetByName( const SubExprEvaluator& eval, @@ -111,7 +112,7 @@ auto BuildMaps::Target::Utils::tree_conflict(const ExpressionPtr& map) struct PathHash { auto operator()(std::filesystem::path const& p) const noexcept -> std::size_t { - return std::filesystem::hash_value(p); + return std::hash<std::filesystem::path>{}(p); } }; std::unordered_set<std::filesystem::path, PathHash> blocked{}; diff --git a/src/other_tools/ops_maps/TARGETS b/src/other_tools/ops_maps/TARGETS index c270978a..21a63306 100644 --- a/src/other_tools/ops_maps/TARGETS +++ b/src/other_tools/ops_maps/TARGETS @@ -7,6 +7,7 @@ [ ["src/buildtool/multithreading", "async_map_consumer"] , ["src/other_tools/git_operations", "git_operations"] , ["src/utils/cpp", "hash_combine"] + , ["src/utils/cpp", "path_hash"] ] , "stage": ["src", "other_tools", "ops_maps"] } @@ -20,6 +21,7 @@ , ["src/other_tools/git_operations", "git_repo_remote"] , ["@", "fmt", "", "fmt"] , ["src/utils/cpp", "path"] + , ["src/utils/cpp", "path_hash"] ] , "stage": ["src", "other_tools", "ops_maps"] , "private-deps": diff --git a/src/other_tools/ops_maps/critical_git_op_map.hpp b/src/other_tools/ops_maps/critical_git_op_map.hpp index bb9b2765..58c2d3a1 100644 --- a/src/other_tools/ops_maps/critical_git_op_map.hpp +++ b/src/other_tools/ops_maps/critical_git_op_map.hpp @@ -22,6 +22,7 @@ #include "src/buildtool/multithreading/async_map_consumer.hpp" #include "src/other_tools/git_operations/git_operations.hpp" #include "src/utils/cpp/hash_combine.hpp" +#include "src/utils/cpp/path_hash.hpp" using GitOpKeyMap = std::unordered_map< GitOpType, @@ -66,7 +67,7 @@ class CriticalGitOpGuard { // making sure only one thread at a time processes this section std::scoped_lock<std::mutex> const lock(critical_key_mutex_); auto target_path_key = - std::filesystem::hash_value(new_key.params.target_path); + std::hash<std::filesystem::path>{}(new_key.params.target_path); if (curr_critical_key_.contains(target_path_key)) { GitOpKey old_key = curr_critical_key_[target_path_key]; // return stored key @@ -89,11 +90,7 @@ struct hash<GitOpParams> { [[nodiscard]] auto operator()(GitOpParams const& ct) const noexcept -> std::size_t { size_t seed{}; - // hash_value is used due to a bug in stdlibc++ which makes - // std::hash<std::filesystem::path>{}() fail with `temporary of type - // '__hash_enum<std::filesystem::__cxx11::path>' has private destructor` - hash_combine<size_t>(&seed, - std::filesystem::hash_value(ct.target_path)); + hash_combine<std::filesystem::path>(&seed, ct.target_path); hash_combine<std::string>(&seed, ct.git_hash); hash_combine<std::string>(&seed, ct.branch); return seed; diff --git a/src/other_tools/ops_maps/import_to_git_map.hpp b/src/other_tools/ops_maps/import_to_git_map.hpp index ee0b3c8f..487bae7c 100644 --- a/src/other_tools/ops_maps/import_to_git_map.hpp +++ b/src/other_tools/ops_maps/import_to_git_map.hpp @@ -21,6 +21,7 @@ #include "src/other_tools/git_operations/git_repo_remote.hpp" #include "src/other_tools/ops_maps/critical_git_op_map.hpp" #include "src/utils/cpp/path.hpp" +#include "src/utils/cpp/path_hash.hpp" struct CommitInfo { std::filesystem::path target_path{}; /*key*/ @@ -45,9 +46,7 @@ template <> struct hash<CommitInfo> { [[nodiscard]] auto operator()(CommitInfo const& ct) const noexcept -> std::size_t { - // hash_value is used due to a bug in stdlibc++ - // (see critical_git_op_map.hpp) - return std::filesystem::hash_value(ct.target_path); + return std::hash<std::filesystem::path>{}(ct.target_path); } }; } // namespace std diff --git a/src/other_tools/root_maps/TARGETS b/src/other_tools/root_maps/TARGETS index d2bb01a3..e4bc6990 100644 --- a/src/other_tools/root_maps/TARGETS +++ b/src/other_tools/root_maps/TARGETS @@ -49,6 +49,7 @@ , "deps": [ ["src/other_tools/ops_maps", "import_to_git_map"] , ["@", "json", "", "json"] + , ["src/utils/cpp", "path_hash"] ] , "stage": ["src", "other_tools", "root_maps"] , "private-deps": diff --git a/src/other_tools/root_maps/fpath_git_map.hpp b/src/other_tools/root_maps/fpath_git_map.hpp index 7f772eff..9b209163 100644 --- a/src/other_tools/root_maps/fpath_git_map.hpp +++ b/src/other_tools/root_maps/fpath_git_map.hpp @@ -17,26 +17,11 @@ #include "nlohmann/json.hpp" #include "src/other_tools/ops_maps/import_to_git_map.hpp" +#include "src/utils/cpp/path_hash.hpp" /// \brief Maps the path to a repo on the file system to its Git tree WS root. using FilePathGitMap = AsyncMapConsumer<std::filesystem::path, nlohmann::json>; -#if (defined(__GLIBCXX__) and _GLIBCXX_RELEASE < 12) or \ - (defined(_LIBCPP_VERSION) and _LIBCPP_VERSION < 16000) -// std::hash<std::filesystem::path> is missing for -// - GNU's libstdc++ < 12 -// - LLVM's libcxx < 16 (see https://reviews.llvm.org/D125394) -namespace std { -template <> -struct hash<std::filesystem::path> { - [[nodiscard]] auto operator()( - std::filesystem::path const& ct) const noexcept -> std::size_t { - return std::filesystem::hash_value(ct); - } -}; -} // namespace std -#endif - [[nodiscard]] auto CreateFilePathGitMap( std::optional<std::string> const& current_subcmd, gsl::not_null<CriticalGitOpMap*> const& critical_git_op_map, diff --git a/src/utils/cpp/TARGETS b/src/utils/cpp/TARGETS index fffb2e7b..73c5e462 100644 --- a/src/utils/cpp/TARGETS +++ b/src/utils/cpp/TARGETS @@ -77,4 +77,10 @@ , "deps": [["@", "gsl", "", "gsl"]] , "stage": ["src", "utils", "cpp"] } +, "path_hash": + { "type": ["@", "rules", "CC", "library"] + , "name": ["path_hash"] + , "hdrs": ["path_hash.hpp"] + , "stage": ["src", "utils", "cpp"] + } } diff --git a/src/utils/cpp/path_hash.hpp b/src/utils/cpp/path_hash.hpp new file mode 100644 index 00000000..b990161c --- /dev/null +++ b/src/utils/cpp/path_hash.hpp @@ -0,0 +1,36 @@ +// Copyright 2023 Huawei Cloud Computing Technology Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef INCLUDED_SRC_UTILS_CPP_PATH_HASH_HPP +#define INCLUDED_SRC_UTILS_CPP_PATH_HASH_HPP + +#include <filesystem> + +#if (defined(__GLIBCXX__) and _GLIBCXX_RELEASE < 12) or \ + (defined(_LIBCPP_VERSION) and _LIBCPP_VERSION < 16000) +// std::hash<std::filesystem::path> is missing for +// - GNU's libstdc++ < 12 +// - LLVM's libcxx < 16 (see https://reviews.llvm.org/D125394) +namespace std { +template <> +struct hash<std::filesystem::path> { + [[nodiscard]] auto operator()( + std::filesystem::path const& ct) const noexcept -> std::size_t { + return std::filesystem::hash_value(ct); + } +}; +} // namespace std +#endif + +#endif // INCLUDED_SRC_UTILS_CPP_PATH_HASH_HPP |