From cedb88a2640be49b597994ce61054c9dbca25bf6 Mon Sep 17 00:00:00 2001 From: Tim van der Meij Date: Thu, 27 Apr 2017 21:42:07 +0200 Subject: [PATCH 1/4] Port the `mozcentralbaseline` target to Gulp The baseline fix is dead code since three years, so we can safely remove it. --- gulpfile.js | 25 +++++++++++++++++++++++++ make.js | 34 +--------------------------------- 2 files changed, 26 insertions(+), 33 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 1edd8d963b6de..93971be38abba 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -43,6 +43,7 @@ var TEST_DIR = 'test/'; var EXTENSION_SRC_DIR = 'extensions/'; var BASELINE_DIR = BUILD_DIR + 'baseline/'; +var MOZCENTRAL_BASELINE_DIR = BUILD_DIR + 'mozcentral.baseline/'; var GENERIC_DIR = BUILD_DIR + 'generic/'; var COMPONENTS_DIR = BUILD_DIR + 'components/'; var SINGLE_FILE_DIR = BUILD_DIR + 'singlefile/'; @@ -1347,6 +1348,30 @@ gulp.task('dist-repo-git', ['dist-repo-prepare'], function () { gulp.task('dist', ['dist-repo-git']); +gulp.task('mozcentralbaseline', ['baseline'], function (done) { + console.log(); + console.log('### Creating mozcentral baseline environment'); + + // Create a mozcentral build. + rimraf.sync(BASELINE_DIR + BUILD_DIR); + spawnSync('gulp', ['mozcentral', '--cwd', BASELINE_DIR], {env: process.env}); + + // Copy the mozcentral build to the mozcentral baseline directory. + rimraf.sync(MOZCENTRAL_BASELINE_DIR); + mkdirp.sync(MOZCENTRAL_BASELINE_DIR); + + gulp.src([BASELINE_DIR + BUILD_DIR + 'mozcentral/**/*']) + .pipe(gulp.dest(MOZCENTRAL_BASELINE_DIR)) + .on('end', function () { + // Commit the mozcentral baseline. + spawnSync('git', ['init'], {cwd: MOZCENTRAL_BASELINE_DIR}); + spawnSync('git', ['add', '.'], {cwd: MOZCENTRAL_BASELINE_DIR}); + spawnSync('git', ['commit', '-m', 'mozcentral baseline'], + {cwd: MOZCENTRAL_BASELINE_DIR}); + done(); + }); +}); + // Getting all shelljs registered tasks and register them with gulp require('./make.js'); diff --git a/make.js b/make.js index c4f1679baecff..7030aa8fc716c 100644 --- a/make.js +++ b/make.js @@ -223,39 +223,7 @@ target.baseline = function() { }; target.mozcentralbaseline = function() { - target.baseline(); - - cd(ROOT_DIR); - - echo(); - echo('### Creating mozcentral baseline environment'); - - var BASELINE_DIR = BUILD_DIR + 'baseline'; - var MOZCENTRAL_BASELINE_DIR = BUILD_DIR + 'mozcentral.baseline'; - if (test('-d', MOZCENTRAL_BASELINE_DIR)) { - rm('-rf', MOZCENTRAL_BASELINE_DIR); - } - - cd(BASELINE_DIR); - if (test('-d', 'build')) { - rm('-rf', 'build'); - } - exec('node make mozcentral'); - - cd(ROOT_DIR); - mkdir(MOZCENTRAL_BASELINE_DIR); - cp('-Rf', BASELINE_DIR + '/build/mozcentral/*', MOZCENTRAL_BASELINE_DIR); - // fixing baseline - if (test('-f', MOZCENTRAL_BASELINE_DIR + - '/browser/extensions/pdfjs/PdfStreamConverter.js')) { - rm(MOZCENTRAL_BASELINE_DIR + - '/browser/extensions/pdfjs/PdfStreamConverter.js'); - } - - cd(MOZCENTRAL_BASELINE_DIR); - exec('git init'); - exec('git add .'); - exec('git commit -m "mozcentral baseline"'); + execGulp('mozcentralbaseline'); }; target.mozcentraldiff = function() { From f57f0698238f568a0a19350fa39259aa2f81c268 Mon Sep 17 00:00:00 2001 From: Tim van der Meij Date: Thu, 27 Apr 2017 22:59:45 +0200 Subject: [PATCH 2/4] Port the `mozcentraldiff` target to Gulp --- gulpfile.js | 31 +++++++++++++++++++++++++++++++ make.js | 29 +---------------------------- 2 files changed, 32 insertions(+), 28 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 93971be38abba..a12d6aa7dac06 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -59,6 +59,7 @@ var COMMON_WEB_FILES = [ 'web/images/*.{png,svg,gif,cur}', 'web/debugger.js' ]; +var MOZCENTRAL_DIFF_FILE = 'mozcentral.diff'; var REPO = 'git@github.com:mozilla/pdf.js.git'; var DIST_REPO_URL = 'https://github.com/mozilla/pdfjs-dist'; @@ -1372,6 +1373,36 @@ gulp.task('mozcentralbaseline', ['baseline'], function (done) { }); }); +gulp.task('mozcentraldiff', ['mozcentral', 'mozcentralbaseline'], + function (done) { + console.log(); + console.log('### Creating mozcentral diff'); + + // Create the diff between the current mozcentral build and the + // baseline mozcentral build, which both exist at this point. + // The mozcentral baseline directory is a Git repository, so we + // remove all files and copy the current mozcentral build files + // into it to create the diff. + rimraf.sync(MOZCENTRAL_BASELINE_DIR + '*'); + + gulp.src([BUILD_DIR + 'mozcentral/**/*']) + .pipe(gulp.dest(MOZCENTRAL_BASELINE_DIR)) + .on('end', function () { + spawnSync('git', ['add', '-A'], {cwd: MOZCENTRAL_BASELINE_DIR}); + var diff = spawnSync('git', + ['diff', '--binary', '--cached', '--unified=8'], + {cwd: MOZCENTRAL_BASELINE_DIR}).stdout; + + createStringSource(MOZCENTRAL_DIFF_FILE, diff) + .pipe(gulp.dest(BUILD_DIR)) + .on('end', function () { + console.log('Result diff can be found at ' + BUILD_DIR + + MOZCENTRAL_DIFF_FILE); + done(); + }); + }); +}); + // Getting all shelljs registered tasks and register them with gulp require('./make.js'); diff --git a/make.js b/make.js index 7030aa8fc716c..1263476d251a3 100644 --- a/make.js +++ b/make.js @@ -227,34 +227,7 @@ target.mozcentralbaseline = function() { }; target.mozcentraldiff = function() { - target.mozcentral(); - - cd(ROOT_DIR); - - echo(); - echo('### Creating mozcentral diff'); - - var MOZCENTRAL_DIFF = BUILD_DIR + 'mozcentral.diff'; - if (test('-f', MOZCENTRAL_DIFF)) { - rm(MOZCENTRAL_DIFF); - } - - var MOZCENTRAL_BASELINE_DIR = BUILD_DIR + 'mozcentral.baseline'; - if (!test('-d', MOZCENTRAL_BASELINE_DIR)) { - echo('mozcentral baseline was not found'); - echo('Please build one using "gulp mozcentralbaseline"'); - exit(1); - } - cd(MOZCENTRAL_BASELINE_DIR); - exec('git reset --hard'); - cd(ROOT_DIR); rm('-rf', MOZCENTRAL_BASELINE_DIR + '/*'); // trying to be safe - cd(MOZCENTRAL_BASELINE_DIR); - cp('-Rf', '../mozcentral/*', '.'); - exec('git add -A'); - exec('git diff --binary --cached --unified=8', {silent: true}).output. - to('../mozcentral.diff'); - - echo('Result diff can be found at ' + MOZCENTRAL_DIFF); + execGulp('mozcentraldiff'); }; //////////////////////////////////////////////////////////////////////////////// From 2e7ec9b666321ccbdfd01c9cb95dbe6d047ddc61 Mon Sep 17 00:00:00 2001 From: Tim van der Meij Date: Thu, 27 Apr 2017 23:16:20 +0200 Subject: [PATCH 3/4] Remove unused Gulp target for testing To run the regression tests, developers use `gulp browsertest` and the bot uses `gulp bottest`. We're not passing the `noreftest` option anywhere in the code (probably because the `bottest` command takes care of this already), so we should remove this. --- gulpfile.js | 4 ---- make.js | 6 +----- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index a12d6aa7dac06..b47592c62c5a8 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1044,10 +1044,6 @@ gulp.task('browsertest', function () { return createTestSource('browser'); }); -gulp.task('browsertest-noreftest', function () { - return createTestSource('browser (no reftest)'); -}); - gulp.task('unittest', function () { return createTestSource('unit'); }); diff --git a/make.js b/make.js index 1263476d251a3..498860459b52d 100644 --- a/make.js +++ b/make.js @@ -186,11 +186,7 @@ target.bottest = function() { // make browsertest // target.browsertest = function(options) { - if (options && options.noreftest) { - execGulp('browsertest-noreftest'); - } else { - execGulp('browsertest'); - } + execGulp('browsertest'); }; // From 61f00900d38ab1878a9275f7d06630be215ba147 Mon Sep 17 00:00:00 2001 From: Tim van der Meij Date: Thu, 27 Apr 2017 23:21:26 +0200 Subject: [PATCH 4/4] Remove `make.js` and the target fetching in `gulpfile.js` Note that we have to use `fs.writeFileSync` since `.to()` is not available anymore. Moreover, introduce `safeSpawnSync` to make sure that we check the return codes of the spawned processes properly. --- gulpfile.js | 100 ++++++++------------ make.js | 267 ---------------------------------------------------- 2 files changed, 41 insertions(+), 326 deletions(-) delete mode 100644 make.js diff --git a/gulpfile.js b/gulpfile.js index b47592c62c5a8..2ac60cbeef270 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -83,6 +83,20 @@ var DEFINES = { PDFJS_NEXT: false, }; +function safeSpawnSync(command, parameters, options) { + // Execute all commands in a shell. + options = options || {}; + options.shell = true; + + var result = spawnSync(command, parameters, options); + if (result.status !== 0) { + console.log('Error: command "' + command + '" with parameters "' + + parameters + '" exited with code ' + result.status); + process.exit(result.status); + } + return result; +} + function createStringSource(filename, content) { var source = stream.Readable({ objectMode: true }); source._read = function () { @@ -679,12 +693,13 @@ gulp.task('minified-post', ['minified-pre'], function () { // V8 chokes on very long sequences. Works around that. var optsForHugeFile = {compress: {sequences: false}}; - UglifyJS.minify(viewerFiles).code - .to(MINIFIED_DIR + '/web/pdf.viewer.js'); - UglifyJS.minify(MINIFIED_DIR + '/build/pdf.js').code - .to(MINIFIED_DIR + '/build/pdf.min.js'); - UglifyJS.minify(MINIFIED_DIR + '/build/pdf.worker.js', optsForHugeFile).code - .to(MINIFIED_DIR + '/build/pdf.worker.min.js'); + fs.writeFileSync(MINIFIED_DIR + '/web/pdf.viewer.js', + UglifyJS.minify(viewerFiles).code); + fs.writeFileSync(MINIFIED_DIR + '/build/pdf.min.js', + UglifyJS.minify(MINIFIED_DIR + '/build/pdf.js').code); + fs.writeFileSync(MINIFIED_DIR + '/build/pdf.worker.min.js', + UglifyJS.minify(MINIFIED_DIR + '/build/pdf.worker.js', + optsForHugeFile).code); console.log(); console.log('### Cleaning js files'); @@ -1220,14 +1235,14 @@ gulp.task('gh-pages-git', ['gh-pages-prepare', 'wintersmith'], function () { var VERSION = getVersionJSON().version; var reason = process.env['PDFJS_UPDATE_REASON']; - spawnSync('git', ['init'], {cwd: GH_PAGES_DIR}); - spawnSync('git', ['remote', 'add', 'origin', REPO], {cwd: GH_PAGES_DIR}); - spawnSync('git', ['add', '-A'], {cwd: GH_PAGES_DIR}); - spawnSync('git', [ + safeSpawnSync('git', ['init'], {cwd: GH_PAGES_DIR}); + safeSpawnSync('git', ['remote', 'add', 'origin', REPO], {cwd: GH_PAGES_DIR}); + safeSpawnSync('git', ['add', '-A'], {cwd: GH_PAGES_DIR}); + safeSpawnSync('git', [ 'commit', '-am', 'gh-pages site created via gulpfile.js script', '-m', 'PDF.js version ' + VERSION + (reason ? ' - ' + reason : '') ], {cwd: GH_PAGES_DIR}); - spawnSync('git', ['branch', '-m', 'gh-pages'], {cwd: GH_PAGES_DIR}); + safeSpawnSync('git', ['branch', '-m', 'gh-pages'], {cwd: GH_PAGES_DIR}); console.log(); console.log('Website built in ' + GH_PAGES_DIR); @@ -1243,7 +1258,7 @@ gulp.task('dist-repo-prepare', ['dist-pre'], function () { rimraf.sync(DIST_DIR); mkdirp.sync(DIST_DIR); - spawnSync('git', ['clone', '--depth', '1', DIST_REPO_URL, DIST_DIR]); + safeSpawnSync('git', ['clone', '--depth', '1', DIST_REPO_URL, DIST_DIR]); console.log(); console.log('### Overwriting all files'); @@ -1331,10 +1346,10 @@ gulp.task('dist-repo-git', ['dist-repo-prepare'], function () { var reason = process.env['PDFJS_UPDATE_REASON']; var message = 'PDF.js version ' + VERSION + (reason ? ' - ' + reason : ''); - spawnSync('git', ['add', '*'], {cwd: DIST_DIR}); - spawnSync('git', ['commit', '-am', message], {cwd: DIST_DIR}); - spawnSync('git', ['tag', '-a', 'v' + VERSION, '-m', message], - {cwd: DIST_DIR}); + safeSpawnSync('git', ['add', '*'], {cwd: DIST_DIR}); + safeSpawnSync('git', ['commit', '-am', message], {cwd: DIST_DIR}); + safeSpawnSync('git', ['tag', '-a', 'v' + VERSION, '-m', message], + {cwd: DIST_DIR}); console.log(); console.log('Done. Push with'); @@ -1351,7 +1366,10 @@ gulp.task('mozcentralbaseline', ['baseline'], function (done) { // Create a mozcentral build. rimraf.sync(BASELINE_DIR + BUILD_DIR); - spawnSync('gulp', ['mozcentral', '--cwd', BASELINE_DIR], {env: process.env}); + + var workingDirectory = path.resolve(process.cwd(), BASELINE_DIR); + safeSpawnSync('gulp', ['mozcentral'], + {env: process.env, cwd: workingDirectory, stdio: 'inherit'}); // Copy the mozcentral build to the mozcentral baseline directory. rimraf.sync(MOZCENTRAL_BASELINE_DIR); @@ -1361,10 +1379,10 @@ gulp.task('mozcentralbaseline', ['baseline'], function (done) { .pipe(gulp.dest(MOZCENTRAL_BASELINE_DIR)) .on('end', function () { // Commit the mozcentral baseline. - spawnSync('git', ['init'], {cwd: MOZCENTRAL_BASELINE_DIR}); - spawnSync('git', ['add', '.'], {cwd: MOZCENTRAL_BASELINE_DIR}); - spawnSync('git', ['commit', '-m', 'mozcentral baseline'], - {cwd: MOZCENTRAL_BASELINE_DIR}); + safeSpawnSync('git', ['init'], {cwd: MOZCENTRAL_BASELINE_DIR}); + safeSpawnSync('git', ['add', '.'], {cwd: MOZCENTRAL_BASELINE_DIR}); + safeSpawnSync('git', ['commit', '-m', '"mozcentral baseline"'], + {cwd: MOZCENTRAL_BASELINE_DIR}); done(); }); }); @@ -1384,8 +1402,8 @@ gulp.task('mozcentraldiff', ['mozcentral', 'mozcentralbaseline'], gulp.src([BUILD_DIR + 'mozcentral/**/*']) .pipe(gulp.dest(MOZCENTRAL_BASELINE_DIR)) .on('end', function () { - spawnSync('git', ['add', '-A'], {cwd: MOZCENTRAL_BASELINE_DIR}); - var diff = spawnSync('git', + safeSpawnSync('git', ['add', '-A'], {cwd: MOZCENTRAL_BASELINE_DIR}); + var diff = safeSpawnSync('git', ['diff', '--binary', '--cached', '--unified=8'], {cwd: MOZCENTRAL_BASELINE_DIR}).stdout; @@ -1398,39 +1416,3 @@ gulp.task('mozcentraldiff', ['mozcentral', 'mozcentralbaseline'], }); }); }); - -// Getting all shelljs registered tasks and register them with gulp -require('./make.js'); - -var gulpContext = false; -for (var taskName in global.target) { - if (taskName in gulp.tasks) { - continue; - } - - var task = (function (shellJsTask) { - return function () { - gulpContext = true; - try { - shellJsTask.call(global.target); - } finally { - gulpContext = false; - } - }; - })(global.target[taskName]); - gulp.task(taskName, task); -} - -Object.keys(gulp.tasks).forEach(function (taskName) { - var oldTask = global.target[taskName] || function () { - gulp.run(taskName); - }; - - global.target[taskName] = function (args) { - // The require('shelljs/make') import in make.js will try to execute tasks - // listed in arguments, guarding with gulpContext - if (gulpContext) { - oldTask.call(global.target, args); - } - }; -}); diff --git a/make.js b/make.js deleted file mode 100644 index 498860459b52d..0000000000000 --- a/make.js +++ /dev/null @@ -1,267 +0,0 @@ -/* Copyright 2012 Mozilla Foundation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/* eslint-env node, shelljs */ - -'use strict'; - -try { - require('shelljs/make'); -} catch (e) { - throw new Error('ShellJS is not installed. Run "npm install" to install ' + - 'all dependencies.'); -} - -var ROOT_DIR = __dirname + '/', // absolute path to project's root - BUILD_DIR = 'build/'; - -function execGulp(cmd) { - var result = exec('gulp ' + cmd); - if (result.code) { - echo('ERROR: gulp exited with ' + result.code); - exit(result.code); - } -} - -// -// make all -// -target.all = function() { - execGulp('default'); -}; - - -//////////////////////////////////////////////////////////////////////////////// -// -// Production stuff -// - -// -// make generic -// Builds the generic production viewer that should be compatible with most -// modern HTML5 browsers. -// -target.generic = function() { - execGulp('generic'); -}; - -target.components = function() { - execGulp('components'); -}; - -target.jsdoc = function() { - execGulp('jsdoc'); -}; - -// -// make web -// Generates the website for the project, by checking out the gh-pages branch -// underneath the build directory, and then moving the various viewer files -// into place. -// -target.web = function() { - execGulp('web'); -}; - -target.dist = function() { - execGulp('dist'); -}; - -target.publish = function() { - execGulp('publish'); -}; - -// -// make locale -// Creates localized resources for the viewer and extension. -// -target.locale = function() { - execGulp('locale'); -}; - -// -// make cmaps -// Compresses cmap files. Ensure that Adobe cmap download and uncompressed at -// ./external/cmaps location. -// -target.cmaps = function () { - execGulp('cmaps'); -}; - -// -// make bundle -// Bundles all source files into one wrapper 'pdf.js' file, in the given order. -// -target.bundle = function(args) { - execGulp('bundle'); -}; - -// -// make singlefile -// Concatenates pdf.js and pdf.worker.js into one big pdf.combined.js, and -// flags the script loader to not attempt to load the separate worker JS file. -// -target.singlefile = function() { - execGulp('singlefile'); -}; - -// -// make minified -// Builds the minified production viewer that should be compatible with most -// modern HTML5 browsers. -// -target.minified = function() { - execGulp('minified'); -}; - -//////////////////////////////////////////////////////////////////////////////// -// -// Extension stuff -// - -// -// make extension -// -target.extension = function() { - execGulp('extension'); -}; - -target.buildnumber = function() { - execGulp('buildnumber'); -}; - -// -// make firefox -// -target.firefox = function() { - execGulp('firefox'); -}; - -// -// make mozcentral -// -target.mozcentral = function() { - execGulp('mozcentral'); -}; - -// -// make chrome -// -target.chromium = function() { - execGulp('chromium'); -}; - -//////////////////////////////////////////////////////////////////////////////// -// -// Test stuff -// - -// -// make test -// -target.test = function() { - execGulp('test'); -}; - -// -// make bottest -// (Special tests for the Github bot) -// -target.bottest = function() { - execGulp('bottest'); -}; - -// -// make browsertest -// -target.browsertest = function(options) { - execGulp('browsertest'); -}; - -// -// make unittest -// -target.unittest = function(options, callback) { - execGulp('unittest'); -}; - -// -// make fonttest -// -target.fonttest = function(options, callback) { - execGulp('fonttest'); -}; - -// -// make botmakeref -// -target.botmakeref = function() { - execGulp('botmakeref'); -}; - -//////////////////////////////////////////////////////////////////////////////// -// -// Baseline operation -// -target.baseline = function() { - execGulp('baseline'); -}; - -target.mozcentralbaseline = function() { - execGulp('mozcentralbaseline'); -}; - -target.mozcentraldiff = function() { - execGulp('mozcentraldiff'); -}; - -//////////////////////////////////////////////////////////////////////////////// -// -// Other -// - -// -// make server -// -target.server = function () { - execGulp('server'); -}; - -// -// make lint -// -target.lint = function() { - execGulp('lint'); -}; - -// -// make clean -// -target.clean = function() { - execGulp('clean'); -}; - -// -// make makefile -// -target.makefile = function () { - execGulp('makefile'); -}; - -// -// make importl10n -// -target.importl10n = function() { - execGulp('importl10n'); -};