Skip to content

Commit

Permalink
Don't add extra args to chk/ingen/inwer C/CXXFLAGS in makefile.in
Browse files Browse the repository at this point in the history
This is already not done locally by sinol-make, so make the exported
makefile.in match the local behaviour.
  • Loading branch information
j4b6ski committed Dec 8, 2024
1 parent 5bebd72 commit cbb01bb
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
22 changes: 19 additions & 3 deletions src/sinol_make/commands/export/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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):
"""
Expand Down
23 changes: 15 additions & 8 deletions tests/commands/export/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand All @@ -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

0 comments on commit cbb01bb

Please sign in to comment.