66import re
77
88# Script to generate compile_commands.json based on Makefile output
9- # Works by accepting Makefile output from stdin, parsing it, and
9+ # Works by accepting Makefile output from stdin, parsing it, and
1010# turning into json records. These are then printed to stdout.
1111# More details on the compile_commands format at:
1212# https://clang.llvm.org/docs/JSONCompilationDatabase.html
@@ -28,11 +28,12 @@ def generate():
2828 for line in sys .stdin .readlines ():
2929 if TOKEN_DENOTING_COMPILED_FILE in line :
3030 match = matcher .match (line )
31- compile_commands .append ({
32- "directory" : build_dir ,
33- "command" : line .strip (),
34- "file" : os .path .normpath (os .path .join (build_dir ,match .group (2 )))
35- })
31+ if match :
32+ compile_commands .append ({
33+ "directory" : build_dir ,
34+ "command" : line .strip (),
35+ "file" : os .path .normpath (os .path .join (build_dir ,match .group (2 )))
36+ })
3637 print (json .dumps (compile_commands ,indent = 4 ))
3738
3839if __name__ == '__main__' :
0 commit comments