You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by sh...@apache.org on 2017/05/30 22:23:23 UTC

ios commit: CB-12856 - Skip CocoaPods check_reqs if on non-darwin (macOS) platform

Repository: cordova-ios
Updated Branches:
  refs/heads/master a9532aed0 -> 08af7f2ca


CB-12856 - Skip CocoaPods check_reqs if on non-darwin (macOS) platform

 This closes #313


Project: http://git-wip-us.apache.org/repos/asf/cordova-ios/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-ios/commit/08af7f2c
Tree: http://git-wip-us.apache.org/repos/asf/cordova-ios/tree/08af7f2c
Diff: http://git-wip-us.apache.org/repos/asf/cordova-ios/diff/08af7f2c

Branch: refs/heads/master
Commit: 08af7f2ca4a1b95a1e17b8aed82682796911bac0
Parents: a9532ae
Author: Shazron Abdullah <sh...@gmail.com>
Authored: Thu May 25 17:41:29 2017 -0700
Committer: Shazron Abdullah <sh...@gmail.com>
Committed: Tue May 30 15:23:13 2017 -0700

----------------------------------------------------------------------
 .jshintrc                                     |   3 +-
 bin/lib/check_reqs.js                         | 109 ++++++++++++---------
 bin/templates/scripts/cordova/lib/Podfile.js  |  41 +++++---
 tests/spec/unit/Api.spec.js                   |  68 +++++++++++++
 tests/spec/unit/Plugman/pluginHandler.spec.js |   4 +-
 5 files changed, 160 insertions(+), 65 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/08af7f2c/.jshintrc
----------------------------------------------------------------------
diff --git a/.jshintrc b/.jshintrc
index f55d504..d18f0a1 100644
--- a/.jshintrc
+++ b/.jshintrc
@@ -7,5 +7,6 @@
   , "indent": 4
   , "unused": "vars"
   , "latedef": "nofunc"
-  , "esversion": "6"
+  , "jasmine": true
+  , "esversion": 6
 }

http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/08af7f2c/bin/lib/check_reqs.js
----------------------------------------------------------------------
diff --git a/bin/lib/check_reqs.js b/bin/lib/check_reqs.js
index ae21f98..97877af 100644
--- a/bin/lib/check_reqs.js
+++ b/bin/lib/check_reqs.js
@@ -16,30 +16,33 @@
        specific language governing permissions and limitations
        under the License.
 */
+'use strict';
 
-var Q     = require('q'),
+const Q   = require('q'),
     shell = require('shelljs'),
-    util = require('util'),
+    util  = require('util'),
     versions = require('./versions');
 
-var XCODEBUILD_MIN_VERSION = '7.0.0';
-var XCODEBUILD_NOT_FOUND_MESSAGE =
+const SUPPORTED_OS_PLATFORMS = [ 'darwin' ];
+
+const XCODEBUILD_MIN_VERSION = '7.0.0';
+const XCODEBUILD_NOT_FOUND_MESSAGE =
     'Please install version ' + XCODEBUILD_MIN_VERSION + ' or greater from App Store';
 
-var IOS_DEPLOY_MIN_VERSION = '1.9.0';
-var IOS_DEPLOY_NOT_FOUND_MESSAGE =
+const IOS_DEPLOY_MIN_VERSION = '1.9.0';
+const IOS_DEPLOY_NOT_FOUND_MESSAGE =
     'Please download, build and install version ' + IOS_DEPLOY_MIN_VERSION + ' or greater' +
     ' from https://github.com/phonegap/ios-deploy into your path, or do \'npm install -g ios-deploy\'';
 
-var COCOAPODS_MIN_VERSION = '1.0.1';
-var COCOAPODS_NOT_FOUND_MESSAGE =
+const COCOAPODS_MIN_VERSION = '1.0.1';
+const COCOAPODS_NOT_FOUND_MESSAGE =
     'Please install version ' + COCOAPODS_MIN_VERSION + ' or greater from https://cocoapods.org/';
-var COCOAPODS_NOT_SYNCED_MESSAGE =
+const COCOAPODS_NOT_SYNCED_MESSAGE =
     'The CocoaPods repo has not been synced yet, this will take a long time (approximately 500MB as of Sept 2016). Please run `pod setup` first to sync the repo.';
-var COCOAPODS_SYNCED_MIN_SIZE = 475; // in megabytes
-var COCOAPODS_SYNC_ERROR_MESSAGE =
+const COCOAPODS_SYNCED_MIN_SIZE = 475; // in megabytes
+const COCOAPODS_SYNC_ERROR_MESSAGE =
     'The CocoaPods repo has been created, but there appears to be a sync error. The repo size should be at least ' + COCOAPODS_SYNCED_MIN_SIZE + '. Please run `pod setup --verbose` to sync the repo.';
-var COCOAPODS_REPO_NOT_FOUND_MESSAGE = 'The CocoaPods repo at ~/.cocoapods was not found.';
+const COCOAPODS_REPO_NOT_FOUND_MESSAGE = 'The CocoaPods repo at ~/.cocoapods was not found.';
 
 /**
  * Checks if xcode util is available
@@ -59,13 +62,25 @@ module.exports.check_ios_deploy = function () {
 
 module.exports.check_os = function () {
     // Build iOS apps available for OSX platform only, so we reject on others platforms
-    return process.platform === 'darwin' ?
+    return os_platform_is_supported() ?
         Q.resolve(process.platform) :
-        Q.reject('Cordova tooling for iOS requires Apple OS X');
+        Q.reject('Cordova tooling for iOS requires Apple macOS');
 };
 
-function check_cocoapod_tool() {
-    return checkTool('pod', COCOAPODS_MIN_VERSION, COCOAPODS_NOT_FOUND_MESSAGE, 'CocoaPods');
+function os_platform_is_supported() {
+    return (SUPPORTED_OS_PLATFORMS.indexOf(process.platform) != -1);
+}
+
+function check_cocoapod_tool(toolChecker) {
+    toolChecker = toolChecker || checkTool;
+    if (os_platform_is_supported()) { // CB-12856
+        return toolChecker('pod', COCOAPODS_MIN_VERSION, COCOAPODS_NOT_FOUND_MESSAGE, 'CocoaPods');
+    } else {
+        return Q.resolve({ 
+            'ignore': true, 
+            'ignoreMessage': `CocoaPods check and installation ignored on ${process.platform}`
+        });
+    }   
 }
 
 /**
@@ -74,23 +89,25 @@ function check_cocoapod_tool() {
  */
 module.exports.check_cocoapods_repo_size = function () {
     return check_cocoapod_tool()
-    .then(function() {
+    .then(function(toolOptions) {
         // check size of ~/.cocoapods repo
-        var commandString = util.format('du -sh %s/.cocoapods', process.env.HOME);
-        var command = shell.exec(commandString,  { silent:true });
-        if (command.code !== 0) { // error, perhaps not found 
+        let commandString = util.format('du -sh %s/.cocoapods', process.env.HOME);
+        let command = shell.exec(commandString,  { silent:true });
+        // command.output is e.g "750M   path/to/.cocoapods", we just scan the number
+        let size = toolOptions.ignore? 0 : parseFloat(command.output);
+
+        if (toolOptions.ignore || command.code === 0) { // success, parse output
+            return Q.resolve(size, toolOptions);
+        } else { // error, perhaps not found 
             return Q.reject(util.format('%s (%s)', COCOAPODS_REPO_NOT_FOUND_MESSAGE, command.output));
-        } else { // success, parse output
-            // command.output is e.g "750M   path/to/.cocoapods", we just scan the number
-            return Q.resolve(parseFloat(command.output));
         }
     })
-    .then(function(repoSize) {
-        if (COCOAPODS_SYNCED_MIN_SIZE > repoSize) {
-            return Q.reject(COCOAPODS_SYNC_ERROR_MESSAGE);
+    .then(function(repoSize, toolOptions) {
+        if (toolOptions.ignore || COCOAPODS_SYNCED_MIN_SIZE <= repoSize) { // success, expected size
+            return Q.resolve(toolOptions);
         } else {
-            return Q.resolve();
-        }
+            return Q.reject(COCOAPODS_SYNC_ERROR_MESSAGE);
+        }        
     });
 };
 
@@ -98,19 +115,18 @@ module.exports.check_cocoapods_repo_size = function () {
  * Checks if cocoapods is available, and whether the repo is synced (because it takes a long time to download)
  * @return {Promise} Returns a promise either resolved or rejected
  */
-module.exports.check_cocoapods = function () {
-    return check_cocoapod_tool()
+module.exports.check_cocoapods = function (toolChecker) {
+    return check_cocoapod_tool(toolChecker)
     // check whether the cocoapods repo has been synced through `pod repo` command
     // a value of '0 repos' means it hasn't been synced
-    .then(function() {
-        var code = shell.exec('pod repo | grep -e "^0 repos"',  { silent:true }).code;
-        return Q.resolve(code !== 0); // non-zero means it is synced (has 1 repo at least)
-    })
-    .then(function(repoIsSynced) {
-        if (repoIsSynced) {
+    .then(function(toolOptions) {
+        let code = shell.exec('pod repo | grep -e "^0 repos"',  { silent:true }).code;
+        let repoIsSynced = (code !== 0);
+
+        if (toolOptions.ignore || repoIsSynced) {
             // return check_cocoapods_repo_size();
             // we could check the repo size above, but it takes too long.
-            return Q.resolve();
+            return Q.resolve(toolOptions);
         } else {
             return Q.reject(COCOAPODS_NOT_SYNCED_MESSAGE);
         }
@@ -129,15 +145,16 @@ function checkTool (tool, minVersion, message, toolFriendlyName) {
     toolFriendlyName = toolFriendlyName || tool;
 
     // Check whether tool command is available at all
-    var tool_command = shell.which(tool);
+    let tool_command = shell.which(tool);
     if (!tool_command) {
         return Q.reject(toolFriendlyName + ' was not found. ' + (message || ''));
     }
+    
     // check if tool version is greater than specified one
     return versions.get_tool_version(tool).then(function (version) {
         version = version.trim();
         return versions.compareVersions(version, minVersion) >= 0 ?
-            Q.resolve(version) :
+            Q.resolve({ 'version': version }) :
             Q.reject('Cordova needs ' + toolFriendlyName + ' version ' + minVersion +
               ' or greater, you have version ' + version + '. ' + (message || ''));
     });
@@ -150,7 +167,7 @@ function checkTool (tool, minVersion, message, toolFriendlyName) {
  * @param {Boolean} isFatal   Marks the requirement as fatal. If such requirement will fail
  *                            next requirements' checks will be skipped.
  */
-var Requirement = function (id, name, isFatal) {
+let Requirement = function (id, name, isFatal) {
     this.id = id;
     this.name = name;
     this.installed = false;
@@ -166,17 +183,17 @@ var Requirement = function (id, name, isFatal) {
  */
 module.exports.check_all = function() {
 
-    var requirements = [
-        new Requirement('os', 'Apple OS X', true),
+    const requirements = [
+        new Requirement('os', 'Apple macOS', true),
         new Requirement('xcode', 'Xcode'),
         new Requirement('ios-deploy', 'ios-deploy'),
         new Requirement('CocoaPods', 'CocoaPods')
     ];
 
-    var result = [];
-    var fatalIsHit = false;
+    let result = [];
+    let fatalIsHit = false;
 
-    var checkFns = [
+    let checkFns = [
         module.exports.check_os,
         module.exports.check_xcodebuild,
         module.exports.check_ios_deploy,
@@ -190,7 +207,7 @@ module.exports.check_all = function() {
             // we don't need to check others
             if (fatalIsHit) return Q();
 
-            var requirement = requirements[idx];
+            let requirement = requirements[idx];
             return checkFn()
             .then(function (version) {
                 requirement.installed = true;

http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/08af7f2c/bin/templates/scripts/cordova/lib/Podfile.js
----------------------------------------------------------------------
diff --git a/bin/templates/scripts/cordova/lib/Podfile.js b/bin/templates/scripts/cordova/lib/Podfile.js
index 084c10c..b648d37 100644
--- a/bin/templates/scripts/cordova/lib/Podfile.js
+++ b/bin/templates/scripts/cordova/lib/Podfile.js
@@ -16,6 +16,7 @@
        specific language governing permissions and limitations
        under the License.
 */
+'use strict';
 
 var fs = require('fs'),
     path = require('path'),
@@ -173,7 +174,9 @@ Podfile.prototype.isDirty = function() {
     return this.__dirty;
 };
 
-Podfile.prototype.before_install = function() {
+Podfile.prototype.before_install = function(toolOptions) {
+    toolOptions = toolOptions || {};
+
     // Template tokens in order: project name, project name, debug | release
     var template =
     '// DO NOT MODIFY -- auto-generated by Apache Cordova\n' + 
@@ -188,7 +191,7 @@ Podfile.prototype.before_install = function() {
     fs.writeFileSync(debugConfigPath, debugContents, 'utf8');
     fs.writeFileSync(releaseConfigPath, releaseContents, 'utf8');
 
-    return Q.resolve();
+    return Q.resolve(toolOptions);
 };
 
 Podfile.prototype.install = function(requirementsCheckerFunction) {
@@ -203,21 +206,27 @@ Podfile.prototype.install = function(requirementsCheckerFunction) {
     }
 
     return requirementsCheckerFunction()
-    .then(function() {
-        return self.before_install();
+    .then(function(toolOptions) {
+        return self.before_install(toolOptions);
     })
-    .then(function() {
-        return superspawn.spawn('pod', ['install', '--verbose'], opts)
-        .progress(function (stdio){
-            if (stdio.stderr) { console.error(stdio.stderr); }
-            if (stdio.stdout) {
-                if (first) {
-                    events.emit('verbose', '==== pod install start ====\n');
-                    first = false;
-                }
-                events.emit('verbose', stdio.stdout); 
-            } 
-        });
+    .then(function(toolOptions) {
+        if (toolOptions.ignore) {
+            events.emit('verbose', '==== pod install start ====\n');
+            events.emit('verbose', toolOptions.ignoreMessage);
+            return Q.resolve();
+        } else {
+            return superspawn.spawn('pod', ['install', '--verbose'], opts)
+            .progress(function (stdio){
+                if (stdio.stderr) { console.error(stdio.stderr); }
+                if (stdio.stdout) {
+                    if (first) {
+                        events.emit('verbose', '==== pod install start ====\n');
+                        first = false;
+                    }
+                    events.emit('verbose', stdio.stdout); 
+                } 
+            });
+        }
     })
     .then(function() { // done
         events.emit('verbose', '==== pod install end ====\n');

http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/08af7f2c/tests/spec/unit/Api.spec.js
----------------------------------------------------------------------
diff --git a/tests/spec/unit/Api.spec.js b/tests/spec/unit/Api.spec.js
index facd507..6792bcd 100644
--- a/tests/spec/unit/Api.spec.js
+++ b/tests/spec/unit/Api.spec.js
@@ -19,6 +19,8 @@
 
 var path = require('path');
 var Api = require('../../../bin/templates/scripts/cordova/Api');
+var check_reqs = require('../../../bin/lib/check_reqs');
+var Q = require('q');
 var FIXTURES = path.join(__dirname, 'fixtures');
 var iosProjectFixture = path.join(FIXTURES, 'ios-config-xml');
 
@@ -38,5 +40,71 @@ describe('Platform Api', function () {
                 expect(p.locations.configXml).toEqual(path.join(iosProjectFixture, 'SampleApp', 'config.xml'));
             }).not.toThrow();
         });
+        it('Test 003 : test cocoapods check_reqs, on darwin (macOS)', function(done) {
+            // the purpose of this test is not to actually test whether CocoaPods is installed
+            // it is to test check_reqs can run and be covered (we mock the actual checking, simple check)
+
+            check_reqs.check_os()
+            .then(function(message) {
+                // supported os
+                function fail() {
+                    done.fail('check_reqs fail (' + message + ')');
+                }
+                function success() {
+                    done();
+                }
+                var toolsChecker = {
+                    success: function() {
+                        return Q.resolve('CocoaPods found');
+                    },
+                    fail: function() {
+                        return Q.reject('CocoaPods NOT found');
+                    }
+                };
+
+                // success expected
+                check_reqs.check_cocoapods(toolsChecker.success)
+                    .then(success, fail)
+                    .catch(fail);
+
+                // fail expected
+                check_reqs.check_cocoapods(toolsChecker.fail)
+                    .then(fail, success)
+                    .catch(success);
+                    
+            }, function(){
+                // unsupported os, do nothing
+                done();
+            });
+        });
+        it('Test 004 : test cocoapods check_reqs, expected success on non-darwin (macOS)', function(done) {
+            // the purpose of this test is not to actually test whether CocoaPods is installed
+            // it is to test check_reqs can run and be covered (we mock the actual checking, simple check)
+            check_reqs.check_os()
+            .then(function(){
+                // supported os, do nothing
+                done();
+            }, function(message) {
+                // unsupported os, check_reqs should be ignored
+                function fail() {
+                    done.fail('check_reqs fail (' + message + ')');
+                }
+                function success(toolOptions) {
+                    expect(toolOptions.ignore).toBeDefined();
+                    expect(toolOptions.ignoreMessage).toBeDefined();
+                    done();
+                }
+                var toolsChecker = function () {
+                    done.fail(); // this function should not ever be called if non-darwin
+                    return Q.reject('CocoaPods NOT found');
+                };
+
+                // success expected
+                check_reqs.check_cocoapods(toolsChecker)
+                    .then(success, fail)
+                    .catch(fail);
+            });
+
+        });
     });
 });

http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/08af7f2c/tests/spec/unit/Plugman/pluginHandler.spec.js
----------------------------------------------------------------------
diff --git a/tests/spec/unit/Plugman/pluginHandler.spec.js b/tests/spec/unit/Plugman/pluginHandler.spec.js
index d615bc6..ee4fabe 100644
--- a/tests/spec/unit/Plugman/pluginHandler.spec.js
+++ b/tests/spec/unit/Plugman/pluginHandler.spec.js
@@ -294,7 +294,7 @@ describe('ios plugin handler', function() {
         });
 
         describe('of <js-module> elements', function() {
-            var jsModule = {src: 'www/dummyPlugin.js'};
+            var jsModule = {src: 'www/dummyplugin.js'};
             var install = pluginHandlers.getInstaller('js-module');
             var wwwDest, platformWwwDest;
 
@@ -318,7 +318,7 @@ describe('ios plugin handler', function() {
         });
 
         describe('of <asset> elements', function() {
-            var asset = {src: 'www/dummyPlugin.js', target: 'foo/dummy.js'};
+            var asset = {src: 'www/dummyplugin.js', target: 'foo/dummy.js'};
             var install = pluginHandlers.getInstaller('asset');
             var wwwDest, platformWwwDest;
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org