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:
parent
f172136752
commit
5fee5b0e22
3 changed files with 37 additions and 32 deletions
|
@ -1,5 +1,6 @@
|
|||
const { GitProcess } = require('dugite');
|
||||
const fs = require('fs');
|
||||
const os = require('os');
|
||||
const path = require('path');
|
||||
|
||||
const ELECTRON_DIR = path.resolve(__dirname, '..', '..');
|
||||
|
@ -95,7 +96,35 @@ async function getCurrentBranch (gitDir) {
|
|||
return branch.trim();
|
||||
}
|
||||
|
||||
function chunkFilenames (filenames, offset = 0) {
|
||||
// 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. Other platforms may have higher limits, but 4095 might be
|
||||
// the limit on Linux systems according to `termios(3)`, so cap it there.
|
||||
const MAX_FILENAME_ARGS_LENGTH =
|
||||
(os.platform() === 'win32' ? 2047 : 4095) - offset;
|
||||
|
||||
return filenames.reduce(
|
||||
(chunkedFilenames, 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;
|
||||
},
|
||||
[[]]
|
||||
);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
chunkFilenames,
|
||||
getCurrentBranch,
|
||||
getElectronExec,
|
||||
getOutDir,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue