From cbb01bbb9b62eac7a9118136d40feae3bba9d32a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Bartmi=C5=84ski?= Date: Sun, 8 Dec 2024 19:54:41 +0100 Subject: [PATCH] Don't add extra args to chk/ingen/inwer C/CXXFLAGS in makefile.in This is already not done locally by sinol-make, so make the exported makefile.in match the local behaviour. --- src/sinol_make/commands/export/__init__.py | 22 ++++++++++++++++++--- tests/commands/export/util.py | 23 ++++++++++++++-------- 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/src/sinol_make/commands/export/__init__.py b/src/sinol_make/commands/export/__init__.py index b4f17fc0..49dd3563 100644 --- a/src/sinol_make/commands/export/__init__.py +++ b/src/sinol_make/commands/export/__init__.py @@ -212,11 +212,18 @@ def format_multiple_arguments(obj): return obj return ' '.join(obj) + # Only use extra_compilation_args for compiling solution files. + # One usecase of this is "reverse-library" problem packages, + # that provide a main.cpp file to be compiled with submissions. + # If extra args need to be passed to chk/ingen/inwer in the future, + # support for a new separate config option will have to be added. + extra_cxx_args = "" + extra_c_args = "" if 'extra_compilation_args' in config: if 'cpp' in config['extra_compilation_args']: - cxx_flags += ' ' + format_multiple_arguments(config['extra_compilation_args']['cpp']) + extra_cxx_args = format_multiple_arguments(config['extra_compilation_args']['cpp']) if 'c' in config['extra_compilation_args']: - c_flags += ' ' + format_multiple_arguments(config['extra_compilation_args']['c']) + extra_c_args = format_multiple_arguments(config['extra_compilation_args']['c']) tl = config.get('time_limit', None) if not tl: @@ -232,7 +239,16 @@ def format_multiple_arguments(obj): f'OI_TIME = oiejq\n' f'\n' f'CXXFLAGS += {cxx_flags}\n' - f'CFLAGS += {c_flags}\n') + f'{self.task_id}chk.e: CXXFLAGS := $(CXXFLAGS)\n' + f'{self.task_id}ingen.e: CXXFLAGS := $(CXXFLAGS)\n' + f'{self.task_id}inwer.e: CXXFLAGS := $(CXXFLAGS)\n' + f'CXXFLAGS += {extra_cxx_args}\n' + f'\n' + f'CFLAGS += {c_flags}\n' + f'{self.task_id}chk.e: CFLAGS := $(CFLAGS)\n' + f'{self.task_id}ingen.e: CFLAGS := $(CFLAGS)\n' + f'{self.task_id}inwer.e: CFLAGS := $(CFLAGS)\n' + f'CFLAGS += {extra_c_args}\n') def compress(self, target_dir): """ diff --git a/tests/commands/export/util.py b/tests/commands/export/util.py index e4c374f5..ad703948 100644 --- a/tests/commands/export/util.py +++ b/tests/commands/export/util.py @@ -41,12 +41,15 @@ def assert_makefile_in(lines, task_id, config): :param task_id: Task id :param config: Config dict """ - def _get_value_from_key(key, seperator): + def _get_values_from_key(key, separator): for line in lines: - split = line.split(seperator) + split = line.split(separator) if split[0].strip() == key: - return split[1].strip().strip('\n') - return None + yield split[1].strip().strip('\n') + + def _get_value_from_key(key, separator): + value, = _get_values_from_key(key, separator) + return value assert _get_value_from_key("ID", "=") == task_id assert _get_value_from_key("TIMELIMIT", "=") == str(config["time_limit"]) @@ -60,11 +63,15 @@ def format_multiple_arguments(obj): return obj return ' '.join(obj) + cxx_flags_vals = list(_get_values_from_key("CXXFLAGS", "+=")) + c_flags_vals = list(_get_values_from_key("CFLAGS", "+=")) + assert cxx_flags_vals[0] == cxx_flags + assert c_flags_vals[0] == c_flags if 'extra_compilation_args' in config: + # extra C/CXX args should be appended after ingen/inwer/chk targets if 'cpp' in config['extra_compilation_args']: - cxx_flags += ' ' + format_multiple_arguments(config['extra_compilation_args']['cpp']) + extra_cxx_args = format_multiple_arguments(config['extra_compilation_args']['cpp']) + assert cxx_flags_vals[1] == extra_cxx_args if 'c' in config['extra_compilation_args']: c_flags += ' ' + format_multiple_arguments(config['extra_compilation_args']['c']) - - assert _get_value_from_key("CXXFLAGS", "+=") == cxx_flags - assert _get_value_from_key("CFLAGS", "+=") == c_flags + assert c_flags_vals[1] == extra_c_args