From e1557ad4b6024aa2c75f7066b7241bae1bfd78b5 Mon Sep 17 00:00:00 2001 From: Paul Mathieu Date: Sat, 13 Mar 2021 15:44:12 -0800 Subject: [PATCH] cc: add -I preprocessor option --- tools/cc.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tools/cc.py b/tools/cc.py index b0e2406..07a8576 100644 --- a/tools/cc.py +++ b/tools/cc.py @@ -1186,12 +1186,18 @@ def parse_args(): default=sys.stdin, help='input file (default: stdin)') parser.add_argument('--output', '-o', type=argparse.FileType('wb'), default=sys.stdout.buffer, help='output file') + parser.add_argument('-I', dest='include_dirs', action='append', + default=[], help='include dirs') return parser.parse_args() -def preprocess(fin): - p = subprocess.Popen(CPP, stdin=fin, stdout=subprocess.PIPE) - return p.stdout +def preprocess(fin, include_dirs): + cmd = list(CPP) + [f'-I{x}' for x in include_dirs] + p = subprocess.Popen(cmd, stdin=fin, stdout=subprocess.PIPE) + out, _ = p.communicate() + if p.returncode != 0: + raise RuntimeError(f'preprocessor error') + return io.StringIO(out.decode()) def assemble(text, fout): @@ -1202,7 +1208,7 @@ def assemble(text, fout): def main(): args = parse_args() - assy = larkparse(preprocess(args.input), debug=args.debug) + assy = larkparse(preprocess(args.input, args.include_dirs), debug=args.debug) if args.assembly: args.output.write(assy.encode() + b'\n') else: