Re-enable local predictor metrics.
[chromium-blink-merge.git] / build / gyp_chromium
blobe74af2c8cb060176bbf4e246ee41a1178b37ed95
1 #!/usr/bin/env python
3 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
7 # This script is wrapper for Chromium that adds some support for how GYP
8 # is invoked by Chromium beyond what can be done in the gclient hooks.
10 import glob
11 import os
12 import shlex
13 import subprocess
14 import sys
16 script_dir = os.path.dirname(__file__)
17 chrome_src = os.path.abspath(os.path.join(script_dir, os.pardir))
19 sys.path.insert(0, os.path.join(chrome_src, 'tools', 'gyp', 'pylib'))
20 import gyp
22 # Add paths so that pymod_do_main(...) can import files.
23 sys.path.insert(1, os.path.join(chrome_src, 'tools', 'grit'))
24 sys.path.insert(1, os.path.join(chrome_src, 'chrome', 'tools', 'build'))
25 sys.path.insert(1, os.path.join(chrome_src, 'native_client', 'build'))
28 # On Windows, Psyco shortens warm runs of build/gyp_chromium by about
29 # 20 seconds on a z600 machine with 12 GB of RAM, from 90 down to 70
30 # seconds. Conversely, memory usage of build/gyp_chromium with Psyco
31 # maxes out at about 158 MB vs. 132 MB without it.
33 # Psyco uses native libraries, so we need to load a different
34 # installation depending on which OS we are running under. It has not
35 # been tested whether using Psyco on our Mac and Linux builds is worth
36 # it (the GYP running time is a lot shorter, so the JIT startup cost
37 # may not be worth it).
38 if sys.platform == 'win32':
39 try:
40 sys.path.insert(0, os.path.join(chrome_src, 'third_party', 'psyco_win32'))
41 import psyco
42 except:
43 psyco = None
44 else:
45 psyco = None
47 def apply_gyp_environment(file_path=None):
48 """
49 Reads in a *.gyp_env file and applies the valid keys to os.environ.
50 """
51 if not file_path or not os.path.exists(file_path):
52 return
53 file_contents = open(file_path).read()
54 try:
55 file_data = eval(file_contents, {'__builtins__': None}, None)
56 except SyntaxError, e:
57 e.filename = os.path.abspath(file_path)
58 raise
59 supported_vars = ( 'CHROMIUM_GYP_FILE',
60 'CHROMIUM_GYP_SYNTAX_CHECK',
61 'GYP_DEFINES',
62 'GYP_GENERATOR_FLAGS',
63 'GYP_GENERATOR_OUTPUT',
64 'GYP_GENERATORS', )
65 for var in supported_vars:
66 val = file_data.get(var)
67 if val:
68 if var in os.environ:
69 print 'INFO: Environment value for "%s" overrides value in %s.' % (
70 var, os.path.abspath(file_path)
72 else:
73 os.environ[var] = val
75 def additional_include_files(args=[]):
76 """
77 Returns a list of additional (.gypi) files to include, without
78 duplicating ones that are already specified on the command line.
79 """
80 # Determine the include files specified on the command line.
81 # This doesn't cover all the different option formats you can use,
82 # but it's mainly intended to avoid duplicating flags on the automatic
83 # makefile regeneration which only uses this format.
84 specified_includes = set()
85 for arg in args:
86 if arg.startswith('-I') and len(arg) > 2:
87 specified_includes.add(os.path.realpath(arg[2:]))
89 result = []
90 def AddInclude(path):
91 if os.path.realpath(path) not in specified_includes:
92 result.append(path)
94 # Always include common.gypi.
95 AddInclude(os.path.join(script_dir, 'common.gypi'))
97 # Optionally add supplemental .gypi files if present.
98 supplements = glob.glob(os.path.join(chrome_src, '*', 'supplement.gypi'))
99 for supplement in supplements:
100 AddInclude(supplement)
102 return result
104 if __name__ == '__main__':
105 args = sys.argv[1:]
107 # Use the Psyco JIT if available.
108 if psyco:
109 psyco.profile()
110 print "Enabled Psyco JIT."
112 # Fall back on hermetic python if we happen to get run under cygwin.
113 # TODO(bradnelson): take this out once this issue is fixed:
114 # http://code.google.com/p/gyp/issues/detail?id=177
115 if sys.platform == 'cygwin':
116 python_dir = os.path.join(chrome_src, 'third_party', 'python_26')
117 env = os.environ.copy()
118 env['PATH'] = python_dir + os.pathsep + env.get('PATH', '')
119 p = subprocess.Popen(
120 [os.path.join(python_dir, 'python.exe')] + sys.argv,
121 env=env, shell=False)
122 p.communicate()
123 sys.exit(p.returncode)
125 if 'SKIP_CHROMIUM_GYP_ENV' not in os.environ:
126 # Update the environment based on chromium.gyp_env
127 gyp_env_path = os.path.join(os.path.dirname(chrome_src), 'chromium.gyp_env')
128 apply_gyp_environment(gyp_env_path)
130 # This could give false positives since it doesn't actually do real option
131 # parsing. Oh well.
132 gyp_file_specified = False
133 for arg in args:
134 if arg.endswith('.gyp'):
135 gyp_file_specified = True
136 break
138 # If we didn't get a file, check an env var, and then fall back to
139 # assuming 'all.gyp' from the same directory as the script.
140 if not gyp_file_specified:
141 gyp_file = os.environ.get('CHROMIUM_GYP_FILE')
142 if gyp_file:
143 # Note that CHROMIUM_GYP_FILE values can't have backslashes as
144 # path separators even on Windows due to the use of shlex.split().
145 args.extend(shlex.split(gyp_file))
146 else:
147 args.append(os.path.join(script_dir, 'all.gyp'))
149 args.extend(['-I' + i for i in additional_include_files(args)])
151 # There shouldn't be a circular dependency relationship between .gyp files,
152 # but in Chromium's .gyp files, on non-Mac platforms, circular relationships
153 # currently exist. The check for circular dependencies is currently
154 # bypassed on other platforms, but is left enabled on the Mac, where a
155 # violation of the rule causes Xcode to misbehave badly.
156 # TODO(mark): Find and kill remaining circular dependencies, and remove this
157 # option. http://crbug.com/35878.
158 # TODO(tc): Fix circular dependencies in ChromiumOS then add linux2 to the
159 # list.
160 if sys.platform not in ('darwin',):
161 args.append('--no-circular-check')
163 # If CHROMIUM_GYP_SYNTAX_CHECK is set to 1, it will invoke gyp with --check
164 # to enfore syntax checking.
165 syntax_check = os.environ.get('CHROMIUM_GYP_SYNTAX_CHECK')
166 if syntax_check and int(syntax_check):
167 args.append('--check')
169 print 'Updating projects from gyp files...'
170 sys.stdout.flush()
172 # Off we go...
173 sys.exit(gyp.main(args))