From 617d693102bc06fbd667694064ea4dc9dc90b55d Mon Sep 17 00:00:00 2001 From: Caitlin Potter Date: Mon, 8 Jun 2015 17:52:05 -0400 Subject: [PATCH] fix(dartfmt): don't break win32 command line limit Closes #2420 Closes #1875 --- tools/broccoli/broccoli-dartfmt.ts | 55 ++++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 15 deletions(-) diff --git a/tools/broccoli/broccoli-dartfmt.ts b/tools/broccoli/broccoli-dartfmt.ts index 806549c311..7872c81a4d 100644 --- a/tools/broccoli/broccoli-dartfmt.ts +++ b/tools/broccoli/broccoli-dartfmt.ts @@ -21,6 +21,7 @@ function processToPromise(process) { class DartFormatter implements DiffingBroccoliPlugin { private DARTFMT: string; private verbose: boolean; + private firstBuild: boolean = true; constructor(public inputPath: string, public cachePath: string, options) { if (!options.dartSDK) throw new Error("Missing Dart SDK"); @@ -30,11 +31,23 @@ class DartFormatter implements DiffingBroccoliPlugin { rebuild(treeDiff: DiffResult): Promise { let args = ['-w']; + let argsLength = 2; + let argPackages = []; + let firstBuild = this.firstBuild; treeDiff.addedPaths.concat(treeDiff.changedPaths) .forEach((changedFile) => { let sourcePath = path.join(this.inputPath, changedFile); let destPath = path.join(this.cachePath, changedFile); - if (/\.dart$/.test(changedFile)) args.push(destPath); + if (!firstBuild && /\.dart$/.test(changedFile)) { + if ((argsLength + destPath.length + 2) >= 0x2000) { + // Win32 command line arguments length + argPackages.push(args); + args = ['-w']; + argsLength = 2; + } + args.push(destPath); + argsLength += destPath.length + 2; + } fse.copySync(sourcePath, destPath); }); treeDiff.removedPaths.forEach((removedFile) => { @@ -42,22 +55,34 @@ class DartFormatter implements DiffingBroccoliPlugin { fse.removeSync(destPath); }); - if (args.length < 1) { - return Promise.resolve(); + if (!firstBuild && args.length > 1) { + argPackages.push(args); } - return new Promise((resolve, reject) => { - exec(this.DARTFMT + ' ' + args.join(' '), (err, stdout, stderr) => { - if (this.verbose) { - console.log(stdout); - } - if (err) { - console.error(shortenFormatterOutput(stderr)); - reject('Formatting failed.'); - } else { - resolve(); - } + + let execute = (args) => { + if (args.length < 2) return Promise.resolve(); + return new Promise((resolve, reject) => { + exec(this.DARTFMT + ' ' + args.join(' '), (err, stdout, stderr) => { + if (this.verbose) { + console.log(stdout); + } + if (err) { + console.error(shortenFormatterOutput(stderr)); + reject('Formatting failed.'); + } else { + resolve(); + } + }); }); - }); + }; + + if (firstBuild) { + // On firstBuild, format the entire cachePath + this.firstBuild = false; + return execute(['-w', this.cachePath]); + } + + return Promise.all(argPackages.map(execute)); } }