Repository: cordova-windows
Updated Branches:
  refs/heads/master a86922382 -> 8d971f5e5


CB-12636 Fix check_reqs to properly find VS 2017


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

Branch: refs/heads/master
Commit: 8d971f5e530c64db743842eccabff30e967d576a
Parents: a869223
Author: Alexander Sorokin <alexander.soro...@akvelon.com>
Authored: Thu Jul 13 11:47:07 2017 +0300
Committer: Alexander Sorokin <alexander.soro...@akvelon.com>
Committed: Mon Jul 17 10:16:27 2017 +0300

----------------------------------------------------------------------
 bin/lib/check_reqs.js                | 11 +++++-
 template/cordova/lib/MSBuildTools.js | 64 +++++++++++++++++++++++++++++--
 2 files changed, 71 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/8d971f5e/bin/lib/check_reqs.js
----------------------------------------------------------------------
diff --git a/bin/lib/check_reqs.js b/bin/lib/check_reqs.js
index 792cec3..6c70ddc 100644
--- a/bin/lib/check_reqs.js
+++ b/bin/lib/check_reqs.js
@@ -94,7 +94,7 @@ function getHighestAppropriateVersion (versions, 
requiredVersion) {
         .sort(Version.comparer)
         .filter(function (toolVersion) {
             return toolVersion.gte(requiredVersion);
-        })[0];
+        }).reverse()[0];
 }
 
 /**
@@ -147,6 +147,12 @@ function getInstalledVSVersions () {
                     
installedVersions.splice(installedVersions.indexOf('12.0'), 1);
                     return installedVersions;
                 });
+        })
+        .then(function (installedVersions) {
+            var willowVersions = 
MSBuildTools.getWillowInstallations().map(function (installation) {
+                return installation.version;
+            });
+            return installedVersions.concat(willowVersions);
         });
 }
 
@@ -280,6 +286,9 @@ var checkMSBuild = function (windowsTargetVersion, 
windowsPhoneTargetVersion) {
 var checkVS = function (windowsTargetVersion, windowsPhoneTargetVersion) {
     var vsRequiredVersion = getMinimalRequiredVersionFor('visualstudio', 
windowsTargetVersion, windowsPhoneTargetVersion);
 
+    if (process.env.VSINSTALLDIR) {
+        return Q('(user-specified)');
+    }
     return getInstalledVSVersions()
         .then(function (installedVersions) {
             var appropriateVersion = 
getHighestAppropriateVersion(installedVersions, vsRequiredVersion);

http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/8d971f5e/template/cordova/lib/MSBuildTools.js
----------------------------------------------------------------------
diff --git a/template/cordova/lib/MSBuildTools.js 
b/template/cordova/lib/MSBuildTools.js
index 8bc92e6..d706831 100644
--- a/template/cordova/lib/MSBuildTools.js
+++ b/template/cordova/lib/MSBuildTools.js
@@ -19,6 +19,7 @@
 
 var Q = require('q');
 var path = require('path');
+var fs = require('fs');
 var shell = require('shelljs');
 var Version = require('./Version');
 var events = require('cordova-common').events;
@@ -124,6 +125,16 @@ module.exports.getMSBuildToolsAt = function (location) {
 };
 
 function checkMSBuildVersion (version) {
+    // first, check if we have a VS 2017+ with such a version
+    var correspondingWillow = 
module.exports.getWillowInstallations().filter(function (inst) {
+        return inst.version === version;
+    })[0];
+    if (correspondingWillow) {
+        var toolsPath = path.join(correspondingWillow.path, 'MSBuild', 
version, 'Bin');
+        if (shell.test('-e', toolsPath)) {
+            return module.exports.getMSBuildToolsAt(toolsPath);
+        }
+    }
     return spawn('reg', ['query', 
'HKLM\\SOFTWARE\\Microsoft\\MSBuild\\ToolsVersions\\' + version, '/v', 
'MSBuildToolsPath'])
         .then(function (output) {
             // fetch msbuild path from 'reg' output
@@ -140,12 +151,11 @@ function checkMSBuildVersion (version) {
             }
         }).catch(function (err) { /* eslint handle-callback-err : 0 */
             // if 'reg' exits with error, assume that registry key not found
-
         });
 }
 
 /// returns an array of available UAP Versions
-function getAvailableUAPVersions () {
+module.exports.getAvailableUAPVersions = function () {
     /* jshint -W069 */
     var programFilesFolder = process.env['ProgramFiles(x86)'] || 
process.env['ProgramFiles'];
     // No Program Files folder found, so we won't be able to find UAP SDK
@@ -168,6 +178,54 @@ function getAvailableUAPVersions () {
     });
 
     return result;
+};
+
+/**
+ * Lists all VS 2017+ instances dirs in ProgramData
+ * 
+ * @return {String[]} List of paths to all VS2017+ instances
+ */
+function getWillowProgDataPaths () {
+    if (!process.env.systemdrive) {
+        // running on linux/osx?
+        return [];
+    }
+    var instancesRoot = path.join(process.env.systemdrive, 
'ProgramData/Microsoft/VisualStudio/Packages/_Instances');
+    if (!shell.test('-d', instancesRoot)) {
+        // can't seem to find VS instances dir, return empty result
+        return [];
+    }
+
+    return fs.readdirSync(instancesRoot).map(function (file) {
+        var instanceDir = path.join(instancesRoot, file);
+        if (shell.test('-d', instanceDir)) {
+            return instanceDir;
+        }
+    }).filter(function (progDataPath) {
+        // make sure state.json exists
+        return shell.test('-e', path.join(progDataPath, 'state.json'));
+    });
 }
 
-module.exports.getAvailableUAPVersions = getAvailableUAPVersions;
+/**
+ * Lists all installed VS 2017+ versions
+ * 
+ * @return {Object[]} List of all VS 2017+ versions
+ */
+module.exports.getWillowInstallations = function () {
+    var progDataPaths = getWillowProgDataPaths();
+    var installations = [];
+    progDataPaths.forEach(function (progDataPath) {
+        try {
+            var stateJsonPath = path.join(progDataPath, 'state.json');
+            var fileContents = fs.readFileSync(stateJsonPath, 'utf-8');
+            var state = JSON.parse(fileContents);
+            // get only major and minor version
+            var version = state.product.version.match(/^(\d+\.\d+)/)[1];
+            installations.push({ version: version, path: 
state.installationPath });
+        } catch (err) {
+            // something's wrong, skip this one
+        }
+    });
+    return installations;
+};


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

Reply via email to