Skip to content

Instantly share code, notes, and snippets.

@kborkows
Created December 19, 2016 19:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kborkows/0838e72fae0b90a05dee6a797a1b121a to your computer and use it in GitHub Desktop.
Save kborkows/0838e72fae0b90a05dee6a797a1b121a to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# What this script does is:
# split (on '-' char) and list-concat all "command" fields
# filter out non-includes (includes start with 'I')
# filter out non-component includes
# make paths relative to component and print them out
component = "mctrl"
import sys
import json
flatten = lambda l : [item for sublist in l for item in sublist]
if len(sys.argv) < 2:
print("Path to compile_commands.json not provided")
filename = sys.argv[1]
data = json.load(open(filename))
args = flatten(obj["command"].split('-') for obj in data)
includes = filter(lambda x : x and x[0] == "I", args)
component_includes = filter(lambda inc : ('/' + component + '/') in inc and "build" not in inc, includes)
for include in sorted(set(component_includes)):
print(include[include.index(component) + len(component) + 1:])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment