diff options
| author | Leitwolf | 2026-10-24 19:03:40 +0300 |
|---|---|---|
| committer | GitHub | 2026-10-24 19:03:40 +0300 |
| commit | 4f1c759cffcb14bd6511e1d7c5fbace682e24f2d (patch) | |
| tree | 415fe5d48a5b48650bba3747beaf245d727c4f61 /tools/scripts/generateAmalgamatedFiles.py | |
| parent | 83c6fc3ac13abe83fa39f7b5f8559ccaf4412233 (diff) | |
| parent | 622188f9c08e4af35941c146979883ed4882410e (diff) | |
| download | catch3-4f1c759cffcb14bd6511e1d7c5fbace682e24f2d.tar.gz | |
Merge pull request #15 from Progmasoft/feature/catch3-runner
Replace Catch2's runner with the Catch3 runner
Diffstat (limited to 'tools/scripts/generateAmalgamatedFiles.py')
| -rwxr-xr-x | tools/scripts/generateAmalgamatedFiles.py | 54 |
1 files changed, 53 insertions, 1 deletions
diff --git a/tools/scripts/generateAmalgamatedFiles.py b/tools/scripts/generateAmalgamatedFiles.py index e3e86aab..5fed3358 100755 --- a/tools/scripts/generateAmalgamatedFiles.py +++ b/tools/scripts/generateAmalgamatedFiles.py @@ -44,6 +44,10 @@ file_header = '''\ // ---------------------------------------------------------- // This file is an amalgamation of multiple different files. // You probably shouldn't edit it directly. +// +// The parts that come from src/Progmasoft, the Catch3 runner, keep +// their own copyright and license lines (MPL-2.0 WITH +// AdditionRef-Progmasoft-Exception-1.1). The runner needs C++20. // ---------------------------------------------------------- ''' @@ -68,6 +72,9 @@ def concatenate_file(out, filename: str, expand_headers: bool) -> int: if line in copyright_lines: continue m = internal_include_parser.match(line) + # The runner's headers are expanded at the start of the .cpp file. + if not m and not expand_headers and progmasoft_include_parser.match(line): + continue # anything that isn't a Catch2 header can just be copied to # the resulting file if not m: @@ -112,16 +119,61 @@ def generate_header(): print('Concatenated {} headers'.format(concatenate_file(header, starting_header, True))) header.write('#endif // CATCH_AMALGAMATED_HPP_INCLUDED\n') +# The runner's files include each other as <Progmasoft/...> or, inside one +# directory, as "Name.hpp". +progmasoft_include_parser = re.compile(r'\s*#include (?:<(Progmasoft/[^>]+)>|"([A-Za-z/]+\.hpp)").*') +concatenated_runner_headers = set() + + +def concatenate_runner_file(out, filename: str, expand_headers: bool): + """Copies a file of the runner, expanding the runner's headers it + includes once, or dropping those includes from the .cpp files.""" + directory = os.path.dirname(filename) + with open(filename, mode='r', encoding='utf-8') as input: + for line in input: + if line.strip() == '#pragma once': + continue + # Catch2's own headers are all in the amalgamated header. + if internal_include_parser.match(line): + continue + m = progmasoft_include_parser.match(line) + if not m: + out.write(line) + continue + if m.group(1): + header = os.path.normpath(os.path.join(root_path, m.group(1))) + else: + header = os.path.normpath(os.path.join(directory, m.group(2))) + if not expand_headers or header in concatenated_runner_headers: + continue + concatenated_runner_headers.add(header) + concatenate_runner_file(out, header, True) + + def generate_cpp(): from glob import glob cpp_files = sorted(glob(os.path.join(root_path, 'catch2', '**/*.cpp'), recursive=True)) + runner_headers = sorted(glob(os.path.join(root_path, 'Progmasoft', 'Runner', '*.hpp'))) + [ + os.path.join(root_path, 'Progmasoft', 'Catch3', name) + for name in ('Results.hpp', 'Runner.hpp', 'Version.hpp', 'XmlWriter.hpp')] + runner_files = [os.path.join(root_path, 'Progmasoft', 'Results.cpp'), + os.path.join(root_path, 'Progmasoft', 'XmlWriter.cpp')] + \ + sorted(glob(os.path.join(root_path, 'Progmasoft', 'Runner', '*.cpp'))) with open(output_cpp, mode='w', encoding='utf-8') as cpp: cpp.write(formatted_file_header(Version())) cpp.write('\n#include "catch_amalgamated.hpp"\n') concatenate_file(cpp, os.path.join(root_path, 'catch2/internal/catch_windows_h_proxy.hpp'), False) + # The runner's headers come first: Catch::Session reaches the runner. + for header in runner_headers: + header = os.path.normpath(header) + if header not in concatenated_runner_headers: + concatenated_runner_headers.add(header) + concatenate_runner_file(cpp, header, True) for file in cpp_files: concatenate_file(cpp, file, False) - print('Concatenated {} cpp files'.format(len(cpp_files))) + for file in runner_files: + concatenate_runner_file(cpp, file, False) + print('Concatenated {} cpp files'.format(len(cpp_files) + len(runner_files))) if __name__ == "__main__": generate_header() |