Revert 187575 "Change test_isolation_mode default from noop to c..."
[chromium-blink-merge.git] / build / gyp_chromium
blob10e7a2e088049adbfb0204dc67919e78c730b317
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 gyp_helper
12 import os
13 import shlex
14 import subprocess
15 import sys
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'))
21 import gyp
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'))
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':
43 try:
44 sys.path.insert(0, os.path.join(chrome_src, 'third_party', 'psyco_win32'))
45 import psyco
46 except:
47 psyco = None
48 else:
49 psyco = None
51 def additional_include_files(args=[]):
52 """
53 Returns a list of additional (.gypi) files to include, without
54 duplicating ones that are already specified on the command line.
55 """
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()
61 for arg in args:
62 if arg.startswith('-I') and len(arg) > 2:
63 specified_includes.add(os.path.realpath(arg[2:]))
65 result = []
66 def AddInclude(path):
67 if os.path.realpath(path) not in specified_includes:
68 result.append(path)
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)
78 return result
80 if __name__ == '__main__':
81 args = sys.argv[1:]
83 # Use the Psyco JIT if available.
84 if psyco:
85 psyco.profile()
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', '')
95 p = subprocess.Popen(
96 [os.path.join(python_dir, 'python.exe')] + sys.argv,
97 env=env, shell=False)
98 p.communicate()
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
104 # parsing. Oh well.
105 gyp_file_specified = False
106 for arg in args:
107 if arg.endswith('.gyp'):
108 gyp_file_specified = True
109 break
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')
115 if 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))
119 else:
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
132 # list.
133 if sys.platform not in ('darwin',):
134 args.append('--no-circular-check')
136 # If CHROMIUM_GYP_SYNTAX_CHECK is set to 1, it will invoke gyp with --check
137 # to enfore syntax checking.
138 syntax_check = os.environ.get('CHROMIUM_GYP_SYNTAX_CHECK')
139 if syntax_check and int(syntax_check):
140 args.append('--check')
142 print 'Updating projects from gyp files...'
143 sys.stdout.flush()
145 # Off we go...
146 sys.exit(gyp.main(args))