Justin Yun | 0daf186 | 2022-04-27 16:21:16 +0900 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | import os |
| 3 | import sys |
| 4 | import yaml |
| 5 | |
| 6 | from hierarchy import parse_hierarchy |
| 7 | |
| 8 | |
| 9 | def main(): |
| 10 | if len(sys.argv) != 2: |
| 11 | print('usage: %s target' % sys.argv[0]) |
| 12 | exit(1) |
| 13 | |
| 14 | args = sys.argv[1].split('-') |
| 15 | if len(args) != 2: |
| 16 | print('target format: {target}-{variant}') |
| 17 | exit(1) |
| 18 | |
| 19 | target, variant = args |
| 20 | |
| 21 | if variant not in ['eng', 'user', 'userdebug']: |
| 22 | print('unknown variant "%s": expected "eng", "user" or "userdebug"' % |
| 23 | variant) |
| 24 | exit(1) |
| 25 | |
| 26 | build_top = os.getenv('BUFFET_BUILD_TOP') |
| 27 | if not build_top: |
| 28 | print('BUFFET_BUILD_TOP is not set; Did you correctly run envsetup.sh?') |
| 29 | exit(1) |
| 30 | |
| 31 | hierarchy_map = parse_hierarchy(build_top) |
| 32 | |
| 33 | if target not in hierarchy_map: |
| 34 | raise RuntimeError( |
| 35 | "unknown target '%s': couldn't find the target. Supported targets are: %s" |
| 36 | % (target, list(hierarchy_map.keys()))) |
| 37 | |
| 38 | hierarchy = [target] |
| 39 | while hierarchy_map[hierarchy[-1]]: |
| 40 | hierarchy.append(hierarchy_map[hierarchy[-1]]) |
| 41 | |
| 42 | print('Target hierarchy for %s: %s' % (target, hierarchy)) |
| 43 | |
| 44 | |
| 45 | if __name__ == '__main__': |
| 46 | main() |