-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbazel_fast_metadata.cc
More file actions
64 lines (56 loc) · 1.91 KB
/
bazel_fast_metadata.cc
File metadata and controls
64 lines (56 loc) · 1.91 KB
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
#include <string>
#include <filesystem>
#include <iostream>
#include <optional>
using std::filesystem::path;
std::optional<path> find_root(path curpath) {
while (true) {
if (std::filesystem::exists(curpath / "WORKSPACE")) {
return curpath;
}
if (curpath == curpath.parent_path()) {
return std::nullopt;
}
curpath = curpath.parent_path();
}
return curpath;
}
int main(int argc, char** argv) {
std::string directory;
if (argc > 2) {
directory = argv[1];
} else {
directory = ".";
}
path curpath = std::filesystem::absolute(directory);
std::optional<path> maybe_root = find_root(curpath);
if (!maybe_root) {
return 1;
}
path root = std::move(*maybe_root);
path subdir;
if (curpath != root) {
subdir = curpath.lexically_relative(root);
}
if (subdir.filename() == ".") {
std::cout << "truncating subdir" << std::endl;
subdir = subdir.parent_path();
}
if (root.filename() == ".") {
std::cout << "truncating root" << std::endl;
root = root.parent_path();
}
path bazel_bin = root / "bazel-bin" / subdir;
path bazel_testlogs = root / "bazel-testlogs" / subdir;
std::string bazel_repo_dir = root.filename().string();
path bazel_workdir = root / ("bazel-" + bazel_repo_dir);
path bazel_external = bazel_workdir / "external";
std::cout << "BAZEL_SUBDIR=" << (subdir / "") << std::endl;
std::cout << "BAZEL_ROOT=" << (root / "") << std::endl;
std::cout << "BAZEL_BIN=" << (bazel_bin / "") << std::endl;
std::cout << "BAZEL_TESTLOGS=" << (bazel_testlogs / "") << std::endl;
std::cout << "BAZEL_WORKDIR=" << (bazel_workdir / "") << std::endl;
std::cout << "BAZEL_EXTERNAL=" << (bazel_external / "") << std::endl;
std::cout << "BAZEL_REPO_DIR=" << bazel_repo_dir << std::endl;
return 0;
}