1 #!/usr/bin/python 2 # 3 # Copyright 2010 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 sys.path.insert(0, os.path.join(v8_root, 'tools')) 42 import utils 43 44 sys.path.insert(0, os.path.join(v8_root, 'build', 'gyp', 'pylib')) 45 import gyp 46 47 48 def apply_gyp_environment(file_path=None): 49 """ 50 Reads in a *.gyp_env file and applies the valid keys to os.environ. 51 """ 52 if not file_path or not os.path.exists(file_path): 53 return 54 file_contents = open(file_path).read() 55 try: 56 file_data = eval(file_contents, {'__builtins__': None}, None) 57 except SyntaxError, e: 58 e.filename = os.path.abspath(file_path) 59 raise 60 supported_vars = ( 'V8_GYP_FILE', 61 'V8_GYP_SYNTAX_CHECK', 62 'GYP_DEFINES', 63 'GYP_GENERATOR_FLAGS', 64 'GYP_GENERATOR_OUTPUT', ) 65 for var in supported_vars: 66 val = file_data.get(var) 67 if val: 68 if var in os.environ: 69 print 'INFO: Environment value for "%s" overrides value in %s.' % ( 70 var, os.path.abspath(file_path) 71 ) 72 else: 73 os.environ[var] = val 74 75 76 def additional_include_files(args=[]): 77 """ 78 Returns a list of additional (.gypi) files to include, without 79 duplicating ones that are already specified on the command line. 80 """ 81 # Determine the include files specified on the command line. 82 # This doesn't cover all the different option formats you can use, 83 # but it's mainly intended to avoid duplicating flags on the automatic 84 # makefile regeneration which only uses this format. 85 specified_includes = set() 86 for arg in args: 87 if arg.startswith('-I') and len(arg) > 2: 88 specified_includes.add(os.path.realpath(arg[2:])) 89 90 result = [] 91 def AddInclude(path): 92 if os.path.realpath(path) not in specified_includes: 93 result.append(path) 94 95 # Always include standalone.gypi 96 AddInclude(os.path.join(script_dir, 'standalone.gypi')) 97 98 # Optionally add supplemental .gypi files if present. 99 supplements = glob.glob(os.path.join(v8_root, '*', 'supplement.gypi')) 100 for supplement in supplements: 101 AddInclude(supplement) 102 103 return result 104 105 106 def run_gyp(args): 107 rc = gyp.main(args) 108 if rc != 0: 109 print 'Error running GYP' 110 sys.exit(rc) 111 112 113 if __name__ == '__main__': 114 args = sys.argv[1:] 115 116 if 'SKIP_V8_GYP_ENV' not in os.environ: 117 # Update the environment based on v8.gyp_env 118 gyp_env_path = os.path.join(os.path.dirname(v8_root), 'v8.gyp_env') 119 apply_gyp_environment(gyp_env_path) 120 121 # This could give false positives since it doesn't actually do real option 122 # parsing. Oh well. 123 gyp_file_specified = False 124 for arg in args: 125 if arg.endswith('.gyp'): 126 gyp_file_specified = True 127 break 128 129 # If we didn't get a file, check an env var, and then fall back to 130 # assuming 'all.gyp' from the same directory as the script. 131 if not gyp_file_specified: 132 gyp_file = os.environ.get('V8_GYP_FILE') 133 if gyp_file: 134 # Note that V8_GYP_FILE values can't have backslashes as 135 # path separators even on Windows due to the use of shlex.split(). 136 args.extend(shlex.split(gyp_file)) 137 else: 138 args.append(os.path.join(script_dir, 'all.gyp')) 139 140 args.extend(['-I' + i for i in additional_include_files(args)]) 141 142 # There shouldn't be a circular dependency relationship between .gyp files 143 args.append('--no-circular-check') 144 145 # Set the GYP DEPTH variable to the root of the V8 project. 146 args.append('--depth=' + v8_root) 147 148 # If V8_GYP_SYNTAX_CHECK is set to 1, it will invoke gyp with --check 149 # to enfore syntax checking. 150 syntax_check = os.environ.get('V8_GYP_SYNTAX_CHECK') 151 if syntax_check and int(syntax_check): 152 args.append('--check') 153 154 print 'Updating projects from gyp files...' 155 sys.stdout.flush() 156 157 # Generate for the architectures supported on the given platform. 158 gyp_args = list(args) 159 gyp_args.append('-Dtarget_arch=ia32') 160 if utils.GuessOS() == 'linux': 161 gyp_args.append('-S-ia32') 162 run_gyp(gyp_args) 163 164 if utils.GuessOS() == 'linux': 165 gyp_args = list(args) 166 gyp_args.append('-Dtarget_arch=x64') 167 gyp_args.append('-S-x64') 168 run_gyp(gyp_args) 169 170 gyp_args = list(args) 171 gyp_args.append('-I' + v8_root + '/build/armu.gypi') 172 gyp_args.append('-S-armu') 173 run_gyp(gyp_args) 174 175 gyp_args = list(args) 176 gyp_args.append('-I' + v8_root + '/build/mipsu.gypi') 177 gyp_args.append('-S-mipsu') 178 run_gyp(gyp_args) 179