48a2bb91aeb9da96f7f6000515def7985cad7bbe
[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 xwalk_dir = os.path.join(top_dir, '..', 'xwalk')
10 chrome_src = os.environ.get('CHROME_SRC')
11 if 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
16
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"
20   sys.exit(1)
21
22 sys.path.insert(0, script_dir)
23 import gyp_helper
24 sys.path.insert(0, os.path.join(chrome_src, 'tools', 'gyp', 'pylib'))
25 import gyp
26 import gyp.generator.ninja
27
28
29 def gyp_ninja_override_CalculateVariables(default_variables, params):
30   """Calculate additional variables for use in the build (called by gyp)."""
31
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
37   toplevel_offset = ''
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))
43
44 # Override CalculateVariables functions in gyp ninja generator instead of patching gyp.
45 gyp.generator.ninja.CalculateVariables = gyp_ninja_override_CalculateVariables
46
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'))
50
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
54 # Chromium revision.
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'))
59
60 import repack_locales
61
62 def additional_include_files(args=[]):
63   """
64   Returns a list of additional (.gypi) files to include, without
65   duplicating ones that are already specified on the command line.
66   """
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()
72   for arg in args:
73     if arg.startswith('-I') and len(arg) > 2:
74       specified_includes.add(os.path.realpath(arg[2:]))
75
76   result = []
77   def AddInclude(path):
78     if os.path.realpath(path) not in specified_includes:
79       result.append(path)
80
81   # Include xwalk common.gypi to effect chromium source tree.
82   AddInclude(os.path.join(xwalk_dir, 'build', 'common.gypi'))
83
84   # Always include common.gypi.
85   AddInclude(os.path.join(script_dir, 'common.gypi'))
86
87   # Used for additional build tweaks such as file exclusions
88   AddInclude(os.path.join(top_dir, 'ewk', 'chromium-ewk.gypi'))
89
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)
94
95   return result
96
97 def get_output_dir():
98   outdir = os.environ.get("GYP_GENERATOR_OUTPUT")
99   if not outdir:
100     outdir = os.path.join(top_dir, "out")
101   if not os.path.isdir(outdir):
102     os.mkdir(outdir)
103   if not os.path.isdir(outdir):
104     print "cannot create outdir: " + outdir
105     sys.exit(1)
106
107   return outdir
108
109 if __name__ == '__main__':
110   args = sys.argv[1:]
111
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'
117
118   gyp_helper.apply_chromium_gyp_env()
119
120   # This could give false positives since it doesn't actually do real option
121   # parsing.  Oh well.
122   gyp_file_specified = False
123   for arg in args:
124     if arg.endswith('.gyp'):
125       gyp_file_specified = True
126       break
127
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'))
131
132   args.extend(['-I' + i for i in additional_include_files(args)])
133
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'])
138
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
147   # list.
148   if sys.platform not in ('darwin',):
149     args.append('--no-circular-check')
150
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")
164
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')
168   if gbs_build:
169     args.append("--no-parallel")
170
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
175
176     import gyp_trunk
177     gyp_trunk.overwrite_arguments()
178     args = sys.argv[1:]
179
180
181   print 'Updating projects from gyp files...'
182
183   # Off we go...
184   sys.exit(gyp.main(args))