2011-04-14 12:38:55 +04:00
|
|
|
#!/usr/bin/env python
|
2009-09-16 03:52:14 +04:00
|
|
|
|
2011-03-30 22:52:23 +04:00
|
|
|
# Copyright (c) 2011 The Chromium Authors. All rights reserved.
|
2009-09-16 23:44:02 +04:00
|
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
|
|
# found in the LICENSE file.
|
|
|
|
|
2009-09-16 03:52:14 +04:00
|
|
|
# This script is wrapper for Chromium that adds some support for how GYP
|
2009-09-16 23:44:02 +04:00
|
|
|
# is invoked by Chromium beyond what can be done in the gclient hooks.
|
2009-09-16 03:52:14 +04:00
|
|
|
|
|
|
|
import glob
|
|
|
|
import os
|
|
|
|
import shlex
|
2011-02-23 05:00:06 +03:00
|
|
|
import subprocess
|
2009-09-16 03:52:14 +04:00
|
|
|
import sys
|
|
|
|
|
2009-09-17 02:37:47 +04:00
|
|
|
script_dir = os.path.dirname(__file__)
|
2011-04-19 13:33:24 +04:00
|
|
|
chrome_src = os.path.abspath(os.path.join(script_dir, os.pardir))
|
2009-09-16 23:44:02 +04:00
|
|
|
|
2010-07-13 01:56:56 +04:00
|
|
|
sys.path.insert(0, os.path.join(chrome_src, 'tools', 'gyp', 'pylib'))
|
2009-09-17 02:37:47 +04:00
|
|
|
import gyp
|
2009-09-16 03:52:14 +04:00
|
|
|
|
2011-08-17 00:43:27 +04:00
|
|
|
# Add paths so that pymod_do_main(...) can import files.
|
2011-05-28 06:11:24 +04:00
|
|
|
sys.path.insert(1, os.path.join(chrome_src, 'tools', 'grit'))
|
2011-08-17 00:43:27 +04:00
|
|
|
sys.path.insert(1, os.path.join(chrome_src, 'chrome', 'tools', 'build'))
|
2011-05-28 06:11:24 +04:00
|
|
|
|
|
|
|
|
2011-03-30 22:52:23 +04:00
|
|
|
# On Windows, Psyco shortens warm runs of build/gyp_chromium by about
|
|
|
|
# 20 seconds on a z600 machine with 12 GB of RAM, from 90 down to 70
|
|
|
|
# seconds. Conversely, memory usage of build/gyp_chromium with Psyco
|
|
|
|
# maxes out at about 158 MB vs. 132 MB without it.
|
|
|
|
#
|
|
|
|
# Psyco uses native libraries, so we need to load a different
|
|
|
|
# installation depending on which OS we are running under. It has not
|
|
|
|
# been tested whether using Psyco on our Mac and Linux builds is worth
|
|
|
|
# it (the GYP running time is a lot shorter, so the JIT startup cost
|
|
|
|
# may not be worth it).
|
|
|
|
if sys.platform == 'win32':
|
|
|
|
try:
|
|
|
|
sys.path.insert(0, os.path.join(chrome_src, 'third_party', 'psyco_win32'))
|
|
|
|
import psyco
|
|
|
|
except:
|
|
|
|
psyco = None
|
|
|
|
else:
|
|
|
|
psyco = None
|
|
|
|
|
2010-11-08 23:09:23 +03:00
|
|
|
def apply_gyp_environment(file_path=None):
|
|
|
|
"""
|
|
|
|
Reads in a *.gyp_env file and applies the valid keys to os.environ.
|
|
|
|
"""
|
|
|
|
if not file_path or not os.path.exists(file_path):
|
|
|
|
return
|
|
|
|
file_contents = open(file_path).read()
|
|
|
|
try:
|
|
|
|
file_data = eval(file_contents, {'__builtins__': None}, None)
|
|
|
|
except SyntaxError, e:
|
|
|
|
e.filename = os.path.abspath(file_path)
|
|
|
|
raise
|
|
|
|
supported_vars = ( 'CHROMIUM_GYP_FILE',
|
|
|
|
'CHROMIUM_GYP_SYNTAX_CHECK',
|
|
|
|
'GYP_DEFINES',
|
|
|
|
'GYP_GENERATOR_FLAGS',
|
|
|
|
'GYP_GENERATOR_OUTPUT', )
|
|
|
|
for var in supported_vars:
|
|
|
|
val = file_data.get(var)
|
|
|
|
if val:
|
|
|
|
if var in os.environ:
|
|
|
|
print 'INFO: Environment value for "%s" overrides value in %s.' % (
|
|
|
|
var, os.path.abspath(file_path)
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
os.environ[var] = val
|
|
|
|
|
2009-09-23 07:49:50 +04:00
|
|
|
def additional_include_files(args=[]):
|
|
|
|
"""
|
|
|
|
Returns a list of additional (.gypi) files to include, without
|
|
|
|
duplicating ones that are already specified on the command line.
|
|
|
|
"""
|
|
|
|
# Determine the include files specified on the command line.
|
|
|
|
# This doesn't cover all the different option formats you can use,
|
|
|
|
# but it's mainly intended to avoid duplicating flags on the automatic
|
|
|
|
# makefile regeneration which only uses this format.
|
|
|
|
specified_includes = set()
|
|
|
|
for arg in args:
|
|
|
|
if arg.startswith('-I') and len(arg) > 2:
|
|
|
|
specified_includes.add(os.path.realpath(arg[2:]))
|
|
|
|
|
|
|
|
result = []
|
|
|
|
def AddInclude(path):
|
|
|
|
if os.path.realpath(path) not in specified_includes:
|
|
|
|
result.append(path)
|
|
|
|
|
2011-06-11 00:44:47 +04:00
|
|
|
# Always include common.gypi.
|
2009-09-23 07:49:50 +04:00
|
|
|
AddInclude(os.path.join(script_dir, 'common.gypi'))
|
|
|
|
|
|
|
|
# Optionally add supplemental .gypi files if present.
|
|
|
|
supplements = glob.glob(os.path.join(chrome_src, '*', 'supplement.gypi'))
|
|
|
|
for supplement in supplements:
|
|
|
|
AddInclude(supplement)
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
2009-09-16 03:52:14 +04:00
|
|
|
if __name__ == '__main__':
|
|
|
|
args = sys.argv[1:]
|
|
|
|
|
2011-03-30 22:52:23 +04:00
|
|
|
# Use the Psyco JIT if available.
|
|
|
|
if psyco:
|
|
|
|
psyco.profile()
|
|
|
|
print "Enabled Psyco JIT."
|
|
|
|
|
2011-02-23 05:00:06 +03:00
|
|
|
# Fall back on hermetic python if we happen to get run under cygwin.
|
|
|
|
# TODO(bradnelson): take this out once this issue is fixed:
|
|
|
|
# http://code.google.com/p/gyp/issues/detail?id=177
|
|
|
|
if sys.platform == 'cygwin':
|
|
|
|
python_dir = os.path.join(chrome_src, 'third_party', 'python_26')
|
|
|
|
env = os.environ.copy()
|
|
|
|
env['PATH'] = python_dir + os.pathsep + env.get('PATH', '')
|
|
|
|
p = subprocess.Popen(
|
|
|
|
[os.path.join(python_dir, 'python.exe')] + sys.argv,
|
|
|
|
env=env, shell=False)
|
|
|
|
p.communicate()
|
|
|
|
sys.exit(p.returncode)
|
|
|
|
|
2010-11-08 23:09:23 +03:00
|
|
|
if 'SKIP_CHROMIUM_GYP_ENV' not in os.environ:
|
|
|
|
# Update the environment based on chromium.gyp_env
|
|
|
|
gyp_env_path = os.path.join(os.path.dirname(chrome_src), 'chromium.gyp_env')
|
|
|
|
apply_gyp_environment(gyp_env_path)
|
|
|
|
|
2009-09-17 03:16:05 +04:00
|
|
|
# This could give false positives since it doesn't actually do real option
|
|
|
|
# parsing. Oh well.
|
|
|
|
gyp_file_specified = False
|
|
|
|
for arg in args:
|
|
|
|
if arg.endswith('.gyp'):
|
|
|
|
gyp_file_specified = True
|
|
|
|
break
|
|
|
|
|
2009-09-16 03:52:14 +04:00
|
|
|
# If we didn't get a file, check an env var, and then fall back to
|
2009-09-17 02:37:47 +04:00
|
|
|
# assuming 'all.gyp' from the same directory as the script.
|
2009-09-17 03:16:05 +04:00
|
|
|
if not gyp_file_specified:
|
|
|
|
gyp_file = os.environ.get('CHROMIUM_GYP_FILE')
|
|
|
|
if gyp_file:
|
|
|
|
# Note that CHROMIUM_GYP_FILE values can't have backslashes as
|
|
|
|
# path separators even on Windows due to the use of shlex.split().
|
|
|
|
args.extend(shlex.split(gyp_file))
|
|
|
|
else:
|
|
|
|
args.append(os.path.join(script_dir, 'all.gyp'))
|
|
|
|
|
2009-09-23 07:49:50 +04:00
|
|
|
args.extend(['-I' + i for i in additional_include_files(args)])
|
2009-09-16 03:52:14 +04:00
|
|
|
|
2010-02-16 23:14:26 +03:00
|
|
|
# There shouldn't be a circular dependency relationship between .gyp files,
|
|
|
|
# but in Chromium's .gyp files, on non-Mac platforms, circular relationships
|
|
|
|
# currently exist. The check for circular dependencies is currently
|
|
|
|
# bypassed on other platforms, but is left enabled on the Mac, where a
|
|
|
|
# violation of the rule causes Xcode to misbehave badly.
|
|
|
|
# TODO(mark): Find and kill remaining circular dependencies, and remove this
|
|
|
|
# option. http://crbug.com/35878.
|
2010-05-24 04:48:16 +04:00
|
|
|
# TODO(tc): Fix circular dependencies in ChromiumOS then add linux2 to the
|
|
|
|
# list.
|
|
|
|
if sys.platform not in ('darwin',):
|
2010-02-16 23:14:26 +03:00
|
|
|
args.append('--no-circular-check')
|
|
|
|
|
2010-03-26 21:40:49 +03:00
|
|
|
# If CHROMIUM_GYP_SYNTAX_CHECK is set to 1, it will invoke gyp with --check
|
|
|
|
# to enfore syntax checking.
|
|
|
|
syntax_check = os.environ.get('CHROMIUM_GYP_SYNTAX_CHECK')
|
|
|
|
if syntax_check and int(syntax_check):
|
|
|
|
args.append('--check')
|
|
|
|
|
2009-09-17 02:37:47 +04:00
|
|
|
print 'Updating projects from gyp files...'
|
|
|
|
sys.stdout.flush()
|
|
|
|
|
2009-09-16 03:52:14 +04:00
|
|
|
# Off we go...
|
|
|
|
sys.exit(gyp.main(args))
|