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 15:34:07 UTC

[cordova-windows] branch master updated: CB-13878 MSBUILDDIR env variable (#262)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 8c07366  CB-13878 MSBUILDDIR env variable (#262)
8c07366 is described below

commit 8c07366fb8d784563a2fefe7d9bb326cb1cb721d
Author: Jan Piotrowski <pi...@gmail.com>
AuthorDate: Thu Feb 15 16:34:04 2018 +0100

    CB-13878 MSBUILDDIR env variable (#262)
    
    * MSBUILDDIR for MSBuild selection
    
    * Change order of builds on AppVeyor
    
    * Use MSBUILDDIR on AppVeyor
    
    * avoid crosspolution in tests that rely on ENV vars (uh, ugly)
    
    * console.log msbuild command and params that are used to build
---
 appveyor.yml                         | 18 ++++++++++++++----
 spec/unit/build.spec.js              | 34 +++++++++++++++++++++++++++++++++-
 template/cordova/lib/MSBuildTools.js | 22 +++++++++++++++++++++-
 3 files changed, 68 insertions(+), 6 deletions(-)

diff --git a/appveyor.yml b/appveyor.yml
index 382664e..19e7f28 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -19,13 +19,23 @@
 # appveyor file
 # http://www.appveyor.com/docs/appveyor-yml
 
-image:
-- Visual Studio 2015
-- Visual Studio 2017
 environment:
   matrix:
-    - nodejs_version: "4"
     - nodejs_version: "6"
+      APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
+
+    - nodejs_version: "6"
+      APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
+      MSBUILDDIR: "C:\\Program Files (x86)\\MSBuild\\14.0\\bin\\"
+
+    - nodejs_version: "6"
+      APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
+
+    - nodejs_version: "4"
+      APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
+
+    - nodejs_version: "4"
+      APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
 
 install:
   - ps: Install-Product node $env:nodejs_version
diff --git a/spec/unit/build.spec.js b/spec/unit/build.spec.js
index 81b2ada..f9f55fa 100644
--- a/spec/unit/build.spec.js
+++ b/spec/unit/build.spec.js
@@ -371,11 +371,14 @@ 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';
         process.env.VSINSTALLDIR = customMSBuildPath;
+        // avoid crosspollution with MSBUILDDIR
+        var backupMSBUILDDIR = process.env.MSBUILDDIR;
+        delete process.env.MSBUILDDIR;
 
         spyOn(MSBuildTools, 'getMSBuildToolsAt')
             .and.returnValue(Q({
@@ -392,6 +395,35 @@ describe('run method', function () {
                 expect(fail).not.toHaveBeenCalled();
                 expect(MSBuildTools.getMSBuildToolsAt).toHaveBeenCalledWith(msBuildBinPath);
                 delete process.env.VSINSTALLDIR;
+                process.env.MSBUILDDIR = backupMSBUILDDIR;
+                done();
+            });
+    });
+
+    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;
+        // avoid crosspollution with VSINSTALLDIR
+        var backupVSINSTALLDIR = process.env.VSINSTALLDIR;
+        delete process.env.VSINSTALLDIR;
+
+        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;
+                process.env.VSINSTALLDIR = backupVSINSTALLDIR;
                 done();
             });
     });
diff --git a/template/cordova/lib/MSBuildTools.js b/template/cordova/lib/MSBuildTools.js
index fa05e73..c65e169 100644
--- a/template/cordova/lib/MSBuildTools.js
+++ b/template/cordova/lib/MSBuildTools.js
@@ -68,6 +68,7 @@ MSBuildTools.prototype.buildProject = function (projFile, buildType, buildarch,
     }
 
     return promise.then(function () {
+        console.log('buildProject spawn:', path.join(that.path, 'msbuild'), [projFile].concat(args), { stdio: 'inherit' });
         return spawn(path.join(that.path, 'msbuild'), [projFile].concat(args), { stdio: 'inherit' });
     });
 };
@@ -75,9 +76,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