Skip to content

Commit

Permalink
fix race deletions of polyfill folders to accomodate includePolyfill …
Browse files Browse the repository at this point in the history
…on more than just the main binary (#2880)
  • Loading branch information
erwinmombay committed Apr 14, 2016
1 parent 8fe8463 commit 3181cbb
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 13 deletions.
24 changes: 17 additions & 7 deletions build-system/tasks/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,26 @@ exports.closureCompile = function(entryModuleFilename, outputDir,
});
};

function cleanupBuildDir() {
fs.mkdirsSync('build/cc');
rimraf.sync('build/fake-module');
fs.mkdirsSync('build/fake-module/third_party/babel');
fs.mkdirsSync('build/fake-module/src/polyfills/');
}
exports.cleanupBuildDir = cleanupBuildDir;

function compile(entryModuleFilename, outputDir,
outputFilename, options) {
return new Promise(function(resolve, reject) {
var intermediateFilename = 'build/cc/' +
entryModuleFilename.replace(/\//g, '_').replace(/^\./, '');
console./*OK*/log('Starting closure compiler for ', entryModuleFilename);
fs.mkdirsSync('build/cc');
rimraf.sync('build/fake-module');
fs.mkdirsSync('build/fake-module/third_party/babel');
fs.mkdirsSync('build/fake-module/src/polyfills/');
console./*OK*/log('Starting closure compiler for', entryModuleFilename);

// If undefined/null or false then we're ok executing the deletions
// and mkdir.
if (!options.preventRemoveAndMakeDir) {
cleanupBuildDir();
}
var unneededFiles = [
'build/fake-module/third_party/babel/custom-babel-helpers.js',
];
Expand Down Expand Up @@ -187,8 +197,8 @@ function compile(entryModuleFilename, outputDir,
.pipe(replace(/\$internalRuntimeToken\$/g, internalRuntimeToken))
.pipe(gulp.dest(outputDir))
.on('end', function() {
console./*OK*/log('Compiled ', entryModuleFilename, 'to',
outputDir + '/' + outputFilename, 'via', intermediateFilename);
console./*OK*/log('Compiled', entryModuleFilename, 'to',
outputDir + outputFilename, 'via', intermediateFilename);
gulp.src(intermediateFilename + '.map')
.pipe(rename(outputFilename + '.map'))
.pipe(gulp.dest(outputDir))
Expand Down
22 changes: 16 additions & 6 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var babel = require('babelify');
var browserify = require('browserify');
var buffer = require('vinyl-buffer');
var closureCompile = require('./build-system/tasks/compile').closureCompile;
var cleanupBuildDir = require('./build-system/tasks/compile').cleanupBuildDir;
var cssnano = require('cssnano');
var fs = require('fs-extra');
var gulp = $$.help(require('gulp'));
Expand Down Expand Up @@ -122,8 +123,9 @@ function polyfillsForTests() {
*
* @param {boolean} watch
* @param {boolean} shouldMinify
* @param {boolean=} opt_preventRemoveAndMakeDir
*/
function compile(watch, shouldMinify) {
function compile(watch, shouldMinify, opt_preventRemoveAndMakeDir) {
compileCss();
// For compilation with babel we start with the amp-babel entry point,
// but then rename to the amp.js which we've been using all along.
Expand All @@ -132,6 +134,7 @@ function compile(watch, shouldMinify) {
minifiedName: 'v0.js',
includePolyfills: true,
watch: watch,
preventRemoveAndMakeDir: opt_preventRemoveAndMakeDir,
minify: shouldMinify,
// If there is a sync JS error during initial load,
// at least try to unhide the body.
Expand All @@ -147,7 +150,8 @@ function compile(watch, shouldMinify) {
compileJs('./3p/', 'integration.js', './dist.3p/' + internalRuntimeVersion, {
minifiedName: 'f.js',
watch: watch,
minify: shouldMinify
minify: shouldMinify,
preventRemoveAndMakeDir: opt_preventRemoveAndMakeDir,
});
thirdPartyBootstrap(watch, shouldMinify);
}
Expand Down Expand Up @@ -266,6 +270,7 @@ function buildExtension(name, version, hasCss, options) {
function buildExtensionJs(path, name, version, options) {
compileJs(path + '/', name + '.js', './dist/v0', {
watch: options.watch,
preventRemoveAndMakeDir: options.preventRemoveAndMakeDir,
minify: options.minify,
toName: name + '-' + version + '.max.js',
minifiedName: name + '-' + version + '.js',
Expand All @@ -291,10 +296,11 @@ function build() {
*/
function dist() {
process.env.NODE_ENV = 'production';
compile(false, true);
buildExtensions({minify: true});
buildExperiments({minify: true, watch: false});
buildLoginDone({minify: true, watch: false});
cleanupBuildDir();
compile(false, true, true);
buildExtensions({minify: true, preventRemoveAndMakeDir: true});
buildExperiments({minify: true, watch: false, preventRemoveAndMakeDir: true});
buildLoginDone({minify: true, watch: false, preventRemoveAndMakeDir: true});
}

/**
Expand Down Expand Up @@ -600,7 +606,9 @@ function buildExperiments(options) {
compileJs('./build/experiments/', builtName, './dist.tools/experiments/', {
watch: false,
minify: options.minify || argv.minify,
includePolyfills: true,
minifiedName: minifiedName,
preventRemoveAndMakeDir: options.preventRemoveAndMakeDir,
});
});
}
Expand Down Expand Up @@ -675,8 +683,10 @@ function buildLoginDoneVersion(version, options) {
.on('end', function() {
compileJs('./build/all/v0/', builtName, './dist/v0/', {
watch: false,
includePolyfills: true,
minify: options.minify || argv.minify,
minifiedName: minifiedName,
preventRemoveAndMakeDir: options.preventRemoveAndMakeDir,
latestName: latestName,
});
});
Expand Down

0 comments on commit 3181cbb

Please sign in to comment.