summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/buildtool/main/TARGETS18
-rw-r--r--src/buildtool/main/build_utils.cpp85
-rw-r--r--src/buildtool/main/build_utils.hpp51
-rw-r--r--src/buildtool/main/main.cpp70
4 files changed, 155 insertions, 69 deletions
diff --git a/src/buildtool/main/TARGETS b/src/buildtool/main/TARGETS
index d1c5ba08..a9ea78f4 100644
--- a/src/buildtool/main/TARGETS
+++ b/src/buildtool/main/TARGETS
@@ -34,6 +34,7 @@
, "diagnose"
, "constants"
, "serve"
+ , "build_utils"
]
, "stage": ["src", "buildtool", "main"]
, "private-ldflags":
@@ -201,4 +202,21 @@
, "common"
]
}
+, "build_utils":
+ { "type": ["@", "rules", "CC", "library"]
+ , "name": ["build_utils"]
+ , "hdrs": ["build_utils.hpp"]
+ , "srcs": ["build_utils.cpp"]
+ , "deps":
+ [ ["@", "gsl", "", "gsl"]
+ , ["src/buildtool/build_engine/analysed_target", "target"]
+ , ["src/buildtool/common", "artifact_description"]
+ , ["src/buildtool/common", "common"]
+ , ["src/buildtool/common", "config"]
+ , ["src/buildtool/execution_api/common", "common"]
+ , ["src/buildtool/storage", "storage"]
+ ]
+ , "stage": ["src", "buildtool", "main"]
+ , "private-deps": [["src/buildtool/logging", "logging"]]
+ }
}
diff --git a/src/buildtool/main/build_utils.cpp b/src/buildtool/main/build_utils.cpp
new file mode 100644
index 00000000..e15e5296
--- /dev/null
+++ b/src/buildtool/main/build_utils.cpp
@@ -0,0 +1,85 @@
+// 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/buildtool/main/build_utils.hpp"
+#ifndef BOOTSTRAP_BUILD_TOOL
+#include "src/buildtool/logging/logger.hpp"
+#include "src/buildtool/storage/storage.hpp"
+#include "src/buildtool/storage/target_cache_entry.hpp"
+#endif // BOOTSTRAP_BUILD_TOOL
+
+auto ReadOutputArtifacts(AnalysedTargetPtr const& target)
+ -> std::pair<std::map<std::string, ArtifactDescription>,
+ std::map<std::string, ArtifactDescription>> {
+ std::map<std::string, ArtifactDescription> artifacts{};
+ std::map<std::string, ArtifactDescription> runfiles{};
+ for (auto const& [path, artifact] : target->Artifacts()->Map()) {
+ artifacts.emplace(path, artifact->Artifact());
+ }
+ for (auto const& [path, artifact] : target->RunFiles()->Map()) {
+ if (not artifacts.contains(path)) {
+ runfiles.emplace(path, artifact->Artifact());
+ }
+ }
+ return {artifacts, runfiles};
+}
+
+auto CollectNonKnownArtifacts(
+ std::unordered_map<TargetCacheKey, AnalysedTargetPtr> const& cache_targets)
+ -> std::vector<ArtifactDescription> {
+ auto cache_artifacts = std::unordered_set<ArtifactDescription>{};
+ for (auto const& [_, target] : cache_targets) {
+ auto artifacts = target->ContainedNonKnownArtifacts();
+ cache_artifacts.insert(std::make_move_iterator(artifacts.begin()),
+ std::make_move_iterator(artifacts.end()));
+ }
+ return {std::make_move_iterator(cache_artifacts.begin()),
+ std::make_move_iterator(cache_artifacts.end())};
+}
+
+#ifndef BOOTSTRAP_BUILD_TOOL
+void WriteTargetCacheEntries(
+ std::unordered_map<TargetCacheKey, AnalysedTargetPtr> const& cache_targets,
+ std::unordered_map<ArtifactDescription, Artifact::ObjectInfo> const&
+ extra_infos,
+ std::size_t jobs,
+ gsl::not_null<IExecutionApi*> const& local_api,
+ gsl::not_null<IExecutionApi*> const& remote_api) {
+ if (!cache_targets.empty()) {
+ Logger::Log(LogLevel::Info,
+ "Backing up artifacts of {} export targets",
+ cache_targets.size());
+ }
+ auto downloader = [&local_api, &remote_api, &jobs](auto infos) {
+ return remote_api->ParallelRetrieveToCas(infos, local_api, jobs, false);
+ };
+ for (auto const& [key, target] : cache_targets) {
+ if (auto entry = TargetCacheEntry::FromTarget(target, extra_infos)) {
+ if (not Storage::Instance().TargetCache().Store(
+ key, *entry, downloader)) {
+ Logger::Log(LogLevel::Warning,
+ "Failed writing target cache entry for {}",
+ key.Id().ToString());
+ }
+ }
+ else {
+ Logger::Log(LogLevel::Warning,
+ "Failed creating target cache entry for {}",
+ key.Id().ToString());
+ }
+ }
+ Logger::Log(LogLevel::Debug,
+ "Finished backing up artifacts of export targets");
+}
+#endif // BOOTSTRAP_BUILD_TOOL
diff --git a/src/buildtool/main/build_utils.hpp b/src/buildtool/main/build_utils.hpp
new file mode 100644
index 00000000..2db29839
--- /dev/null
+++ b/src/buildtool/main/build_utils.hpp
@@ -0,0 +1,51 @@
+// 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_BUILDOOL_MAIN_BUILD_UTILS_HPP
+#define INCLUDED_SRC_BUILDOOL_MAIN_BUILD_UTILS_HPP
+
+#include <map>
+#include <unordered_map>
+
+#include "src/buildtool/build_engine/analysed_target/analysed_target.hpp"
+#include "src/buildtool/common/artifact_description.hpp"
+#include "src/buildtool/common/repository_config.hpp"
+#include "src/buildtool/storage/target_cache_key.hpp"
+#ifndef BOOTSTRAP_BUILD_TOOL
+#include "gsl/gsl"
+#include "src/buildtool/common/artifact.hpp"
+#include "src/buildtool/execution_api/common/execution_api.hpp"
+#endif // BOOTSTRAP_BUILD_TOOL
+
+// Return disjoint maps for artifacts and runfiles
+[[nodiscard]] auto ReadOutputArtifacts(AnalysedTargetPtr const& target)
+ -> std::pair<std::map<std::string, ArtifactDescription>,
+ std::map<std::string, ArtifactDescription>>;
+
+// Collect non-known artifacts
+[[nodiscard]] auto CollectNonKnownArtifacts(
+ std::unordered_map<TargetCacheKey, AnalysedTargetPtr> const& cache_targets)
+ -> std::vector<ArtifactDescription>;
+
+#ifndef BOOTSTRAP_BUILD_TOOL
+void WriteTargetCacheEntries(
+ std::unordered_map<TargetCacheKey, AnalysedTargetPtr> const& cache_targets,
+ std::unordered_map<ArtifactDescription, Artifact::ObjectInfo> const&
+ extra_infos,
+ std::size_t jobs,
+ gsl::not_null<IExecutionApi*> const& local_api,
+ gsl::not_null<IExecutionApi*> const& remote_api);
+#endif // BOOTSTRAP_BUILD_TOOL
+
+#endif // INCLUDED_SRC_BUILDOOL_MAIN_BUILD_UTILS_HPP
diff --git a/src/buildtool/main/main.cpp b/src/buildtool/main/main.cpp
index 3503129d..6fd8dded 100644
--- a/src/buildtool/main/main.cpp
+++ b/src/buildtool/main/main.cpp
@@ -40,8 +40,6 @@
#include "src/buildtool/storage/config.hpp"
#include "src/buildtool/storage/garbage_collector.hpp"
#include "src/buildtool/storage/target_cache.hpp"
-#include "src/buildtool/storage/target_cache_entry.hpp"
-#include "src/buildtool/storage/target_cache_key.hpp"
#ifndef BOOTSTRAP_BUILD_TOOL
#include "src/buildtool/auth/authentication.hpp"
#include "src/buildtool/execution_api/execution_service/operation_cache.hpp"
@@ -57,6 +55,7 @@
#include "src/buildtool/logging/log_config.hpp"
#include "src/buildtool/logging/log_sink_cmdline.hpp"
#include "src/buildtool/logging/log_sink_file.hpp"
+#include "src/buildtool/main/build_utils.hpp"
#include "src/buildtool/main/version.hpp"
#include "src/buildtool/multithreading/async_map_consumer.hpp"
#include "src/buildtool/multithreading/task_system.hpp"
@@ -717,23 +716,6 @@ auto DetermineRoots(gsl::not_null<RepositoryConfig*> const& repository_config,
return {main_repo, main_ws_root};
}
-// Return disjoint maps for artifacts and runfiles
-[[nodiscard]] auto ReadOutputArtifacts(AnalysedTargetPtr const& target)
- -> std::pair<std::map<std::string, ArtifactDescription>,
- std::map<std::string, ArtifactDescription>> {
- std::map<std::string, ArtifactDescription> artifacts{};
- std::map<std::string, ArtifactDescription> runfiles{};
- for (auto const& [path, artifact] : target->Artifacts()->Map()) {
- artifacts.emplace(path, artifact->Artifact());
- }
- for (auto const& [path, artifact] : target->RunFiles()->Map()) {
- if (not artifacts.contains(path)) {
- runfiles.emplace(path, artifact->Artifact());
- }
- }
- return {artifacts, runfiles};
-}
-
void ReportTaintedness(const AnalysisResult& result) {
if (result.target->Tainted().empty()) {
// Never report untainted targets
@@ -791,56 +773,6 @@ void DumpArtifactsToBuild(
os << dump_string << std::endl;
}
-auto CollectNonKnownArtifacts(
- std::unordered_map<TargetCacheKey, AnalysedTargetPtr> const& cache_targets)
- -> std::vector<ArtifactDescription> {
- auto cache_artifacts = std::unordered_set<ArtifactDescription>{};
- for (auto const& [_, target] : cache_targets) {
- auto artifacts = target->ContainedNonKnownArtifacts();
- cache_artifacts.insert(std::make_move_iterator(artifacts.begin()),
- std::make_move_iterator(artifacts.end()));
- }
- return {std::make_move_iterator(cache_artifacts.begin()),
- std::make_move_iterator(cache_artifacts.end())};
-}
-
-#ifndef BOOTSTRAP_BUILD_TOOL
-void WriteTargetCacheEntries(
- std::unordered_map<TargetCacheKey, AnalysedTargetPtr> const& cache_targets,
- std::unordered_map<ArtifactDescription, Artifact::ObjectInfo> const&
- extra_infos,
- std::size_t jobs,
- gsl::not_null<IExecutionApi*> const& local_api,
- gsl::not_null<IExecutionApi*> const& remote_api) {
- if (!cache_targets.empty()) {
- Logger::Log(LogLevel::Info,
- "Backing up artifacts of {} export targets",
- cache_targets.size());
- }
- auto downloader = [&local_api, &remote_api, &jobs](auto infos) {
- return remote_api->ParallelRetrieveToCas(infos, local_api, jobs, false);
- };
- for (auto const& [key, target] : cache_targets) {
- if (auto entry = TargetCacheEntry::FromTarget(target, extra_infos)) {
- if (not Storage::Instance().TargetCache().Store(
- key, *entry, downloader)) {
- Logger::Log(LogLevel::Warning,
- "Failed writing target cache entry for {}",
- key.Id().ToString());
- }
- }
- else {
- Logger::Log(LogLevel::Warning,
- "Failed creating target cache entry for {}",
- key.Id().ToString());
- }
- }
- Logger::Log(LogLevel::Debug,
- "Finished backing up artifacts of export targets");
-}
-
-#endif // BOOTSTRAP_BUILD_TOOL
-
} // namespace
auto main(int argc, char* argv[]) -> int {