From bfe256891cd29147f275562ea63e5447a99eb332 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Fri, 30 Aug 2019 10:37:02 -0700 Subject: [PATCH] build: add gn-check to precommit linting (#19850) --- package.json | 2 ++ script/gn-check.js | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 script/gn-check.js diff --git a/package.json b/package.json index 4071b030862d6..59e05e3371f03 100644 --- a/package.json +++ b/package.json @@ -79,6 +79,7 @@ "create-typescript-definitions": "npm run create-api-json && electron-typescript-definitions --api=electron-api.json && node spec/ts-smoke/runner.js", "gn-typescript-definitions": "npm run create-typescript-definitions && shx cp electron.d.ts", "pre-flight": "pre-flight", + "gn-check": "node ./script/gn-check.js", "preinstall": "node -e 'process.exit(0)'", "prepack": "check-for-leaks", "repl": "node ./script/start.js --interactive", @@ -115,6 +116,7 @@ "remark -qf" ], "*.{gn,gni}": [ + "npm run gn-check", "python script/run-gn-format.py", "git add" ], diff --git a/script/gn-check.js b/script/gn-check.js new file mode 100644 index 0000000000000..4652c7bebd7e7 --- /dev/null +++ b/script/gn-check.js @@ -0,0 +1,34 @@ +const cp = require('child_process') +const path = require('path') + +const { getOutDir } = require('./lib/utils') + +const SOURCE_ROOT = path.normalize(path.dirname(__dirname)) +const DEPOT_TOOLS = path.resolve(SOURCE_ROOT, '..', 'third_party', 'depot_tools') +const OUT_DIR = getOutDir() + +if (!OUT_DIR) { + throw new Error(`No viable out dir: one of Debug, Testing, or Release must exist.`) +} + +const env = Object.assign({ + CHROMIUM_BUILDTOOLS_PATH: path.resolve(SOURCE_ROOT, '..', 'buildtools'), + DEPOT_TOOLS_WIN_TOOLCHAIN: '0' +}, process.env) +// Users may not have depot_tools in PATH. +env.PATH = `${env.PATH}${path.delimiter}${DEPOT_TOOLS}` + +const gnCheckDirs = [ + '//electron:electron_lib', + '//electron:electron_app', + '//electron:manifests', + '//electron/shell/common/api:mojo' +] + +for (const dir of gnCheckDirs) { + const args = ['check', `../out/${OUT_DIR}`, dir] + const result = cp.spawnSync('gn', args, { env, stdio: 'inherit' }) + if (result.status !== 0) process.exit(result.status) +} + +process.exit(0)