diff options
Diffstat (limited to 'src/buildtool/execution_api/local')
-rw-r--r-- | src/buildtool/execution_api/local/config.hpp | 69 | ||||
-rw-r--r-- | src/buildtool/execution_api/local/local_action.cpp | 27 | ||||
-rw-r--r-- | src/buildtool/execution_api/local/local_api.hpp | 1 | ||||
-rw-r--r-- | src/buildtool/execution_api/local/local_storage.cpp | 29 | ||||
-rw-r--r-- | src/buildtool/execution_api/local/local_storage.hpp | 2 |
5 files changed, 74 insertions, 54 deletions
diff --git a/src/buildtool/execution_api/local/config.hpp b/src/buildtool/execution_api/local/config.hpp index 5f3a2a80..3f293b95 100644 --- a/src/buildtool/execution_api/local/config.hpp +++ b/src/buildtool/execution_api/local/config.hpp @@ -19,6 +19,24 @@ /// \brief Store global build system configuration. class LocalExecutionConfig { + struct ConfigData { + // User root directory (Unix default: /home/${USER}) + std::filesystem::path user_root{}; + + // Build root directory (default: empty) + std::filesystem::path build_root{}; + + // Disk cache directory (default: empty) + std::filesystem::path disk_cache{}; + + // Launcher to be prepended to action's command before executed. + // Default: ["env", "--"] + std::vector<std::string> launcher{"env", "--"}; + + // Persistent build directory option + bool keep_build_dir{false}; + }; + public: [[nodiscard]] static auto SetBuildRoot( std::filesystem::path const& dir) noexcept -> bool { @@ -28,7 +46,7 @@ class LocalExecutionConfig { dir.string()); return false; } - build_root_ = dir; + Data().build_root = dir; return true; } @@ -40,14 +58,14 @@ class LocalExecutionConfig { dir.string()); return false; } - disk_cache_ = dir; + Data().disk_cache = dir; return true; } [[nodiscard]] static auto SetLauncher( std::vector<std::string> const& launcher) noexcept -> bool { try { - launcher_ = launcher; + Data().launcher = launcher; } catch (std::exception const& e) { Logger::Log(LogLevel::Error, "when setting the local launcher\n{}", @@ -59,63 +77,54 @@ class LocalExecutionConfig { [[nodiscard]] static auto SetKeepBuildDir(bool is_persistent) noexcept -> bool { - keep_build_dir_ = is_persistent; + Data().keep_build_dir = is_persistent; return true; } /// \brief User directory. [[nodiscard]] static auto GetUserDir() noexcept -> std::filesystem::path { - if (user_root_.empty()) { - user_root_ = GetUserRoot() / ".cache" / "just"; + auto& user_root = Data().user_root; + if (user_root.empty()) { + user_root = GetUserRoot() / ".cache" / "just"; } - return user_root_; + return user_root; } /// \brief Build directory, defaults to user directory if not set [[nodiscard]] static auto GetBuildDir() noexcept -> std::filesystem::path { - if (build_root_.empty()) { + auto& build_root = Data().build_root; + if (build_root.empty()) { return GetUserDir(); } - return build_root_; + return build_root; } /// \brief Cache directory, defaults to user directory if not set [[nodiscard]] static auto GetCacheDir() noexcept -> std::filesystem::path { - if (disk_cache_.empty()) { + auto& disk_cache = Data().disk_cache; + if (disk_cache.empty()) { return GetBuildDir(); } - return disk_cache_; + return disk_cache; } [[nodiscard]] static auto GetLauncher() noexcept -> std::vector<std::string> { - return launcher_; + return Data().launcher; } [[nodiscard]] static auto KeepBuildDir() noexcept -> bool { - return keep_build_dir_; + return Data().keep_build_dir; } private: - // User root directory (Unix default: /home/${USER}) - static inline std::filesystem::path user_root_{}; - - // Build root directory (default: empty) - static inline std::filesystem::path build_root_{}; - - // Disk cache directory (default: empty) - static inline std::filesystem::path disk_cache_{}; - - // Launcher to be prepended to action's command before executed. - // Default: ["env", "--"] - static inline std::vector<std::string> launcher_{"env", "--"}; - - // Persistent build directory option - static inline bool keep_build_dir_{false}; + [[nodiscard]] static auto Data() noexcept -> ConfigData& { + static ConfigData instance{}; + return instance; + } /// \brief Determine user root directory - [[nodiscard]] static inline auto GetUserRoot() noexcept - -> std::filesystem::path { + [[nodiscard]] static auto GetUserRoot() noexcept -> std::filesystem::path { char const* root{nullptr}; #ifdef __unix__ diff --git a/src/buildtool/execution_api/local/local_action.cpp b/src/buildtool/execution_api/local/local_action.cpp index 0c71a84b..d8ec8be3 100644 --- a/src/buildtool/execution_api/local/local_action.cpp +++ b/src/buildtool/execution_api/local/local_action.cpp @@ -184,21 +184,24 @@ auto LocalAction::CreateDirectoryStructure( } // create output paths - for (auto const& local_path : output_files_) { - if (not FileSystemManager::CreateDirectory( - (exec_path / local_path).parent_path())) { + auto const create_dir = [this](auto const& dir) { + if (not FileSystemManager::CreateDirectory(dir)) { logger_.Emit(LogLevel::Error, "failed to create output directory"); return false; } - } - for (auto const& local_path : output_dirs_) { - if (not FileSystemManager::CreateDirectory(exec_path / local_path)) { - logger_.Emit(LogLevel::Error, "failed to create output directory"); - return false; - } - } - - return true; + return true; + }; + return std::all_of(output_files_.begin(), + output_files_.end(), + [&exec_path, &create_dir](auto const& local_path) { + auto dir = (exec_path / local_path).parent_path(); + return create_dir(dir); + }) and + std::all_of(output_dirs_.begin(), + output_dirs_.end(), + [&exec_path, &create_dir](auto const& local_path) { + return create_dir(exec_path / local_path); + }); } auto LocalAction::CollectOutputFile(std::filesystem::path const& exec_path, diff --git a/src/buildtool/execution_api/local/local_api.hpp b/src/buildtool/execution_api/local/local_api.hpp index 96b96416..ebbb10ef 100644 --- a/src/buildtool/execution_api/local/local_api.hpp +++ b/src/buildtool/execution_api/local/local_api.hpp @@ -34,6 +34,7 @@ class LocalApi final : public IExecutionApi { properties}}; } + // NOLINTNEXTLINE(misc-no-recursion) [[nodiscard]] auto RetrieveToPaths( std::vector<Artifact::ObjectInfo> const& artifacts_info, std::vector<std::filesystem::path> const& output_paths) noexcept diff --git a/src/buildtool/execution_api/local/local_storage.cpp b/src/buildtool/execution_api/local/local_storage.cpp index c007fc1d..5e4115df 100644 --- a/src/buildtool/execution_api/local/local_storage.cpp +++ b/src/buildtool/execution_api/local/local_storage.cpp @@ -23,7 +23,8 @@ namespace { gsl::not_null<FILE*> const& stream) noexcept -> bool { if (auto dir = ReadDirectory(storage, tree_digest)) { if (auto data = BazelMsgFactory::DirectoryToString(*dir)) { - std::fwrite(data->data(), 1, data->size(), stream); + auto const& str = *data; + std::fwrite(str.data(), 1, str.size(), stream); return true; } } @@ -71,6 +72,7 @@ auto LocalStorage::ReadTreeInfos( return std::nullopt; } +// NOLINTNEXTLINE(misc-no-recursion) auto LocalStorage::ReadObjectInfosRecursively( BazelMsgFactory::InfoStoreFunc const& store_info, std::filesystem::path const& parent, @@ -79,19 +81,22 @@ auto LocalStorage::ReadObjectInfosRecursively( if (tree_map_) { auto const* tree = tree_map_->GetTree(digest); if (tree != nullptr) { - for (auto const& [path, info] : *tree) { - try { - if (IsTreeObject(info->type) - ? not ReadObjectInfosRecursively( - store_info, parent / path, info->digest) - : not store_info(parent / path, *info)) { + return std::all_of( + tree->begin(), + tree->end(), + // NOLINTNEXTLINE(misc-no-recursion) + [this, &store_info, &parent](auto const& entry) { + try { + auto const& [path, info] = entry; + return IsTreeObject(info->type) + ? ReadObjectInfosRecursively(store_info, + parent / path, + info->digest) + : store_info(parent / path, *info); + } catch (...) { // satisfy clang-tidy, store_info() could return false; } - } catch (...) { // satisfy clang-tidy, store_info() could throw - return false; - } - } - return true; + }); } Logger::Log( LogLevel::Debug, "tree {} not found in tree map", digest.hash()); diff --git a/src/buildtool/execution_api/local/local_storage.hpp b/src/buildtool/execution_api/local/local_storage.hpp index a071a5d5..568d412d 100644 --- a/src/buildtool/execution_api/local/local_storage.hpp +++ b/src/buildtool/execution_api/local/local_storage.hpp @@ -52,6 +52,7 @@ class LocalStorage { } /// \brief Obtain blob path from digest with x-bit. + /// NOLINTNEXTLINE(misc-no-recursion) [[nodiscard]] auto BlobPath(bazel_re::Digest const& digest, bool is_executable) const noexcept -> std::optional<std::filesystem::path> { @@ -91,6 +92,7 @@ class LocalStorage { /// \param digest Blob digest. /// \param to_executable Sync direction. /// \returns Path to blob in target CAS. + /// NOLINTNEXTLINE(misc-no-recursion) [[nodiscard]] auto TrySyncBlob(bazel_re::Digest const& digest, bool to_executable) const noexcept -> std::optional<std::filesystem::path> { |