Fixed clangd problems with emscripten.
This commit is contained in:
42
clean_compile_commands.py
Normal file
42
clean_compile_commands.py
Normal file
@@ -0,0 +1,42 @@
|
||||
#!/usr/bin/env python3
|
||||
import json
|
||||
import re
|
||||
import sys
|
||||
import os
|
||||
|
||||
def clean_compile_commands(compile_commands_path):
|
||||
# Load the compile_commands.json file
|
||||
with open(compile_commands_path, 'r') as f:
|
||||
data = json.load(f)
|
||||
|
||||
# Flags to remove (Emscripten-specific)
|
||||
flags_to_remove = [
|
||||
r'-s\w+=\S*', # Matches -sSTRICT=0, -sMODULARIZE=1, etc.
|
||||
r'-s\w+', # Matches -sWASM, -sASSERTIONS, etc.
|
||||
r'--no-entry',
|
||||
r'--bind',
|
||||
r'--cache',
|
||||
]
|
||||
|
||||
# Clean each command
|
||||
for entry in data:
|
||||
if 'command' in entry:
|
||||
command = entry['command']
|
||||
# Remove all unwanted flags
|
||||
for flag_pattern in flags_to_remove:
|
||||
command = re.sub(flag_pattern, '', command)
|
||||
# Remove extra spaces
|
||||
command = ' '.join(command.split())
|
||||
entry['command'] = command
|
||||
|
||||
# Save the cleaned file
|
||||
with open(compile_commands_path, 'w') as f:
|
||||
json.dump(data, f, indent=2)
|
||||
|
||||
print(f"Cleaned {compile_commands_path}")
|
||||
|
||||
if __name__ == '__main__':
|
||||
if len(sys.argv) != 2:
|
||||
print("Usage: python clean_compile_commands.py <compile_commands.json>")
|
||||
sys.exit(1)
|
||||
clean_compile_commands(sys.argv[1])
|
||||
Reference in New Issue
Block a user