Add creating compile_commands.json to the build system.

I'm really not proud of how I did this though.

It must be run from the same environment as one's editor (ie. not in the
docker image) so that the paths are correct.
This commit is contained in:
Alex Miller 2018-08-10 15:16:19 -07:00
parent 69aa33eed5
commit 9bcc7685d2
5 changed files with 49 additions and 0 deletions

2
.gitignore vendored
View File

@ -42,6 +42,7 @@ packaging/msi/FDBInstaller.wix*
.ccache
.deps/
.objs/
.cmds/
bindings/c/fdb_c.symbols
bindings/go/build
bindings/go/godoc
@ -71,6 +72,7 @@ FoundationDB.xcodeproj
foundationdb.VC.db
foundationdb.VC.VC.opendb
ipch/
compile_commands.json
# Temporary and user configuration files
*~

View File

@ -160,6 +160,11 @@ $(CPP_MK_GENERATED): build/vcxprojtom4.py build/vcxproj.mk Makefile
DEPSDIR := .deps
OBJDIR := .objs
CMDDIR := .cmds
COMPILE_COMMANDS_JSONS := $(addprefix $(CMDDIR)/,$(addsuffix /compile_commands.json,${CPP_PROJECTS}))
compile_commands.json: build/concatinate_jsons.py ${COMPILE_COMMANDS_JSONS}
@build/concatinate_jsons.py ${COMPILE_COMMANDS_JSONS}
include $(MK_INCLUDE)
@ -169,6 +174,7 @@ clean: $(CLEAN_TARGETS) docpreview_clean
@rm -rf $(DEPSDIR)
@rm -rf lib/
@rm -rf bin/coverage.*.xml
@rm -rf $(CMDDIR) compile_commands.json
@find . -name "*.g.cpp" -exec rm -f {} \; -or -name "*.g.h" -exec rm -f {} \;
targets:

11
build/concatinate_jsons.py Executable file
View File

@ -0,0 +1,11 @@
#!/usr/bin/env python
import sys
import json
lst = []
for filename in sys.argv[1:]:
commands = json.load(open(filename))
lst.extend(commands)
json.dump(lst, open("compile_commands.json", "w"))

26
build/project_commands.py Executable file
View File

@ -0,0 +1,26 @@
#!/usr/bin/env python
import sys
import os
import os.path
import json
flags = sys.argv[1]
all_files = sys.argv[2]
outfile = sys.argv[3]
cwd = os.getcwd()
commands = []
for fname in all_files.split(' '):
d = {}
d["directory"] = cwd
if fname.endswith("cpp") or fname.endswith(".h"):
compiler = "clang++ -x c++ "
if fname.endswith("c"):
compiler = "clang -x c "
d["command"] = compiler + flags.replace('-DNO_INTELLISENSE', '').replace("/opt/boost", cwd+"/../boost") + "-c " + fname
d["file"] = fname
commands.append(d)
json.dump(commands, open(outfile, "w"))

View File

@ -58,6 +58,10 @@ GENNAME()_DEPS := $(addprefix $(DEPSDIR)/,$(GENNAME()_BUILD_SOURCES:=.d))
GENNAME: GENTARGET
$(CMDDIR)/GENDIR/compile_commands.json: build/project_commands.py ${GENNAME()_ALL_SOURCES}
@mkdir -p $(basename $@)
@build/project_commands.py "$(CFLAGS) $(CXXFLAGS) $(GENNAME()_CFLAGS) $(GENNAME()_CXXFLAGS)" "$(GENNAME()_ALL_SOURCES)" "$@"
-include $(GENNAME()_DEPS)
$(OBJDIR)/GENDIR/%.actor.g.cpp: GENDIR/%.actor.cpp $(ACTORCOMPILER)