cc: add -I preprocessor option
This commit is contained in:
parent
a3a67105eb
commit
e1557ad4b6
14
tools/cc.py
14
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:
|
||||
|
Loading…
Reference in New Issue
Block a user