8 top_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
9 if '--xwalk' in sys.argv:
10 xwalk_dir = os.path.join(top_dir, '..', 'xwalk')
11 sys.argv.remove('--xwalk')
14 chrome_src = os.environ.get('CHROME_SRC')
16 chrome_src = os.path.abspath(chrome_src)
17 if not chrome_src or not os.path.isdir(chrome_src):
18 chrome_src = os.path.join(top_dir, '..')
19 print 'CHROME_SRC not set, falling back to ' + chrome_src
21 script_dir = os.path.abspath(os.path.join(chrome_src, 'build'))
22 if not os.path.isdir(script_dir):
23 print script_dir + " is not a valid directory"
26 sys.path.insert(0, script_dir)
28 sys.path.insert(0, os.path.join(chrome_src, 'tools', 'gyp', 'pylib'))
30 import gyp.generator.ninja
33 def gyp_ninja_override_CalculateVariables(default_variables, params):
34 """Calculate additional variables for use in the build (called by gyp)."""
36 default_variables.setdefault('OS', 'linux')
37 default_variables.setdefault('SHARED_LIB_SUFFIX', '.so')
38 default_variables.setdefault('SHARED_LIB_DIR',
39 os.path.join('$!PRODUCT_DIR', 'lib'))
40 # Take into account the fact that toplevel_dir might not be equal to depth
42 if 'options' in params:
43 options = params['options']
44 toplevel_offset = os.path.relpath(options.depth, options.toplevel_dir)
45 default_variables.setdefault('LIB_DIR',
46 os.path.join('$!PRODUCT_DIR', 'obj', toplevel_offset))
48 # Override CalculateVariables functions in gyp ninja generator instead of patching gyp.
49 gyp.generator.ninja.CalculateVariables = gyp_ninja_override_CalculateVariables
51 # Add paths so that pymod_do_main(...) can import files.
52 sys.path.insert(1, os.path.join(chrome_src, 'tools', 'generate_shim_headers'))
53 sys.path.insert(1, os.path.join(chrome_src, 'tools', 'grit'))
55 sys.path.insert(1, os.path.join(chrome_src, 'third_party', 'WebKit',
56 'Source', 'core', 'core.gyp', 'scripts'))
57 # Remove the above and keep the line below once we require a newer specific
59 sys.path.insert(1, os.path.join(chrome_src, 'third_party', 'WebKit',
60 'Source', 'build', 'scripts'))
61 sys.path.insert(1, os.path.join(chrome_src, 'chrome', 'tools', 'build'))
62 sys.path.insert(1, os.path.join(chrome_src, 'native_client', 'build'))
66 def additional_include_files(args=[]):
68 Returns a list of additional (.gypi) files to include, without
69 duplicating ones that are already specified on the command line.
71 # Determine the include files specified on the command line.
72 # This doesn't cover all the different option formats you can use,
73 # but it's mainly intended to avoid duplicating flags on the automatic
74 # makefile regeneration which only uses this format.
75 specified_includes = set()
77 if arg.startswith('-I') and len(arg) > 2:
78 specified_includes.add(os.path.realpath(arg[2:]))
82 if os.path.realpath(path) not in specified_includes:
85 # Include xwalk common.gypi to effect chromium source tree.
87 AddInclude(os.path.join(xwalk_dir, 'build', 'common.gypi'))
89 # Always include common.gypi.
90 AddInclude(os.path.join(script_dir, 'common.gypi'))
92 # Used for additional build tweaks such as file exclusions
93 AddInclude(os.path.join(top_dir, 'ewk', 'chromium-ewk.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 def get_output_dir():
103 outdir = os.environ.get("GYP_GENERATOR_OUTPUT")
105 outdir = os.path.join(top_dir, "out")
106 if not os.path.isdir(outdir):
108 if not os.path.isdir(outdir):
109 print "cannot create outdir: " + outdir
114 if __name__ == '__main__':
117 # On Mac we want to override CXX and CC that is provided with
118 # the Chromium GYP environment.
119 if sys.platform.startswith('darwin'):
120 os.environ['CXX'] = 'clang++'
121 os.environ['CC'] = 'clang'
123 gyp_helper.apply_chromium_gyp_env()
125 # This could give false positives since it doesn't actually do real option
127 gyp_file_specified = False
129 if arg.endswith('.gyp'):
130 gyp_file_specified = True
133 if not gyp_file_specified:
134 args.append(os.path.join(top_dir, 'ewk', 'chromium-ewk.gyp'))
137 args.append(os.path.join(xwalk_dir, 'xwalk.gyp'))
139 args.extend(['-I' + i for i in additional_include_files(args)])
141 # On Mac we want to build in x64 mode. And we want to use libc++.
142 # Even though we are not on linux, it seems we specifically have to disable linux_use_tcmalloc.
143 if sys.platform in ('darwin',):
144 args.extend(['-D', 'host_arch=x64', '-D', 'use_libcpp=1', '-D', 'linux_use_tcmalloc=0'])
146 # There shouldn't be a circular dependency relationship between .gyp files,
147 # but in Chromium's .gyp files, on non-Mac platforms, circular relationships
148 # currently exist. The check for circular dependencies is currently
149 # bypassed on other platforms, but is left enabled on the Mac, where a
150 # violation of the rule causes Xcode to misbehave badly.
151 # TODO(mark): Find and kill remaining circular dependencies, and remove this
152 # option. http://crbug.com/35878.
153 # TODO(tc): Fix circular dependencies in ChromiumOS then add linux2 to the
155 if sys.platform not in ('darwin',):
156 args.append('--no-circular-check')
158 # the top_level source directory is the first common ancestor of our module and the chromium source tree for the build to be sane.
159 # commonprefix works on a character basis, so it might return a phony common prefix (not the common parent directory we expect),
160 toplevel= os.path.commonprefix([top_dir, chrome_src])
161 if not os.path.exists(toplevel):
162 toplevel = os.path.join(toplevel, os.pardir)
163 args.extend(["--toplevel-dir=" + toplevel])
164 # Chromium specific Hack: for Chromium to build, the depth has to be set to the chromium src dir.
165 args.extend(["--depth=" + chrome_src])
166 # Tweak the output location and format (hardcode ninja for now)
167 args.extend(['--generator-output', os.path.abspath(get_output_dir())])
168 args.extend(['-Goutput_dir='+ os.path.abspath(get_output_dir())])
169 args.extend(['--format=ninja'])
170 args.append("--check")
172 # gyp on gbs fails with multiprocessing.SemLock() not implemented
173 # disabling parallel gyp for gbs
174 gbs_build = os.environ.get('BUILDING_WITH_GBS')
176 args.append("--no-parallel")
178 # TODO(b.kelemen): remove the condition once gyp_trunk.py has landed.
179 if os.path.exists(os.path.join(script_dir, 'gyp_trunk.py')):
180 # gyp_trunk works on sys.argv so we merge |args| back.
181 sys.argv = [sys.argv[0]] + args
184 gyp_trunk.overwrite_arguments()
188 print 'Updating projects from gyp files...'
191 sys.exit(gyp.main(args))