GN: Add an option to build against the Debian wheezy sysroot

Set the environment variable DART_USE_WHEEZY to build against
the wheezy sysroot on Linux.

R=johnmccutchan@google.com

Review URL: https://codereview.chromium.org/2476343004 .
This commit is contained in:
Zachary Anderson 2016-11-07 13:09:45 -08:00
parent f059523037
commit 7b86880b01
7 changed files with 102 additions and 17 deletions

14
DEPS
View file

@ -555,6 +555,20 @@ hooks = [
Var('dart_root') + "/third_party/clang.tar.gz.sha1",
],
},
{
# Pull Debian wheezy sysroot for i386 Linux
'name': 'sysroot_i386',
'pattern': '.',
'action': ['python', 'sdk/build/linux/sysroot_scripts/install-sysroot.py',
'--running-as-hook', --arch', 'i386'],
},
{
# Pull Debian wheezy sysroot for amd64 Linux
'name': 'sysroot_amd64',
'pattern': '.',
'action': ['python', 'sdk/build/linux/sysroot_scripts/install-sysroot.py',
'--running-as-hook', '--arch', 'amd64'],
},
{
# Pull clang if needed or requested via GYP_DEFINES.
'name': 'gn_clang',

4
build/.gitignore vendored
View file

@ -1,2 +1,6 @@
# Generated file containing information about the VS toolchain on Windows
win_toolchain.json
# Pulled Debian wheezy sysroots
linux/debian_wheezy_amd64-sysroot
linux/debian_wheezy_i386-sysroot

View file

@ -17,5 +17,14 @@ config("sdk") {
sysroot,
],
"value") ]
# When using the pulled wheezy sysroot with gcc, we have to specify these
# excplicitly.
if (dart_use_wheezy_sysroot && !is_clang) {
cflags += [
"-I=/usr/include/c++/4.6",
"-I=/usr/include/c++/4.6/i486-linux-gnu",
]
}
}
}

View file

@ -9,6 +9,20 @@ declare_args() {
# The absolute path of the sysroot that is applied when compiling using
# the target toolchain.
target_sysroot = ""
# Whether the Debian wheezy sysroot should be used.
dart_use_wheezy_sysroot = false
}
if (is_linux && dart_use_wheezy_sysroot) {
if (current_cpu == "x86") {
target_sysroot = rebase_path("//build/linux/debian_wheezy_i386-sysroot")
} else if (current_cpu == "x64") {
target_sysroot = rebase_path("//build/linux/debian_wheezy_amd64-sysroot")
} else {
print("There is no Debian wheezy sysroot present for $current_cpu")
assert(false)
}
}
if (current_toolchain == default_toolchain && target_sysroot != "") {

40
build/detect_host_arch.py Executable file
View file

@ -0,0 +1,40 @@
#!/usr/bin/env python
# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Outputs host CPU architecture in format recognized by gyp."""
import platform
import re
import sys
def HostArch():
"""Returns the host architecture with a predictable string."""
host_arch = platform.machine()
# Convert machine type to format recognized by gyp.
if re.match(r'i.86', host_arch) or host_arch == 'i86pc':
host_arch = 'ia32'
elif host_arch in ['x86_64', 'amd64']:
host_arch = 'x64'
elif host_arch.startswith('arm'):
host_arch = 'arm'
# platform.machine is based on running kernel. It's possible to use 64-bit
# kernel with 32-bit userland, e.g. to give linker slightly more memory.
# Distinguish between different userland bitness by querying
# the python binary.
if host_arch == 'x64' and platform.architecture()[0] == '32bit':
host_arch = 'ia32'
return host_arch
def DoMain(_):
"""Hook to be called from gyp without starting a separate python
interpreter."""
return HostArch()
if __name__ == '__main__':
print DoMain([])

View file

@ -108,18 +108,6 @@ def main():
print 'Unable to detect host architecture'
return 1
if options.running_as_hook and target_arch != 'arm' and target_arch != 'mips':
# When run from runhooks, only install the sysroot for an Official Chrome
# Linux build, except on ARM where we always use a sysroot.
skip_if_defined = ['branding=Chrome', 'buildtype=Official']
skip_if_undefined = ['chromeos=1']
for option in skip_if_defined:
if option not in gyp_defines:
return 0
for option in skip_if_undefined:
if option in gyp_defines:
return 0
# The sysroot directory should match the one specified in build/common.gypi.
# TODO(thestig) Consider putting this else where to avoid having to recreate
# it on every build.

View file

@ -113,11 +113,15 @@ def to_gn_args(args, mode, arch, target_os):
gn_args['is_asan'] = args.asan and gn_args['is_clang']
if args.target_sysroot:
gn_args['target_sysroot'] = args.target_sysroot
# Setup the user-defined sysroot.
if gn_args['target_os'] == 'linux' and args.wheezy:
gn_args['dart_use_wheezy_sysroot'] = True
else:
if args.target_sysroot:
gn_args['target_sysroot'] = args.target_sysroot
if args.toolchain_prefix:
gn_args['toolchain_prefix'] = args.toolchain_prefix
if args.toolchain_prefix:
gn_args['toolchain_prefix'] = args.toolchain_prefix
goma_dir = os.environ.get('GOMA_DIR')
goma_home_dir = os.path.join(os.getenv('HOME', ''), 'goma')
@ -197,12 +201,16 @@ def ide_switch(host_os):
# Environment variables for default settings.
DART_USE_ASAN = "DART_USE_ASAN"
DART_USE_WHEEZY = "DART_USE_WHEEZY"
def use_asan():
return DART_USE_ASAN in os.environ
def use_wheezy():
return DART_USE_WHEEZY in os.environ
def parse_args(args):
args = args[1:]
parser = argparse.ArgumentParser(description='A script to run `gn gen`.')
@ -234,6 +242,14 @@ def parse_args(args):
help='Disable ASAN',
dest='asan',
action='store_false')
parser.add_argument('--wheezy',
help='Use the Debian wheezy sysroot on Linux',
default=use_wheezy(),
action='store_true')
parser.add_argument('--no-wheezy',
help='Disable the Debian wheezy sysroot on Linux',
dest='wheezy',
action='store_false')
parser.add_argument('--goma',
help='Use goma',
default=True,