Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions onlinejudge_verify/languages/cplusplus_bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,17 @@ def _get_uncommented_code(path: pathlib.Path, *, iquotes_options: Tuple[str, ...
if compiler == 'g++':
raise BundleError(f'A fake g++ is detected. Please install the GNU C++ compiler.: {compiler}')
raise BundleError(f"It's not g++. Please specify g++ with $CXX envvar.: {compiler}")
command = [compiler, '-x', 'c++', *iquotes_options, '-fpreprocessed', '-dD', '-E', str(path)]
return subprocess.check_output(command)

# Comment out #pragma GCC target() before preprocessing to avoid GCC emitting extra macros
with open(str(path), 'rb') as f:
source = f.read()
source = re.sub(rb'^(\s*)#\s*pragma\s+GCC\s+target\s*\(', rb'\1/* OJ_BUNDLE_PRAGMA */ // #pragma GCC target(', source, flags=re.MULTILINE)

command = [compiler, '-x', 'c++', *iquotes_options, '-fpreprocessed', '-dD', '-E', '-']
result = subprocess.check_output(command, input=source)

# Uncomment pragmas in output
return re.sub(rb'^(\s*)/\*\s*OJ_BUNDLE_PRAGMA\s*\*/\s*//\s*#\s*pragma\s+GCC\s+target\s*\(', rb'\1#pragma GCC target(', result, flags=re.MULTILINE)


def get_uncommented_code(path: pathlib.Path, *, iquotes: List[pathlib.Path], compiler: str) -> bytes:
Expand Down