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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
|
// Copyright 2022 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_UTILS_HPP
#define INCLUDED_SRC_OTHER_TOOLS_JUST_MR_UTILS_HPP
#include <cstdint>
#include <filesystem>
#include <functional>
#include <map>
#include <optional>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include "gsl/gsl"
#include "nlohmann/json.hpp"
#include "src/buildtool/build_engine/expression/expression_ptr.hpp"
#include "src/buildtool/file_system/file_system_manager.hpp"
#include "src/buildtool/storage/config.hpp"
/* Paths and constants required by just-mr */
auto const kDefaultJustPath = "just";
auto const kDefaultGitPath = "git";
auto const kDefaultRCPath = FileSystemManager::GetUserHome() / ".just-mrrc";
auto const kDefaultBuildRoot = StorageConfig::kDefaultBuildRoot;
auto const kDefaultCheckoutLocationsFile =
FileSystemManager::GetUserHome() / ".just-local.json";
auto const kDefaultDistdirs = FileSystemManager::GetUserHome() / ".distfiles";
std::vector<std::string> const kTakeOver = {"bindings",
"target_file_name",
"rule_file_name",
"expression_file_name"};
struct JustSubCmdFlags {
bool config; // requires setup
bool build_root; // supports the local build root arg
bool launch; // supports the local launcher arg
bool defines; // supports defines arg
bool remote; // supports remote exec args, including client-side auth
bool remote_props; // supports remote-execution properties
bool serve; // supports a serve endpoint
bool dispatch; // supports dispatching of the remote-execution endpoint
bool does_build; // is actually building something, i.e., supports options
// related to the build result
};
// ordered, so that we have replicability
std::map<std::string, JustSubCmdFlags> const kKnownJustSubcommands{
{"version",
{.config = false,
.build_root = false,
.launch = false,
.defines = false,
.remote = false,
.remote_props = false,
.serve = false,
.dispatch = false,
.does_build = false}},
{"describe",
{.config = true,
.build_root = true,
.launch = false,
.defines = true,
.remote = true,
.remote_props = false,
.serve = true,
.dispatch = false,
.does_build = false}},
{"analyse",
{.config = true,
.build_root = true,
.launch = true,
.defines = true,
.remote = true,
.remote_props = true,
.serve = true,
.dispatch = true,
.does_build = false}},
{"build",
{.config = true,
.build_root = true,
.launch = true,
.defines = true,
.remote = true,
.remote_props = true,
.serve = true,
.dispatch = true,
.does_build = true}},
{"install",
{.config = true,
.build_root = true,
.launch = true,
.defines = true,
.remote = true,
.remote_props = true,
.serve = true,
.dispatch = true,
.does_build = true}},
{"rebuild",
{.config = true,
.build_root = true,
.launch = true,
.defines = true,
.remote = true,
.remote_props = true,
.serve = true,
.dispatch = true,
.does_build = true}},
{"add-to-cas",
{.config = false,
.build_root = true,
.launch = false,
.defines = false,
.remote = true,
.remote_props = false,
.serve = false,
.dispatch = false,
.does_build = false}},
{"install-cas",
{.config = false,
.build_root = true,
.launch = false,
.defines = false,
.remote = true,
.remote_props = false,
.serve = false,
.dispatch = false,
.does_build = false}},
{"gc",
{.config = false,
.build_root = true,
.launch = false,
.defines = false,
.remote = false,
.remote_props = false,
.serve = false,
.dispatch = false,
.does_build = false}}};
nlohmann::json const kDefaultConfigLocations = nlohmann::json::array(
{{{"root", "workspace"}, {"path", "repos.json"}},
{{"root", "workspace"}, {"path", "etc/repos.json"}},
{{"root", "home"}, {"path", ".just-repos.json"}},
{{"root", "system"}, {"path", "etc/just-repos.json"}}});
/// \brief Checkout type enum
enum class CheckoutType : std::uint8_t {
Git,
Archive,
ForeignFile,
File,
Distdir,
GitTree,
Precomputed
};
/// \brief Checkout type map
std::unordered_map<std::string, CheckoutType> const kCheckoutTypeMap = {
{"git", CheckoutType::Git},
{"archive", CheckoutType::Archive},
{"zip", CheckoutType::Archive}, // treated the same as "archive"
{"foreign file", CheckoutType::ForeignFile},
{"file", CheckoutType::File},
{"distdir", CheckoutType::Distdir},
{"git tree", CheckoutType::GitTree},
{"computed", CheckoutType::Precomputed},
{"tree structure", CheckoutType::Precomputed}};
namespace JustMR::Utils {
/// \brief Recursive part of the ResolveRepo function.
/// Keeps track of repository names to detect any cyclic dependencies.
/// \param repos ExpressionPtr of Map type.
[[nodiscard]] auto ResolveRepo(
ExpressionPtr const& repo_desc,
ExpressionPtr const& repos,
gsl::not_null<std::unordered_set<std::string>*> const& seen)
-> std::optional<ExpressionPtr>;
/// \brief Resolves any cyclic dependency issues and follows the repository
/// dependencies until the one containing the workspace root is found.
/// Returns a repository entry as an ExpressionPtr, or nullopt if cyclic
/// dependency found.
/// \param repos ExpressionPtr of Map type.
[[nodiscard]] auto ResolveRepo(ExpressionPtr const& repo_desc,
ExpressionPtr const& repos) noexcept
-> std::optional<ExpressionPtr>;
} // namespace JustMR::Utils
#endif // INCLUDED_SRC_OTHER_TOOLS_JUST_MR_UTILS_HPP
|