| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 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 |
|
| 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() |