You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by pu...@apache.org on 2014/04/10 00:51:40 UTC

git commit: CB-6341 don't rely on msbuild being in the path.

Repository: cordova-wp8
Updated Branches:
  refs/heads/master 1fae9f993 -> 30fba4235


CB-6341 don't rely on msbuild being in the path.


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

Branch: refs/heads/master
Commit: 30fba42357f8b6cf2e9a433128369c8f4cc914bb
Parents: 1fae9f9
Author: Jesse MacFadyen <pu...@gmail.com>
Authored: Wed Apr 9 15:50:15 2014 -0700
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Wed Apr 9 15:50:15 2014 -0700

----------------------------------------------------------------------
 wp7/template/cordova/lib/build.js | 56 +++++++++++++++++++++++++++++++---
 wp8/template/cordova/lib/build.js | 56 +++++++++++++++++++++++++++++++---
 2 files changed, 104 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/30fba423/wp7/template/cordova/lib/build.js
----------------------------------------------------------------------
diff --git a/wp7/template/cordova/lib/build.js b/wp7/template/cordova/lib/build.js
index bd7c494..1dadbe0 100644
--- a/wp7/template/cordova/lib/build.js
+++ b/wp7/template/cordova/lib/build.js
@@ -72,6 +72,11 @@ function exec_verbose(command) {
     }
 }
 
+// escapes a path so that it can be passed to shell command. 
+function escapePath(path) {
+    return '"' + path + '"';
+}
+
 // checks to see if a .csproj file exists in the project root
 function is_cordova_project(path) {
     if (fso.FolderExists(path)) {
@@ -99,6 +104,21 @@ function get_solution_name(path) {
     return null;
 }
 
+// returns full path to msbuild tools required to build the project
+function getMSBuildToolsPath() {
+    // use the latest version of the msbuild tools available on this machine
+    var toolsVersions = ['4.0'];          // for WP7 we REQUIRE 4.0 !!!
+    for (idx in toolsVersions) {
+        try {
+            return wscript_shell.RegRead('HKLM\\SOFTWARE\\Microsoft\\MSBuild\\ToolsVersions\\' + toolsVersions[idx] + '\\MSBuildToolsPath');
+        } catch (err) {
+            Log("toolsVersion " + idx + " is not supported");
+        }
+    }
+    Log('MSBuild tools have not been found. Please install Microsoft Visual Studio 2012 or later', true);
+    WScript.Quit(2);
+}
+
 // builds the project and .xap in release mode
 function build_xap_release(path) {
 
@@ -109,8 +129,22 @@ function build_xap_release(path) {
     Log("\tDirectory : " + path);
 
     wscript_shell.CurrentDirectory = path;
-    var cmd = 'msbuild "' + get_solution_name(path) + '" /clp:NoSummary;NoItemAndPropertyList;Verbosity=minimal /nologo /p:Configuration=Release';
-    exec_verbose(cmd);
+    
+    var MSBuildToolsPath = getMSBuildToolsPath();
+    Log("\tMSBuildToolsPath: " + MSBuildToolsPath);
+
+    var buildCommand = escapePath(MSBuildToolsPath + 'msbuild') + ' ' + escapePath(get_solution_name(path)) +
+            ' /clp:NoSummary;NoItemAndPropertyList;Verbosity=minimal /nologo /p:Configuration=Release';
+        
+    // hack to get rid of 'Access is denied.' error when running the shell w/ access to C:\path..
+    buildCommand = 'cmd /c "' + buildCommand + '"';
+        
+    Log("buildCommand = " + buildCommand);
+
+    if (exec_verbose(buildCommand) != 0) {
+        // msbuild failed
+        WScript.Quit(2);
+    }
 
     // check if file xap was created
     if (fso.FolderExists(path + '\\Bin\\Release')) {
@@ -137,8 +171,22 @@ function build_xap_debug(path) {
     Log("\tDirectory : " + path);
 
     wscript_shell.CurrentDirectory = path;
-    var cmd = 'msbuild "' + get_solution_name(path) + '" /clp:NoSummary;NoItemAndPropertyList;Verbosity=minimal /nologo /p:Configuration=Debug';
-    exec_verbose(cmd);
+
+    var MSBuildToolsPath = getMSBuildToolsPath();
+    Log("\tMSBuildToolsPath: " + MSBuildToolsPath);
+
+    var buildCommand = escapePath(MSBuildToolsPath + 'msbuild') + ' ' + escapePath(get_solution_name(path)) +
+            ' /clp:NoSummary;NoItemAndPropertyList;Verbosity=minimal /nologo /p:Configuration=Debug';
+
+    // hack to get rid of 'Access is denied.' error when running the shell w/ access to C:\path..
+    buildCommand = '%comspec% /c "' + buildCommand + '"';
+
+    Log("buildCommand = " + buildCommand);
+
+    if (exec_verbose(buildCommand) != 0) {
+        // msbuild failed
+        WScript.Quit(2);
+    }
 
     // check if file xap was created
     if (fso.FolderExists(path + '\\Bin\\Debug')) {

http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/30fba423/wp8/template/cordova/lib/build.js
----------------------------------------------------------------------
diff --git a/wp8/template/cordova/lib/build.js b/wp8/template/cordova/lib/build.js
index 2c6406a..c5b3b69 100644
--- a/wp8/template/cordova/lib/build.js
+++ b/wp8/template/cordova/lib/build.js
@@ -72,6 +72,11 @@ function exec_verbose(command) {
     }
 }
 
+// escapes a path so that it can be passed to shell command. 
+function escapePath(path) {
+    return '"' + path + '"';
+}
+
 // checks to see if a .csproj file exists in the project root
 function is_cordova_project(path) {
     if (fso.FolderExists(path)) {
@@ -99,6 +104,21 @@ function get_solution_name(path) {
     return null;
 }
 
+// returns full path to msbuild tools required to build the project
+function getMSBuildToolsPath() {
+    // use the latest version of the msbuild tools available on this machine
+    var toolsVersions = ['12.0','4.0'];          // for WP8 we REQUIRE 4.0 !!!
+    for (idx in toolsVersions) {
+        try {
+            return wscript_shell.RegRead('HKLM\\SOFTWARE\\Microsoft\\MSBuild\\ToolsVersions\\' + toolsVersions[idx] + '\\MSBuildToolsPath');
+        } catch (err) {
+            Log("toolsVersion " + idx + " is not supported");
+        }
+    }
+    Log('MSBuild tools have not been found. Please install Microsoft Visual Studio 2012 or later', true);
+    WScript.Quit(2);
+}
+
 // builds the project and .xap in release mode
 function build_xap_release(path) {
 
@@ -109,8 +129,22 @@ function build_xap_release(path) {
     Log("\tDirectory : " + path);
 
     wscript_shell.CurrentDirectory = path;
-    var cmd = 'msbuild "' + get_solution_name(path) + '" /clp:NoSummary;NoItemAndPropertyList;Verbosity=minimal /nologo /p:Configuration=Release';
-    exec_verbose(cmd);
+    
+    var MSBuildToolsPath = getMSBuildToolsPath();
+    Log("\tMSBuildToolsPath: " + MSBuildToolsPath);
+
+    var buildCommand = escapePath(MSBuildToolsPath + 'msbuild') + ' ' + escapePath(get_solution_name(path)) +
+            ' /clp:NoSummary;NoItemAndPropertyList;Verbosity=minimal /nologo /p:Configuration=Release';
+        
+    // hack to get rid of 'Access is denied.' error when running the shell w/ access to C:\path..
+    buildCommand = 'cmd /c "' + buildCommand + '"';
+        
+    Log("buildCommand = " + buildCommand);
+
+    if (exec_verbose(buildCommand) != 0) {
+        // msbuild failed
+        WScript.Quit(2);
+    }
 
     // check if file xap was created
     if (fso.FolderExists(path + '\\Bin\\Release')) {
@@ -137,8 +171,22 @@ function build_xap_debug(path) {
     Log("\tDirectory : " + path);
 
     wscript_shell.CurrentDirectory = path;
-    var cmd = 'msbuild "' + get_solution_name(path) + '" /clp:NoSummary;NoItemAndPropertyList;Verbosity=minimal /nologo /p:Configuration=Debug';
-    exec_verbose(cmd);
+
+    var MSBuildToolsPath = getMSBuildToolsPath();
+    Log("\tMSBuildToolsPath: " + MSBuildToolsPath);
+
+    var buildCommand = escapePath(MSBuildToolsPath + 'msbuild') + ' ' + escapePath(get_solution_name(path)) +
+            ' /clp:NoSummary;NoItemAndPropertyList;Verbosity=minimal /nologo /p:Configuration=Debug';
+
+    // hack to get rid of 'Access is denied.' error when running the shell w/ access to C:\path..
+    buildCommand = '%comspec% /c "' + buildCommand + '"';
+
+    Log("buildCommand = " + buildCommand);
+
+    if (exec_verbose(buildCommand) != 0) {
+        // msbuild failed
+        WScript.Quit(2);
+    }
 
     // check if file xap was created
     if (fso.FolderExists(path + '\\Bin\\Debug')) {