Bug 1183077: Include CPU architecture in build target on Windows. r=rstrong
authorStephen A Pohl <spohl.mozilla.bugs@gmail.com>
Mon, 27 Jul 2015 10:17:53 -0400
changeset 286413 2a1163cd7736bc2cdff56defaf4f24f3d5b186bb
parent 286412 b44a29e2044c60f5409c56d5767d5a1ff2dd8108
child 286414 c22ad1335d55c58e3ea1311617900dd81fd11160
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrstrong
bugs1183077
milestone42.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1183077: Include CPU architecture in build target on Windows. r=rstrong
toolkit/mozapps/update/nsUpdateService.js
--- a/toolkit/mozapps/update/nsUpdateService.js
+++ b/toolkit/mozapps/update/nsUpdateService.js
@@ -240,16 +240,19 @@ XPCOMUtils.defineLazyGetter(this, "gABI"
     // Mac universal build should report a different ABI than either macppc
     // or mactel.
     let macutils = Cc["@mozilla.org/xpcom/mac-utils;1"].
                    getService(Ci.nsIMacUtils);
 
     if (macutils.isUniversalBinary) {
       abi += "-u-" + macutils.architecturesInBinary;
     }
+  } else if (AppConstants.platform == "win") {
+    // Windows build should report the CPU architecture that it's running on.
+    abi += "-" + gWinCPUArch;
   }
   return abi;
 });
 
 XPCOMUtils.defineLazyGetter(this, "gOSVersion", function aus_gOSVersion() {
   let osVersion;
   try {
     osVersion = Services.sysinfo.getProperty("name") + " " +
@@ -305,17 +308,17 @@ XPCOMUtils.defineLazyGetter(this, "gOSVe
       let kernel32 = false;
       try {
         kernel32 = ctypes.open("Kernel32");
       } catch (e) {
         LOG("gOSVersion - Unable to open kernel32! " + e);
         osVersion += ".unknown (unknown)";
       }
 
-      if(kernel32) {
+      if (kernel32) {
         try {
           // Get Service pack info
           try {
             let GetVersionEx = kernel32.declare("GetVersionExW",
                                                 ctypes.default_abi,
                                                 BOOL,
                                                 OSVERSIONINFOEXW.ptr);
             let winVer = OSVERSIONINFOEXW();
@@ -327,62 +330,101 @@ XPCOMUtils.defineLazyGetter(this, "gOSVe
             } else {
               LOG("gOSVersion - Unknown failure in GetVersionEX (returned 0)");
               osVersion += ".unknown";
             }
           } catch (e) {
             LOG("gOSVersion - error getting service pack information. Exception: " + e);
             osVersion += ".unknown";
           }
-
-          // Get processor architecture
-          let arch = "unknown";
-          try {
-            let GetNativeSystemInfo = kernel32.declare("GetNativeSystemInfo",
-                                                       ctypes.default_abi,
-                                                       ctypes.void_t,
-                                                       SYSTEM_INFO.ptr);
-            let winSystemInfo = SYSTEM_INFO();
-            // Default to unknown
-            winSystemInfo.wProcessorArchitecture = 0xffff;
-
-            GetNativeSystemInfo(winSystemInfo.address());
-            switch(winSystemInfo.wProcessorArchitecture) {
-              case 9:
-                arch = "x64";
-                break;
-              case 6:
-                arch = "IA64";
-                break;
-              case 0:
-                arch = "x86";
-                break;
-            }
-          } catch (e) {
-            LOG("gOSVersion - error getting processor architecture.  Exception: " + e);
-          } finally {
-            osVersion += " (" + arch + ")";
-          }
         } finally {
           kernel32.close();
         }
+
+        // Add processor architecture
+        osVersion += " (" + gWinCPUArch + ")";
       }
     }
 
     try {
       osVersion += " (" + Services.sysinfo.getProperty("secondaryLibrary") + ")";
     }
     catch (e) {
       // Not all platforms have a secondary widget library, so an error is nothing to worry about.
     }
     osVersion = encodeURIComponent(osVersion);
   }
   return osVersion;
 });
 
+/* Windows only getter that returns the processor architecture. */
+XPCOMUtils.defineLazyGetter(this, "gWinCPUArch", function aus_gWinCPUArch() {
+  // Get processor architecture
+  let arch = "unknown";
+
+  const WORD = ctypes.uint16_t;
+  const DWORD = ctypes.uint32_t;
+
+  // This structure is described at:
+  // http://msdn.microsoft.com/en-us/library/ms724958%28v=vs.85%29.aspx
+  const SYSTEM_INFO = new ctypes.StructType('SYSTEM_INFO',
+      [
+      {wProcessorArchitecture: WORD},
+      {wReserved: WORD},
+      {dwPageSize: DWORD},
+      {lpMinimumApplicationAddress: ctypes.voidptr_t},
+      {lpMaximumApplicationAddress: ctypes.voidptr_t},
+      {dwActiveProcessorMask: DWORD.ptr},
+      {dwNumberOfProcessors: DWORD},
+      {dwProcessorType: DWORD},
+      {dwAllocationGranularity: DWORD},
+      {wProcessorLevel: WORD},
+      {wProcessorRevision: WORD}
+      ]);
+
+  let kernel32 = false;
+  try {
+    kernel32 = ctypes.open("Kernel32");
+  } catch (e) {
+    LOG("gWinCPUArch - Unable to open kernel32! Exception: " + e);
+  }
+
+  if (kernel32) {
+    try {
+      let GetNativeSystemInfo = kernel32.declare("GetNativeSystemInfo",
+                                                 ctypes.default_abi,
+                                                 ctypes.void_t,
+                                                 SYSTEM_INFO.ptr);
+      let winSystemInfo = SYSTEM_INFO();
+      // Default to unknown
+      winSystemInfo.wProcessorArchitecture = 0xffff;
+
+      GetNativeSystemInfo(winSystemInfo.address());
+      switch (winSystemInfo.wProcessorArchitecture) {
+        case 9:
+          arch = "x64";
+          break;
+        case 6:
+          arch = "IA64";
+          break;
+        case 0:
+          arch = "x86";
+          break;
+      }
+    } catch (e) {
+      LOG("gWinCPUArch - error getting processor architecture. " +
+          "Exception: " + e);
+    } finally {
+      kernel32.close();
+    }
+  }
+
+  return arch;
+});
+
 /**
  * Tests to make sure that we can write to a given directory.
  *
  * @param updateTestFile a test file in the directory that needs to be tested.
  * @param createDirectory whether a test directory should be created.
  * @throws if we don't have right access to the directory.
  */
 function testWriteAccess(updateTestFile, createDirectory) {