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