From 4971670e566ebbbd59f1a380bd464b961ec2069f Mon Sep 17 00:00:00 2001 From: Andrew Grieve Date: Wed, 15 Jan 2014 11:41:03 -0500 Subject: [PATCH] CB-5801 exec->spawn in build to make sure compile errors are shown. --- 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(-) create mode 100644 bin/templates/cordova/lib/spawn.js diff --git a/bin/templates/cordova/lib/build.js b/bin/templates/cordova/lib/build.js index 668e1a52..7ea7d094 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); + }); } /* diff --git a/bin/templates/cordova/lib/clean.js b/bin/templates/cordova/lib/clean.js index 4fc43afc..14c9b153 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() { diff --git a/bin/templates/cordova/lib/spawn.js b/bin/templates/cordova/lib/spawn.js new file mode 100644 index 00000000..cea7a06d --- /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; +} +