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