| 186 | |
| 187 | |
| 188 | def CheckNode(node, keypath): |
| 189 | if isinstance(node, ast.Dict): |
| 190 | dict = {} |
| 191 | for key, value in zip(node.keys, node.values): |
| 192 | assert isinstance(key, ast.Str) |
| 193 | key = key.s |
| 194 | if key in dict: |
| 195 | raise GypError( |
| 196 | "Key '" |
| 197 | + key |
| 198 | + "' repeated at level " |
| 199 | + repr(len(keypath) + 1) |
| 200 | + " with key path '" |
| 201 | + ".".join(keypath) |
| 202 | + "'" |
| 203 | ) |
| 204 | kp = list(keypath) # Make a copy of the list for descending this node. |
| 205 | kp.append(key) |
| 206 | dict[key] = CheckNode(value, kp) |
| 207 | return dict |
| 208 | elif isinstance(node, ast.List): |
| 209 | children = [] |
| 210 | for index, child in enumerate(node.elts): |
| 211 | kp = list(keypath) # Copy list. |
| 212 | kp.append(repr(index)) |
| 213 | children.append(CheckNode(child, kp)) |
| 214 | return children |
| 215 | elif isinstance(node, ast.Str): |
| 216 | return node.s |
| 217 | else: |
| 218 | raise TypeError( |
| 219 | "Unknown AST node at key path '" + ".".join(keypath) + "': " + repr(node) |
| 220 | ) |
| 221 | |
| 222 | |
| 223 | def LoadOneBuildFile(build_file_path, data, aux_data, includes, is_target, check): |