6""" Utilities for dealing with builder names. This module obtains its attributes
7dynamically from builder_name_schema.json. """
17BUILDER_NAME_SCHEMA =
None
20BUILDER_NAME_SEP =
None
23BUILDER_ROLE_BAZELBUILD =
'BazelBuild'
24BUILDER_ROLE_BAZELTEST =
'BazelTest'
25BUILDER_ROLE_BUILD =
'Build'
26BUILDER_ROLE_BUILDSTATS =
'BuildStats'
27BUILDER_ROLE_CANARY =
'Canary'
28BUILDER_ROLE_CODESIZE =
'CodeSize'
29BUILDER_ROLE_HOUSEKEEPER =
'Housekeeper'
30BUILDER_ROLE_INFRA =
'Infra'
31BUILDER_ROLE_PERF =
'Perf'
32BUILDER_ROLE_TEST =
'Test'
33BUILDER_ROLE_UPLOAD =
'Upload'
34BUILDER_ROLES = (BUILDER_ROLE_BAZELBUILD,
35 BUILDER_ROLE_BAZELTEST,
37 BUILDER_ROLE_BUILDSTATS,
39 BUILDER_ROLE_CODESIZE,
40 BUILDER_ROLE_HOUSEKEEPER,
48 """ Load the builder naming schema from the JSON file. """
51 """ Convert all unicode strings in obj to Python strings. """
52 if isinstance(obj, str):
54 elif isinstance(obj, dict):
55 return dict(
map(ToStr, obj.items()))
56 elif isinstance(obj, list):
57 return list(
map(ToStr, obj))
58 elif isinstance(obj, tuple):
59 return tuple(
map(ToStr, obj))
61 return obj.decode(
'utf-8')
63 builder_name_json_filename = os.path.join(
64 os.path.dirname(__file__),
'builder_name_schema.json')
65 builder_name_schema_json = json.load(open(builder_name_json_filename))
67 global BUILDER_NAME_SCHEMA
68 BUILDER_NAME_SCHEMA = ToStr(
69 builder_name_schema_json[
'builder_name_schema'])
71 global BUILDER_NAME_SEP
72 BUILDER_NAME_SEP = ToStr(
73 builder_name_schema_json[
'builder_name_sep'])
77 assert len(BUILDER_ROLES) ==
len(BUILDER_NAME_SCHEMA)
78 for role
in BUILDER_ROLES:
79 assert role
in BUILDER_NAME_SCHEMA
86 for v
in parts.values():
87 if BUILDER_NAME_SEP
in v:
88 raise ValueError(
'Parts cannot contain "%s"' % BUILDER_NAME_SEP)
95 role_key =
'sub-role-%d' % depth
96 role = parts.get(role_key)
98 raise ValueError(
'Invalid parts; missing key %s' % role_key)
99 s = BUILDER_NAME_SCHEMA.get(role)
101 raise ValueError(
'Invalid parts; unknown role %s' % role)
102 rv_parts.append(role)
105 for key
in s.get(
'keys', []):
106 value = parts.get(key)
108 raise ValueError(
'Invalid parts; missing %s' % key)
109 rv_parts.append(value)
112 recurse_roles = s.get(
'recurse_roles', [])
113 if len(recurse_roles) > 0:
114 sub_role_key =
'sub-role-%d' % (depth+1)
115 sub_role = parts.get(sub_role_key)
117 raise ValueError(
'Invalid parts; missing %s' % sub_role_key)
120 for recurse_role
in recurse_roles:
121 if recurse_role == sub_role:
123 parts =
process(depth+1, parts)
126 raise ValueError(
'Invalid parts; unknown sub-role %s' % sub_role)
128 for key
in s.get(
'optional_keys', []):
130 rv_parts.append(parts[key])
134 raise ValueError(
'Invalid parts; too many parts: %s' % parts)
140 return BUILDER_NAME_SEP.join(rv_parts)
144 """Makes a dictionary containing details about the builder from its name."""
145 split = builder_name.split(BUILDER_NAME_SEP)
147 def pop_front(items):
149 return items.pop(0), items
152 'Invalid builder name: %s (not enough parts)' % builder_name)
156 def _parse(depth, role, parts):
157 schema = BUILDER_NAME_SCHEMA.get(role)
159 raise ValueError(
'Invalid builder name: %s' % builder_name)
161 result[
'role'] = str(role)
163 result[
'sub-role-%d' % depth] = str(role)
164 for key
in schema.get(
'keys', []):
165 value, parts = pop_front(parts)
166 result[key] = str(value)
167 for sub_role
in schema.get(
'recurse_roles', []):
168 if len(parts) > 0
and sub_role == parts[0]:
169 parts = _parse(depth+1, parts[0], parts[1:])
170 for key
in schema.get(
'optional_keys', []):
172 value, parts = pop_front(parts)
173 result[key] = str(value)
175 raise ValueError(
'Invalid builder name: %s' % builder_name)
178 _parse(0, split[0], split[1:])
def MakeBuilderName(**parts)
def DictForBuilderName(builder_name)
SI auto map(std::index_sequence< I... >, Fn &&fn, const Args &... args) -> skvx::Vec< sizeof...(I), decltype(fn(args[0]...))>
static void process(const char *inPath, const char *lexer, const char *token, const char *hPath, const char *cppPath)