diff --git a/src/sinol_make/commands/ingen/ingen_util.py b/src/sinol_make/commands/ingen/ingen_util.py index 5e9263fe..2b6608da 100644 --- a/src/sinol_make/commands/ingen/ingen_util.py +++ b/src/sinol_make/commands/ingen/ingen_util.py @@ -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) diff --git a/src/sinol_make/commands/inwer/__init__.py b/src/sinol_make/commands/inwer/__init__.py index 40bcf8d0..71245b97 100644 --- a/src/sinol_make/commands/inwer/__init__.py +++ b/src/sinol_make/commands/inwer/__init__.py @@ -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: """ @@ -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('') diff --git a/src/sinol_make/commands/inwer/inwer_util.py b/src/sinol_make/commands/inwer/inwer_util.py index d423f5db..6d21f0c0 100644 --- a/src/sinol_make/commands/inwer/inwer_util.py +++ b/src/sinol_make/commands/inwer/inwer_util.py @@ -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. """ @@ -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): @@ -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) diff --git a/src/sinol_make/helpers/compile.py b/src/sinol_make/helpers/compile.py index 7b99e17c..07500090 100644 --- a/src/sinol_make/helpers/compile.py +++ b/src/sinol_make/helpers/compile.py @@ -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 @@ -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) @@ -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') diff --git a/tests/commands/inwer/test_unit.py b/tests/commands/inwer/test_unit.py index 0cb7818d..cdb76a90 100644 --- a/tests/commands/inwer/test_unit.py +++ b/tests/commands/inwer/test_unit.py @@ -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) @@ -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, diff --git a/tests/packages/gen/no-precompile b/tests/packages/gen/no-precompile new file mode 100644 index 00000000..e69de29b diff --git a/tests/packages/gen/prog/geningen5.cpp b/tests/packages/gen/prog/geningen5.cpp index ee2ff2bf..c086786b 100644 --- a/tests/packages/gen/prog/geningen5.cpp +++ b/tests/packages/gen/prog/geningen5.cpp @@ -3,6 +3,7 @@ using namespace std; int main() { + #ifdef _INGEN ofstream f("gen1.in"); f << "1 2\n"; f.close(); @@ -10,4 +11,7 @@ int main() { f.open("gen2.in"); f << "2 3\n"; f.close(); + #else + This should not compile + #endif } diff --git a/tests/packages/wer/no-precompile b/tests/packages/wer/no-precompile new file mode 100644 index 00000000..e69de29b diff --git a/tests/packages/wer/prog/werinwer.cpp b/tests/packages/wer/prog/werinwer.cpp index c6a54564..7e925f82 100644 --- a/tests/packages/wer/prog/werinwer.cpp +++ b/tests/packages/wer/prog/werinwer.cpp @@ -3,6 +3,7 @@ using namespace std; int main() { + #ifdef _INWER int n, a; cin >> n; for (int i = 0; i < n; i++) { @@ -16,4 +17,7 @@ int main() { cout << "OK" << endl << "Group " << n - 1 << endl; return 0; + #else + This should not compile + #endif }