forked from rems-project/asl-interpreter
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add check.py to perform syntax-checking of generated cpp
it would be nice to run this in ci. note llvm 17 dependency
- Loading branch information
1 parent
467c981
commit 963c670
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#!/usr/bin/env python3 | ||
|
||
""" | ||
Configures a meson build for syntax-checking only. | ||
To use, run `meson compile -C build` after this script. | ||
This script works by manually editing the meson-generated | ||
ninja files. This is obviously a bit hacky, but meson does | ||
not yet properly support -fsyntax-only. | ||
""" | ||
|
||
import os | ||
import shutil | ||
import subprocess | ||
|
||
clangpp = shutil.which('clang++') | ||
true = shutil.which('true') | ||
assert clangpp | ||
assert true | ||
|
||
def main(): | ||
os.environ['CXX'] = str(clangpp) | ||
|
||
subprocess.check_call('meson setup --reconfigure build'.split()) | ||
|
||
with open('build/build.ninja', 'rb') as f: | ||
build = f.readlines() | ||
|
||
bstr = lambda x: str(x).encode('utf-8') | ||
|
||
# replacement rules, keyed by sentinel line, and values are | ||
# replacements to perform on the NEXT line. | ||
repls = { | ||
b'rule cpp_COMPILER\n': (b' $ARGS ', b' $ARGS -fsyntax-only '), | ||
b'rule cpp_LINKER\n': (bstr(clangpp), bstr(true)), | ||
b'rule cpp_LINKER_RSP\n': (bstr(clangpp), bstr(true)), | ||
} | ||
|
||
with open('build/build.ninja', 'wb') as f: | ||
repl = None | ||
for l in build: | ||
if repl is not None: | ||
assert repl[0] in l, f'replacement failed {repl} in {l!r}' | ||
f.write(l.replace(repl[0], repl[1])) | ||
repl = None | ||
else: | ||
repl = repls.get(l) # must match exactly | ||
f.write(l) | ||
|
||
if __name__ == '__main__': | ||
main() | ||
|