Skip to content

Commit

Permalink
ingen and inwer compilation parity
Browse files Browse the repository at this point in the history
flags for ingen and inwer
  • Loading branch information
adespawn committed Mar 11, 2024
1 parent c1e010c commit 5e05c9b
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 18 deletions.
5 changes: 3 additions & 2 deletions src/sinol_make/commands/ingen/ingen_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ def compile_ingen(ingen_path: str, args: argparse.Namespace, compilation_flags='
return ingen_path

compilers = compiler.verify_compilers(args, [ingen_path])
ingen_exe, compile_log_path = compile.compile_file(ingen_path, package_util.get_executable(ingen_path), compilers,
compilation_flags, use_fsanitize=True)
ingen_exe, compile_log_path = compile.compile_file(ingen_path, package_util.get_executable(ingen_path),
compilers, compilation_flags, use_fsanitize=True,
additional_flags='-D_INGEN')

if ingen_exe is None:
compile.print_compile_log(compile_log_path)
Expand Down
9 changes: 1 addition & 8 deletions src/sinol_make/commands/inwer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,6 @@ def configure_subparser(self, subparser: argparse.ArgumentParser):
help=f'number of cpus to use (default: {util.default_cpu_count()})')
add_compilation_arguments(parser)

def compile_inwer(self, args: argparse.Namespace):
self.inwer_executable, compile_log_path = inwer_util.compile_inwer(self.inwer, args, args.compile_mode)
if self.inwer_executable is None:
util.exit_with_error('Compilation failed.', lambda: compile.print_compile_log(compile_log_path))
else:
print(util.info('Compilation successful.'))

@staticmethod
def verify_test(execution: InwerExecution) -> VerificationResult:
"""
Expand Down Expand Up @@ -210,7 +203,7 @@ def run(self, args: argparse.Namespace):
print('Verifying tests: ' + util.bold(', '.join(self.tests)))

util.change_stack_size_to_unlimited()
self.compile_inwer(args)
self.inwer_executable = inwer_util.compile_inwer(self.inwer, args, args.compile_mode)
results: Dict[str, TestResult] = self.verify_and_print_table()
print('')

Expand Down
20 changes: 15 additions & 5 deletions src/sinol_make/commands/inwer/inwer_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from sinol_make.interfaces.Errors import CompilationError


def get_inwer_path(task_id: str, path = None) -> Union[str, None]:
def get_inwer_path(task_id: str, path=None) -> Union[str, None]:
"""
Returns path to inwer executable for given task or None if no inwer was found.
"""
Expand All @@ -34,8 +34,16 @@ def compile_inwer(inwer_path: str, args: argparse.Namespace, compilation_flags='
Compiles inwer and returns path to compiled executable and path to compile log.
"""
compilers = compiler.verify_compilers(args, [inwer_path])
return compile.compile_file(inwer_path, package_util.get_executable(inwer_path), compilers, compilation_flags,
use_fsanitize=True)
inwer_exe, compile_log_path = compile.compile_file(inwer_path, package_util.get_executable(inwer_path), compilers,
compilation_flags, use_fsanitize=True,
additional_flags='-D_INWER')

if inwer_exe is None:
compile.print_compile_log(compile_log_path)
util.exit_with_error('Failed inwer compilation.')
else:
print(util.info('Compilation successful.'))
return inwer_exe


def sort_tests(tests, task_id):
Expand All @@ -62,11 +70,13 @@ def print_view(term_width, term_height, table_data: TableData):
tests.append(result.test_path)
tests = sort_tests(tests, table_data.task_id)

column_lengths[3] = max(10, term_width - column_lengths[0] - column_lengths[1] - column_lengths[2] - 9 - 3) # 9 is for " | " between columns, 3 for margin.
column_lengths[3] = max(10, term_width - column_lengths[0] - column_lengths[1] - column_lengths[
2] - 9 - 3) # 9 is for " | " between columns, 3 for margin.
margin = " "

def print_line_separator():
res = "-" * (column_lengths[0] + 3) + "+" + "-" * (column_lengths[1] + 1) + "+" + "-" * (column_lengths[2] + 1) + "+"
res = "-" * (column_lengths[0] + 3) + "+" + "-" * (column_lengths[1] + 1) + "+" + "-" * (
column_lengths[2] + 1) + "+"
res += "-" * (term_width - len(res) - 1)
print(res)

Expand Down
6 changes: 5 additions & 1 deletion src/sinol_make/helpers/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ def compile(program, output, compilers: Compilers = None, compile_log=None, comp
return True


def compile_file(file_path: str, name: str, compilers: Compilers, compilation_flags='default', use_fsanitize=False) \
def compile_file(file_path: str, name: str, compilers: Compilers, compilation_flags='default',
use_fsanitize=False, additional_flags=None) \
-> Tuple[Union[str, None], str]:
"""
Compile a file
Expand All @@ -121,6 +122,7 @@ def compile_file(file_path: str, name: str, compilers: Compilers, compilation_fl
:param compilers: Compilers object
:param compilation_flags: Group of compilation flags to use
:param use_fsanitize: Whether to use fsanitize when compiling C/C++ programs. Sanitizes address and undefined behavior.
:param additional_flags: Additional flags for c / c++ compiler.
:return: Tuple of (executable path or None if compilation failed, log path)
"""
os.makedirs(paths.get_executables_path(), exist_ok=True)
Expand All @@ -135,6 +137,8 @@ def compile_file(file_path: str, name: str, compilers: Compilers, compilation_fl
if isinstance(args, str):
args = [args]
extra_compilation_args = [os.path.join(os.getcwd(), "prog", file) for file in args]
if additional_flags is not None:
extra_compilation_args.append(additional_flags)

output = paths.get_executables_path(name)
compile_log_path = paths.get_compilation_log_path(os.path.splitext(name)[0] + '.compile_log')
Expand Down
4 changes: 2 additions & 2 deletions tests/commands/inwer/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def test_compile_inwer(create_package):
task_id = package_util.get_task_id()
inwer_path = inwer_util.get_inwer_path(task_id)
args = compiler.get_default_compilers()
executable, compile_log = inwer_util.compile_inwer(inwer_path, args)
executable = inwer_util.compile_inwer(inwer_path, args)
assert os.path.exists(executable)


Expand All @@ -45,7 +45,7 @@ def test_asserting_inwer(create_package):
python_interpreter_path=compiler.get_python_interpreter_path(),
java_compiler_path=compiler.get_java_compiler_path()
)
executable, compile_log = inwer_util.compile_inwer(inwer_path, args)
executable = inwer_util.compile_inwer(inwer_path, args)

execution = InwerExecution(
inwer_exe_path=executable,
Expand Down

0 comments on commit 5e05c9b

Please sign in to comment.