cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rakat...@apache.org
Subject cordova-windows git commit: CB-11204: Catch when SDK not present on build and give appropriate error message
Date Mon, 16 May 2016 18:33:00 GMT
Repository: cordova-windows
Updated Branches:
  refs/heads/master f4e20a3a1 -> acfb01ead


CB-11204: Catch when SDK not present on build and give appropriate error message

 This closes #177


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

Branch: refs/heads/master
Commit: acfb01ead6040c6aec39ced31818b8fb96ee6998
Parents: f4e20a3
Author: Raghav Katyal <rakatyal@microsoft.com>
Authored: Fri May 13 20:17:36 2016 -0700
Committer: Raghav Katyal <rakatyal@microsoft.com>
Committed: Mon May 16 11:32:24 2016 -0700

----------------------------------------------------------------------
 bin/lib/check_reqs.js                | 88 +++++++++++++++++--------------
 spec/unit/check_reqs.spec.js         | 18 +++++--
 template/cordova/lib/MSBuildTools.js | 26 ++++++++-
 3 files changed, 87 insertions(+), 45 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/acfb01ea/bin/lib/check_reqs.js
----------------------------------------------------------------------
diff --git a/bin/lib/check_reqs.js b/bin/lib/check_reqs.js
index 42f67e7..6bb8628 100644
--- a/bin/lib/check_reqs.js
+++ b/bin/lib/check_reqs.js
@@ -62,21 +62,7 @@ var REQUIRED_VERSIONS = {
     }
 };
 
-function getConfig() {
-    try {
-        return new ConfigParser(path.join(__dirname, '../../config.xml'));
-    } catch (e) {
-        throw new CordovaError('Can\'t check requirements for Windows platform.' +
-            'The config.xml file is either missing or malformed.');
-    }
-}
-
-
-function getMinimalRequiredVersionFor (requirement) {
-
-    var config = getConfig();
-    var windowsTargetVersion = config.getWindowsTargetVersion();
-    var windowsPhoneTargetVersion = config.getWindowsPhoneTargetVersion();
+function getMinimalRequiredVersionFor (requirement, windowsTargetVersion, windowsPhoneTargetVersion)
{
 
     if (windowsTargetVersion === '8' || windowsTargetVersion === '8.0') {
         throw new CordovaError('windows8 platform is deprecated. To use windows-target-version=8.0
you may downgrade to cordova-windows@4.');
@@ -85,7 +71,6 @@ function getMinimalRequiredVersionFor (requirement) {
     if (windowsPhoneTargetVersion === '8' || windowsPhoneTargetVersion === '8.0') {
         throw new CordovaError('8.0 is not a valid version for windows-phone-target-version
(use the wp8 Cordova platform instead)');
     }
-
     var windowsReqVersion = Version.tryParse(REQUIRED_VERSIONS[windowsTargetVersion][requirement]);
     var phoneReqVersion = Version.tryParse(REQUIRED_VERSIONS[windowsPhoneTargetVersion][requirement]);
 
@@ -260,14 +245,14 @@ function mapVSVersionToName(version) {
  * Check if current OS is supports building windows platform
  * @return {Promise} Promise either fullfilled or rejected with error message.
  */
-var checkOS = function () {
+var checkOS = function (windowsTargetVersion, windowsPhoneTargetVersion) {
     if (process.platform !== 'win32') {
         // Build Universal windows apps available for windows platform only, so we reject
on others platforms
         return Q.reject('Cordova tooling for Windows requires Windows OS to build project');
     }
 
     return getWindowsVersion().then(function (actualVersion) {
-        var requiredOsVersion = getMinimalRequiredVersionFor('os');
+        var requiredOsVersion = getMinimalRequiredVersionFor('os', windowsTargetVersion,
windowsPhoneTargetVersion);
         if (actualVersion.gte(requiredOsVersion) ||
             // Special case for Windows 10/Phone 10  targets which can be built on Windows
7 (version 6.1)
             actualVersion.major === 6 && actualVersion.minor === 1 && getConfig().getWindowsTargetVersion()
=== '10.0') {
@@ -284,10 +269,10 @@ var checkOS = function () {
  * @return {Promise} Promise either fullfilled with MSBuild version
  *                           or rejected with error message.
  */
-var checkMSBuild = function () {
+var checkMSBuild = function (windowsTargetVersion, windowsPhoneTargetVersion) {
     return MSBuildTools.findAllAvailableVersions()
     .then(function (msbuildToolsVersions) {
-        var msbuildRequiredVersion = getMinimalRequiredVersionFor('msbuild');
+        var msbuildRequiredVersion = getMinimalRequiredVersionFor('msbuild', windowsTargetVersion,
windowsPhoneTargetVersion);
         msbuildToolsVersions = msbuildToolsVersions.map(function (msbuildToolsVersion) {
             return msbuildToolsVersion.version;
         });
@@ -296,13 +281,13 @@ var checkMSBuild = function () {
         return appropriateVersion ?
             shortenVersion(appropriateVersion) :
             Q.reject('MSBuild tools v.' + shortenVersion(msbuildRequiredVersion) + ' not
found. ' +
-                'Please install Visual Studio ' + mapVSVersionToName(getMinimalRequiredVersionFor('visualstudio'))
+
+                'Please install Visual Studio ' + mapVSVersionToName(getMinimalRequiredVersionFor('visualstudio',
windowsTargetVersion, windowsPhoneTargetVersion)) +
                 ' from https://www.visualstudio.com/downloads/download-visual-studio-vs');
     });
 };
 
-var checkVS = function () {
-    var vsRequiredVersion = getMinimalRequiredVersionFor('visualstudio');
+var checkVS = function (windowsTargetVersion, windowsPhoneTargetVersion) {
+    var vsRequiredVersion = getMinimalRequiredVersionFor('visualstudio', windowsTargetVersion,
windowsPhoneTargetVersion);
 
     return getInstalledVSVersions()
     .then(function (installedVersions) {
@@ -315,10 +300,10 @@ var checkVS = function () {
     });
 };
 
-var checkWinSdk = function () {
+var checkWinSdk = function (windowsTargetVersion, windowsPhoneTargetVersion) {
     return getInstalledWindowsSdks()
     .then(function (installedSdks) {
-        var requiredVersion = getMinimalRequiredVersionFor('windowssdk');
+        var requiredVersion = getMinimalRequiredVersionFor('windowssdk', windowsTargetVersion,
windowsPhoneTargetVersion);
         var hasSdkInstalled = installedSdks.some(function (installedSdk) {
             return installedSdk.eq(requiredVersion);
         });
@@ -333,13 +318,10 @@ var checkWinSdk = function () {
     });
 };
 
-var checkPhoneSdk = function () {
-    var requiredVersion = getMinimalRequiredVersionFor('phonesdk');
-
+var checkPhoneSdk = function (windowsTargetVersion, windowsPhoneTargetVersion) {
+    var requiredVersion = getMinimalRequiredVersionFor('phonesdk', windowsTargetVersion,
windowsPhoneTargetVersion);
     return getInstalledPhoneSdks()
     .then(function (installedSdks) {
-        var requiredVersion = getMinimalRequiredVersionFor('phonesdk');
-
         var hasSdkInstalled = installedSdks.some(function (installedSdk) {
             return installedSdk.eq(requiredVersion);
         });
@@ -362,6 +344,18 @@ module.exports.run = function () {
     });
 };
 
+/** Checks if Windows SDK required to build the target_platform is present
+ * @param {String}  target_platorm        Target platform ('8.1' or '10.0')
+ */ 
+module.exports.isWinSDKPresent = function (target_platform) {
+    return checkWinSdk(target_platform, '8.1');
+};
+
+// Checks if min SDK required to build Windows Phone 8.1 project is present
+module.exports.isPhoneSDKPresent = function () {
+    return checkPhoneSdk('8.1', '8.1');
+};
+
 /**
  * Object that represents one of requirements for current platform.
  * @param {String}  id        The unique identifier for this requirements.
@@ -388,6 +382,17 @@ var requirements = [
 // Define list of checks needs to be performed
 var checkFns = [checkOS, checkMSBuild, checkVS, checkWinSdk, checkPhoneSdk];
 
+var config = null;
+function getConfig() {
+    try {
+        config = config || new ConfigParser(path.join(__dirname, '../../config.xml'));
+        return Q(config);
+    } catch (e) {
+        return Q.reject(new CordovaError('Can\'t check requirements for Windows platform.'
+
+            'The config.xml file is either missing or malformed.'));
+    }
+}
+
 /**
  * Methods that runs all checks one by one and returns a result of checks
  * as an array of Requirement objects. This method intended to be used by cordova-lib check_reqs
method.
@@ -404,18 +409,21 @@ module.exports.check_all = function() {
             // If fatal requirement is failed,
             // we don't need to check others
             if (fatalIsHit) return Q();
-
             var requirement = requirements[idx];
-            return checkFn()
-            .then(function (version) {
-                requirement.installed = true;
-                requirement.metadata.version = version;
-                result.push(requirement);
-            }, function (err) {
-                if (requirement.isFatal) fatalIsHit = true;
-                requirement.metadata.reason = err;
-                result.push(requirement);
+            return getConfig()
+            .then(function (config) {
+                return checkFn(config.getWindowsTargetVersion(), config.getWindowsPhoneTargetVersion())
+                .then(function (version) {
+                    requirement.installed = true;
+                    requirement.metadata.version = version;
+                    result.push(requirement);
+                }).catch( function (err) {
+                    if (requirement.isFatal) fatalIsHit = true;
+                    requirement.metadata.reason = err;
+                    result.push(requirement);
+                });  
             });
+            
         });
     }, Q())
     .then(function () {

http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/acfb01ea/spec/unit/check_reqs.spec.js
----------------------------------------------------------------------
diff --git a/spec/unit/check_reqs.spec.js b/spec/unit/check_reqs.spec.js
index 3b337e4..deebb67 100644
--- a/spec/unit/check_reqs.spec.js
+++ b/spec/unit/check_reqs.spec.js
@@ -21,7 +21,10 @@ var Q = require('q');
 var path = require('path');
 var rewire = require('rewire');
 var binPath = '../../bin';
-
+var et = require('elementtree');
+var xml = require('cordova-common').xmlHelpers;
+var TEST_XML = '<?xml version="1.0" encoding="UTF-8"?><widget/>';
+var ConfigParser = require('../../template/cordova/lib/ConfigParser');
 var check_reqs = rewire(path.join(binPath, 'lib/check_reqs.js'));
 
 describe('check_reqs module', function () {
@@ -53,14 +56,15 @@ describe('check_reqs module', function () {
         // var consoleLogOriginal;
 
         var Requirement,
-            originalrequirements, originalcheckFns,
-            fakeRequirements, fakeCheckFns,
+            originalrequirements, originalcheckFns, originalconfig,
+            fakeRequirements, fakeCheckFns, fakeConfig,
             checkSpy;
 
         beforeEach(function () {
             Requirement = check_reqs.__get__('Requirement');
             originalrequirements = check_reqs.__get__('requirements');
             originalcheckFns = check_reqs.__get__('checkFns');
+            originalconfig = check_reqs.__get__('config');
 
             fakeRequirements = [
                 new Requirement('1', 'First requirement'),
@@ -75,17 +79,20 @@ describe('check_reqs module', function () {
                 checkSpy.andReturn(Q('2.0')),
                 checkSpy.andReturn(Q('3.0'))
             ];
+            spyOn(xml, 'parseElementtreeSync').andReturn(new et.ElementTree(et.XML(TEST_XML)));
+            fakeConfig = new ConfigParser('/some/file');
         });
 
         afterEach(function() {
             check_reqs.__set__('requirements', originalrequirements);
             check_reqs.__set__('checkFns', originalcheckFns);
+            check_reqs.__set__('config', originalconfig);
         });
 
         it('that should return a promise, fulfilled with an array of Requirements', function
(done) {
             check_reqs.__set__('requirements', fakeRequirements);
             check_reqs.__set__('checkFns', fakeCheckFns);
-
+            check_reqs.__set__('config', fakeConfig);
             var checkResult = check_reqs.check_all();
             expect(Q.isPromise(checkResult)).toBeTruthy();
             checkResult.then(function (result) {
@@ -103,6 +110,7 @@ describe('check_reqs module', function () {
             check_reqs.__set__('requirements', fakeRequirements);
             fakeCheckFns[0] = function () { return Q.reject('Error message'); };
             check_reqs.__set__('checkFns', fakeCheckFns);
+            check_reqs.__set__('config', fakeConfig);
 
             check_reqs.check_all()
             .then(function (requirements) {
@@ -120,6 +128,7 @@ describe('check_reqs module', function () {
             check_reqs.__set__('requirements', fakeRequirements);
             fakeCheckFns[0] = checkSpy.andThrow('Fatal error');
             check_reqs.__set__('checkFns', fakeCheckFns);
+            check_reqs.__set__('config', fakeConfig);
 
             check_reqs.check_all()
             .then(function (requirements) {
@@ -137,6 +146,7 @@ describe('check_reqs module', function () {
             // The second requirement is fatal, so we're setting up second check to fail
             fakeCheckFns[1] = checkSpy.andReturn(Q.reject('Error message'));
             check_reqs.__set__('checkFns', fakeCheckFns);
+            check_reqs.__set__('config', fakeConfig);
 
             check_reqs.check_all()
             .then(function (requirements) {

http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/acfb01ea/template/cordova/lib/MSBuildTools.js
----------------------------------------------------------------------
diff --git a/template/cordova/lib/MSBuildTools.js b/template/cordova/lib/MSBuildTools.js
index 114c12c..72208e8 100644
--- a/template/cordova/lib/MSBuildTools.js
+++ b/template/cordova/lib/MSBuildTools.js
@@ -33,6 +33,14 @@ MSBuildTools.prototype.buildProject = function(projFile, buildType, buildarch,
o
     events.emit('log', 'Building project: ' + projFile);
     events.emit('log', '\tConfiguration : ' + buildType);
     events.emit('log', '\tPlatform      : ' + buildarch);
+    
+    var checkWinSDK = function (target_platform) {
+        return require('./check_reqs').isWinSDKPresent(target_platform);
+    };
+
+    var checkPhoneSDK = function () {
+        return require('./check_reqs').isPhoneSDKPresent();
+    };
 
     var args = ['/clp:NoSummary;NoItemAndPropertyList;Verbosity=minimal', '/nologo',
     '/p:Configuration=' + buildType,
@@ -45,7 +53,23 @@ MSBuildTools.prototype.buildProject = function(projFile, buildType, buildarch,
o
         });
     }
 
-    return spawn(path.join(this.path, 'msbuild'), [projFile].concat(args), { stdio: 'inherit'
});
+    var that = this;
+    var promise;
+
+    // Check if SDK required to build the respective platform is present. If not present,
return with corresponding error, else call msbuild.
+    if (projFile.indexOf('CordovaApp.Phone.jsproj') > -1) {
+        promise = checkPhoneSDK();
+    }
+    else if (projFile.indexOf('CordovaApp.Windows.jsproj') > -1) {
+        promise = checkWinSDK('8.1');
+    }
+    else {
+        promise = checkWinSDK('10.0');
+    }
+
+    return promise.then(function () {
+        return spawn(path.join(that.path, 'msbuild'), [projFile].concat(args), { stdio: 'inherit'
});
+    });
 };
 
 // returns full path to msbuild tools required to build the project and tools version


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


Mime
View raw message