From 2562138ede21fbe12c39c47a740b59fda212ac10 Mon Sep 17 00:00:00 2001 From: Gregory Szorc Date: Mon, 15 Aug 2016 18:11:48 -0700 Subject: [PATCH] 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 --HG-- extra : rebase_source : 8fd7ca7f253d9e9e18d64784652a5ff934ad2272 --- build/moz.configure/util.configure | 26 +++++++++++++++++++ moz.configure | 10 +++++++ .../mozbuild/mozbuild/configure/constants.py | 5 ++++ 3 files changed, 41 insertions(+) diff --git a/build/moz.configure/util.configure b/build/moz.configure/util.configure index 2c476c0c1add..537b6f0ab66c 100644 --- a/build/moz.configure/util.configure +++ b/build/moz.configure/util.configure @@ -62,6 +62,32 @@ 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(): diff --git a/moz.configure b/moz.configure index a027a7d2b456..dcb58bc1f783 100644 --- a/moz.configure +++ b/moz.configure @@ -295,6 +295,16 @@ def nsis_version(nsis): 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') diff --git a/python/mozbuild/mozbuild/configure/constants.py b/python/mozbuild/mozbuild/configure/constants.py index fb946a10fd83..dfc7cf8ad76e 100644 --- a/python/mozbuild/mozbuild/configure/constants.py +++ b/python/mozbuild/mozbuild/configure/constants.py @@ -63,6 +63,11 @@ Endianness = EnumString.subclass( 'little', ) +WindowsBinaryType = EnumString.subclass( + 'win32', + 'win64', +) + # The order of those checks matter CPU_preprocessor_checks = OrderedDict(( ('x86', '__i386__ || _M_IX86'),