3 # Copyright (c) 2011 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.
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'))
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'))
27 # On Windows, Psyco shortens warm runs of build/gyp_chromium by about
28 # 20 seconds on a z600 machine with 12 GB of RAM, from 90 down to 70
29 # seconds. Conversely, memory usage of build/gyp_chromium with Psyco
30 # maxes out at about 158 MB vs. 132 MB without it.
32 # Psyco uses native libraries, so we need to load a different
33 # installation depending on which OS we are running under. It has not
34 # been tested whether using Psyco on our Mac and Linux builds is worth
35 # it (the GYP running time is a lot shorter, so the JIT startup cost
36 # may not be worth it).
37 if sys
.platform
== 'win32':
39 sys
.path
.insert(0, os
.path
.join(chrome_src
, 'third_party', 'psyco_win32'))
46 def apply_gyp_environment(file_path
=None):
48 Reads in a *.gyp_env file and applies the valid keys to os.environ.
50 if not file_path
or not os
.path
.exists(file_path
):
52 file_contents
= open(file_path
).read()
54 file_data
= eval(file_contents
, {'__builtins__': None}, None)
55 except SyntaxError, e
:
56 e
.filename
= os
.path
.abspath(file_path
)
58 supported_vars
= ( 'CHROMIUM_GYP_FILE',
59 'CHROMIUM_GYP_SYNTAX_CHECK',
61 'GYP_GENERATOR_FLAGS',
62 'GYP_GENERATOR_OUTPUT', )
63 for var
in supported_vars
:
64 val
= file_data
.get(var
)
67 print 'INFO: Environment value for "%s" overrides value in %s.' % (
68 var
, os
.path
.abspath(file_path
)
73 def additional_include_files(args
=[]):
75 Returns a list of additional (.gypi) files to include, without
76 duplicating ones that are already specified on the command line.
78 # Determine the include files specified on the command line.
79 # This doesn't cover all the different option formats you can use,
80 # but it's mainly intended to avoid duplicating flags on the automatic
81 # makefile regeneration which only uses this format.
82 specified_includes
= set()
84 if arg
.startswith('-I') and len(arg
) > 2:
85 specified_includes
.add(os
.path
.realpath(arg
[2:]))
89 if os
.path
.realpath(path
) not in specified_includes
:
92 # Always include common.gypi.
93 AddInclude(os
.path
.join(script_dir
, 'common.gypi'))
95 # Optionally add supplemental .gypi files if present.
96 supplements
= glob
.glob(os
.path
.join(chrome_src
, '*', 'supplement.gypi'))
97 for supplement
in supplements
:
98 AddInclude(supplement
)
102 if __name__
== '__main__':
105 # Use the Psyco JIT if available.
108 print "Enabled Psyco JIT."
110 # Fall back on hermetic python if we happen to get run under cygwin.
111 # TODO(bradnelson): take this out once this issue is fixed:
112 # http://code.google.com/p/gyp/issues/detail?id=177
113 if sys
.platform
== 'cygwin':
114 python_dir
= os
.path
.join(chrome_src
, 'third_party', 'python_26')
115 env
= os
.environ
.copy()
116 env
['PATH'] = python_dir
+ os
.pathsep
+ env
.get('PATH', '')
117 p
= subprocess
.Popen(
118 [os
.path
.join(python_dir
, 'python.exe')] + sys
.argv
,
119 env
=env
, shell
=False)
121 sys
.exit(p
.returncode
)
123 if 'SKIP_CHROMIUM_GYP_ENV' not in os
.environ
:
124 # Update the environment based on chromium.gyp_env
125 gyp_env_path
= os
.path
.join(os
.path
.dirname(chrome_src
), 'chromium.gyp_env')
126 apply_gyp_environment(gyp_env_path
)
128 # This could give false positives since it doesn't actually do real option
130 gyp_file_specified
= False
132 if arg
.endswith('.gyp'):
133 gyp_file_specified
= True
136 # If we didn't get a file, check an env var, and then fall back to
137 # assuming 'all.gyp' from the same directory as the script.
138 if not gyp_file_specified
:
139 gyp_file
= os
.environ
.get('CHROMIUM_GYP_FILE')
141 # Note that CHROMIUM_GYP_FILE values can't have backslashes as
142 # path separators even on Windows due to the use of shlex.split().
143 args
.extend(shlex
.split(gyp_file
))
145 args
.append(os
.path
.join(script_dir
, 'all.gyp'))
147 args
.extend(['-I' + i
for i
in additional_include_files(args
)])
149 # There shouldn't be a circular dependency relationship between .gyp files,
150 # but in Chromium's .gyp files, on non-Mac platforms, circular relationships
151 # currently exist. The check for circular dependencies is currently
152 # bypassed on other platforms, but is left enabled on the Mac, where a
153 # violation of the rule causes Xcode to misbehave badly.
154 # TODO(mark): Find and kill remaining circular dependencies, and remove this
155 # option. http://crbug.com/35878.
156 # TODO(tc): Fix circular dependencies in ChromiumOS then add linux2 to the
158 if sys
.platform
not in ('darwin',):
159 args
.append('--no-circular-check')
161 # If CHROMIUM_GYP_SYNTAX_CHECK is set to 1, it will invoke gyp with --check
162 # to enfore syntax checking.
163 syntax_check
= os
.environ
.get('CHROMIUM_GYP_SYNTAX_CHECK')
164 if syntax_check
and int(syntax_check
):
165 args
.append('--check')
167 print 'Updating projects from gyp files...'
171 sys
.exit(gyp
.main(args
))