| 1 |
# SPDX-License-Identifier: Apache-2.0 |
| 2 |
|
| 3 |
"""Wrapper for manually generating depfiles of resource files.""" |
| 4 |
|
| 5 |
from __future__ import annotations |
| 6 |
|
| 7 |
import argparse |
| 8 |
import subprocess |
| 9 |
import sys |
| 10 |
import typing as T |
| 11 |
|
| 12 |
|
| 13 |
parser = argparse.ArgumentParser() |
| 14 |
parser.add_argument('--rc', nargs='+', required=True) |
| 15 |
parser.add_argument('--cl', nargs='+', required=True) |
| 16 |
parser.add_argument('--Xarg', action='append') |
| 17 |
|
| 18 |
|
| 19 |
def run(args: T.List[str]) -> int: |
| 20 |
options, rc_args = parser.parse_known_args(args) |
| 21 |
target = rc_args[-1] if rc_args else None |
| 22 |
|
| 23 |
rc = options.rc |
| 24 |
cl = options.cl |
| 25 |
|
| 26 |
# Use preprocessor to display include files |
| 27 |
include_args = [a for a in rc_args if a.startswith(('/I', '-I'))] |
| 28 |
cmd = [*cl, *include_args, *options.Xarg] |
| 29 |
if target: |
| 30 |
cmd += [target] |
| 31 |
result = subprocess.call(cmd, stdout=subprocess.DEVNULL) |
| 32 |
if result != 0: |
| 33 |
print('Error running preprocessor to find resource dependencies', file=sys.stderr) |
| 34 |
# continue anyway. the resource compiler should catch the error later |
| 35 |
|
| 36 |
cmd = [*rc, *rc_args] |
| 37 |
return subprocess.call(cmd) |