Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions | Variables
builder_name_schema.builder_name_schema Namespace Reference

Functions

 _LoadSchema ()
 
 MakeBuilderName (**parts)
 
 DictForBuilderName (builder_name)
 

Variables

 BUILDER_NAME_SCHEMA = None
 
 BUILDER_NAME_SEP = None
 
str BUILDER_ROLE_BAZELBUILD = 'BazelBuild'
 
str BUILDER_ROLE_BAZELTEST = 'BazelTest'
 
str BUILDER_ROLE_BUILD = 'Build'
 
str BUILDER_ROLE_BUILDSTATS = 'BuildStats'
 
str BUILDER_ROLE_CANARY = 'Canary'
 
str BUILDER_ROLE_CODESIZE = 'CodeSize'
 
str BUILDER_ROLE_HOUSEKEEPER = 'Housekeeper'
 
str BUILDER_ROLE_INFRA = 'Infra'
 
str BUILDER_ROLE_PERF = 'Perf'
 
str BUILDER_ROLE_TEST = 'Test'
 
str BUILDER_ROLE_UPLOAD = 'Upload'
 
tuple BUILDER_ROLES
 

Detailed Description

 Utilities for dealing with builder names. This module obtains its attributes
dynamically from builder_name_schema.json. 

Function Documentation

◆ _LoadSchema()

builder_name_schema.builder_name_schema._LoadSchema ( )
protected
 Load the builder naming schema from the JSON file. 

Definition at line 47 of file builder_name_schema.py.

47def _LoadSchema():
48 """ Load the builder naming schema from the JSON file. """
49
50 def ToStr(obj):
51 """ Convert all unicode strings in obj to Python strings. """
52 if isinstance(obj, str):
53 return obj # pragma: nocover
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))
60 else:
61 return obj.decode('utf-8') # pragma: nocover
62
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))
66
67 global BUILDER_NAME_SCHEMA
68 BUILDER_NAME_SCHEMA = ToStr(
69 builder_name_schema_json['builder_name_schema'])
70
71 global BUILDER_NAME_SEP
72 BUILDER_NAME_SEP = ToStr(
73 builder_name_schema_json['builder_name_sep'])
74
75 # Since the builder roles are dictionary keys, just assert that the global
76 # variables above account for all of them.
77 assert len(BUILDER_ROLES) == len(BUILDER_NAME_SCHEMA)
78 for role in BUILDER_ROLES:
79 assert role in BUILDER_NAME_SCHEMA
80
81

◆ DictForBuilderName()

builder_name_schema.builder_name_schema.DictForBuilderName (   builder_name)
Makes a dictionary containing details about the builder from its name.

Definition at line 143 of file builder_name_schema.py.

143def DictForBuilderName(builder_name):
144 """Makes a dictionary containing details about the builder from its name."""
145 split = builder_name.split(BUILDER_NAME_SEP)
146
147 def pop_front(items):
148 try:
149 return items.pop(0), items
150 except:
151 raise ValueError(
152 'Invalid builder name: %s (not enough parts)' % builder_name)
153
154 result = {}
155
156 def _parse(depth, role, parts):
157 schema = BUILDER_NAME_SCHEMA.get(role)
158 if not schema:
159 raise ValueError('Invalid builder name: %s' % builder_name)
160 if depth == 0:
161 result['role'] = str(role)
162 else:
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', []):
171 if parts:
172 value, parts = pop_front(parts)
173 result[key] = str(value)
174 if parts:
175 raise ValueError('Invalid builder name: %s' % builder_name)
176 return parts
177
178 _parse(0, split[0], split[1:])
179
180 return result

◆ MakeBuilderName()

builder_name_schema.builder_name_schema.MakeBuilderName ( **  parts)

Definition at line 85 of file builder_name_schema.py.

85def MakeBuilderName(**parts):
86 for v in parts.values():
87 if BUILDER_NAME_SEP in v:
88 raise ValueError('Parts cannot contain "%s"' % BUILDER_NAME_SEP)
89
90 rv_parts = []
91
92 def process(depth, parts):
93 role_key = 'role'
94 if depth != 0:
95 role_key = 'sub-role-%d' % depth
96 role = parts.get(role_key)
97 if not role:
98 raise ValueError('Invalid parts; missing key %s' % role_key)
99 s = BUILDER_NAME_SCHEMA.get(role)
100 if not s:
101 raise ValueError('Invalid parts; unknown role %s' % role)
102 rv_parts.append(role)
103 del parts[role_key]
104
105 for key in s.get('keys', []):
106 value = parts.get(key)
107 if not value:
108 raise ValueError('Invalid parts; missing %s' % key)
109 rv_parts.append(value)
110 del parts[key]
111
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)
116 if not sub_role:
117 raise ValueError('Invalid parts; missing %s' % sub_role_key)
118
119 found = False
120 for recurse_role in recurse_roles:
121 if recurse_role == sub_role:
122 found = True
123 parts = process(depth+1, parts)
124 break
125 if not found:
126 raise ValueError('Invalid parts; unknown sub-role %s' % sub_role)
127
128 for key in s.get('optional_keys', []):
129 if parts.get(key):
130 rv_parts.append(parts[key])
131 del parts[key]
132
133 if len(parts) > 0:
134 raise ValueError('Invalid parts; too many parts: %s' % parts)
135
136 return parts
137
138 process(0, parts)
139
140 return BUILDER_NAME_SEP.join(rv_parts)
141
142
static void process(const char *inPath, const char *lexer, const char *token, const char *hPath, const char *cppPath)
Definition Main.cpp:114

Variable Documentation

◆ BUILDER_NAME_SCHEMA

builder_name_schema.builder_name_schema.BUILDER_NAME_SCHEMA = None

Definition at line 17 of file builder_name_schema.py.

◆ BUILDER_NAME_SEP

builder_name_schema.builder_name_schema.BUILDER_NAME_SEP = None

Definition at line 20 of file builder_name_schema.py.

◆ BUILDER_ROLE_BAZELBUILD

str builder_name_schema.builder_name_schema.BUILDER_ROLE_BAZELBUILD = 'BazelBuild'

Definition at line 23 of file builder_name_schema.py.

◆ BUILDER_ROLE_BAZELTEST

str builder_name_schema.builder_name_schema.BUILDER_ROLE_BAZELTEST = 'BazelTest'

Definition at line 24 of file builder_name_schema.py.

◆ BUILDER_ROLE_BUILD

str builder_name_schema.builder_name_schema.BUILDER_ROLE_BUILD = 'Build'

Definition at line 25 of file builder_name_schema.py.

◆ BUILDER_ROLE_BUILDSTATS

str builder_name_schema.builder_name_schema.BUILDER_ROLE_BUILDSTATS = 'BuildStats'

Definition at line 26 of file builder_name_schema.py.

◆ BUILDER_ROLE_CANARY

str builder_name_schema.builder_name_schema.BUILDER_ROLE_CANARY = 'Canary'

Definition at line 27 of file builder_name_schema.py.

◆ BUILDER_ROLE_CODESIZE

str builder_name_schema.builder_name_schema.BUILDER_ROLE_CODESIZE = 'CodeSize'

Definition at line 28 of file builder_name_schema.py.

◆ BUILDER_ROLE_HOUSEKEEPER

str builder_name_schema.builder_name_schema.BUILDER_ROLE_HOUSEKEEPER = 'Housekeeper'

Definition at line 29 of file builder_name_schema.py.

◆ BUILDER_ROLE_INFRA

str builder_name_schema.builder_name_schema.BUILDER_ROLE_INFRA = 'Infra'

Definition at line 30 of file builder_name_schema.py.

◆ BUILDER_ROLE_PERF

str builder_name_schema.builder_name_schema.BUILDER_ROLE_PERF = 'Perf'

Definition at line 31 of file builder_name_schema.py.

◆ BUILDER_ROLE_TEST

str builder_name_schema.builder_name_schema.BUILDER_ROLE_TEST = 'Test'

Definition at line 32 of file builder_name_schema.py.

◆ BUILDER_ROLE_UPLOAD

str builder_name_schema.builder_name_schema.BUILDER_ROLE_UPLOAD = 'Upload'

Definition at line 33 of file builder_name_schema.py.

◆ BUILDER_ROLES

tuple builder_name_schema.builder_name_schema.BUILDER_ROLES
Initial value:
1= (BUILDER_ROLE_BAZELBUILD,
2 BUILDER_ROLE_BAZELTEST,
3 BUILDER_ROLE_BUILD,
4 BUILDER_ROLE_BUILDSTATS,
5 BUILDER_ROLE_CANARY,
6 BUILDER_ROLE_CODESIZE,
7 BUILDER_ROLE_HOUSEKEEPER,
8 BUILDER_ROLE_INFRA,
9 BUILDER_ROLE_PERF,
10 BUILDER_ROLE_TEST,
11 BUILDER_ROLE_UPLOAD)

Definition at line 34 of file builder_name_schema.py.