summaryrefslogtreecommitdiff
path: root/src/other_tools/just_mr/setup_utils.hpp
blob: 7dc482e657b2f96ab6ec0bd3c51ac69fc950fb37 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// 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 <functional>
#include <memory>
#include <optional>
#include <string>
#include <unordered_set>
#include <vector>

#include "src/buildtool/auth/authentication.hpp"
#include "src/buildtool/build_engine/expression/configuration.hpp"
#include "src/buildtool/build_engine/expression/expression_ptr.hpp"
#include "src/buildtool/execution_api/local/config.hpp"
#include "src/buildtool/execution_api/remote/config.hpp"
#include "src/buildtool/serve_api/remote/config.hpp"
#include "src/other_tools/just_mr/cli.hpp"

/* Setup-related constants and utilities for just-mr */

std::vector<std::string> const kAltDirs = {"target_root",
                                           "rule_root",
                                           "expression_root"};

auto const kRepositoryExpectedFields =
    std::unordered_set<std::string>{"bindings",
                                    "expression_file_name",
                                    "expression_root",
                                    "repository",
                                    "rule_file_name",
                                    "rule_root",
                                    "target_file_name",
                                    "target_root"};

// Substrings in repository field names that indicate commonly-used
// additional keys not used by just-mr but deliberately added by the
// author of the repository configuration.
auto const kRepositoryPossibleFieldTrunks =
    std::vector<std::string>{"bootstrap", "doc", "extra"};

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.
/// If main repository is absent, emits a warning for any reachable
/// non-content-fixed repository found.
/// \param repos ExpressionPtr of Map type.
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.
/// \param repos ExpressionPtr of Map type.
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,
    std::optional<std::filesystem::path> const& absent_file_opt)
    -> std::shared_ptr<Configuration>;

[[nodiscard]] auto CreateAuthConfig(
    MultiRepoRemoteAuthArguments const& authargs) noexcept
    -> std::optional<Auth>;

[[nodiscard]] auto CreateLocalExecutionConfig(
    MultiRepoCommonArguments const& cargs) noexcept
    -> std::optional<LocalExecutionConfig>;

[[nodiscard]] auto CreateRemoteExecutionConfig(
    std::optional<std::string> const& remote_exec_addr,
    std::optional<std::string> const& remote_serve_addr) noexcept
    -> std::optional<RemoteExecutionConfig>;

/// \brief Setup of a 'just serve' remote API based on just-mr arguments.
/// \returns RemoteServeConfig if initialization was successful or std::nullopt
/// if failed.
[[nodiscard]] auto CreateServeConfig(
    std::optional<std::string> const& remote_serve_addr) noexcept
    -> std::optional<RemoteServeConfig>;

}  // namespace Utils

}  // namespace JustMR

#endif  // INCLUDED_SRC_OTHER_TOOLS_JUST_MR_SETUP_UTILS_HPP