You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ja...@apache.org on 2018/02/15 14:46:14 UTC

[cordova-windows] 22/26: MSBUILDDIR for MSBuild selection

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 79d6a0d5b0c6c42c07d9d8fee62f46eb2742c818
Author: Jan Piotrowski <pi...@gmail.com>
AuthorDate: Thu Feb 15 12:48:33 2018 +0100

    MSBUILDDIR for MSBuild selection
---
 spec/unit/build.spec.js              | 26 +++++++++++++++++++++++++-
 template/cordova/lib/MSBuildTools.js | 21 ++++++++++++++++++++-
 2 files changed, 45 insertions(+), 2 deletions(-)

diff --git a/spec/unit/build.spec.js b/spec/unit/build.spec.js
index 81b2ada..ad25c99 100644
--- a/spec/unit/build.spec.js
+++ b/spec/unit/build.spec.js
@@ -371,7 +371,7 @@ describe('run method', function () {
             });
     });
 
-    it('spec.14 should use user-specified msbuild if VSINSTALLDIR variable is set', function (done) {
+    it('spec.14a should use user-specified msbuild if VSINSTALLDIR variable is set', function (done) {
         var customMSBuildPath = '/some/path';
         var msBuildBinPath = path.join(customMSBuildPath, 'MSBuild/15.0/Bin');
         var customMSBuildVersion = '15.0';
@@ -396,6 +396,30 @@ describe('run method', function () {
             });
     });
 
+    it('spec.14b should use user-specified msbuild if MSBUILDDIR variable is set', function (done) {
+        var msBuildBinPath = path.join('/some/path', 'MSBuild/15.0/Bin');
+        var customMSBuildVersion = '15.0';
+        process.env.MSBUILDDIR = msBuildBinPath;
+
+        spyOn(MSBuildTools, 'getMSBuildToolsAt')
+            .and.returnValue(Q({
+                path: msBuildBinPath,
+                version: customMSBuildVersion,
+                buildProject: jasmine.createSpy('buildProject').and.returnValue(Q())
+            }));
+
+        var fail = jasmine.createSpy('fail');
+
+        build.run({})
+            .fail(fail)
+            .finally(function () {
+                expect(fail).not.toHaveBeenCalled();
+                expect(MSBuildTools.getMSBuildToolsAt).toHaveBeenCalledWith(msBuildBinPath);
+                delete process.env.MSBUILDDIR;
+                done();
+            });
+    });
+
     it('spec.15a should choose latest version if there are multiple versions available with minor version difference', function (done) {
         var fail = jasmine.createSpy('fail');
         var buildTools14 = { version: '14.0', buildProject: jasmine.createSpy('buildTools14'), path: testPath };
diff --git a/template/cordova/lib/MSBuildTools.js b/template/cordova/lib/MSBuildTools.js
index b694fe9..2384242 100644
--- a/template/cordova/lib/MSBuildTools.js
+++ b/template/cordova/lib/MSBuildTools.js
@@ -75,9 +75,28 @@ MSBuildTools.prototype.buildProject = function (projFile, buildType, buildarch,
 // check_reqs.js -> checkMSBuild()
 module.exports.findAllAvailableVersions = function () {
     console.log('findAllAvailableVersions');
+
+    var msBuildPath = '';
+
+    // Use MSBUILDDIR environment variable if defined to find MSBuild.
+    // MSBUILDDIR = C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin
+    // MSBUILDDIR = C:\Program Files (x86)\MSBuild\14.0\bin\
+    if (process.env.MSBUILDDIR) {
+        console.log('ENV var MSBUILDDIR is set', process.env.MSBUILDDIR);
+        msBuildPath = process.env.MSBUILDDIR;
+        return module.exports.getMSBuildToolsAt(msBuildPath)
+            .then(function (msBuildTools) {
+                return [msBuildTools];
+            })
+            // If MSBUILDDIR is not specified or doesn't contain a valid MSBuild
+            // - fall back to default discovery mechanism.
+            .catch(findAllAvailableVersionsFallBack);
+    }
+
     // CB-11548 use VSINSTALLDIR environment if defined to find MSBuild.
     if (process.env.VSINSTALLDIR) {
-        var msBuildPath = path.join(process.env.VSINSTALLDIR, 'MSBuild/15.0/Bin');
+        console.log('ENV var VSINSTALLDIR is set', process.env.VSINSTALLDIR);
+        msBuildPath = path.join(process.env.VSINSTALLDIR, 'MSBuild/15.0/Bin');
         return module.exports.getMSBuildToolsAt(msBuildPath)
             .then(function (msBuildTools) {
                 return [msBuildTools];

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

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