diff --git a/.gitignore b/.gitignore index 11d5d1da5a..13942d1317 100644 --- a/.gitignore +++ b/.gitignore @@ -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 *~ diff --git a/Makefile b/Makefile index a006cec6aa..76f5186bde 100644 --- a/Makefile +++ b/Makefile @@ -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: diff --git a/build/concatinate_jsons.py b/build/concatinate_jsons.py new file mode 100755 index 0000000000..cf98c99987 --- /dev/null +++ b/build/concatinate_jsons.py @@ -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")) diff --git a/build/project_commands.py b/build/project_commands.py new file mode 100755 index 0000000000..242c8aecbe --- /dev/null +++ b/build/project_commands.py @@ -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")) diff --git a/build/vcxproj.mk b/build/vcxproj.mk index 86dbec0a49..1a0f23974a 100644 --- a/build/vcxproj.mk +++ b/build/vcxproj.mk @@ -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)