Skip to content

Commit bfe2568

Browse files
authored
build: add gn-check to precommit linting (electron#19850)
1 parent 0f5ff1f commit bfe2568

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
"create-typescript-definitions": "npm run create-api-json && electron-typescript-definitions --api=electron-api.json && node spec/ts-smoke/runner.js",
8080
"gn-typescript-definitions": "npm run create-typescript-definitions && shx cp electron.d.ts",
8181
"pre-flight": "pre-flight",
82+
"gn-check": "node ./script/gn-check.js",
8283
"preinstall": "node -e 'process.exit(0)'",
8384
"prepack": "check-for-leaks",
8485
"repl": "node ./script/start.js --interactive",
@@ -115,6 +116,7 @@
115116
"remark -qf"
116117
],
117118
"*.{gn,gni}": [
119+
"npm run gn-check",
118120
"python script/run-gn-format.py",
119121
"git add"
120122
],

script/gn-check.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
const cp = require('child_process')
2+
const path = require('path')
3+
4+
const { getOutDir } = require('./lib/utils')
5+
6+
const SOURCE_ROOT = path.normalize(path.dirname(__dirname))
7+
const DEPOT_TOOLS = path.resolve(SOURCE_ROOT, '..', 'third_party', 'depot_tools')
8+
const OUT_DIR = getOutDir()
9+
10+
if (!OUT_DIR) {
11+
throw new Error(`No viable out dir: one of Debug, Testing, or Release must exist.`)
12+
}
13+
14+
const env = Object.assign({
15+
CHROMIUM_BUILDTOOLS_PATH: path.resolve(SOURCE_ROOT, '..', 'buildtools'),
16+
DEPOT_TOOLS_WIN_TOOLCHAIN: '0'
17+
}, process.env)
18+
// Users may not have depot_tools in PATH.
19+
env.PATH = `${env.PATH}${path.delimiter}${DEPOT_TOOLS}`
20+
21+
const gnCheckDirs = [
22+
'//electron:electron_lib',
23+
'//electron:electron_app',
24+
'//electron:manifests',
25+
'//electron/shell/common/api:mojo'
26+
]
27+
28+
for (const dir of gnCheckDirs) {
29+
const args = ['check', `../out/${OUT_DIR}`, dir]
30+
const result = cp.spawnSync('gn', args, { env, stdio: 'inherit' })
31+
if (result.status !== 0) process.exit(result.status)
32+
}
33+
34+
process.exit(0)

0 commit comments

Comments
 (0)