diff --git a/gulpfile.js b/gulpfile.js index a176456e9..ce56fd745 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -23,6 +23,7 @@ var gutil = require('gulp-util'); var rename = require('gulp-rename'); var replace = require('gulp-replace'); var mkdirp = require('mkdirp'); +var path = require('path'); var rimraf = require('rimraf'); var runSequence = require('run-sequence'); var stream = require('stream'); @@ -40,6 +41,7 @@ var L10N_DIR = 'l10n/'; var TEST_DIR = 'test/'; var EXTENSION_SRC_DIR = 'extensions/'; +var BASELINE_DIR = BUILD_DIR + 'baseline/'; var GENERIC_DIR = BUILD_DIR + 'generic/'; var COMPONENTS_DIR = BUILD_DIR + 'components/'; var SINGLE_FILE_DIR = BUILD_DIR + 'singlefile/'; @@ -956,6 +958,42 @@ gulp.task('botmakeref', function (done) { }); }); +gulp.task('baseline', function (done) { + console.log(); + console.log('### Creating baseline environment'); + + var baselineCommit = process.env['BASELINE']; + if (!baselineCommit) { + done(new Error('Missing baseline commit. Specify the BASELINE variable.')); + return; + } + + var initializeCommand = 'git fetch origin'; + if (!checkDir(BASELINE_DIR)) { + mkdirp.sync(BASELINE_DIR); + initializeCommand = 'git clone ../../ .'; + } + + var workingDirectory = path.resolve(process.cwd(), BASELINE_DIR); + exec(initializeCommand, { cwd: workingDirectory }, function (error) { + if (error) { + done(new Error('Baseline clone/fetch failed.')); + return; + } + + exec('git checkout ' + baselineCommit, { cwd: workingDirectory }, + function (error) { + if (error) { + done(new Error('Baseline commit checkout failed.')); + return; + } + + console.log('Baseline commit "' + baselineCommit + '" checked out.'); + done(); + }); + }); +}); + gulp.task('unittestcli', function (done) { var args = ['JASMINE_CONFIG_PATH=test/unit/clitests.json']; var testProcess = spawn('node_modules/.bin/jasmine', args, diff --git a/make.js b/make.js index 9e2afc789..b3e1e2ca0 100644 --- a/make.js +++ b/make.js @@ -498,31 +498,7 @@ target.botmakeref = function() { // Baseline operation // target.baseline = function() { - cd(ROOT_DIR); - - echo(); - echo('### Creating baseline environment'); - - var baselineCommit = env['BASELINE']; - if (!baselineCommit) { - echo('Baseline commit is not provided. Please specify BASELINE variable'); - exit(1); - } - - if (!test('-d', BUILD_DIR)) { - mkdir(BUILD_DIR); - } - - var BASELINE_DIR = BUILD_DIR + 'baseline'; - if (test('-d', BASELINE_DIR)) { - cd(BASELINE_DIR); - exec('git fetch origin'); - } else { - cd(BUILD_DIR); - exec('git clone .. baseline'); - cd(ROOT_DIR + BASELINE_DIR); - } - exec('git checkout ' + baselineCommit); + execGulp('baseline'); }; target.mozcentralbaseline = function() {