- add third_party src.
[platform/framework/web/crosswalk.git] / src / xwalk / gyp_xwalk
1 #!/usr/bin/env python
2
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.
6
7 # This script is wrapper for Crosswalk that adds some support for how GYP
8 # is invoked by Chromium beyond what can be done in the gclient hooks.
9
10 import glob
11 import os
12 import shlex
13 import subprocess
14 import sys
15
16 xwalk_dir = os.path.dirname(os.path.realpath(__file__))
17 chrome_src = os.path.abspath(os.path.join(xwalk_dir, os.pardir))
18
19 sys.path.insert(0, os.path.join(chrome_src, 'tools', 'gyp', 'pylib'))
20 import gyp
21
22 sys.path.insert(0, os.path.join(chrome_src, 'build'))
23 import gyp_helper
24 import landmine_utils
25
26 # Add paths so that pymod_do_main(...) can import files.
27 sys.path.insert(1, os.path.join(chrome_src, 'tools', 'generate_shim_headers'))
28 sys.path.insert(1, os.path.join(chrome_src, 'tools', 'grit'))
29 sys.path.insert(1, os.path.join(chrome_src, 'chrome', 'tools', 'build'))
30 sys.path.insert(1, os.path.join(chrome_src, 'native_client', 'build'))
31 sys.path.insert(1, os.path.join(chrome_src, 'remoting', 'tools', 'build'))
32 sys.path.insert(1, os.path.join(chrome_src, 'third_party', 'WebKit',
33     'Source', 'build', 'scripts'))
34
35 # On Windows, Psyco shortens warm runs of build/gyp_chromium by about
36 # 20 seconds on a z600 machine with 12 GB of RAM, from 90 down to 70
37 # seconds.  Conversely, memory usage of build/gyp_chromium with Psyco
38 # maxes out at about 158 MB vs. 132 MB without it.
39 #
40 # Psyco uses native libraries, so we need to load a different
41 # installation depending on which OS we are running under. It has not
42 # been tested whether using Psyco on our Mac and Linux builds is worth
43 # it (the GYP running time is a lot shorter, so the JIT startup cost
44 # may not be worth it).
45 if sys.platform == 'win32':
46   try:
47     sys.path.insert(0, os.path.join(chrome_src, 'third_party', 'psyco_win32'))
48     import psyco
49   except:
50     psyco = None
51 else:
52   psyco = None
53
54 def additional_include_files(args=[]):
55   """
56   Returns a list of additional (.gypi) files to include, without
57   duplicating ones that are already specified on the command line.
58   """
59   # Determine the include files specified on the command line.
60   # This doesn't cover all the different option formats you can use,
61   # but it's mainly intended to avoid duplicating flags on the automatic
62   # makefile regeneration which only uses this format.
63   specified_includes = set()
64   for arg in args:
65     if arg.startswith('-I') and len(arg) > 2:
66       specified_includes.add(os.path.realpath(arg[2:]))
67
68   result = []
69   def AddInclude(path):
70     if os.path.realpath(path) not in specified_includes:
71       result.append(path)
72
73   # Include xwalk common.gypi to effect chromium source tree.
74   AddInclude(os.path.join(xwalk_dir, 'build', 'common.gypi'))
75
76   # Always include common.gypi.
77   AddInclude(os.path.join(chrome_src, 'build', 'common.gypi'))
78
79   # Optionally add supplemental .gypi files if present.
80   supplements = glob.glob(os.path.join(chrome_src, '*', 'supplement.gypi'))
81   for supplement in supplements:
82     AddInclude(supplement)
83
84   return result
85
86 if __name__ == '__main__':
87   args = sys.argv[1:]
88
89   # Support external media types capability such as MP4/MP3.
90   args = list(set(args))
91   delist = []
92   ip_media_codecs = False # Default: no third-party codecs be build in.
93   for arg in args:
94     if arg.startswith('-Dproprietary_codecs') or arg.startswith('-Dffmpeg_branding'):
95       continue
96     elif arg == '-Dmediacodecs_EULA=1':
97       ip_media_codecs = True  # Exception: mediacodecs_EULA be enabled.
98     else:
99       delist.append(arg)
100
101   args = delist
102   args.append('-Dproprietary_codecs=1')
103
104   # Triggering media playback dynamically with third-party codecs by owner.
105   if ip_media_codecs == True:
106       args.append('-Dffmpeg_branding=Chrome')
107
108   # Enable Web Audio by default on Android x86
109   if landmine_utils.platform() == 'android':
110     args.append('-Duse_openmax_dl_fft=1')
111
112   # Enable Aura by default on all platforms except Android
113   if landmine_utils.platform() != 'android' and landmine_utils.platform() != 'mac':
114     args.append('-Duse_aura=1')
115
116   # Use the Psyco JIT if available.
117   if psyco:
118     psyco.profile()
119     print "Enabled Psyco JIT."
120
121   # Fall back on hermetic python if we happen to get run under cygwin.
122   # TODO(bradnelson): take this out once this issue is fixed:
123   #    http://code.google.com/p/gyp/issues/detail?id=177
124   if sys.platform == 'cygwin':
125     python_dir = os.path.join(chrome_src, 'third_party', 'python_26')
126     env = os.environ.copy()
127     env['PATH'] = python_dir + os.pathsep + env.get('PATH', '')
128     p = subprocess.Popen(
129        [os.path.join(python_dir, 'python.exe')] + sys.argv,
130        env=env, shell=False)
131     p.communicate()
132     sys.exit(p.returncode)
133
134   gyp_helper.apply_chromium_gyp_env()
135
136   # This could give false positives since it doesn't actually do real option
137   # parsing.  Oh well.
138   gyp_file_specified = False
139   for arg in args:
140     if arg.endswith('.gyp'):
141       gyp_file_specified = True
142       break
143
144   # If we didn't get a file, check an env var, and then fall back to
145   # assuming 'all.gyp' from the same directory as the script.
146   if not gyp_file_specified:
147     gyp_file = os.environ.get('CHROMIUM_GYP_FILE')
148     if gyp_file:
149       # Note that CHROMIUM_GYP_FILE values can't have backslashes as
150       # path separators even on Windows due to the use of shlex.split().
151       args.extend(shlex.split(gyp_file))
152     else:
153       args.append(os.path.join(xwalk_dir, 'xwalk.gyp'))
154
155   args.extend(['-I' + i for i in additional_include_files(args)])
156
157   # There shouldn't be a circular dependency relationship between .gyp files,
158   # but in Chromium's .gyp files, circular relationships currently exist.
159   # TODO(mark): Find and kill remaining circular dependencies, and remove this
160   # option.  http://crbug.com/35878.
161   # TODO(tc): Fix circular dependencies in ChromiumOS then add linux2 to the
162   # list.
163   # TODO(tmpsantos): Make runtime a proper module and enable the circular check
164   # back for Mac.
165   args.append('--no-circular-check')
166
167   # If CHROMIUM_GYP_SYNTAX_CHECK is set to 1, it will invoke gyp with --check
168   # to enfore syntax checking.
169   syntax_check = os.environ.get('CHROMIUM_GYP_SYNTAX_CHECK')
170   if syntax_check and int(syntax_check):
171     args.append('--check')
172
173   print 'Updating projects from gyp files...'
174   sys.stdout.flush()
175
176   # Off we go...
177   sys.exit(gyp.main(args))