Skip to content

Commit 7fc1ee6

Browse files
committed
build: speed up karma run by passing in list of dist files that changed
This change causes the build system to write a log file into the tmp folder after each build. This file contains command line arguments that tell karma about all the added/changed/removed files from the last build. Karma can then use this list instead of doing internal globbing which can be very expensive especially for hte dart builds that contain thousands of files. Closes angular#2437
1 parent 3e65037 commit 7fc1ee6

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

gulpfile.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,9 +416,27 @@ gulp.task('docs/angular.io', ['build/clean.docs_angular_io'], function() {
416416
// CI tests suites
417417

418418
function runKarma(configFile, done) {
419+
var fs = require('fs');
420+
var path = require('path');
419421
var cmd = process.platform === 'win32' ? 'node_modules\\.bin\\karma run ' :
420422
'node node_modules/.bin/karma run ';
421423
cmd += configFile;
424+
425+
// this file is written into the tmp folder by DestCopy broccoli plugin after each build
426+
var karmaArgsPath = path.join('tmp', 'build-log-karma-args.txt');
427+
428+
if (fs.existsSync(karmaArgsPath)) {
429+
var changedFilesArgs = fs.readFileSync(karmaArgsPath, {encoding: 'utf-8'});
430+
431+
// windows has a limit for the length of the command it can execute, so on win we check the
432+
// length of args provide them only if the length is not over the limit.
433+
// additionally, the arguments don't help the speedup the initial run, so we can safely ignore
434+
// the args when there is lots of them on all platforms
435+
if (changedFilesArgs.length > 10 && changedFilesArgs.length + cmd.length < 0x2000) {
436+
cmd += changedFilesArgs;
437+
}
438+
}
439+
422440
exec(cmd, function(e, stdout) {
423441
// ignore errors, we don't want to fail the build in the interactive (non-ci) mode
424442
// karma server will print all test failures

tools/broccoli/broccoli-dest-copy.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,20 @@ class DestCopy implements DiffingBroccoliPlugin {
3030
// TODO: what about obsolete directories? we are not cleaning those up yet
3131
fs.unlinkSync(destFilePath);
3232
});
33+
34+
35+
// Write log of added/changed/removed files to be used when we call `karma run` from gulp.
36+
var karmaArgs = '';
37+
if (treeDiff.addedPaths.length) {
38+
karmaArgs += ' --addedFiles ' + treeDiff.addedPaths.join(',');
39+
}
40+
if (treeDiff.changedPaths.length) {
41+
karmaArgs += ' --changedFiles ' + treeDiff.changedPaths.join(',');
42+
}
43+
if (treeDiff.removedPaths.length) {
44+
karmaArgs += ' --removedFiles ' + treeDiff.removedPaths.join(',')
45+
}
46+
fs.writeFileSync(path.join('tmp', 'build-log-karma-args.txt'), karmaArgs, {encoding: 'utf-8'});
3347
}
3448
}
3549

0 commit comments

Comments
 (0)