Skip to content

Commit

Permalink
Run tasks only once
Browse files Browse the repository at this point in the history
  • Loading branch information
fortuna committed Aug 30, 2016
1 parent 5bc6060 commit 907fa6f
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 32 deletions.
76 changes: 44 additions & 32 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,18 @@ module.exports = function(grunt) {
return tasks;
}

grunt.registerTask('base', [
// Returns a task name that will run the input task only once if
// called multiple times.
function makeRunOnce(taskName) {
return 'run-once:' + taskName;
}

// Register a task, making sure subtasks only run once.
function registerTask(grunt, taskName, subTasks) {
return grunt.registerTask(taskName, subTasks.map(makeRunOnce));
}

registerTask(grunt, 'base', [
'copy:resources',
'copy:devGenericCore',
'ts',
Expand All @@ -1043,95 +1054,95 @@ module.exports = function(grunt) {
'browserify:cloudSocialProviderFreedomModule',
'browserify:digitalOceanFreedomModule'
]);
grunt.registerTask('echoServer', [
registerTask(grunt, 'echoServer', [
'base',
'browserify:echoServerFreedomModule',
'copy:libsForEchoServerChromeApp',
'copy:libsForEchoServerFirefoxApp',
'copy:libsForEchoServerNode'
]);
grunt.registerTask('copypasteChat', [
registerTask(grunt, 'copypasteChat', [
'base',
'browserify:copypasteChatFreedomModule',
'browserify:copypasteChatMain',
'copy:libsForCopypasteChatChromeApp',
'copy:libsForCopypasteChatFirefoxApp',
'copy:libsForCopypasteChatWebApp'
]);
grunt.registerTask('copypasteSocks', [
registerTask(grunt, 'copypasteSocks', [
'base',
'browserify:copypasteSocksFreedomModule',
'browserify:copypasteSocksMain',
'vulcanize:copypasteSocks',
'copy:libsForCopyPasteSocksChromeApp',
'copy:libsForCopyPasteSocksFirefoxApp'
]);
grunt.registerTask('deployer', [
registerTask(grunt, 'deployer', [
'base',
'browserify:deployerFreedomModule',
'copy:libsForDeployerChromeApp',
'copy:libsForDeployerFirefoxApp'
]);
grunt.registerTask('simpleChat', [
registerTask(grunt, 'simpleChat', [
'base',
'browserify:simpleChatFreedomModule',
'browserify:simpleChatMain',
'copy:libsForSimpleChatChromeApp',
'copy:libsForSimpleChatFirefoxApp',
'copy:libsForSimpleChatWebApp'
]);
grunt.registerTask('simpleSocks', [
registerTask(grunt, 'simpleSocks', [
'base',
'browserify:simpleSocksFreedomModule',
'copy:libsForSimpleSocksChromeApp',
'copy:libsForSimpleSocksFirefoxApp',
'copy:libsForSimpleSocksNode'
]);
grunt.registerTask('uprobe', [
registerTask(grunt, 'uprobe', [
'base',
'browserify:uprobeFreedomModule',
'copy:libsForUprobeChromeApp',
'copy:libsForUprobeFirefoxApp'
]);
grunt.registerTask('zork', [
registerTask(grunt, 'zork', [
'base',
'browserify:zorkFreedomModule',
'copy:libsForZorkChromeApp',
'copy:libsForZorkFirefoxApp',
'copy:libsForZorkNode',
'exec:installFreedomForNodeForZork'
]);
grunt.registerTask('version_file', [
registerTask(grunt, 'version_file', [
'gitinfo',
'string-replace:version'
]);
grunt.registerTask('build_chrome_app', [
registerTask(grunt, 'build_chrome_app', [
'base',
'copy:chrome_app'
].concat(fullyVulcanize('chrome/app/polymer', 'ext-missing', 'vulcanized')));
grunt.registerTask('build_chrome_ext', [
registerTask(grunt, 'build_chrome_ext', [
'base',
'copy:chrome_extension',
'copy:chrome_extension_additional',
'browserify:chromeExtMain',
'browserify:chromeContext'
].concat(fullyVulcanize('chrome/extension/generic_ui/polymer', 'root', 'vulcanized', true)));

grunt.registerTask('build_chrome', [
registerTask(grunt, 'build_chrome', [
'build_chrome_app',
'build_chrome_ext'
]);

// Firefox build tasks.
grunt.registerTask('build_firefox', [
registerTask(grunt, 'build_firefox', [
'base',
'copy:firefox',
'copy:firefox_additional',
'browserify:firefoxContext'
].concat(fullyVulcanize('firefox/data/generic_ui/polymer', 'root', 'vulcanized', true)));

// CCA build tasks
grunt.registerTask('build_cca', [
registerTask(grunt, 'build_cca', [
'base',
'copy:cca',
'copy:cca_additional',
Expand All @@ -1140,7 +1151,7 @@ module.exports = function(grunt) {
].concat(fullyVulcanize('cca/app/generic_ui/polymer', 'root', 'vulcanized', true)));

// Mobile OS build tasks
grunt.registerTask('build_android', [
registerTask(grunt, 'build_android', [
'exec:cleanAndroid',
'build_cca',
'exec:ccaCreateDev',
Expand All @@ -1150,7 +1161,7 @@ module.exports = function(grunt) {
'exec:ccaBuildAndroid',
'exec:androidReplaceXwalkDev'
]);
grunt.registerTask('release_android', [
registerTask(grunt, 'release_android', [
'build_cca',
'copy:dist',
'exec:ccaCreateDist',
Expand All @@ -1163,47 +1174,47 @@ module.exports = function(grunt) {
]);

// Emulate the mobile client for android
grunt.registerTask('emulate_android', [
registerTask(grunt, 'emulate_android', [
'build_android',
'exec:ccaEmulateAndroid'
]);

grunt.registerTask('build_ios', [
registerTask(grunt, 'build_ios', [
'exec:cleanIos',
'build_cca',
'exec:ccaCreateIosDev',
'exec:ccaAddPluginsIosBuild',
'exec:addIosrtcHook',
'exec:ccaPrepareIosDev'
]);
grunt.registerTask('test_chrome', [
registerTask(grunt, 'test_chrome', [
'build_chrome',
'browserify:chromeExtensionCoreConnectorSpec',
'jasmine:chrome_core_connector'
]);
grunt.registerTask('tcpIntegrationTestModule', [
registerTask(grunt, 'tcpIntegrationTestModule', [
'base',
'copy:libsForIntegrationTcp',
'browserify:integrationTcpFreedomModule',
'browserify:integrationTcpSpec'
]);
grunt.registerTask('tcpIntegrationTest', [
registerTask(grunt, 'tcpIntegrationTest', [
'tcpIntegrationTestModule',
'jasmine_chromeapp:tcp'
]);
grunt.registerTask('socksEchoIntegrationTestModule', [
registerTask(grunt, 'socksEchoIntegrationTestModule', [
'base',
'copy:libsForIntegrationSocksEcho',
'browserify:integrationSocksEchoFreedomModule',
'browserify:integrationSocksEchoChurnSpec',
'browserify:integrationSocksEchoNochurnSpec',
'browserify:integrationSocksEchoSlowSpec'
]);
grunt.registerTask('socksEchoIntegrationTest', [
registerTask(grunt, 'socksEchoIntegrationTest', [
'socksEchoIntegrationTestModule',
'jasmine_chromeapp:socksEcho'
]);
grunt.registerTask('unit_test_nobuild', _.flatten([].concat(
registerTask(grunt, 'unit_test_nobuild', _.flatten([].concat(
Rule.getTests('src', 'lib', ['build-tools', 'integration-tests']),
Rule.getTests('src', 'generic_core'),
Rule.getTests('src', 'generic_ui/scripts')
Expand All @@ -1212,40 +1223,40 @@ module.exports = function(grunt) {
})
));

grunt.registerTask('unit_test', [
registerTask(grunt, 'unit_test', [
'base',
'unit_test_nobuild'
]);
// TODO: add test_chrome once it passes reliably
grunt.registerTask('integration_test', [
registerTask(grunt, 'integration_test', [
'tcpIntegrationTest',
'socksEchoIntegrationTest'
]);
grunt.registerTask('test', [
registerTask(grunt, 'test', [
'unit_test',
'integration_test'
]);
// Builds all code, including the "dist" build, but skips
// iOS and Android as well as
// ts-linting and testing which can be annoying and slow.
// We added jshint here because catches hard syntax errors, etc.
grunt.registerTask('build', [
registerTask(grunt, 'build', [
'build_chrome',
'build_firefox',
'build_cca',
'jshint',
'copy:dist',
'jpm:xpi'
]);
grunt.registerTask('lint', ['tslint']);
registerTask(grunt, 'lint', ['tslint']);
// This is run prior to releasing uProxy and, in addition to
// building, tests and lints all code.
grunt.registerTask('dist', [
registerTask(grunt, 'dist', [
'build',
'lint',
'test'
]);
grunt.registerTask('default', ['build']);
registerTask(grunt, 'default', ['build']);

//-------------------------------------------------------------------------
grunt.loadNpmTasks('grunt-browserify');
Expand All @@ -1259,6 +1270,7 @@ module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-gitinfo');
grunt.loadNpmTasks('grunt-jasmine-chromeapp');
grunt.loadNpmTasks('grunt-jpm');
grunt.loadNpmTasks('grunt-run-once');
grunt.loadNpmTasks('grunt-string-replace');
grunt.loadNpmTasks('grunt-ts');
grunt.loadNpmTasks('grunt-tslint');
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"grunt-gitinfo": "^0.1.7",
"grunt-jasmine-chromeapp": "git://github.com/uproxy/grunt-jasmine-chromeapp",
"grunt-jpm": "^0.1.3",
"grunt-run-once": "^0.2.0",
"grunt-string-replace": "^1.0.0",
"grunt-subgrunt": "^1.2.0",
"grunt-template-jasmine-istanbul": "^0.3.0",
Expand Down

0 comments on commit 907fa6f

Please sign in to comment.