Bug 1291944 - Verify makensis binary is 32-bits; r?glandium
This required implementing a utility function to resolve the binary
type. I used GetBinaryTypeW via ctypes because this seems the fastest.
I arbitrarily limited the function to testing 32-bit and 64-bit Windows
executables because hopefully those are the only executables we'll
ever encounter. We can expand the binary detection later, if needed.
This includes support for running on non-Windows platforms.
MozReview-Commit-ID: CYwyDWQrePc
--- a/build/moz.configure/util.configure
+++ b/build/moz.configure/util.configure
@@ -59,16 +59,42 @@ def is_absolute_or_relative(path):
@imports(_import='mozpack.path', _as='mozpath')
def normsep(path):
return mozpath.normsep(path)
@imports('ctypes')
@imports(_from='ctypes', _import='wintypes')
+@imports(_from='mozbuild.configure.constants', _import='WindowsBinaryType')
+def windows_binary_type(path):
+ """Obtain the type of a binary on Windows.
+
+ Returns WindowsBinaryType constant.
+ """
+ GetBinaryTypeW = ctypes.windll.kernel32.GetBinaryTypeW
+ GetBinaryTypeW.argtypes = [wintypes.LPWSTR, wintypes.POINTER(wintypes.DWORD)]
+ GetBinaryTypeW.restype = wintypes.BOOL
+
+ bin_type = wintypes.DWORD()
+ res = GetBinaryTypeW(path, ctypes.byref(bin_type))
+ if not res:
+ die('could not obtain binary type of %s' % path)
+
+ if bin_type.value == 0:
+ return WindowsBinaryType('win32')
+ elif bin_type.value == 6:
+ return WindowsBinaryType('win64')
+ # If we see another binary type, something is likely horribly wrong.
+ else:
+ die('unsupported binary type on %s: %s' % (path, bin_type))
+
+
+@imports('ctypes')
+@imports(_from='ctypes', _import='wintypes')
def get_GetShortPathNameW():
GetShortPathNameW = ctypes.windll.kernel32.GetShortPathNameW
GetShortPathNameW.argtypes = [wintypes.LPCWSTR, wintypes.LPWSTR,
wintypes.DWORD]
GetShortPathNameW.restype = wintypes.DWORD
return GetShortPathNameW
--- a/moz.configure
+++ b/moz.configure
@@ -290,12 +290,22 @@ def nsis_version(nsis):
if ver < nsis_min_version:
raise FatalCheckError('To build the installer you must have NSIS'
' version %s or greater in your path'
% nsis_min_version)
return ver
+# And that makensis is 32-bit.
+@depends_if(nsis)
+@checking('for 32-bit NSIS')
+def nsis_binary_type(nsis):
+ bin_type = windows_binary_type(nsis)
+ if bin_type != 'win32':
+ raise FatalCheckError('%s is not a 32-bit Windows application' % nsis)
+
+ return 'yes'
+
# Fallthrough to autoconf-based configure
include('build/moz.configure/old.configure')
# Please do not add anything after the include of old.configure.
--- a/python/mozbuild/mozbuild/configure/constants.py
+++ b/python/mozbuild/mozbuild/configure/constants.py
@@ -58,16 +58,21 @@ CPU_bitness = {
CPU = EnumString.subclass(*CPU_bitness.keys())
Endianness = EnumString.subclass(
'big',
'little',
)
+WindowsBinaryType = EnumString.subclass(
+ 'win32',
+ 'win64',
+)
+
# The order of those checks matter
CPU_preprocessor_checks = OrderedDict((
('x86', '__i386__ || _M_IX86'),
('x86_64', '__x86_64__ || _M_X64'),
('arm', '__arm__ || _M_ARM'),
('aarch64', '__aarch64__'),
('ia64', '__ia64__'),
('s390x', '__s390x__'),