diff --git a/DEPS b/DEPS index 190f5a3..aefedbc 100644 --- a/DEPS +++ b/DEPS @@ -38,7 +38,7 @@ deps = { 'crashpad/third_party/mini_chromium/mini_chromium': Var('chromium_git') + '/chromium/mini_chromium@' + - '9e0d322ae9f87acbe17c4ced025319b4964bf0b7', + '62e6015f633dd4acb1610db15a064889315cadaa', 'crashpad/third_party/zlib/zlib': Var('chromium_git') + '/chromium/src/third_party/zlib@' + '13dc246a58e4b72104d35f9b1809af95221ebda7', diff --git a/build/gyp_crashpad_android.py b/build/gyp_crashpad_android.py index 852839a..a6ad1b4 100755 --- a/build/gyp_crashpad_android.py +++ b/build/gyp_crashpad_android.py @@ -1,4 +1,5 @@ #!/usr/bin/env python +# coding: utf-8 # Copyright 2017 The Crashpad Authors. All rights reserved. # @@ -18,6 +19,7 @@ import argparse import glob import gyp_crashpad import os +import re import subprocess import sys @@ -31,7 +33,7 @@ def main(args): default='clang', choices=('clang', 'gcc'), help='The compiler to use, clang by default') - (parsed, extra_args) = parser.parse_known_args(args) + (parsed, extra_command_line_args) = parser.parse_known_args(args) NDK_ERROR=( 'NDK must be a valid standalone NDK toolchain.\n' + @@ -55,8 +57,11 @@ def main(args): ndk_bin_dir = os.path.join(parsed.ndk, 'bin') + clang_path = os.path.join(ndk_bin_dir, 'clang') + extra_args = [] + if parsed.compiler == 'clang': - os.environ['CC_target'] = os.path.join(ndk_bin_dir, 'clang') + os.environ['CC_target'] = clang_path os.environ['CXX_target'] = os.path.join(ndk_bin_dir, 'clang++') elif parsed.compiler == 'gcc': os.environ['CC_target'] = os.path.join(ndk_bin_dir, @@ -64,6 +69,27 @@ def main(args): os.environ['CXX_target'] = os.path.join(ndk_bin_dir, '%s-g++' % arch_triplet) + # Unlike the Clang build, when using GCC with “unified headers,” + # __ANDROID_API__ isn’t set automatically and must be pushed in to the + # build. Fish the correct value out of the Clang wrapper script. If unified + # headers are not being used, the Clang wrapper won’t mention + # __ANDROID_API__, but the standalone toolchain’s will + # #define it for both Clang and GCC. + # + # Unified headers are the way of the future, according to + # https://android.googlesource.com/platform/ndk/+/ndk-r14/CHANGELOG.md and + # https://android.googlesource.com/platform/ndk/+/master/docs/UnifiedHeaders.md. + with open(clang_path, 'r') as file: + clang_script_contents = file.read() + matches = re.finditer(r'\s-D__ANDROID_API__=([\d]+)\s', + clang_script_contents) + match = next(matches, None) + if match: + android_api = int(match.group(1)) + extra_args.extend(['-D', 'android_api_level=%d' % android_api]) + if next(matches, None): + raise AssertionError('__ANDROID_API__ defined too many times') + for tool in ('ar', 'nm', 'readelf'): os.environ['%s_target' % tool.upper()] = ( os.path.join(ndk_bin_dir, '%s-%s' % (arch_triplet, tool))) @@ -72,7 +98,9 @@ def main(args): ['-D', 'OS=android', '-D', 'target_arch=%s' % arch, '-D', 'clang=%d' % (1 if parsed.compiler == 'clang' else 0), - '-f', 'ninja-android'] + extra_args) + '-f', 'ninja-android'] + + extra_args + + extra_command_line_args) if __name__ == '__main__':