"""
ExaBayes GCC 11 Compatibility Patcher
This script patches the ExaBayes source code to ensure compatibility with GCC version 11.
It primarily addresses issues related to the 'byte' type definition conflicts by
replacing instances of 'byte' with a custom type name 'exabayes_byte'. This
modification resolves ambiguities between std::byte and the project's internal byte
definition, allowing successful compilation with GCC version 11.
The script recursively scans the ExaBayes source directories, identifies relevant files,
and performs necessary replacements to maintain the software's functionality while
eliminating compiler errors related to type ambiguity.
"""
import os
import re
# Define the directories to search
src_dirs = ['src', 'include'] # Add or modify directories as needed
# Define the new type name
new_type_name = 'exabayes_byte'
# Define patterns to match and replace
patterns = [
(r'\btypedef\s+uint8_t\s+byte\s*;', f'typedef uint8_t {new_type_name};'),
(r'\bstd::vector<byte>', f'std::vector<{new_type_name}>'),
(r'\bvector<byte>', f'vector<{new_type_name}>'),
(r'\bbyte\s+\*', f'{new_type_name} *'),
(r'\bbyte\s+&', f'{new_type_name} &'),
(r'\bbyte>', f'{new_type_name}>'),
(r'\bbyte,', f'{new_type_name},'),
(r'\bbyte\s*\)', f'{new_type_name})'),
(r'\bbyte;', f'{new_type_name};'),
(r'reinterpret_cast<byte\s*\*>', f'reinterpret_cast<{new_type_name}*>'), # New pattern
]
def process_file(filepath):
with open(filepath, 'r') as file:
content = file.read()
modified = False
for pattern, replacement in patterns:
new_content, count = re.subn(pattern, replacement, content)
if count > 0:
content = new_content
modified = True
if modified:
with open(filepath, 'w') as file:
file.write(content)
print(f"Modified: {filepath}")
def process_directory(directory):
for root, _, files in os.walk(directory):
for file in files:
if file.endswith(('.cpp', '.hpp', '.h', '.tpp')):
filepath = os.path.join(root, file)
process_file(filepath)
if __name__ == "__main__":
for src_dir in src_dirs:
if os.path.exists(src_dir):
process_directory(src_dir)
else:
print(f"Directory not found: {src_dir}")
print("Processing complete. Please review the changes before compiling.")