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.
17 script_dir
= os
.path
.dirname(os
.path
.realpath(__file__
))
18 chrome_src
= os
.path
.abspath(os
.path
.join(script_dir
, os
.pardir
))
20 sys
.path
.insert(0, os
.path
.join(chrome_src
, 'tools', 'gyp', 'pylib'))
23 # Add paths so that pymod_do_main(...) can import files.
24 sys
.path
.insert(1, os
.path
.join(chrome_src
, 'tools', 'generate_shim_headers'))
25 sys
.path
.insert(1, os
.path
.join(chrome_src
, 'tools', 'grit'))
26 sys
.path
.insert(1, os
.path
.join(chrome_src
, 'chrome', 'tools', 'build'))
27 sys
.path
.insert(1, os
.path
.join(chrome_src
, 'native_client', 'build'))
28 sys
.path
.insert(1, os
.path
.join(chrome_src
, 'third_party', 'WebKit',
29 'Source', 'WebCore', 'WebCore.gyp', 'scripts'))
30 sys
.path
.insert(1, os
.path
.join(chrome_src
, 'third_party', 'WebKit',
31 'Source', 'core', 'core.gyp', 'scripts'))
34 # On Windows, Psyco shortens warm runs of build/gyp_chromium by about
35 # 20 seconds on a z600 machine with 12 GB of RAM, from 90 down to 70
36 # seconds. Conversely, memory usage of build/gyp_chromium with Psyco
37 # maxes out at about 158 MB vs. 132 MB without it.
39 # Psyco uses native libraries, so we need to load a different
40 # installation depending on which OS we are running under. It has not
41 # been tested whether using Psyco on our Mac and Linux builds is worth
42 # it (the GYP running time is a lot shorter, so the JIT startup cost
43 # may not be worth it).
44 if sys
.platform
== 'win32':
46 sys
.path
.insert(0, os
.path
.join(chrome_src
, 'third_party', 'psyco_win32'))
53 def additional_include_files(args
=[]):
55 Returns a list of additional (.gypi) files to include, without
56 duplicating ones that are already specified on the command line.
58 # Determine the include files specified on the command line.
59 # This doesn't cover all the different option formats you can use,
60 # but it's mainly intended to avoid duplicating flags on the automatic
61 # makefile regeneration which only uses this format.
62 specified_includes
= set()
64 if arg
.startswith('-I') and len(arg
) > 2:
65 specified_includes
.add(os
.path
.realpath(arg
[2:]))
69 if os
.path
.realpath(path
) not in specified_includes
:
72 # Always include common.gypi.
73 AddInclude(os
.path
.join(script_dir
, 'common.gypi'))
75 # Optionally add supplemental .gypi files if present.
76 supplements
= glob
.glob(os
.path
.join(chrome_src
, '*', 'supplement.gypi'))
77 for supplement
in supplements
:
78 AddInclude(supplement
)
82 if __name__
== '__main__':
85 # Use the Psyco JIT if available.
88 print "Enabled Psyco JIT."
90 # Fall back on hermetic python if we happen to get run under cygwin.
91 # TODO(bradnelson): take this out once this issue is fixed:
92 # http://code.google.com/p/gyp/issues/detail?id=177
93 if sys
.platform
== 'cygwin':
94 python_dir
= os
.path
.join(chrome_src
, 'third_party', 'python_26')
95 env
= os
.environ
.copy()
96 env
['PATH'] = python_dir
+ os
.pathsep
+ env
.get('PATH', '')
98 [os
.path
.join(python_dir
, 'python.exe')] + sys
.argv
,
101 sys
.exit(p
.returncode
)
103 gyp_helper
.apply_chromium_gyp_env()
105 # This could give false positives since it doesn't actually do real option
107 gyp_file_specified
= False
109 if arg
.endswith('.gyp'):
110 gyp_file_specified
= True
113 # If we didn't get a file, check an env var, and then fall back to
114 # assuming 'all.gyp' from the same directory as the script.
115 if not gyp_file_specified
:
116 gyp_file
= os
.environ
.get('CHROMIUM_GYP_FILE')
118 # Note that CHROMIUM_GYP_FILE values can't have backslashes as
119 # path separators even on Windows due to the use of shlex.split().
120 args
.extend(shlex
.split(gyp_file
))
122 args
.append(os
.path
.join(script_dir
, 'all.gyp'))
124 args
.extend(['-I' + i
for i
in additional_include_files(args
)])
126 # There shouldn't be a circular dependency relationship between .gyp files,
127 # but in Chromium's .gyp files, on non-Mac platforms, circular relationships
128 # currently exist. The check for circular dependencies is currently
129 # bypassed on other platforms, but is left enabled on the Mac, where a
130 # violation of the rule causes Xcode to misbehave badly.
131 # TODO(mark): Find and kill remaining circular dependencies, and remove this
132 # option. http://crbug.com/35878.
133 # TODO(tc): Fix circular dependencies in ChromiumOS then add linux2 to the
135 if sys
.platform
not in ('darwin',):
136 args
.append('--no-circular-check')
138 # Default to ninja on linux, but only if no generator has explicitly been set.
139 # . -f / --format has precedence over the env var, no need to check for it
140 # . set the env var only if it hasn't been set yet
141 # . chromium.gyp_env has been applied to os.environ at this point already
142 if sys
.platform
.startswith('linux') and not os
.environ
.get('GYP_GENERATORS'):
143 os
.environ
['GYP_GENERATORS'] = 'ninja'
145 # If CHROMIUM_GYP_SYNTAX_CHECK is set to 1, it will invoke gyp with --check
146 # to enfore syntax checking.
147 syntax_check
= os
.environ
.get('CHROMIUM_GYP_SYNTAX_CHECK')
148 if syntax_check
and int(syntax_check
):
149 args
.append('--check')
151 print 'Updating projects from gyp files...'
155 sys
.exit(gyp
.main(args
))