build: don't use //third_party/depot_tools in lint.js (#51261)

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
This commit is contained in:
David Sanders
2026-04-22 16:58:23 -07:00
committed by GitHub
parent 12410f16ba
commit 285efaf87b

View File

@@ -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');