You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by na...@apache.org on 2014/02/03 19:37:27 UTC
[14/33] git commit: CB-5801 exec->spawn in build to make sure compile
errors are shown.
CB-5801 exec->spawn in build to make sure compile errors are shown.
Project: http://git-wip-us.apache.org/repos/asf/cordova-amazon-fireos/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-amazon-fireos/commit/acf8a561
Tree: http://git-wip-us.apache.org/repos/asf/cordova-amazon-fireos/tree/acf8a561
Diff: http://git-wip-us.apache.org/repos/asf/cordova-amazon-fireos/diff/acf8a561
Branch: refs/heads/master
Commit: acf8a56159d65165bc97496131dd1f8143975566
Parents: 185547e
Author: Andrew Grieve <ag...@chromium.org>
Authored: Wed Jan 15 11:41:03 2014 -0500
Committer: Archana Naik <na...@lab126.com>
Committed: Fri Jan 31 14:59:18 2014 -0800
----------------------------------------------------------------------
bin/templates/cordova/lib/build.js | 21 +++++++---------
bin/templates/cordova/lib/clean.js | 6 ++---
bin/templates/cordova/lib/spawn.js | 43 +++++++++++++++++++++++++++++++++
3 files changed, 55 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-amazon-fireos/blob/acf8a561/bin/templates/cordova/lib/build.js
----------------------------------------------------------------------
diff --git a/bin/templates/cordova/lib/build.js b/bin/templates/cordova/lib/build.js
index f0adb37..7ea7d09 100644
--- a/bin/templates/cordova/lib/build.js
+++ b/bin/templates/cordova/lib/build.js
@@ -20,9 +20,9 @@
*/
var shell = require('shelljs'),
- exec = require('./exec'),
- Q = require('q'),
clean = require('./clean'),
+ spawn = require('./spawn'),
+ Q = require('q'),
path = require('path'),
fs = require('fs'),
ROOT = path.join(__dirname, '..', '..');
@@ -34,13 +34,13 @@ var shell = require('shelljs'),
module.exports.run = function(build_type) {
//default build type
build_type = typeof build_type !== 'undefined' ? build_type : "--debug";
- var cmd;
+ var args;
switch(build_type) {
case '--debug' :
- cmd = 'ant debug -f ' + path.join(ROOT, 'build.xml');
+ args = ['debug', '-f', path.join(ROOT, 'build.xml')];
break;
case '--release' :
- cmd = 'ant release -f ' + path.join(ROOT, 'build.xml');
+ args = ['release', '-f', path.join(ROOT, 'build.xml')];
break;
case '--nobuild' :
console.log('Skipping build...');
@@ -48,13 +48,10 @@ module.exports.run = function(build_type) {
default :
return Q.reject('Build option \'' + build_type + '\' not recognized.');
}
- if(cmd) {
- return clean.run() // TODO: Can we stop cleaning every time and let ant build incrementally?
- .then(function() {
- return exec(cmd);
- });
- }
- return Q();
+ return clean.run() // TODO: Can we stop cleaning every time and let ant build incrementally?
+ .then(function() {
+ return spawn('ant', args);
+ });
}
/*
http://git-wip-us.apache.org/repos/asf/cordova-amazon-fireos/blob/acf8a561/bin/templates/cordova/lib/clean.js
----------------------------------------------------------------------
diff --git a/bin/templates/cordova/lib/clean.js b/bin/templates/cordova/lib/clean.js
index 0f955f6..14c9b15 100644
--- a/bin/templates/cordova/lib/clean.js
+++ b/bin/templates/cordova/lib/clean.js
@@ -19,16 +19,16 @@
under the License.
*/
-var exec = require('./exec'),
+var spawn = require('./spawn'),
path = require('path'),
- ROOT = path.join(__dirname, '..', '..');
+ ROOT = path.join(__dirname, '..', '..');
/*
* Cleans the project using ant
* Returns a promise.
*/
module.exports.run = function() {
- return exec('ant clean -f ' + path.join(ROOT, 'build.xml'));
+ return spawn('ant', ['clean', '-f', path.join(ROOT, 'build.xml')]);
}
module.exports.help = function() {
http://git-wip-us.apache.org/repos/asf/cordova-amazon-fireos/blob/acf8a561/bin/templates/cordova/lib/spawn.js
----------------------------------------------------------------------
diff --git a/bin/templates/cordova/lib/spawn.js b/bin/templates/cordova/lib/spawn.js
new file mode 100644
index 0000000..cea7a06
--- /dev/null
+++ b/bin/templates/cordova/lib/spawn.js
@@ -0,0 +1,43 @@
+#!/usr/bin/env node
+
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you 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.
+*/
+
+var child_process = require('child_process'),
+ Q = require('q');
+
+// Takes a command and optional current working directory.
+module.exports = function(cmd, args, opt_cwd) {
+ var d = Q.defer();
+ try {
+ var child = child_process.spawn(cmd, args, {cwd: opt_cwd, stdio: 'inherit'});
+ child.on('exit', function(code) {
+ if (code) {
+ d.reject('Error code ' + code + ' for command: ' + cmd + ' with args: ' + args);
+ } else {
+ d.resolve();
+ }
+ });
+ } catch(e) {
+ console.error('error caught: ' + e);
+ d.reject(e);
+ }
+ return d.promise;
+}
+