Advanced compilation gulp script to replace the shell script. (#3996)

This commit is contained in:
Sam El-Husseini
2020-07-01 10:55:17 -07:00
committed by GitHub
parent fcc3a09661
commit f3136e61a1
4 changed files with 60 additions and 10 deletions

1
.gitignore vendored
View File

@@ -10,6 +10,7 @@ build-debug.log
/nbproject/private/
tests/compile/main_compressed.js
tests/compile/main_compressed.js.map
tests/compile/*compiler*.jar
tests/screenshot/outputs/*
local_build/*compiler*.jar

View File

@@ -26,6 +26,7 @@ module.exports = {
buildUncompressed: buildTasks.uncompressed,
buildCompressed: buildTasks.compressed,
buildGenerators: buildTasks.generators,
buildAdvancedCompilationTest: buildTasks.advancedCompilationTest,
gitSyncDevelop: gitTasks.syncDevelop,
gitSyncMaster: gitTasks.syncMaster,
gitCreateRC: gitTasks.createRC,

View File

@@ -38,6 +38,7 @@
"test:run": "tests/run_all_tests.sh",
"test:setupselenium": "selenium-standalone install --config=./tests/scripts/selenium-config.js",
"test:startselenium": "selenium-standalone start --config=./tests/scripts/selenium-config.js",
"test:compile:advanced": "gulp buildAdvancedCompilationTest",
"typings": "gulp typings",
"updateGithubPages": "gulp gitUpdateGithubPages"
},

View File

@@ -109,21 +109,20 @@ var JSCOMP_ERROR = [
* as errors.
*/
function compile(compilerOptions, opt_verbose, opt_warnings_as_error) {
compilerOptions = compilerOptions || {};
compilerOptions.compilation_level = 'SIMPLE_OPTIMIZATIONS';
compilerOptions.warning_level = opt_verbose ? 'VERBOSE' : 'DEFAULT';
compilerOptions.language_in =
compilerOptions.language_in || 'ECMASCRIPT5_STRICT';
compilerOptions.language_out = 'ECMASCRIPT5_STRICT';
compilerOptions.rewrite_polyfills = false;
compilerOptions.hide_warnings_for = 'node_modules';
const options = {};
options.compilation_level = 'SIMPLE_OPTIMIZATIONS';
options.warning_level = opt_verbose ? 'VERBOSE' : 'DEFAULT';
options.language_in = 'ECMASCRIPT5_STRICT';
options.language_out = 'ECMASCRIPT5_STRICT';
options.rewrite_polyfills = false;
options.hide_warnings_for = 'node_modules';
if (opt_warnings_as_error) {
compilerOptions.jscomp_error = JSCOMP_ERROR;
options.jscomp_error = JSCOMP_ERROR;
}
const platform = ['native', 'java', 'javascript'];
return closureCompiler(compilerOptions, { platform });
return closureCompiler({...options, ...compilerOptions}, { platform });
}
/**
@@ -431,6 +430,53 @@ function buildLangfiles(done) {
done();
};
/**
* This task builds Blockly core, blocks and generators together and uses
* closure compiler's ADVANCED_COMPILATION mode.
*/
function buildAdvancedCompilationTest() {
const srcs = [
'tests/compile/main.js',
'tests/blocks/test_blocks.js',
'core/**/**/*.js',
'blocks/*.js',
'generators/**/*.js'];
return gulp.src(maybeAddClosureLibrary(srcs), {base: './'})
.pipe(stripApacheLicense())
.pipe(gulp.sourcemaps.init())
// Directories in Blockly are used to group similar files together
// but are not used to limit access with @package, instead the
// method means something is internal to Blockly and not a public
// API.
// Flatten all files so they're in the same directory, but ensure that
// files with the same name don't conflict.
.pipe(gulp.rename(function (p) {
if (p.dirname.indexOf('core') === 0) {
var dirname = p.dirname.replace(
new RegExp(path.sep.replace(/\\/, '\\\\'), "g"), "-");
p.dirname = "";
p.basename = dirname + "-" + p.basename;
}
}))
.pipe(compile({
dependency_mode: 'PRUNE',
compilation_level: 'ADVANCED_OPTIMIZATIONS',
entry_point: './tests/compile/main.js',
js_output_file: 'main_compressed.js',
externs: ['./externs/svg-externs.js', './externs/goog-externs.js'],
language_in:
argv.closureLibrary ? 'ECMASCRIPT_2015' : 'ECMASCRIPT5_STRICT'
}, argv.verbose, argv.strict))
.pipe(gulp.sourcemaps.mapSources(function (sourcePath, file) {
return sourcePath.replace(/-/g, '/');
}))
.pipe(gulp.sourcemaps.write('.', {
includeContent: false,
sourceRoot: '../../'
}))
.pipe(gulp.dest('./tests/compile/'));
}
/**
* This tasks builds Blockly's core files:
* blockly_compressed.js
@@ -469,4 +515,5 @@ module.exports = {
uncompressed: buildUncompressed,
compressed: buildCompressed,
generators: buildGenerators,
advancedCompilationTest: buildAdvancedCompilationTest,
}