Allow building content shell when xwalk directory is absent
[platform/framework/web/chromium-efl.git] / tizen_src / build / gyp_chromiumefl
1 #!/usr/bin/env python
2
3 import glob
4 import os
5 import subprocess
6 import sys
7
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')
12 else:
13   xwalk_dir = None
14 chrome_src = os.environ.get('CHROME_SRC')
15 if 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
20
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"
24   sys.exit(1)
25
26 sys.path.insert(0, script_dir)
27 import gyp_helper
28 sys.path.insert(0, os.path.join(chrome_src, 'tools', 'gyp', 'pylib'))
29 import gyp
30 import gyp.generator.ninja
31
32
33 def gyp_ninja_override_CalculateVariables(default_variables, params):
34   """Calculate additional variables for use in the build (called by gyp)."""
35
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
41   toplevel_offset = ''
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))
47
48 # Override CalculateVariables functions in gyp ninja generator instead of patching gyp.
49 gyp.generator.ninja.CalculateVariables = gyp_ninja_override_CalculateVariables
50
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'))
54
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
58 # Chromium revision.
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'))
63
64 import repack_locales
65
66 def additional_include_files(args=[]):
67   """
68   Returns a list of additional (.gypi) files to include, without
69   duplicating ones that are already specified on the command line.
70   """
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()
76   for arg in args:
77     if arg.startswith('-I') and len(arg) > 2:
78       specified_includes.add(os.path.realpath(arg[2:]))
79
80   result = []
81   def AddInclude(path):
82     if os.path.realpath(path) not in specified_includes:
83       result.append(path)
84
85   # Include xwalk common.gypi to effect chromium source tree.
86   if xwalk_dir:
87     AddInclude(os.path.join(xwalk_dir, 'build', 'common.gypi'))
88
89   # Always include common.gypi.
90   AddInclude(os.path.join(script_dir, 'common.gypi'))
91
92   # Used for additional build tweaks such as file exclusions
93   AddInclude(os.path.join(top_dir, 'ewk', 'chromium-ewk.gypi'))
94
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)
99
100   return result
101
102 def get_output_dir():
103   outdir = os.environ.get("GYP_GENERATOR_OUTPUT")
104   if not outdir:
105     outdir = os.path.join(top_dir, "out")
106   if not os.path.isdir(outdir):
107     os.mkdir(outdir)
108   if not os.path.isdir(outdir):
109     print "cannot create outdir: " + outdir
110     sys.exit(1)
111
112   return outdir
113
114 if __name__ == '__main__':
115   args = sys.argv[1:]
116
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'
122
123   gyp_helper.apply_chromium_gyp_env()
124
125   # This could give false positives since it doesn't actually do real option
126   # parsing.  Oh well.
127   gyp_file_specified = False
128   for arg in args:
129     if arg.endswith('.gyp'):
130       gyp_file_specified = True
131       break
132
133   if not gyp_file_specified:
134       args.append(os.path.join(top_dir, 'ewk', 'chromium-ewk.gyp'))
135
136   if xwalk_dir:
137     args.append(os.path.join(xwalk_dir, 'xwalk.gyp'))
138
139   args.extend(['-I' + i for i in additional_include_files(args)])
140
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'])
145
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
154   # list.
155   if sys.platform not in ('darwin',):
156     args.append('--no-circular-check')
157
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")
171
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')
175   if gbs_build:
176     args.append("--no-parallel")
177
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
182
183     import gyp_trunk
184     gyp_trunk.overwrite_arguments()
185     args = sys.argv[1:]
186
187
188   print 'Updating projects from gyp files...'
189
190   # Off we go...
191   sys.exit(gyp.main(args))