deps: update v8 to 4.3.61.21
[platform/upstream/nodejs.git] / deps / v8 / build / gyp_v8
1 #!/usr/bin/env 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 gyp_environment
35 import os
36 import platform
37 import shlex
38 import subprocess
39 import sys
40
41 script_dir = os.path.dirname(os.path.realpath(__file__))
42 v8_root = os.path.abspath(os.path.join(script_dir, os.pardir))
43
44 sys.path.insert(0, os.path.join(v8_root, 'build', 'gyp', 'pylib'))
45 import gyp
46
47 # Add paths so that pymod_do_main(...) can import files.
48 sys.path.insert(
49     1, os.path.abspath(os.path.join(v8_root, 'tools', 'generate_shim_headers')))
50
51
52 def additional_include_files(args=[]):
53   """
54   Returns a list of additional (.gypi) files to include, without
55   duplicating ones that are already specified on the command line.
56   """
57   # Determine the include files specified on the command line.
58   # This doesn't cover all the different option formats you can use,
59   # but it's mainly intended to avoid duplicating flags on the automatic
60   # makefile regeneration which only uses this format.
61   specified_includes = set()
62   for arg in args:
63     if arg.startswith('-I') and len(arg) > 2:
64       specified_includes.add(os.path.realpath(arg[2:]))
65
66   result = []
67   def AddInclude(path):
68     if os.path.realpath(path) not in specified_includes:
69       result.append(path)
70
71   # Always include standalone.gypi
72   AddInclude(os.path.join(v8_root, 'build', 'standalone.gypi'))
73
74   # Optionally add supplemental .gypi files if present.
75   supplements = glob.glob(os.path.join(v8_root, '*', 'supplement.gypi'))
76   for supplement in supplements:
77     AddInclude(supplement)
78
79   return result
80
81
82 def run_gyp(args):
83   rc = gyp.main(args)
84
85   if rc != 0:
86     print 'Error running GYP'
87     sys.exit(rc)
88
89
90 if __name__ == '__main__':
91   args = sys.argv[1:]
92
93   gyp_environment.set_environment()
94
95   # This could give false positives since it doesn't actually do real option
96   # parsing.  Oh well.
97   gyp_file_specified = False
98   for arg in args:
99     if arg.endswith('.gyp'):
100       gyp_file_specified = True
101       break
102
103   # If we didn't get a file, check an env var, and then fall back to
104   # assuming 'all.gyp' from the same directory as the script.
105   if not gyp_file_specified:
106     gyp_file = os.environ.get('V8_GYP_FILE')
107     if gyp_file:
108       # Note that V8_GYP_FILE values can't have backslashes as
109       # path separators even on Windows due to the use of shlex.split().
110       args.extend(shlex.split(gyp_file))
111     else:
112       args.append(os.path.join(script_dir, 'all.gyp'))
113
114   args.extend(['-I' + i for i in additional_include_files(args)])
115
116   # There shouldn't be a circular dependency relationship between .gyp files
117   args.append('--no-circular-check')
118
119   # Set the GYP DEPTH variable to the root of the V8 project.
120   args.append('--depth=' + os.path.relpath(v8_root))
121
122   # If V8_GYP_SYNTAX_CHECK is set to 1, it will invoke gyp with --check
123   # to enfore syntax checking.
124   syntax_check = os.environ.get('V8_GYP_SYNTAX_CHECK')
125   if syntax_check and int(syntax_check):
126     args.append('--check')
127
128   print 'Updating projects from gyp files...'
129   sys.stdout.flush()
130
131   # Generate for the architectures supported on the given platform.
132   gyp_args = list(args)
133   gyp_generators = os.environ.get('GYP_GENERATORS')
134   if platform.system() == 'Linux' and gyp_generators != 'ninja':
135     # Work around for crbug.com/331475.
136     for f in glob.glob(os.path.join(v8_root, 'out', 'Makefile.*')):
137       os.unlink(f)
138     # --generator-output defines where the Makefile goes.
139     gyp_args.append('--generator-output=out')
140     # -Goutput_dir defines where the build output goes, relative to the
141     # Makefile. Set it to . so that the build output doesn't end up in out/out.
142     gyp_args.append('-Goutput_dir=.')
143   run_gyp(gyp_args)