Browse Source

chore(build): support generating compilation db (#12104)

OJ Kwon 7 years ago
parent
commit
dabd61bf80

+ 3 - 1
.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
+/npm/path.txt

+ 7 - 0
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

+ 7 - 0
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:

+ 14 - 1
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()