chore: chunk filenames when linting C++ files (#34237)

* chore: chunk filenames when linting C++ files

* chore: refactor code for better readability

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* chore: further tweak

* chore: limit all platforms to 4095 characters on command line

* chore: use python3

* Revert "chore: use python3"

Co-authored-by: Charles Kerr <charles@charleskerr.com>
Co-authored-by: Cheng Zhao <zcbenz@gmail.com>
This commit is contained in:
David Sanders 2022-06-22 03:23:11 -07:00 committed by GitHub
parent f172136752
commit 5fee5b0e22
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 32 deletions

View file

@ -9,6 +9,8 @@ import * as streamJson from 'stream-json';
import { ignore as streamJsonIgnore } from 'stream-json/filters/Ignore';
import { streamArray as streamJsonStreamArray } from 'stream-json/streamers/StreamArray';
import { chunkFilenames } from './lib/utils';
const SOURCE_ROOT = path.normalize(path.dirname(__dirname));
const LLVM_BIN = path.resolve(
SOURCE_ROOT,
@ -108,33 +110,6 @@ function getDepotToolsEnv (): NodeJS.ProcessEnv {
return depotToolsEnv;
}
function chunkFilenames (filenames: string[], offset: number = 0): string[][] {
// Windows has a max command line length of 2047 characters, so we can't
// provide too many filenames without going over that. To work around that,
// chunk up a list of filenames such that it won't go over that limit when
// used as args. Use a much higher limit on other platforms which will
// effectively be a no-op.
const MAX_FILENAME_ARGS_LENGTH =
PLATFORM === 'win32' ? 2047 - offset : 100 * 1024;
return filenames.reduce(
(chunkedFilenames: string[][], filename) => {
const currChunk = chunkedFilenames[chunkedFilenames.length - 1];
const currChunkLength = currChunk.reduce(
(totalLength, _filename) => totalLength + _filename.length + 1,
0
);
if (currChunkLength + filename.length + 1 > MAX_FILENAME_ARGS_LENGTH) {
chunkedFilenames.push([filename]);
} else {
currChunk.push(filename);
}
return chunkedFilenames;
},
[[]]
);
}
async function runClangTidy (
outDir: string,
filenames: string[],