WebKit roll 98705:98715
[chromium-blink-merge.git] / build / gyp_chromium
blob226ba1a0f40479a499342fe31f9496803b48bfff
1 #!/usr/bin/env python
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.
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'))
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':
38 try:
39 sys.path.insert(0, os.path.join(chrome_src, 'third_party', 'psyco_win32'))
40 import psyco
41 except:
42 psyco = None
43 else:
44 psyco = None
46 def apply_gyp_environment(file_path=None):
47 """
48 Reads in a *.gyp_env file and applies the valid keys to os.environ.
49 """
50 if not file_path or not os.path.exists(file_path):
51 return
52 file_contents = open(file_path).read()
53 try:
54 file_data = eval(file_contents, {'__builtins__': None}, None)
55 except SyntaxError, e:
56 e.filename = os.path.abspath(file_path)
57 raise
58 supported_vars = ( 'CHROMIUM_GYP_FILE',
59 'CHROMIUM_GYP_SYNTAX_CHECK',
60 'GYP_DEFINES',
61 'GYP_GENERATOR_FLAGS',
62 'GYP_GENERATOR_OUTPUT', )
63 for var in supported_vars:
64 val = file_data.get(var)
65 if val:
66 if var in os.environ:
67 print 'INFO: Environment value for "%s" overrides value in %s.' % (
68 var, os.path.abspath(file_path)
70 else:
71 os.environ[var] = val
73 def additional_include_files(args=[]):
74 """
75 Returns a list of additional (.gypi) files to include, without
76 duplicating ones that are already specified on the command line.
77 """
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()
83 for arg in args:
84 if arg.startswith('-I') and len(arg) > 2:
85 specified_includes.add(os.path.realpath(arg[2:]))
87 result = []
88 def AddInclude(path):
89 if os.path.realpath(path) not in specified_includes:
90 result.append(path)
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)
100 return result
102 if __name__ == '__main__':
103 args = sys.argv[1:]
105 # Use the Psyco JIT if available.
106 if psyco:
107 psyco.profile()
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)
120 p.communicate()
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
129 # parsing. Oh well.
130 gyp_file_specified = False
131 for arg in args:
132 if arg.endswith('.gyp'):
133 gyp_file_specified = True
134 break
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')
140 if 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))
144 else:
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
157 # list.
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...'
168 sys.stdout.flush()
170 # Off we go...
171 sys.exit(gyp.main(args))