From c2ca9302a2f72eff502d818a7c8f6fd1e0327548 Mon Sep 17 00:00:00 2001 From: David Sanders Date: Wed, 22 Apr 2026 16:58:15 -0700 Subject: [PATCH] build: don't use //third_party/depot_tools in lint.js (#51260) build: don't use //third_party/depot_tools in lint.js (#51034) * build: don't use //third_party/depot_tools in lint.js * chore: also run python3 through depot tools --- script/lint.js | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/script/lint.js b/script/lint.js index 1ca35a3fc3..83a0f0cbc9 100755 --- a/script/lint.js +++ b/script/lint.js @@ -8,16 +8,10 @@ const crypto = require('node:crypto'); const fs = require('node:fs'); const path = require('node:path'); -const { chunkFilenames, findMatchingFiles } = require('./lib/utils'); +const { chunkFilenames, findMatchingFiles, getDepotToolsEnv } = require('./lib/utils'); const ELECTRON_ROOT = path.normalize(path.dirname(__dirname)); const SOURCE_ROOT = path.resolve(ELECTRON_ROOT, '..'); -const DEPOT_TOOLS = path.resolve(SOURCE_ROOT, 'third_party', 'depot_tools'); - -// Augment the PATH for this script so that we can find executables -// in the depot_tools folder even if folks do not have an instance of -// DEPOT_TOOLS in their path already -process.env.PATH = `${process.env.PATH}${path.delimiter}${DEPOT_TOOLS}`; const IGNORELIST = new Set([ ['shell', 'browser', 'resources', 'win', 'resource.h'], @@ -93,7 +87,7 @@ async function runEslint (eslint, filenames, { fix, verbose }) { function cpplint (args) { args.unshift(`--root=${SOURCE_ROOT}`); const cmd = IS_WINDOWS ? 'cpplint.bat' : 'cpplint.py'; - const result = childProcess.spawnSync(cmd, args, { encoding: 'utf8', shell: true }); + const result = childProcess.spawnSync(cmd, args, { encoding: 'utf8', shell: true, env: getDepotToolsEnv() }); // cpplint.py writes EVERYTHING to stderr, including status messages if (result.stderr) { for (const line of result.stderr.split(/[\r\n]+/)) { @@ -118,6 +112,7 @@ const LINTERS = [{ test: filename => filename.endsWith('.cc') || (filename.endsWith('.h') && !isObjCHeader(filename)), run: (opts, filenames) => { const env = { + ...getDepotToolsEnv(), CHROMIUM_BUILDTOOLS_PATH: path.resolve(ELECTRON_ROOT, '..', 'buildtools') }; const clangFormatFlags = opts.fix ? ['--fix'] : []; @@ -132,6 +127,7 @@ const LINTERS = [{ test: filename => filename.endsWith('.mm') || (filename.endsWith('.h') && isObjCHeader(filename)), run: (opts, filenames) => { const env = { + ...getDepotToolsEnv(), CHROMIUM_BUILDTOOLS_PATH: path.resolve(ELECTRON_ROOT, '..', 'buildtools') }; const clangFormatFlags = opts.fix ? ['--fix'] : []; @@ -144,10 +140,8 @@ const LINTERS = [{ roots: ['script'], test: filename => filename.endsWith('.py'), run: (opts, filenames) => { - const rcfile = path.join(DEPOT_TOOLS, 'pylintrc-2.17'); - const args = ['--rcfile=' + rcfile, ...filenames]; - const env = { PYTHONPATH: path.join(ELECTRON_ROOT, 'script'), ...process.env }; - spawnAndCheckExitCode(IS_WINDOWS ? 'pylint-2.17.bat' : 'pylint-2.17', args, { env }); + const env = { ...getDepotToolsEnv(), PYTHONPATH: path.join(ELECTRON_ROOT, 'script') }; + spawnAndCheckExitCode(IS_WINDOWS ? 'pylint-2.17.bat' : 'pylint-2.17', filenames, { env }); } }, { key: 'javascript', @@ -176,9 +170,9 @@ const LINTERS = [{ run: (opts, filenames) => { const allOk = filenames.map(filename => { const env = { + ...getDepotToolsEnv(), CHROMIUM_BUILDTOOLS_PATH: path.resolve(ELECTRON_ROOT, '..', 'buildtools'), - DEPOT_TOOLS_WIN_TOOLCHAIN: '0', - ...process.env + DEPOT_TOOLS_WIN_TOOLCHAIN: '0' }; const args = ['format', filename]; if (!opts.fix) args.push('--dry-run');