-
Notifications
You must be signed in to change notification settings - Fork 12k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Runtimes] Merge 'compile_commands.json' files from runtimes build
Summary: When building a project in a runtime mode, the compilation database is a separate CMake invocation. So its `compile_commands.json` file will be placed elsewhere in the `runtimes/runtime-bins` directory. This is somewhat annoying for ongoing development when a runtimes build is necessary. This patch adds some CMake magic to merge the two files.
- Loading branch information
Showing
2 changed files
with
57 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,42 @@ | ||
#!/usr/bin/env python | ||
"""A command line utility to merge two JSON files. | ||
This is a python program that merges two JSON files into a single one. The | ||
intended use for this is to combine generated 'compile_commands.json' files | ||
created by CMake when performing an LLVM runtime build. | ||
""" | ||
|
||
import argparse | ||
import json | ||
|
||
def main(): | ||
parser = argparse.ArgumentParser(description=__doc__) | ||
parser.add_argument( | ||
"-o", type=str, | ||
help="The output file to write JSON data to", | ||
default=None, nargs="?", | ||
) | ||
parser.add_argument( | ||
"json_files", type=str, nargs='+', help="Input JSON files to merge" | ||
) | ||
args = parser.parse_args() | ||
|
||
merged_data = [] | ||
|
||
for json_file in args.json_files: | ||
try: | ||
with open(json_file, 'r') as f: | ||
data = json.load(f) | ||
merged_data.extend(data) | ||
except (IOError, json.JSONDecodeError): | ||
continue | ||
|
||
# Deduplicate by converting each entry to a tuple of sorted key-value pairs | ||
unique_data = list({json.dumps(entry, sort_keys=True) for entry in merged_data}) | ||
unique_data = [json.loads(entry) for entry in unique_data] | ||
|
||
with open(args.o, 'w') as f: | ||
json.dump(unique_data, f, indent=2) | ||
|
||
if __name__ == "__main__": | ||
main() |
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