-
-
Save andyfriesen/731baabd7cec5d1c24c53cc0691ca249 to your computer and use it in GitHub Desktop.
Trying to work out how to get a single mega-compilation-database out of Buck. This is a pretty naive approach, but I think it works?
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
# compdb/BUCK | |
python_bootstrap_binary( | |
name = "combine_compdbs", | |
main = "combine_compdbs.py", | |
visibility = ["PUBLIC"] | |
) |
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
# compdb/combine_compdbs.py | |
#!/usr/bin/env python3 | |
import sys | |
import argparse | |
import json | |
parser = argparse.ArgumentParser() | |
parser.add_argument("database", nargs='+') | |
parser.add_argument('--output', '-o', dest='output', required=True) | |
def main(argv): | |
args = parser.parse_args(argv) | |
result = {} | |
for fn in args.database: | |
content = json.load(open(fn, 'r')) | |
for row in content: | |
result[row['file']] = row | |
res = list(result.values()) | |
json.dump(res, open(args.output, 'w'), indent = 4) | |
if __name__ == '__main__': | |
main(sys.argv[1:]) |
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
# compdb/defs.bzl | |
def _impl(ctx: "context"): | |
output = ctx.actions.declare_output('compile_commands.json') | |
cmd = [ctx.attrs._combine_compdbs[RunInfo]] | |
cmd.extend(ctx.attrs.databases) | |
cmd.append(cmd_args(output.as_output(), format="--output={}")) | |
ctx.actions.run( | |
cmd, | |
category="combine_compilation_databases", | |
) | |
return [DefaultInfo(default_output=output)] | |
combine_compdbs = rule( | |
impl=_impl, | |
attrs = { | |
"databases": attrs.list(attrs.source()), | |
"_combine_compdbs": attrs.default_only(attrs.exec_dep(providers = [RunInfo], default="//compdb:combine_compdbs")) | |
} | |
) |
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
# example BUCK file. Can go any old place. | |
load("//compdb:defs.bzl", "combine_compdbs") | |
combine_compdbs( | |
name='compile-commands', | |
databases=[ | |
'//:foo[compilation-database]', | |
'//:bar[compilation-database]', | |
'//:baz[compilation-database]', | |
'//:quux[compilation-database]', | |
], | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment