Updated V8 from git://github.com/v8/v8.git to 3e6ec7e018bbf2c63ef04b85ff688198ea204c04
[profile/ivi/qtjsbackend.git] / src / 3rdparty / v8 / build / gyp_v8
1 #!/usr/bin/python
2 #
3 # Copyright 2012 the V8 project authors. All rights reserved.
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are
6 # met:
7 #
8 #     * Redistributions of source code must retain the above copyright
9 #       notice, this list of conditions and the following disclaimer.
10 #     * Redistributions in binary form must reproduce the above
11 #       copyright notice, this list of conditions and the following
12 #       disclaimer in the documentation and/or other materials provided
13 #       with the distribution.
14 #     * Neither the name of Google Inc. nor the names of its
15 #       contributors may be used to endorse or promote products derived
16 #       from this software without specific prior written permission.
17 #
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30 # This script is wrapper for V8 that adds some support for how GYP
31 # is invoked by V8 beyond what can be done in the gclient hooks.
32
33 import glob
34 import os
35 import shlex
36 import sys
37
38 script_dir = os.path.dirname(__file__)
39 v8_root = os.path.normpath(os.path.join(script_dir, os.pardir))
40
41 if __name__ == '__main__':
42   os.chdir(v8_root)
43   script_dir = os.path.dirname(__file__)
44   v8_root = '.'
45
46 sys.path.insert(0, os.path.join(v8_root, 'tools'))
47 import utils
48
49 sys.path.insert(0, os.path.join(v8_root, 'build', 'gyp', 'pylib'))
50 import gyp
51
52
53 def apply_gyp_environment(file_path=None):
54   """
55   Reads in a *.gyp_env file and applies the valid keys to os.environ.
56   """
57   if not file_path or not os.path.exists(file_path):
58     return
59   file_contents = open(file_path).read()
60   try:
61     file_data = eval(file_contents, {'__builtins__': None}, None)
62   except SyntaxError, e:
63     e.filename = os.path.abspath(file_path)
64     raise
65   supported_vars = ( 'V8_GYP_FILE',
66                      'V8_GYP_SYNTAX_CHECK',
67                      'GYP_DEFINES',
68                      'GYP_GENERATOR_FLAGS',
69                      'GYP_GENERATOR_OUTPUT', )
70   for var in supported_vars:
71     val = file_data.get(var)
72     if val:
73       if var in os.environ:
74         print 'INFO: Environment value for "%s" overrides value in %s.' % (
75             var, os.path.abspath(file_path)
76         )
77       else:
78         os.environ[var] = val
79
80
81 def additional_include_files(args=[]):
82   """
83   Returns a list of additional (.gypi) files to include, without
84   duplicating ones that are already specified on the command line.
85   """
86   # Determine the include files specified on the command line.
87   # This doesn't cover all the different option formats you can use,
88   # but it's mainly intended to avoid duplicating flags on the automatic
89   # makefile regeneration which only uses this format.
90   specified_includes = set()
91   for arg in args:
92     if arg.startswith('-I') and len(arg) > 2:
93       specified_includes.add(os.path.realpath(arg[2:]))
94
95   result = []
96   def AddInclude(path):
97     if os.path.realpath(path) not in specified_includes:
98       result.append(path)
99
100   # Always include standalone.gypi
101   AddInclude(os.path.join(v8_root, 'build', 'standalone.gypi'))
102
103   # Optionally add supplemental .gypi files if present.
104   supplements = glob.glob(os.path.join(v8_root, '*', 'supplement.gypi'))
105   for supplement in supplements:
106     AddInclude(supplement)
107
108   return result
109
110
111 def run_gyp(args):
112   rc = gyp.main(args)
113   if rc != 0:
114     print 'Error running GYP'
115     sys.exit(rc)
116
117
118 if __name__ == '__main__':
119   args = sys.argv[1:]
120
121   if 'SKIP_V8_GYP_ENV' not in os.environ:
122     # Update the environment based on v8.gyp_env
123     gyp_env_path = os.path.join(os.path.dirname(v8_root), 'v8.gyp_env')
124     apply_gyp_environment(gyp_env_path)
125
126   # This could give false positives since it doesn't actually do real option
127   # parsing.  Oh well.
128   gyp_file_specified = False
129   for arg in args:
130     if arg.endswith('.gyp'):
131       gyp_file_specified = True
132       break
133
134   # If we didn't get a file, check an env var, and then fall back to
135   # assuming 'all.gyp' from the same directory as the script.
136   if not gyp_file_specified:
137     gyp_file = os.environ.get('V8_GYP_FILE')
138     if gyp_file:
139       # Note that V8_GYP_FILE values can't have backslashes as
140       # path separators even on Windows due to the use of shlex.split().
141       args.extend(shlex.split(gyp_file))
142     else:
143       # Note that this must not start with "./" or things break.
144       # So we rely on having done os.chdir(v8_root) above and use the
145       # relative path.
146       args.append(os.path.join('build', 'all.gyp'))
147
148   args.extend(['-I' + i for i in additional_include_files(args)])
149
150   # There shouldn't be a circular dependency relationship between .gyp files
151   args.append('--no-circular-check')
152
153   # Set the GYP DEPTH variable to the root of the V8 project.
154   args.append('--depth=' + v8_root)
155
156   # If V8_GYP_SYNTAX_CHECK is set to 1, it will invoke gyp with --check
157   # to enfore syntax checking.
158   syntax_check = os.environ.get('V8_GYP_SYNTAX_CHECK')
159   if syntax_check and int(syntax_check):
160     args.append('--check')
161
162   print 'Updating projects from gyp files...'
163   sys.stdout.flush()
164
165   # Generate for the architectures supported on the given platform.
166   gyp_args = list(args)
167   if utils.GuessOS() == 'linux':
168     gyp_args.append('--generator-output=out')
169   run_gyp(gyp_args)