Browse Source

fix: use gn/clang-format from src (#19145)

* fix: use gn/clang-format from src

* fix: download clang-format in lint job

* chore: fix linting warning

* chore: get_path_in_buildtools => get_buildtools_executable

* chore: the clang-format npm package is not used
Cheng Zhao 5 years ago
parent
commit
436d5c9ac1
7 changed files with 39 additions and 26 deletions
  1. 11 2
      .circleci/config.yml
  2. 1 3
      package.json
  3. 12 0
      script/lib/util.py
  4. 2 1
      script/run-clang-format.py
  5. 5 1
      script/run-gn-format.py
  6. 8 7
      shell/common/node_bindings.cc
  7. 0 12
      yarn.lock

+ 11 - 2
.circleci/config.yml

@@ -553,11 +553,20 @@ steps-lint: &steps-lint
 
           cipd ensure -ensure-file - -root . <<-CIPD
           \$ServiceURL https://chrome-infra-packages.appspot.com/
-          @Subdir buildtools/linux64
+          @Subdir src/buildtools/linux64
           gn/gn/linux-amd64 $gn_version
           CIPD
 
-          echo 'export CHROMIUM_BUILDTOOLS_PATH="'"$PWD"'/buildtools"' >> $BASH_ENV
+          echo 'export CHROMIUM_BUILDTOOLS_PATH="'"$PWD"'/src/buildtools"' >> $BASH_ENV
+    - run:
+        name: Download clang-format Binary
+        command: |
+          chromium_revision="$(grep -A1 chromium_version src/electron/DEPS | tr -d '\n' | cut -d\' -f4)"
+
+          sha1_path='buildtools/linux64/clang-format.sha1'
+          curl -sL "https://chromium.googlesource.com/chromium/src/+/${chromium_revision}/${sha1_path}?format=TEXT" | base64 -d > "src/${sha1_path}"
+
+          download_from_google_storage.py --no_resume --no_auth --bucket chromium-clang-format -s "src/${sha1_path}"
     - run:
         name: Run Lint
         command: |

+ 1 - 3
package.json

@@ -21,7 +21,6 @@
     "@typescript-eslint/parser": "^1.4.2",
     "asar": "^1.0.0",
     "check-for-leaks": "^1.2.1",
-    "clang-format": "^1.2.3",
     "colors": "^1.1.2",
     "dotenv-safe": "^4.0.4",
     "dugite": "^1.45.0",
@@ -61,7 +60,6 @@
   "scripts": {
     "asar": "asar",
     "check-tls": "python ./script/tls.py",
-    "clang-format": "find atom/ chromium_src/ -iname *.h -o -iname *.cc -o -iname *.mm | xargs clang-format -i",
     "generate-version-json": "node script/generate-version-json.js",
     "lint": "node ./script/lint.js && npm run lint:clang-format && npm run lint:docs",
     "lint:js": "node ./script/lint.js --js",
@@ -127,4 +125,4 @@
       "git add filenames.auto.gni"
     ]
   }
-}
+}

+ 12 - 0
script/lib/util.py

@@ -246,3 +246,15 @@ def get_electron_exec():
 
   raise Exception(
       "get_electron_exec: unexpected platform '{0}'".format(sys.platform))
+
+def get_buildtools_executable(name):
+  buildtools = os.path.realpath(os.path.join(ELECTRON_DIR, '..', 'buildtools'))
+  chromium_platform = {
+    'darwin': 'mac',
+    'linux2': 'linux64',
+    'win32': 'win',
+  }[sys.platform]
+  path = os.path.join(buildtools, chromium_platform, name)
+  if sys.platform == 'win32':
+    path += '.exe'
+  return path

+ 2 - 1
script/run-clang-format.py

@@ -22,6 +22,7 @@ import traceback
 import tempfile
 
 from functools import partial
+from lib.util import get_buildtools_executable
 
 DEFAULT_EXTENSIONS = 'c,h,C,H,cpp,hpp,cc,hh,c++,h++,cxx,hxx,mm'
 
@@ -188,7 +189,7 @@ def main():
         '--clang-format-executable',
         metavar='EXECUTABLE',
         help='path to the clang-format executable',
-        default='clang-format')
+        default=get_buildtools_executable('clang-format'))
     parser.add_argument(
         '--extensions',
         help='comma separated list of file extensions (default: {})'.format(

+ 5 - 1
script/run-gn-format.py

@@ -2,6 +2,8 @@ import os
 import subprocess
 import sys
 
+from lib.util import get_buildtools_executable
+
 SOURCE_ROOT = os.path.dirname(os.path.dirname(__file__))
 
 # Helper to run gn format on multiple files
@@ -12,9 +14,11 @@ def main():
   new_env['CHROMIUM_BUILDTOOLS_PATH'] = os.path.realpath(
     os.path.join(SOURCE_ROOT, '..', 'buildtools')
   )
+
+  gn_path = get_buildtools_executable('gn')
   for gn_file in sys.argv[1:]:
     subprocess.check_call(
-      ['gn', 'format', gn_file],
+      [gn_path, 'format', gn_file],
       env=new_env
     )
 

+ 8 - 7
shell/common/node_bindings.cc

@@ -98,13 +98,14 @@ namespace {
 void stop_and_close_uv_loop(uv_loop_t* loop) {
   // Close any active handles
   uv_stop(loop);
-  uv_walk(loop,
-          [](uv_handle_t* handle, void*) {
-            if (!uv_is_closing(handle)) {
-              uv_close(handle, nullptr);
-            }
-          },
-          nullptr);
+  uv_walk(
+      loop,
+      [](uv_handle_t* handle, void*) {
+        if (!uv_is_closing(handle)) {
+          uv_close(handle, nullptr);
+        }
+      },
+      nullptr);
 
   // Run the loop to let it finish all the closing handles
   // NB: after uv_stop(), uv_run(UV_RUN_DEFAULT) returns 0 when that's done

+ 0 - 12
yarn.lock

@@ -682,10 +682,6 @@ async-each@^1.0.0, async-each@^1.0.1:
   version "1.0.3"
   resolved "https://registry.yarnpkg.com/async-each/-/async-each-1.0.3.tgz#b727dbf87d7651602f06f4d4ac387f47d91b0cbf"
 
-async@^1.5.2:
-  version "1.5.2"
-  resolved "https://registry.yarnpkg.com/async/-/async-1.5.2.tgz#ec6a61ae56480c0c3cb241c95618e20892f9672a"
-
 asynckit@^0.4.0:
   version "0.4.0"
   resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79"
@@ -1186,14 +1182,6 @@ circular-json@^0.3.1:
   version "0.3.3"
   resolved "https://registry.yarnpkg.com/circular-json/-/circular-json-0.3.3.tgz#815c99ea84f6809529d2f45791bdf82711352d66"
 
-clang-format@^1.2.3:
-  version "1.2.4"
-  resolved "https://registry.yarnpkg.com/clang-format/-/clang-format-1.2.4.tgz#4bb4b0a98180428deb093cf20982e9fc1af20b6c"
-  dependencies:
-    async "^1.5.2"
-    glob "^7.0.0"
-    resolve "^1.1.6"
-
 class-utils@^0.3.5:
   version "0.3.6"
   resolved "https://registry.yarnpkg.com/class-utils/-/class-utils-0.3.6.tgz#f93369ae8b9a7ce02fd41faad0ca83033190c463"