diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/buildtool/computed_roots/TARGETS | 21 | ||||
-rw-r--r-- | src/buildtool/computed_roots/analyse_and_build.cpp | 72 | ||||
-rw-r--r-- | src/buildtool/computed_roots/analyse_and_build.hpp | 40 |
3 files changed, 133 insertions, 0 deletions
diff --git a/src/buildtool/computed_roots/TARGETS b/src/buildtool/computed_roots/TARGETS new file mode 100644 index 00000000..0a51dc9a --- /dev/null +++ b/src/buildtool/computed_roots/TARGETS @@ -0,0 +1,21 @@ +{ "analyse_and_build": + { "type": ["@", "rules", "CC", "library"] + , "name": ["analyse_and_build"] + , "hdrs": ["analyse_and_build.hpp"] + , "srcs": ["analyse_and_build.cpp"] + , "deps": + [ ["@", "gsl", "", "gsl"] + , ["src/buildtool/build_engine/target_map", "configured_target"] + , ["src/buildtool/graph_traverser", "graph_traverser"] + , ["src/buildtool/logging", "logging"] + , ["src/buildtool/main", "analyse"] + , ["src/buildtool/main", "analyse_context"] + ] + , "stage": ["src", "buildtool", "computed_roots"] + , "private-deps": + [ ["src/buildtool/build_engine/target_map", "result_map"] + , ["src/buildtool/logging", "log_level"] + , ["src/buildtool/main", "build_utils"] + ] + } +} diff --git a/src/buildtool/computed_roots/analyse_and_build.cpp b/src/buildtool/computed_roots/analyse_and_build.cpp new file mode 100644 index 00000000..6fc4e24e --- /dev/null +++ b/src/buildtool/computed_roots/analyse_and_build.cpp @@ -0,0 +1,72 @@ +// Copyright 2024 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/computed_roots/analyse_and_build.hpp" + +#include <functional> +#include <utility> + +#include "src/buildtool/build_engine/target_map/result_map.hpp" +#include "src/buildtool/logging/log_level.hpp" +#include "src/buildtool/main/build_utils.hpp" + +[[nodiscard]] auto AnalyseAndBuild( + gsl::not_null<AnalyseContext*> const& analyse_context, + GraphTraverser const& traverser, + BuildMaps::Target::ConfiguredTarget const& id, + std::size_t jobs, + Logger const* logger) -> std::optional<AnalyseAndBuildResult> { + auto analysis_result = AnalyseTarget(analyse_context, + id, + jobs, + /*request_action_input*/ std::nullopt, + logger); + + if (not analysis_result) { + if (logger != nullptr) { + logger->Emit(LogLevel::Warning, + "Failed to analyse target {}", + id.ToString()); + } + return std::nullopt; + } + if (logger != nullptr) { + logger->Emit(LogLevel::Info, "Analysed target {}", id.ToString()); + } + + auto const [artifacts, runfiles] = + ReadOutputArtifacts(analysis_result->target); + + auto const [actions, blobs, trees] = analysis_result->result_map.ToResult( + analyse_context->statistics, analyse_context->progress); + + auto const cache_targets = analysis_result->result_map.CacheTargets(); + auto build_result = + traverser.BuildAndStage(artifacts, + runfiles, + actions, + blobs, + trees, + CollectNonKnownArtifacts(cache_targets)); + + if (not build_result) { + if (logger != nullptr) { + logger->Emit( + LogLevel::Warning, "Build for target {} failed", id.ToString()); + } + return std::nullopt; + } + return AnalyseAndBuildResult{.analysis_result = *std::move(analysis_result), + .build_result = *std::move(build_result)}; +} diff --git a/src/buildtool/computed_roots/analyse_and_build.hpp b/src/buildtool/computed_roots/analyse_and_build.hpp new file mode 100644 index 00000000..61d4b495 --- /dev/null +++ b/src/buildtool/computed_roots/analyse_and_build.hpp @@ -0,0 +1,40 @@ +// Copyright 2024 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_COMPUTED_ROOTS_ANALYSE_AND_BUILD_HPP +#define INCLUDED_SRC_BUILDOOL_COMPUTED_ROOTS_ANALYSE_AND_BUILD_HPP + +#include <cstddef> +#include <optional> + +#include "gsl/gsl" +#include "src/buildtool/build_engine/target_map/configured_target.hpp" +#include "src/buildtool/graph_traverser/graph_traverser.hpp" +#include "src/buildtool/logging/logger.hpp" +#include "src/buildtool/main/analyse.hpp" +#include "src/buildtool/main/analyse_context.hpp" + +struct AnalyseAndBuildResult { + AnalysisResult analysis_result; + GraphTraverser::BuildResult build_result; +}; + +[[nodiscard]] auto AnalyseAndBuild( + gsl::not_null<AnalyseContext*> const& analyse_context, + GraphTraverser const& traverser, + BuildMaps::Target::ConfiguredTarget const& id, + std::size_t jobs, + Logger const* logger = nullptr) -> std::optional<AnalyseAndBuildResult>; + +#endif // INCLUDED_SRC_BUILDOOL_COMPUTED_ROOTS_ANALYSE_AND_BUILD_HPP |