summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/other_tools/just_mr/TARGETS22
-rw-r--r--src/other_tools/just_mr/fetch.cpp1
-rw-r--r--src/other_tools/just_mr/launch.cpp2
-rw-r--r--src/other_tools/just_mr/main.cpp1
-rw-r--r--src/other_tools/just_mr/setup.cpp1
-rw-r--r--src/other_tools/just_mr/setup_utils.cpp138
-rw-r--r--src/other_tools/just_mr/setup_utils.hpp62
-rw-r--r--src/other_tools/just_mr/utils.cpp111
-rw-r--r--src/other_tools/just_mr/utils.hpp25
9 files changed, 225 insertions, 138 deletions
diff --git a/src/other_tools/just_mr/TARGETS b/src/other_tools/just_mr/TARGETS
index 8941c1c9..894d9259 100644
--- a/src/other_tools/just_mr/TARGETS
+++ b/src/other_tools/just_mr/TARGETS
@@ -20,6 +20,7 @@
, "update"
, "setup"
, "launch"
+ , "setup_utils"
]
, "stage": ["src", "other_tools", "just_mr"]
, "private-ldflags":
@@ -50,7 +51,6 @@
[ ["src/utils/cpp", "path"]
, ["src/buildtool/execution_api/local", "local"]
, ["src/buildtool/file_system", "file_storage"]
- , "exit_codes"
]
}
, "exit_codes":
@@ -76,6 +76,23 @@
, "stage": ["src", "other_tools", "just_mr"]
, "private-deps": [["src/buildtool/logging", "logging"]]
}
+, "setup_utils":
+ { "type": ["@", "rules", "CC", "library"]
+ , "name": ["setup_utils"]
+ , "hdrs": ["setup_utils.hpp"]
+ , "srcs": ["setup_utils.cpp"]
+ , "deps":
+ [ ["src/buildtool/build_engine/expression", "expression_ptr_interface"]
+ , ["src/buildtool/build_engine/expression", "expression"]
+ ]
+ , "stage": ["src", "other_tools", "just_mr"]
+ , "private-deps":
+ [ ["@", "json", "", "json"]
+ , ["src/buildtool/file_system", "file_system_manager"]
+ , ["src/buildtool/logging", "logging"]
+ , "exit_codes"
+ ]
+ }
, "fetch":
{ "type": ["@", "rules", "CC", "library"]
, "name": ["fetch"]
@@ -93,6 +110,7 @@
, "utils"
, ["src/other_tools/ops_maps", "content_cas_map"]
, ["src/other_tools/ops_maps", "repo_fetch_map"]
+ , "setup_utils"
]
}
, "update":
@@ -137,6 +155,7 @@
, ["src/other_tools/root_maps", "fpath_git_map"]
, ["src/other_tools/root_maps", "tree_id_git_map"]
, ["src/other_tools/symlinks_map", "resolve_symlinks_map"]
+ , "setup_utils"
]
}
, "launch":
@@ -156,6 +175,7 @@
, "setup"
, "utils"
, ["src/utils/cpp", "file_locking"]
+ , "setup_utils"
]
}
}
diff --git a/src/other_tools/just_mr/fetch.cpp b/src/other_tools/just_mr/fetch.cpp
index c6a4bc17..078586b2 100644
--- a/src/other_tools/just_mr/fetch.cpp
+++ b/src/other_tools/just_mr/fetch.cpp
@@ -23,6 +23,7 @@
#include "src/other_tools/just_mr/exit_codes.hpp"
#include "src/other_tools/just_mr/progress_reporting/progress.hpp"
#include "src/other_tools/just_mr/progress_reporting/progress_reporter.hpp"
+#include "src/other_tools/just_mr/setup_utils.hpp"
#include "src/other_tools/just_mr/utils.hpp"
#include "src/other_tools/ops_maps/content_cas_map.hpp"
#include "src/other_tools/ops_maps/repo_fetch_map.hpp"
diff --git a/src/other_tools/just_mr/launch.cpp b/src/other_tools/just_mr/launch.cpp
index 61953cda..bc70bb7f 100644
--- a/src/other_tools/just_mr/launch.cpp
+++ b/src/other_tools/just_mr/launch.cpp
@@ -25,7 +25,7 @@
#include "src/buildtool/storage/garbage_collector.hpp"
#include "src/other_tools/just_mr/exit_codes.hpp"
#include "src/other_tools/just_mr/setup.hpp"
-#include "src/other_tools/just_mr/utils.hpp"
+#include "src/other_tools/just_mr/setup_utils.hpp"
#include "src/utils/cpp/file_locking.hpp"
auto CallJust(std::optional<std::filesystem::path> const& config_file,
diff --git a/src/other_tools/just_mr/main.cpp b/src/other_tools/just_mr/main.cpp
index 1ef6d25c..e56c7064 100644
--- a/src/other_tools/just_mr/main.cpp
+++ b/src/other_tools/just_mr/main.cpp
@@ -35,6 +35,7 @@
#include "src/other_tools/just_mr/fetch.hpp"
#include "src/other_tools/just_mr/launch.hpp"
#include "src/other_tools/just_mr/setup.hpp"
+#include "src/other_tools/just_mr/setup_utils.hpp"
#include "src/other_tools/just_mr/update.hpp"
namespace {
diff --git a/src/other_tools/just_mr/setup.cpp b/src/other_tools/just_mr/setup.cpp
index 669e9e85..2532ce3e 100644
--- a/src/other_tools/just_mr/setup.cpp
+++ b/src/other_tools/just_mr/setup.cpp
@@ -23,6 +23,7 @@
#include "src/other_tools/just_mr/exit_codes.hpp"
#include "src/other_tools/just_mr/progress_reporting/progress.hpp"
#include "src/other_tools/just_mr/progress_reporting/progress_reporter.hpp"
+#include "src/other_tools/just_mr/setup_utils.hpp"
#include "src/other_tools/just_mr/utils.hpp"
#include "src/other_tools/ops_maps/critical_git_op_map.hpp"
#include "src/other_tools/repo_map/repos_to_setup_map.hpp"
diff --git a/src/other_tools/just_mr/setup_utils.cpp b/src/other_tools/just_mr/setup_utils.cpp
new file mode 100644
index 00000000..9aad1894
--- /dev/null
+++ b/src/other_tools/just_mr/setup_utils.cpp
@@ -0,0 +1,138 @@
+// 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.
+
+#include "src/other_tools/just_mr/setup_utils.hpp"
+
+#include <fstream>
+#include <unordered_set>
+
+#include "nlohmann/json.hpp"
+#include "src/buildtool/build_engine/expression/expression.hpp"
+#include "src/buildtool/file_system/file_system_manager.hpp"
+#include "src/buildtool/logging/logger.hpp"
+#include "src/other_tools/just_mr/exit_codes.hpp"
+
+namespace JustMR::Utils {
+
+void ReachableRepositories(
+ ExpressionPtr const& repos,
+ std::string const& main,
+ std::shared_ptr<JustMR::SetupRepos> const& setup_repos) {
+ // use temporary sets to avoid duplicates
+ std::unordered_set<std::string> include_repos_set{};
+ if (repos->IsMap()) {
+ // traversal of bindings
+ std::function<void(std::string const&)> traverse =
+ [&](std::string const& repo_name) {
+ if (not include_repos_set.contains(repo_name)) {
+ // if not found, add it and repeat for its bindings
+ include_repos_set.insert(repo_name);
+ // check bindings
+ auto repos_repo_name =
+ repos->Get(repo_name, Expression::none_t{});
+ if (not repos_repo_name.IsNotNull()) {
+ return;
+ }
+ auto bindings =
+ repos_repo_name->Get("bindings", Expression::none_t{});
+ if (bindings.IsNotNull() and bindings->IsMap()) {
+ for (auto const& bound : bindings->Map().Values()) {
+ if (bound.IsNotNull() and bound->IsString()) {
+ traverse(bound->String());
+ }
+ }
+ }
+ }
+ };
+ traverse(main); // traverse all bindings of main repository
+
+ // Add overlay repositories
+ std::unordered_set<std::string> setup_repos_set{include_repos_set};
+ for (auto const& repo : include_repos_set) {
+ auto repos_repo = repos->Get(repo, Expression::none_t{});
+ if (repos_repo.IsNotNull()) {
+ // copy over any present alternative root dirs
+ for (auto const& layer : kAltDirs) {
+ auto layer_val =
+ repos_repo->Get(layer, Expression::none_t{});
+ if (layer_val.IsNotNull() and layer_val->IsString()) {
+ auto repo_name = layer_val->String();
+ setup_repos_set.insert(repo_name);
+ }
+ }
+ }
+ }
+
+ // copy to vectors
+ setup_repos->to_setup.clear();
+ setup_repos->to_setup.reserve(setup_repos_set.size());
+ std::copy(
+ setup_repos_set.begin(),
+ setup_repos_set.end(),
+ std::inserter(setup_repos->to_setup, setup_repos->to_setup.end()));
+ setup_repos->to_include.clear();
+ setup_repos->to_include.reserve(include_repos_set.size());
+ std::copy(include_repos_set.begin(),
+ include_repos_set.end(),
+ std::inserter(setup_repos->to_include,
+ setup_repos->to_include.end()));
+ }
+}
+
+void DefaultReachableRepositories(
+ ExpressionPtr const& repos,
+ std::shared_ptr<JustMR::SetupRepos> const& setup_repos) {
+ if (repos.IsNotNull() and repos->IsMap()) {
+ setup_repos->to_setup = repos->Map().Keys();
+ setup_repos->to_include = setup_repos->to_setup;
+ }
+}
+
+auto ReadConfiguration(
+ std::optional<std::filesystem::path> const& config_file_opt) noexcept
+ -> std::shared_ptr<Configuration> {
+ if (not config_file_opt) {
+ Logger::Log(LogLevel::Error, "Cannot find repository configuration.");
+ std::exit(kExitConfigError);
+ }
+ auto const& config_file = *config_file_opt;
+
+ std::shared_ptr<Configuration> config{nullptr};
+ if (not FileSystemManager::IsFile(config_file)) {
+ Logger::Log(LogLevel::Error,
+ "Cannot read config file {}.",
+ config_file.string());
+ std::exit(kExitConfigError);
+ }
+ try {
+ std::ifstream fs(config_file);
+ auto map = Expression::FromJson(nlohmann::json::parse(fs));
+ if (not map->IsMap()) {
+ Logger::Log(LogLevel::Error,
+ "Config file {} does not contain a JSON object.",
+ config_file.string());
+ std::exit(kExitConfigError);
+ }
+ config = std::make_shared<Configuration>(map);
+ } catch (std::exception const& e) {
+ Logger::Log(LogLevel::Error,
+ "Parsing config file {} failed with error:\n{}",
+ config_file.string(),
+ e.what());
+ std::exit(kExitConfigError);
+ }
+ return config;
+}
+
+} // namespace JustMR::Utils
diff --git a/src/other_tools/just_mr/setup_utils.hpp b/src/other_tools/just_mr/setup_utils.hpp
new file mode 100644
index 00000000..a8c4236e
--- /dev/null
+++ b/src/other_tools/just_mr/setup_utils.hpp
@@ -0,0 +1,62 @@
+// 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_OTHER_TOOLS_JUST_MR_SETUP_UTILS_HPP
+#define INCLUDED_SRC_OTHER_TOOLS_JUST_MR_SETUP_UTILS_HPP
+
+#include <filesystem>
+#include <memory>
+#include <optional>
+#include <string>
+#include <vector>
+
+#include "src/buildtool/build_engine/expression/configuration.hpp"
+#include "src/buildtool/build_engine/expression/expression_ptr.hpp"
+
+/* Setup-related constants and utilities for just-mr */
+
+std::vector<std::string> const kAltDirs = {"target_root",
+ "rule_root",
+ "expression_root"};
+
+namespace JustMR {
+
+struct SetupRepos {
+ std::vector<std::string> to_setup;
+ std::vector<std::string> to_include;
+};
+
+namespace Utils {
+
+/// \brief Get the repo dependency closure for a given main repository.
+void ReachableRepositories(
+ ExpressionPtr const& repos,
+ std::string const& main,
+ std::shared_ptr<JustMR::SetupRepos> const& setup_repos);
+
+/// \brief By default, we set up and include the full repo dependency closure.
+void DefaultReachableRepositories(
+ ExpressionPtr const& repos,
+ std::shared_ptr<JustMR::SetupRepos> const& setup_repos);
+
+/// \brief Read in a just-mr configuration file.
+[[nodiscard]] auto ReadConfiguration(
+ std::optional<std::filesystem::path> const& config_file_opt) noexcept
+ -> std::shared_ptr<Configuration>;
+
+} // namespace Utils
+
+} // namespace JustMR
+
+#endif // INCLUDED_SRC_OTHER_TOOLS_JUST_MR_SETUP_UTILS_HPP
diff --git a/src/other_tools/just_mr/utils.cpp b/src/other_tools/just_mr/utils.cpp
index 6bce59a9..57ef6830 100644
--- a/src/other_tools/just_mr/utils.cpp
+++ b/src/other_tools/just_mr/utils.cpp
@@ -16,7 +16,6 @@
#include "src/buildtool/file_system/file_storage.hpp"
#include "src/buildtool/storage/storage.hpp"
-#include "src/other_tools/just_mr/exit_codes.hpp"
#include "src/utils/cpp/path.hpp"
namespace JustMR::Utils {
@@ -137,114 +136,4 @@ auto ResolveRepo(ExpressionPtr const& repo_desc,
}
}
-void ReachableRepositories(
- ExpressionPtr const& repos,
- std::string const& main,
- std::shared_ptr<JustMR::SetupRepos> const& setup_repos) {
- // use temporary sets to avoid duplicates
- std::unordered_set<std::string> include_repos_set{};
- if (repos->IsMap()) {
- // traversal of bindings
- std::function<void(std::string const&)> traverse =
- [&](std::string const& repo_name) {
- if (not include_repos_set.contains(repo_name)) {
- // if not found, add it and repeat for its bindings
- include_repos_set.insert(repo_name);
- // check bindings
- auto repos_repo_name =
- repos->Get(repo_name, Expression::none_t{});
- if (not repos_repo_name.IsNotNull()) {
- return;
- }
- auto bindings =
- repos_repo_name->Get("bindings", Expression::none_t{});
- if (bindings.IsNotNull() and bindings->IsMap()) {
- for (auto const& bound : bindings->Map().Values()) {
- if (bound.IsNotNull() and bound->IsString()) {
- traverse(bound->String());
- }
- }
- }
- }
- };
- traverse(main); // traverse all bindings of main repository
-
- // Add overlay repositories
- std::unordered_set<std::string> setup_repos_set{include_repos_set};
- for (auto const& repo : include_repos_set) {
- auto repos_repo = repos->Get(repo, Expression::none_t{});
- if (repos_repo.IsNotNull()) {
- // copy over any present alternative root dirs
- for (auto const& layer : kAltDirs) {
- auto layer_val =
- repos_repo->Get(layer, Expression::none_t{});
- if (layer_val.IsNotNull() and layer_val->IsString()) {
- auto repo_name = layer_val->String();
- setup_repos_set.insert(repo_name);
- }
- }
- }
- }
-
- // copy to vectors
- setup_repos->to_setup.clear();
- setup_repos->to_setup.reserve(setup_repos_set.size());
- std::copy(
- setup_repos_set.begin(),
- setup_repos_set.end(),
- std::inserter(setup_repos->to_setup, setup_repos->to_setup.end()));
- setup_repos->to_include.clear();
- setup_repos->to_include.reserve(include_repos_set.size());
- std::copy(include_repos_set.begin(),
- include_repos_set.end(),
- std::inserter(setup_repos->to_include,
- setup_repos->to_include.end()));
- }
-}
-
-void DefaultReachableRepositories(
- ExpressionPtr const& repos,
- std::shared_ptr<JustMR::SetupRepos> const& setup_repos) {
- if (repos.IsNotNull() and repos->IsMap()) {
- setup_repos->to_setup = repos->Map().Keys();
- setup_repos->to_include = setup_repos->to_setup;
- }
-}
-
-auto ReadConfiguration(
- std::optional<std::filesystem::path> const& config_file_opt) noexcept
- -> std::shared_ptr<Configuration> {
- if (not config_file_opt) {
- Logger::Log(LogLevel::Error, "Cannot find repository configuration.");
- std::exit(kExitConfigError);
- }
- auto const& config_file = *config_file_opt;
-
- std::shared_ptr<Configuration> config{nullptr};
- if (not FileSystemManager::IsFile(config_file)) {
- Logger::Log(LogLevel::Error,
- "Cannot read config file {}.",
- config_file.string());
- std::exit(kExitConfigError);
- }
- try {
- std::ifstream fs(config_file);
- auto map = Expression::FromJson(nlohmann::json::parse(fs));
- if (not map->IsMap()) {
- Logger::Log(LogLevel::Error,
- "Config file {} does not contain a JSON object.",
- config_file.string());
- std::exit(kExitConfigError);
- }
- config = std::make_shared<Configuration>(map);
- } catch (std::exception const& e) {
- Logger::Log(LogLevel::Error,
- "Parsing config file {} failed with error:\n{}",
- config_file.string(),
- e.what());
- std::exit(kExitConfigError);
- }
- return config;
-}
-
} // namespace JustMR::Utils
diff --git a/src/other_tools/just_mr/utils.hpp b/src/other_tools/just_mr/utils.hpp
index 9ee3d656..65e6eda5 100644
--- a/src/other_tools/just_mr/utils.hpp
+++ b/src/other_tools/just_mr/utils.hpp
@@ -36,10 +36,6 @@ auto const kDefaultCheckoutLocationsFile =
StorageConfig::GetUserHome() / ".just-local.json";
auto const kDefaultDistdirs = StorageConfig::GetUserHome() / ".distfiles";
-std::vector<std::string> const kAltDirs = {"target_root",
- "rule_root",
- "expression_root"};
-
std::vector<std::string> const kTakeOver = {"bindings",
"target_file_name",
"rule_file_name",
@@ -202,11 +198,6 @@ struct CAInfo {
using PathsPtr = std::shared_ptr<JustMR::Paths>;
using CAInfoPtr = std::shared_ptr<JustMR::CAInfo>;
-struct SetupRepos {
- std::vector<std::string> to_setup;
- std::vector<std::string> to_include;
-};
-
namespace Utils {
/// \brief Get location of Git repository. Defaults to the Git cache root when
@@ -264,22 +255,6 @@ auto ResolveRepo(ExpressionPtr const& repo_desc,
ExpressionPtr const& repos) noexcept
-> std::optional<ExpressionPtr>;
-/// \brief Get the repo dependency closure for a given main repository.
-void ReachableRepositories(
- ExpressionPtr const& repos,
- std::string const& main,
- std::shared_ptr<JustMR::SetupRepos> const& setup_repos);
-
-/// \brief By default, we set up and include the full repo dependency closure.
-void DefaultReachableRepositories(
- ExpressionPtr const& repos,
- std::shared_ptr<JustMR::SetupRepos> const& setup_repos);
-
-/// \brief Read in a just-mr configuration file.
-[[nodiscard]] auto ReadConfiguration(
- std::optional<std::filesystem::path> const& config_file_opt) noexcept
- -> std::shared_ptr<Configuration>;
-
} // namespace Utils
} // namespace JustMR