Debian Codegraph @

mini_soong/main.py

raw symbols SCIP
1 # Soong to Makefile translator
2 #
3 # Copyright 2020 Andrej Shadura
4 #
5 # SPDX-License-Identifier: MIT
6 #
7 # Permission is hereby granted, free of charge, to any person obtaining
8 # a copy of this software and associated documentation files (the
9 # "Software"), to deal in the Software without restriction, including
10 # without limitation the rights to use, copy, modify, merge, publish,
11 # distribute, sublicense, and/or sell copies of the Software, and to
12 # permit persons to whom the Software is furnished to do so, subject to
13 # the following conditions:
14 #
15 # The above copyright notice and this permission notice shall be
16 # included in all copies or substantial portions of the Software.
17 #
18 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
22 # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
26 from .parser import soong
27 from .model import defaults, all_targets, all_modules, current_recipe, Module
28 from .utils import mergedefaults, print_vars
29 from .builders import flag_defaults, extra_targets
30 import argparse
31 import os
32 from pathlib import Path
33
34 def run():
35 import sys
36 global all_modules, current_recipe
37
38 parser = argparse.ArgumentParser(description='Convert Soong recipes to a Makefile')
39 parser.add_argument('bp', metavar='RECIPES', type=str, default='**/Android.bp', nargs='?', help='pattern used to find recipes')
40 parser.add_argument('poutput', metavar='OUTPUT', type=str, nargs='?', help='where to write the Makefile (default: stdout)')
41 parser.add_argument('--output', '-o', metavar='OUTPUT', type=str, help='where to write the Makefile (default: stdout)')
42 args = parser.parse_args()
43
44 bp = args.bp
45 output = args.poutput or args.output
46
47 if output:
48 sys.stdout = open(output, 'w')
49
50 flag_defaults()
51 all_modules.clear()
52
53 # todo: allow chdir
54 recipes = sorted([path for path in Path('.').glob(bp) if not path.parts[0].startswith('.')])
55 for recipe in recipes:
56 parsed = soong.parseString(recipe.read_text())
57 all_modules += [r.arguments['name'] for r in parsed if isinstance(r, Module) and 'name' in r.arguments]
58
59 current_recipe.update({
60 'name': str(recipe),
61 'dir': recipe.parents[0],
62 'parsed': parsed
63 })
64 for r in parsed:
65 r.run()
66
67 print(f"build: {' '.join(all_targets)}")
68 if all_targets:
69 clean_targets = [f"clean-{target}" for target in all_targets]
70 print(f"clean: {' '.join(clean_targets)}")
71 else:
72 print(f"clean:")
73 extra_targets()