diff options
author | Klaus Aehlig <klaus.aehlig@huawei.com> | 2024-03-01 12:02:37 +0100 |
---|---|---|
committer | Klaus Aehlig <klaus.aehlig@huawei.com> | 2024-03-05 11:05:10 +0100 |
commit | c403ab0da5095d3eb7d139f94a8e9e360e000300 (patch) | |
tree | d13b965bfc3283f16d9a2f2758a4cb730d02b5a4 | |
parent | d90076c91f7aa83c35a8a0c3840048178dfc1e39 (diff) | |
download | justbuild-c403ab0da5095d3eb7d139f94a8e9e360e000300.tar.gz |
fs_utils: specify path for foreign-file root cache
As the internal distdir data structure now supports the
executable bit, it is also expressive enough to support
foreign-file repositories. Hence we can use this cache,
getting potentially more cache hits.
-rw-r--r-- | src/buildtool/storage/TARGETS | 3 | ||||
-rw-r--r-- | src/buildtool/storage/fs_utils.cpp | 17 | ||||
-rw-r--r-- | src/buildtool/storage/fs_utils.hpp | 7 |
3 files changed, 26 insertions, 1 deletions
diff --git a/src/buildtool/storage/TARGETS b/src/buildtool/storage/TARGETS index 38a118cf..9bde508c 100644 --- a/src/buildtool/storage/TARGETS +++ b/src/buildtool/storage/TARGETS @@ -70,7 +70,8 @@ ] , "stage": ["src", "buildtool", "storage"] , "private-deps": - [ ["src/buildtool/file_system", "file_system_manager"] + [ ["@", "json", "", "json"] + , ["src/buildtool/file_system", "file_system_manager"] , ["src/utils/cpp", "path"] , "config" , "storage" diff --git a/src/buildtool/storage/fs_utils.cpp b/src/buildtool/storage/fs_utils.cpp index f6055579..83167181 100644 --- a/src/buildtool/storage/fs_utils.cpp +++ b/src/buildtool/storage/fs_utils.cpp @@ -14,6 +14,10 @@ #include "src/buildtool/storage/fs_utils.hpp" +#include <unordered_map> +#include <utility> + +#include "nlohmann/json.hpp" #include "src/buildtool/file_system/file_system_manager.hpp" #include "src/buildtool/storage/config.hpp" #include "src/buildtool/storage/storage.hpp" @@ -63,6 +67,19 @@ auto GetArchiveTreeIDFile(std::string const& repo_type, return StorageConfig::BuildRoot() / "tree-map" / repo_type / content; } +auto GetForeignFileTreeIDFile(std::string const& content, + std::string const& name, + bool executable) noexcept + -> std::filesystem::path { + return GetDistdirTreeIDFile( + HashFunction::ComputeBlobHash( + nlohmann::json( + std::unordered_map<std::string, std::pair<std::string, bool>>{ + {name, {content, executable}}}) + .dump()) + .HexString()); +} + auto GetDistdirTreeIDFile(std::string const& content) noexcept -> std::filesystem::path { return StorageConfig::BuildRoot() / "distfiles-tree-map" / content; diff --git a/src/buildtool/storage/fs_utils.hpp b/src/buildtool/storage/fs_utils.hpp index ba66dac5..6e8f640b 100644 --- a/src/buildtool/storage/fs_utils.hpp +++ b/src/buildtool/storage/fs_utils.hpp @@ -49,6 +49,13 @@ namespace StorageUtils { std::string const& content) noexcept -> std::filesystem::path; +/// \brief Get the path to the file storing the tree id of an archive +/// content. +[[nodiscard]] auto GetForeignFileTreeIDFile(std::string const& content, + std::string const& name, + bool executable) noexcept + -> std::filesystem::path; + /// \brief Get the path to the file storing the tree id of a distdir list /// content. [[nodiscard]] auto GetDistdirTreeIDFile(std::string const& content) noexcept |