Skip to content

Commit

Permalink
Bug 1291944 - Verify makensis binary is 32-bits; r=glandium
Browse files Browse the repository at this point in the history
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
  • Loading branch information
indygreg committed Aug 16, 2016
1 parent 3dffde2 commit 2562138
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
26 changes: 26 additions & 0 deletions build/moz.configure/util.configure
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
10 changes: 10 additions & 0 deletions moz.configure
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
5 changes: 5 additions & 0 deletions python/mozbuild/mozbuild/configure/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@
'little',
)

WindowsBinaryType = EnumString.subclass(
'win32',
'win64',
)

# The order of those checks matter
CPU_preprocessor_checks = OrderedDict((
('x86', '__i386__ || _M_IX86'),
Expand Down

0 comments on commit 2562138

Please sign in to comment.