diff --git a/.gitignore b/.gitignore index bbfe5148b51..ea4b9e2d06b 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 442b3ded9d7..56d31a8be39 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 42dcc626fa5..081f7dc0ea5 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 0f40804db63..fb2b95d3bb7 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()