This repository has been archived by the owner on Sep 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bazelwrapper.py
executable file
·67 lines (48 loc) · 1.85 KB
/
bazelwrapper.py
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
import os
import platform
import subprocess
import sys
import remotecache
custom_bazel_env = {
# here we can take control over the PATH or set env variables for other tools and bazel rules.
# these are currently laid over the global shell env.
# NOTE! bazelisk 'USE_BAZEL_VERSION' cannot be used in a wrapper script, because when that script executes, bazelisk
# has already determined the version and we do not want to make recursive calls, or implement bazelisk logic
# ourselves.
}
def extract_user_args():
args = []
sys.argv.pop(0) # remove the wrapper script argument
for arg in sys.argv:
args.append(arg)
return args
def bazel_env():
return {**os.environ, **custom_bazel_env}
def _resolve_workspace_dir():
current_dir = os.getcwd()
ws_dir = current_dir
while ws_dir != "/":
if os.path.exists(os.path.join(ws_dir, "WORKSPACE")):
return ws_dir
else:
ws_dir = os.path.abspath(os.path.join(ws_dir, os.pardir))
return ws_dir
def build_bazel_command():
user_args = extract_user_args()
bazel_command = [
os.environ["BAZEL_REAL"] # this is set by the calling bazel command
]
if "info" not in user_args and "version" not in user_args:
target_list_found = False
for user_arg in user_args:
if user_arg == "--": # target list must come last
target_list_found = True
bazel_command = bazel_command + remotecache.remote_cache_flags_for(platform.system())
bazel_command.append(user_arg)
if not target_list_found:
bazel_command = bazel_command + remotecache.remote_cache_flags_for(platform.system())
else:
bazel_command = bazel_command + user_args
return bazel_command
def main():
subprocess.call(args=build_bazel_command(), env=bazel_env())