Created
February 12, 2023 11:09
-
-
Save afq984/1df3281804c20ec0df3776dff35ec11b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import re | |
import subprocess | |
include_map = {} | |
include_re = re.compile(r'#include "([^"]+)"') | |
for fn in subprocess.check_output(['git', 'ls-files', '*.h', '*.c'], text=True).splitlines(): | |
if fn.startswith('cras/include/'): | |
continue | |
include_map[os.path.basename(fn)] = fn | |
include_map['cras_dbus_bindings.h'] = 'cras/src/common/cras_dbus_bindings.h' | |
include_map['cras_version.h'] = 'cras/src/common/cras_version.h' | |
def repl(m): | |
basename = os.path.basename(m.group(1)) | |
return f'#include "{include_map.get(basename, m.group(1))}"' | |
for fn in subprocess.check_output(['git', 'ls-files', '*.h', '*.c', '*.cc'], text=True).splitlines(): | |
with open(fn) as file: | |
text = file.read() | |
out = include_re.sub(repl, text) | |
if out != text: | |
with open(fn, 'w') as file: | |
file.write(out) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment