From dabd61bf8013f70f61e58793b7874407de980d78 Mon Sep 17 00:00:00 2001 From: OJ Kwon Date: Sun, 8 Apr 2018 22:54:14 -0700 Subject: [PATCH] chore(build): support generating compilation db (#12104) --- .gitignore | 4 +++- docs/development/build-instructions-linux.md | 7 +++++++ docs/development/build-instructions-osx.md | 7 +++++++ script/build.py | 15 ++++++++++++++- 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index bbfe5148b511..ea4b9e2d06b4 100644 --- a/.gitignore +++ b/.gitignore @@ -44,7 +44,9 @@ node_modules/ SHASUMS256.txt **/package-lock.json **/yarn.lock +compile_commands.json +.envrc # npm package /npm/dist -/npm/path.txt \ No newline at end of file +/npm/path.txt diff --git a/docs/development/build-instructions-linux.md b/docs/development/build-instructions-linux.md index 442b3ded9d75..56d31a8be39c 100644 --- a/docs/development/build-instructions-linux.md +++ b/docs/development/build-instructions-linux.md @@ -63,6 +63,13 @@ $ cd electron $ ./script/bootstrap.py --verbose ``` +If you are using editor supports [JSON compilation database](http://clang.llvm.org/docs/JSONCompilationDatabase.html) based +language server, you can generate it: + +```sh +$ ./script/build.py --compdb +``` + ### Cross compilation If you want to build for an `arm` target you should also install the following diff --git a/docs/development/build-instructions-osx.md b/docs/development/build-instructions-osx.md index 42dcc626fa5b..081f7dc0ea5e 100644 --- a/docs/development/build-instructions-osx.md +++ b/docs/development/build-instructions-osx.md @@ -56,6 +56,13 @@ $ cd electron $ ./script/bootstrap.py -v ``` +If you are using editor supports [JSON compilation database](http://clang.llvm.org/docs/JSONCompilationDatabase.html) based +language server, you can generate it: + +```sh +$ ./script/build.py --compdb +``` + ## Building Build both `Release` and `Debug` targets: diff --git a/script/build.py b/script/build.py index 0f40804db63c..fb2b95d3bb71 100755 --- a/script/build.py +++ b/script/build.py @@ -56,7 +56,14 @@ def main(): env = build_env() for config in args.configuration: build_path = os.path.join('out', config[0]) - ret = subprocess.call(ninja + ['-C', build_path, args.target], env=env) + build_args = ['-C', build_path, args.target] + if args.compdb: + build_args += ['-t', 'compdb', 'cxx', 'cc'] + compdb = open(r'compile_commands.json','w') + ret = subprocess.call(ninja + build_args, env=env, stdout=compdb) + compdb.close() + else: + ret = subprocess.call(ninja + build_args, env=env) if ret != 0: sys.exit(ret) @@ -86,6 +93,12 @@ def parse_args(): parser.add_argument('--ninja-path', help='Path of ninja command to use.', required=False) + parser.add_argument('--compdb', + help=( + 'Generate JSON compilation database. This will not ' + 'trigger actual build. ' + ), + action='store_true', default=False) return parser.parse_args()