cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From purplecabb...@apache.org
Subject [1/2] git commit: CB-6083 [windows8] Use registry to read msbuild tools path
Date Sat, 22 Feb 2014 05:19:52 GMT
Repository: cordova-windows
Updated Branches:
  refs/heads/master 9768a159a -> b4c4f2324


CB-6083 [windows8] Use registry to read msbuild tools path


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

Branch: refs/heads/master
Commit: ba2d1d0e65e9bff80bd8f09095f574b760003070
Parents: feac47f
Author: sgrebnov <sergei.grebnov@gmail.com>
Authored: Fri Feb 21 18:02:26 2014 +0400
Committer: sgrebnov <sergei.grebnov@gmail.com>
Committed: Fri Feb 21 18:02:26 2014 +0400

----------------------------------------------------------------------
 windows8/template/cordova/lib/build.js | 103 ++++++++++++++++++++++------
 1 file changed, 83 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/ba2d1d0e/windows8/template/cordova/lib/build.js
----------------------------------------------------------------------
diff --git a/windows8/template/cordova/lib/build.js b/windows8/template/cordova/lib/build.js
index 87fd42c..77296e0 100644
--- a/windows8/template/cordova/lib/build.js
+++ b/windows8/template/cordova/lib/build.js
@@ -70,6 +70,7 @@ function exec_verbose(command) {
         Log(line, true);
         WScript.Quit(2);
     }
+    return oShell.ExitCode;
 }
 
 // checks to see if a .jsproj file exists in the project root
@@ -86,6 +87,51 @@ function is_cordova_project(path) {
     return false;
 }
 
+// escapes a path so that it can be passed to shell command. 
+function escapePath(path) {
+    return '"' + path + '"';
+}
+
+// returns full path to .sln file
+function getSolutionDir(path) {
+    var proj_folder = fso.GetFolder(path);
+    var proj_files = new Enumerator(proj_folder.Files);
+    for (;!proj_files.atEnd(); proj_files.moveNext()) {
+        if (fso.GetExtensionName(proj_files.item()) == 'sln') {
+            return path + '\\' + fso.GetFileName(proj_files.item());  
+        }
+    }
+
+    return null;
+}
+
+// returns full path to msbuild tools required to build the project
+function getMSBuildToolsPath(path) {
+    // target windows8 by default
+    var MSBuildVer = '4.0';
+    var installInstructions = 'Please install the .NET Framework v4.0.';
+    // windows8.1 template requires msbuild v12.0
+    // get tools version from jsproj file
+    var proj_folder = fso.GetFolder(path);
+    var proj_files = new Enumerator(proj_folder.Files);
+    for (;!proj_files.atEnd(); proj_files.moveNext()) {
+        if (fso.GetExtensionName(proj_files.item()) == 'jsproj' && 
+            fso.OpenTextFile(proj_files.item(), 1).ReadAll().indexOf('ToolsVersion="12.0"')
> 0) {
+                MSBuildVer = '12.0';
+                installInstructions = 'Please install Microsoft Visual Studio 2013 or later';
+        }
+    }
+    Log('\tMSBuild version required: ' + MSBuildVer);
+    try {
+        return wscript_shell.RegRead('HKLM\\SOFTWARE\\Microsoft\\MSBuild\\ToolsVersions\\'
+ MSBuildVer + '\\MSBuildToolsPath');
+    } catch (err) {
+        Log(installInstructions, true);
+        WScript.Quit(2);
+    }
+    
+    return MSBuildToolsPath;
+}
+
 // builds the project and .xap in debug mode
 function build_appx(path,isRelease) {
 
@@ -93,32 +139,49 @@ function build_appx(path,isRelease) {
     Log("Building Cordova Windows 8 Project:");
     Log("\tConfiguration : " + mode);
     Log("\tDirectory : " + path);
-    
-    wscript_shell.CurrentDirectory = path;
-    exec_verbose('msbuild /clp:NoSummary;NoItemAndPropertyList;Verbosity=minimal /nologo
/p:Configuration=' + mode);
-
-    // TODO: there could be multiple AppPackages
-    // check if AppPackages created
-    if (fso.FolderExists(path + '\\AppPackages')) {
-        var out_folder = fso.GetFolder(path + '\\AppPackages');
-        var subFolders = new Enumerator(out_folder.SubFolders);
-        for(;!subFolders.atEnd();subFolders.moveNext())
-        {
-            var subFolder = subFolders.item();
-            var files = new Enumerator(subFolder.Files);
-            for(;!files.atEnd();files.moveNext())
+
+    try {
+        wscript_shell.CurrentDirectory = path;
+        var MSBuildToolsPath = getMSBuildToolsPath(path);
+        Log("\tMSBuildToolsPath: " + MSBuildToolsPath);
+        var solutionDir = getSolutionDir(path);
+        var buildCommand = escapePath(MSBuildToolsPath + 'msbuild') + ' ' + escapePath(solutionDir)
+
+            ' /clp:NoSummary;NoItemAndPropertyList;Verbosity=minimal /nologo /p:Configuration='
+ mode;
+        
+        // hack to get rid of 'Access is denied.' error when running the shell w/ access
to C:\path..
+        buildCommand = 'cmd /c "' + buildCommand + '"';
+        Log(buildCommand);
+        if (exec_verbose(buildCommand) != 0) {
+            // msbuild failed
+            WScript.Quit(2);
+        }
+
+        // TODO: there could be multiple AppPackages
+        // check if AppPackages created
+        if (fso.FolderExists(path + '\\AppPackages')) {
+            var out_folder = fso.GetFolder(path + '\\AppPackages');
+            var subFolders = new Enumerator(out_folder.SubFolders);
+            for(;!subFolders.atEnd();subFolders.moveNext())
             {
-                if(fso.GetExtensionName(files.item()) == "ps1")
+                var subFolder = subFolders.item();
+                var files = new Enumerator(subFolder.Files);
+                for(;!files.atEnd();files.moveNext())
                 {
-                    // app was built, installation script exists
-                    return "Success";
-                }
+                    if(fso.GetExtensionName(files.item()) == "ps1")
+                    {
+                        // app was built, installation script exists
+                        return "Success";
+                    }
 
+                }
             }
-        }
 
+        }
+    } catch (err) {
+        Log("Build failed: " + err.message, true);
     }
-    return "Error : AppPackages were not built";
+    Log("Error : AppPackages were not built");
+    WScript.Quit(2);
 
 }
 


Mime
View raw message