From bac71a43c95fc2c2f7a580320c2457ee585926e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Bartmi=C5=84ski?= Date: Fri, 9 Aug 2024 20:41:32 +0200 Subject: [PATCH] Fix passing arbitrary args to compiler Only prepend cwd to the arg if it actually is a path. This allows passing actual compile arguments that are not additional files. (cherry picked from commit 7fe4509974079ba08a67ca88cb4a7e71a2895572) --- src/sinol_make/commands/run/__init__.py | 8 ++++++-- src/sinol_make/helpers/compile.py | 25 +++++++++++++++---------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/sinol_make/commands/run/__init__.py b/src/sinol_make/commands/run/__init__.py index f973ea26..3587737e 100644 --- a/src/sinol_make/commands/run/__init__.py +++ b/src/sinol_make/commands/run/__init__.py @@ -354,8 +354,12 @@ def compile(self, solution, dest=None, use_extras=False, clear_cache=False, name args = self.config.get("extra_compilation_args", {}).get(lang, []) if isinstance(args, str): args = [args] - for file in args: - extra_compilation_args.append(os.path.join(os.getcwd(), "prog", file)) + for arg in args: + path = os.path.join(os.getcwd(), "prog", arg) + if os.path.exists(path): + extra_compilation_args.append(path) + else: + extra_compilation_args.append(arg) for file in self.config.get("extra_compilation_files", []): extra_compilation_files.append(os.path.join(os.getcwd(), "prog", file)) diff --git a/src/sinol_make/helpers/compile.py b/src/sinol_make/helpers/compile.py index d30e1273..2e28630e 100644 --- a/src/sinol_make/helpers/compile.py +++ b/src/sinol_make/helpers/compile.py @@ -137,17 +137,22 @@ def compile_file(file_path: str, name: str, compilers: Compilers, compilation_fl config = package_util.get_config() - lang = os.path.splitext(file_path)[1][1:] - args = config.get('extra_compilation_args', {}).get(lang, []) - if isinstance(args, str): - args = [args] + extra_compilation_args = [] + extra_compilation_files = [] if use_extras: - extra_compilation_args = [os.path.join(os.getcwd(), "prog", file) for file in args] - extra_compilation_files = [os.path.join(os.getcwd(), "prog", file) - for file in config.get("extra_compilation_files", [])] - else: - extra_compilation_args = [] - extra_compilation_files = [] + lang = os.path.splitext(file_path)[1][1:] + args = config.get("extra_compilation_args", {}).get(lang, []) + if isinstance(args, str): + args = [args] + for arg in args: + path = os.path.join(os.getcwd(), "prog", arg) + if os.path.exists(path): + extra_compilation_args.append(path) + else: + extra_compilation_args.append(arg) + + for file in config.get("extra_compilation_files", []): + extra_compilation_files.append(os.path.join(os.getcwd(), "prog", file)) if additional_flags is not None: extra_compilation_args.append(additional_flags)