Bug 1289291 - Move Windows SDK detection to python configure. r=chmanchester
authorMike Hommey <mh+mozilla@glandium.org>
Fri, 22 Jul 2016 19:10:04 +0900
changeset 331817 656febbe6d05dc01c16fca8ff0a12c8e89141927
parent 331816 be8b0845f2839a5209aa6cb2bb98df1ec8f4b7b3
child 331818 a9896c4309bb5eca9ae6973e261fd51422c65ad3
push id9858
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 14:37:10 +0000
treeherdermozilla-aurora@203106ef6cb6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerschmanchester
bugs1289291
milestone50.0a1
Bug 1289291 - Move Windows SDK detection to python configure. r=chmanchester At the same time, autodetect the SDK if WINDOWSSDKDIR is not given.
aclocal.m4
build/autoconf/winsdk.m4
build/moz.configure/windows.configure
js/src/aclocal.m4
js/src/old-configure.in
old-configure.in
--- a/aclocal.m4
+++ b/aclocal.m4
@@ -20,17 +20,16 @@ builtin(include, build/autoconf/mozcommo
 builtin(include, build/autoconf/lto.m4)dnl
 builtin(include, build/autoconf/frameptr.m4)dnl
 builtin(include, build/autoconf/compiler-opts.m4)dnl
 builtin(include, build/autoconf/expandlibs.m4)dnl
 builtin(include, build/autoconf/arch.m4)dnl
 builtin(include, build/autoconf/android.m4)dnl
 builtin(include, build/autoconf/zlib.m4)dnl
 builtin(include, build/autoconf/linux.m4)dnl
-builtin(include, build/autoconf/winsdk.m4)dnl
 builtin(include, build/autoconf/icu.m4)dnl
 builtin(include, build/autoconf/ffi.m4)dnl
 builtin(include, build/autoconf/clang-plugin.m4)dnl
 builtin(include, build/autoconf/alloc.m4)dnl
 builtin(include, build/autoconf/ios.m4)dnl
 builtin(include, build/autoconf/jemalloc.m4)dnl
 builtin(include, build/autoconf/sanitize.m4)dnl
 
deleted file mode 100644
--- a/build/autoconf/winsdk.m4
+++ /dev/null
@@ -1,22 +0,0 @@
-dnl This Source Code Form is subject to the terms of the Mozilla Public
-dnl License, v. 2.0. If a copy of the MPL was not distributed with this
-dnl file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
-dnl Identify which version of the SDK we're building with
-dnl Windows Server 2008 and newer SDKs have WinSDKVer.h, get the version
-dnl from there
-AC_DEFUN([MOZ_FIND_WINSDK_VERSION], [
-  AC_CACHE_CHECK(for highest Windows version supported by this SDK,
-                 ac_cv_winsdk_maxver,
-                 [cat > conftest.h <<EOF
-#include <winsdkver.h>
-
-WINVER_MAXVER
-EOF
-                      ac_cv_winsdk_maxver=`$CPP conftest.h 2>/dev/null | tail -n1`
-                      rm -f conftest.h
-                     ])
-      dnl WinSDKVer.h returns the version number in 4-digit format while many
-      dnl consumers expect 8. Therefore, pad the result with an extra 4 zeroes.
-      MOZ_WINSDK_MAXVER=${ac_cv_winsdk_maxver}0000
-])
--- a/build/moz.configure/windows.configure
+++ b/build/moz.configure/windows.configure
@@ -8,25 +8,114 @@ option('--with-windows-version', nargs=1
        help='Windows SDK version to target. Win 8.1 (603) is currently'
             'the minimum supported version.')
 
 @depends(target)
 def is_windows(target):
     return target.kernel == 'WINNT'
 
 
-@depends_when('--with-windows-version', when=is_windows)
+@template
+def depends_win(*args):
+    return depends_when(*args, when=is_windows)
+
+
+@depends_win('--with-windows-version')
 @imports(_from='__builtin__', _import='ValueError')
 def valid_windows_version(value):
     if not value:
         die('Cannot build with --without-windows-version')
     try:
         version = int(value[0], 16)
         if version in (0x603,):
             return version
     except ValueError:
         pass
 
     die('Invalid value for --with-windows-version (%s)', value[0])
 
+
+option(env='WINDOWSSDKDIR', nargs=1,
+       help='Directory containing the Windows SDK')
+
+@depends_win('WINDOWSSDKDIR', host)
+def windows_sdk_dir(value, host):
+    if value:
+        return value
+    if host.kernel != 'WINNT':
+        return ()
+
+    return tuple(x[1] for x in get_registry_values(
+        r'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Kits\Installed Roots'
+        r'\KitsRoot*'))
+
+@imports(_from='mozbuild.shellutil', _import='quote')
+def valid_windows_sdk_dir_result(value):
+    if value:
+        return '0x%04x in %s' % (value.version, quote(value.path))
+
+@depends_win(c_compiler, windows_sdk_dir, valid_windows_version,
+             'WINDOWSSDKDIR')
+@checking('for Windows SDK', valid_windows_sdk_dir_result)
+@imports(_from='__builtin__', _import='sorted')
+@imports(_from='textwrap', _import='dedent')
+def valid_windows_sdk_dir(compiler, windows_sdk_dir, target_version,
+                          windows_sdk_dir_env):
+    if windows_sdk_dir_env:
+        windows_sdk_dir_env = windows_sdk_dir_env[0]
+    sdks = {}
+    for d in windows_sdk_dir:
+        um_dir = os.path.join(d, 'include', 'um')
+        shared_dir = os.path.join(d, 'include', 'shared')
+        if os.path.isdir(um_dir) and os.path.isdir(shared_dir):
+            check = dedent('''\
+            #include <winsdkver.h>
+            WINVER_MAXVER
+            ''')
+            result = try_preprocess(compiler.wrapper + [compiler.compiler] +
+                                    compiler.flags +
+                                    ['-I', um_dir, '-I', shared_dir], 'C',
+                                    check)
+            if result:
+                maxver = result.splitlines()[-1]
+                try:
+                    maxver = int(maxver, 0)
+                except:
+                    pass
+                else:
+                    sdks[d] = maxver
+                    continue
+        if d == windows_sdk_dir_env:
+            raise FatalCheckError(
+                'Error while checking the version of the SDK in '
+                'WINDOWSSDKDIR (%s). Please verify it contains a valid and '
+                'complete SDK installation.' % windows_sdk_dir_env)
+
+    valid_sdks = sorted(sdks, key=lambda x: sdks[x], reverse=True)
+    if valid_sdks:
+        biggest_version = sdks[valid_sdks[0]]
+    if not valid_sdks or biggest_version < target_version:
+        if windows_sdk_dir_env:
+            raise FatalCheckError(
+                'You are targeting Windows version 0x%04x, but your SDK only '
+                'supports up to version 0x%04x. Install and use an updated SDK, '
+                'or target a lower version using --with-windows-version. '
+                'Alternatively, try running the Windows SDK Configuration Tool '
+                'and selecting a newer SDK. See '
+                'https://developer.mozilla.org/En/Windows_SDK_versions for '
+                'details on fixing this.' % (target_version, biggest_version))
+
+        raise FatalCheckError(
+            'Cannot find a Windows SDK for version >= 0x%04x.' % target_version)
+
+    return namespace(
+        path=valid_sdks[0],
+        version=biggest_version,
+    )
+
+
 add_old_configure_assignment(
-    'MOZ_WINSDK_TARGETVER',
-    depends(valid_windows_version)(lambda x: '%04x0000' % x if x else None))
+    'WINDOWSSDKDIR',
+    delayed_getattr(valid_windows_sdk_dir, 'path'))
+add_old_configure_assignment(
+    'MOZ_WINSDK_MAXVER',
+    depends(valid_windows_sdk_dir)(
+        lambda x: '0x%04X0000' % x.version if x else None))
--- a/js/src/aclocal.m4
+++ b/js/src/aclocal.m4
@@ -19,17 +19,16 @@ builtin(include, ../../build/autoconf/mo
 builtin(include, ../../build/autoconf/lto.m4)dnl
 builtin(include, ../../build/autoconf/frameptr.m4)dnl
 builtin(include, ../../build/autoconf/compiler-opts.m4)dnl
 builtin(include, ../../build/autoconf/expandlibs.m4)dnl
 builtin(include, ../../build/autoconf/arch.m4)dnl
 builtin(include, ../../build/autoconf/android.m4)dnl
 builtin(include, ../../build/autoconf/zlib.m4)dnl
 builtin(include, ../../build/autoconf/linux.m4)dnl
-builtin(include, ../../build/autoconf/winsdk.m4)dnl
 builtin(include, ../../build/autoconf/icu.m4)dnl
 builtin(include, ../../build/autoconf/ffi.m4)dnl
 builtin(include, ../../build/autoconf/clang-plugin.m4)dnl
 builtin(include, ../../build/autoconf/alloc.m4)dnl
 builtin(include, ../../build/autoconf/jemalloc.m4)dnl
 builtin(include, ../../build/autoconf/sanitize.m4)dnl
 builtin(include, ../../build/autoconf/ios.m4)dnl
 
--- a/js/src/old-configure.in
+++ b/js/src/old-configure.in
@@ -286,32 +286,21 @@ case "$target" in
                 "$_WINDRES_MAJOR_VERSION" -eq "$WINDRES_MAJOR_VERSION" -a \
                 "$_WINDRES_MINOR_VERSION" -eq "$WINDRES_MINOR_VERSION" -a \
                 "$_WINDRES_RELEASE_VERSION" -lt "$WINDRES_RELEASE_VERSION"
         then
             AC_MSG_ERROR([windres version $WINDRES_VERSION or higher is required to build.])
         fi
     fi # !GNU_CC
 
-    MOZ_FIND_WINSDK_VERSION
     AC_DEFINE_UNQUOTED(WINVER,0x$WINVER)
     AC_DEFINE_UNQUOTED(_WIN32_WINNT,0x$WINVER)
     # Require OS features provided by IE 6.0 SP2 (XP SP2)
     AC_DEFINE_UNQUOTED(_WIN32_IE,0x0603)
 
-    # If the maximum version supported by this SDK is lower than the target
-    # version, error out
-    AC_MSG_CHECKING([for Windows SDK being recent enough])
-    if $PERL -e "exit(0x$MOZ_WINSDK_TARGETVER > $MOZ_WINSDK_MAXVER)"; then
-        AC_MSG_RESULT("yes")
-    else
-        AC_MSG_RESULT("no")
-        AC_MSG_ERROR([You are targeting Windows version 0x$MOZ_WINSDK_TARGETVER, but your SDK only supports up to version $MOZ_WINSDK_MAXVER. Install and use an updated SDK, or target a lower version using --with-windows-version. Alternatively, try running the Windows SDK Configuration Tool and selecting a newer SDK. See https://developer.mozilla.org/En/Windows_SDK_versions for more details on fixing this.])
-    fi
-
     ;;
 esac
 
 if test -n "$_WIN32_MSVC"; then
     SKIP_PATH_CHECKS=1
     SKIP_COMPILER_CHECKS=1
     SKIP_LIBRARY_CHECKS=1
 
--- a/old-configure.in
+++ b/old-configure.in
@@ -467,32 +467,21 @@ case "$target" in
             esac
         fi
 
         # strsafe.h on mingw uses macros for function deprecation that pollutes namespace
         # causing problems with local implementations with the same name.
         AC_DEFINE(STRSAFE_NO_DEPRECATE)
     fi # !GNU_CC
 
-    MOZ_FIND_WINSDK_VERSION
     AC_DEFINE_UNQUOTED(WINVER,0x$WINVER)
     AC_DEFINE_UNQUOTED(_WIN32_WINNT,0x$WINVER)
     # Require OS features provided by IE 6.0 SP2 (XP SP2)
     AC_DEFINE_UNQUOTED(_WIN32_IE,0x0603)
 
-    # If the maximum version supported by this SDK is lower than the target
-    # version, error out
-    AC_MSG_CHECKING([for Windows SDK being recent enough])
-    if $PERL -e "exit(0x$MOZ_WINSDK_TARGETVER > $MOZ_WINSDK_MAXVER)"; then
-        AC_MSG_RESULT("yes")
-    else
-        AC_MSG_RESULT("no")
-        AC_MSG_ERROR([You are targeting Windows version 0x$MOZ_WINSDK_TARGETVER, but your SDK only supports up to version $MOZ_WINSDK_MAXVER. Install and use an updated SDK, or target a lower version using --with-windows-version. Alternatively, try running the Windows SDK Configuration Tool and selecting a newer SDK. See https://developer.mozilla.org/En/Windows_SDK_versions for more details on fixing this.])
-    fi
-
     ;;
 esac
 
 if test -n "$_WIN32_MSVC"; then
     SKIP_PATH_CHECKS=1
     SKIP_COMPILER_CHECKS=1
     SKIP_LIBRARY_CHECKS=1