-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[Runtimes] Merge 'compile_commands.json' files from runtimes build #116303
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,48 @@ | ||||||
#!/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 | ||||||
import sys | ||||||
|
||||||
|
||||||
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) as e: | ||||||
print("Failed to parse {json_file}: {e}", file=sys.stderr) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Honestly I think this print shouldn't exist so people don't get confused. |
||||||
continue | ||||||
jhuber6 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
# 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.