forked from mlcommons/ck
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustomize.py
60 lines (44 loc) · 1.9 KB
/
customize.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
from cmind import utils
import os
def preprocess(i):
os_info = i['os_info']
env = i['env']
recursion_spaces = i['recursion_spaces']
file_name = 'bazel.exe' if os_info['platform'] == 'windows' else 'bazel'
env['FILE_NAME'] = file_name
if 'CM_BAZEL_BIN_WITH_PATH' not in env:
r = i['automation'].find_artifact({'file_name': file_name,
'env': env,
'os_info':os_info,
'default_path_env_key': 'PATH',
'detect_version':True,
'env_path_key':'CM_BAZEL_BIN_WITH_PATH',
'run_script_input':i['run_script_input'],
'recursion_spaces':recursion_spaces})
if r['return'] >0 :
if r['return'] == 16:
env['CM_REQUIRE_INSTALL'] = "yes"
return {'return': 0}
else:
return r
return {'return':0}
def detect_version(i):
r = i['automation'].parse_version({'match_text': r'bazel\s*([\d.]+)',
'group_number': 1,
'env_key':'CM_BAZEL_VERSION',
'which_env':i['env']})
if r['return'] >0: return r
version = r['version']
print (i['recursion_spaces'] + ' Detected version: {}'.format(version))
return {'return':0, 'version':version}
def postprocess(i):
env = i['env']
r = detect_version(i)
if r['return'] >0: return r
version = r['version']
found_file_path = env['CM_BAZEL_BIN_WITH_PATH']
found_path = os.path.dirname(found_file_path)
env['CM_BAZEL_INSTALLED_PATH'] = found_path
env['+PATH'] = [ found_path ]
env['CM_BAZEL_CACHE_TAGS'] = 'version-'+version
return {'return':0, 'version': version}