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