From 36fc249a02eb0ef32d3bc1d4e596683b64b1eb5f Mon Sep 17 00:00:00 2001 From: Matthew Sotoudeh Date: Tue, 25 Jul 2023 16:25:28 -0700 Subject: fix some dietcc bugs --- scripts/dietcc | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'scripts') diff --git a/scripts/dietcc b/scripts/dietcc index 8898df2..110a647 100755 --- a/scripts/dietcc +++ b/scripts/dietcc @@ -4,6 +4,9 @@ import sys import re import tempfile import os +import shlex + +CC = "gcc" if sys.argv[1:] == ["--version"]: print("DIETC") @@ -12,7 +15,7 @@ if sys.argv[1:] == ["--version"]: # Have to do this because ./configure seems to do some nasty stuff # https://lists.gnu.org/archive/html/bug-make/2022-11/msg00041.html if "-E" in sys.argv[1:]: - os.system(f"gcc {' '.join(sys.argv[1:])}") + os.system(f"{CC} {' '.join(map(shlex.quote, sys.argv[1:]))}") sys.exit(0) # https://stackoverflow.com/questions/595305 @@ -33,7 +36,7 @@ def preprocess_pass(c, meta): t_file.flush() dirname = os.path.dirname(os.path.realpath(meta["c_path"])) return check_result( - subprocess.run(f"gcc -I{dirname} -E {meta['argstr']} {t_file.name}", + subprocess.run(f"{CC} -I{dirname} -E {meta['argstr']} {t_file.name}", shell=True, capture_output=True)) def strip_after_preprocess_pass(c, meta): @@ -130,7 +133,7 @@ PASSES = [preprocess_pass, final_cleanup_pass] def main(): - args = sys.argv[1:] + args = list(map(shlex.quote, sys.argv[1:])) args.insert(0, f"-I{dietc_dir}/scripts/stdincludes") # first, parse out any DietC passes dietc_passes = [] @@ -146,9 +149,9 @@ def main(): for i, c_file in enumerate(c_files): subargs = [arg for arg in args if not arg.endswith(".c")] if "-o" in subargs: - i = subargs.index("-o") - subargs.pop(i) - subargs.pop(i) + i_ = subargs.index("-o") + subargs.pop(i_) + subargs.pop(i_) argstr = " ".join(subargs) last = open(c_file, "rb").read() @@ -165,7 +168,7 @@ def main(): if c_files and "-o" not in args: if "-c" in args: args += ["-o", c_files[0].replace(".c", ".o")] - gcc = subprocess.run(f"gcc {' '.join(args)} -Wno-int-to-pointer-cast -Wno-builtin-declaration-mismatch", shell=True) + gcc = subprocess.run(f"{CC} {' '.join(args)} -Wno-int-to-pointer-cast -Wno-builtin-declaration-mismatch", shell=True) check_result(gcc) main() -- cgit v1.2.3