This is an automated email from the ASF dual-hosted git repository.

janpio pushed a commit to branch janpio-msbuild_cleanup
in repository https://gitbox.apache.org/repos/asf/cordova-windows.git

commit b00e60b4ac747bb3e7b332131b5d6d08854a2fc9
Author: Jan Piotrowski <piotrow...@gmail.com>
AuthorDate: Wed Feb 14 19:26:04 2018 +0100

    restructure getLatestMSBuild to get the list of available MSBuilds itself
    restructure usage of MSBuildTools in build.js to that new reality (get 
builtTargets earlier, get msBuild instead of list, use both to filter 
buildTargets earlier)
---
 template/cordova/lib/MSBuildTools.js | 50 +++++++++++++++++++++---------------
 template/cordova/lib/build.js        | 33 ++++++++++++------------
 2 files changed, 45 insertions(+), 38 deletions(-)

diff --git a/template/cordova/lib/MSBuildTools.js 
b/template/cordova/lib/MSBuildTools.js
index 80a9fcf..5d9fe2c 100644
--- a/template/cordova/lib/MSBuildTools.js
+++ b/template/cordova/lib/MSBuildTools.js
@@ -211,31 +211,39 @@ module.exports.getAvailableUAPVersions = function () {
 };
 
 // gets the latest MSBuild version from a list of versions
-module.exports.getLatestMSBuild = function (allMsBuildVersions) {
+module.exports.getLatestMSBuild = function () {
     events.emit('verbose', 'getLatestMSBuild');
 
-    var availableVersions = allMsBuildVersions
-        .filter(function (buildTools) {
-            // Sanitize input - filter out tools w/ invalid versions
-            return Version.tryParse(buildTools.version);
-        }).sort(function (a, b) {
-            // Sort tools list - use parsed Version objects for that
-            // to respect both major and minor versions segments
-            var parsedA = Version.fromString(a.version);
-            var parsedB = Version.fromString(b.version);
-
-            if (parsedA.gt(parsedB)) return -1;
-            if (parsedA.eq(parsedB)) return 0;
-            return 1;
-        });
+    return this.findAllAvailableVersions()
+        .then(function (allMsBuildVersions) {
+
+            var availableVersions = allMsBuildVersions
+                .filter(function (buildTools) {
+                    // Sanitize input - filter out tools w/ invalid versions
+                    return Version.tryParse(buildTools.version);
+                }).sort(function (a, b) {
+                    // Sort tools list - use parsed Version objects for that
+                    // to respect both major and minor versions segments
+                    var parsedA = Version.fromString(a.version);
+                    var parsedB = Version.fromString(b.version);
+
+                    if (parsedA.gt(parsedB)) return -1;
+                    if (parsedA.eq(parsedB)) return 0;
+                    return 1;
+                });
+
+            console.log('availableVersions', availableVersions);
+
+            if (availableVersions.length > 0) {
+                // After sorting the first item will be the highest version 
available
+                msbuild = availableVersions[0];
+                events.emit('verbose', 'Using MSBuild v' + msbuild.version + ' 
from ' + msbuild.path);
+                return msbuild;
+            }
+    });
+};
 
-    console.log('availableVersions', availableVersions);
 
-    if (availableVersions.length > 0) {
-        // After sorting the first item will be the highest version available
-        return availableVersions[0];
-    }
-};
 var projFiles = {
     phone: 'CordovaApp.Phone.jsproj',
     win: 'CordovaApp.Windows.jsproj',
diff --git a/template/cordova/lib/build.js b/template/cordova/lib/build.js
index 3006972..0b09d32 100644
--- a/template/cordova/lib/build.js
+++ b/template/cordova/lib/build.js
@@ -57,20 +57,30 @@ module.exports.run = function run (buildOptions) {
 
     var buildConfig = parseAndValidateArgs(buildOptions);
 
-    return MSBuildTools.findAllAvailableVersions()
-        .then(function (msbuildTools) {
+    // get build targets
+    var selectedBuildTargets = getBuildTargets(buildConfig.win, 
buildConfig.phone, buildConfig.projVerOverride, buildConfig);
+
+    return MSBuildTools.getLatestMSBuild() // get latest msbuild tools
+        .then(function (msbuild) {
+
+            // filter targets to make sure they are supported on this 
development machine
+            var myBuildTargets = 
msbuild.filterSupportedTargets(selectedBuildTargets);
+
             // Apply build related configs
             prepare.updateBuildConfig(buildConfig);
 
             if (buildConfig.publisherId) {
-                updateManifestWithPublisher(msbuildTools, buildConfig);
+                updateManifestWithPublisher(buildConfig, myBuildTargets);
             }
 
             cleanIntermediates();
-            return buildTargets(msbuildTools, buildConfig);
+            // build!
+            return buildTargets(buildConfig, myBuildTargets, msbuild);
         }).then(function (pkg) {
             events.emit('verbose', ' BUILD OUTPUT: ' + pkg.appx);
             return pkg;
+        }).catch(function (error) {
+            return Q.reject(new CordovaError('No valid MSBuild was detected 
for the selected target: ' + error, error));
         });
 };
 
@@ -303,12 +313,9 @@ function parseBuildConfig (buildConfigPath, buildType) {
 
 // Note: This function is very narrow and only writes to the app manifest if 
an update is done.  See CB-9450 for the
 // reasoning of why this is the case.
-function updateManifestWithPublisher (allMsBuildVersions, config) {
+function updateManifestWithPublisher (config, myBuildTargets) {
     if (!config.publisherId) return;
 
-    var selectedBuildTargets = getBuildTargets(config.win, config.phone, 
config.projVerOverride, config);
-    var msbuild = MSBuildTools.getLatestMSBuild(allMsBuildVersions);
-    var myBuildTargets = filterSupportedTargets(selectedBuildTargets, msbuild);
     var manifestFiles = myBuildTargets.map(function (proj) {
         return projFilesToManifests[proj];
     });
@@ -319,15 +326,7 @@ function updateManifestWithPublisher (allMsBuildVersions, 
config) {
     });
 }
 
-function buildTargets (allMsBuildVersions, config) {
-    // filter targets to make sure they are supported on this development 
machine
-    var selectedBuildTargets = getBuildTargets(config.win, config.phone, 
config.projVerOverride, config);
-    var msbuild = MSBuildTools.getLatestMSBuild(allMsBuildVersions);
-    if (!msbuild) {
-        return Q.reject(new CordovaError('No valid MSBuild was detected for 
the selected target.'));
-    }
-    events.emit('verbose', 'Using MSBuild v' + msbuild.version + ' from ' + 
msbuild.path);
-    var myBuildTargets = filterSupportedTargets(selectedBuildTargets, msbuild);
+function buildTargets (config, myBuildTargets, msbuild) {
 
     var buildConfigs = [];
     var bundleTerms = '';

-- 
To stop receiving notification emails like this one, please contact
jan...@apache.org.

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

Reply via email to