2013-01-29 10:40:43 +00:00
|
|
|
#!/usr/bin/env python
|
2010-12-14 08:16:39 +00:00
|
|
|
#
|
2012-03-30 15:01:11 +00:00
|
|
|
# Copyright 2012 the V8 project authors. All rights reserved.
|
2010-12-14 08:16:39 +00:00
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
# modification, are permitted provided that the following conditions are
|
|
|
|
# met:
|
|
|
|
#
|
|
|
|
# * Redistributions of source code must retain the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer.
|
|
|
|
# * Redistributions in binary form must reproduce the above
|
|
|
|
# copyright notice, this list of conditions and the following
|
|
|
|
# disclaimer in the documentation and/or other materials provided
|
|
|
|
# with the distribution.
|
|
|
|
# * Neither the name of Google Inc. nor the names of its
|
|
|
|
# contributors may be used to endorse or promote products derived
|
|
|
|
# from this software without specific prior written permission.
|
|
|
|
#
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
# This script is wrapper for V8 that adds some support for how GYP
|
|
|
|
# is invoked by V8 beyond what can be done in the gclient hooks.
|
|
|
|
|
2015-11-02 10:40:16 +00:00
|
|
|
import argparse
|
2010-12-14 08:16:39 +00:00
|
|
|
import glob
|
2015-02-24 16:57:37 +00:00
|
|
|
import gyp_environment
|
2010-12-14 08:16:39 +00:00
|
|
|
import os
|
2013-04-23 10:41:55 +00:00
|
|
|
import platform
|
2010-12-14 08:16:39 +00:00
|
|
|
import shlex
|
2014-07-22 15:06:18 +00:00
|
|
|
import subprocess
|
2010-12-14 08:16:39 +00:00
|
|
|
import sys
|
2015-11-02 10:40:16 +00:00
|
|
|
import vs_toolchain
|
2010-12-14 08:16:39 +00:00
|
|
|
|
2014-01-02 13:50:50 +00:00
|
|
|
script_dir = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
v8_root = os.path.abspath(os.path.join(script_dir, os.pardir))
|
2012-05-11 12:18:09 +00:00
|
|
|
|
2016-04-27 12:35:38 +00:00
|
|
|
sys.path.insert(0, os.path.join(v8_root, 'tools', 'gyp', 'pylib'))
|
2010-12-14 08:16:39 +00:00
|
|
|
import gyp
|
|
|
|
|
2013-07-15 15:41:21 +00:00
|
|
|
# Add paths so that pymod_do_main(...) can import files.
|
|
|
|
sys.path.insert(
|
|
|
|
1, os.path.abspath(os.path.join(v8_root, 'tools', 'generate_shim_headers')))
|
|
|
|
|
2011-06-09 15:51:08 +00:00
|
|
|
|
2015-11-02 10:40:16 +00:00
|
|
|
def GetOutputDirectory():
|
|
|
|
"""Returns the output directory that GYP will use."""
|
|
|
|
|
|
|
|
# Handle command line generator flags.
|
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument('-G', dest='genflags', default=[], action='append')
|
|
|
|
genflags = parser.parse_known_args()[0].genflags
|
|
|
|
|
|
|
|
# Handle generator flags from the environment.
|
|
|
|
genflags += shlex.split(os.environ.get('GYP_GENERATOR_FLAGS', ''))
|
|
|
|
|
|
|
|
needle = 'output_dir='
|
|
|
|
for item in genflags:
|
|
|
|
if item.startswith(needle):
|
|
|
|
return item[len(needle):]
|
|
|
|
|
|
|
|
return 'out'
|
|
|
|
|
|
|
|
|
2010-12-14 08:16:39 +00:00
|
|
|
def additional_include_files(args=[]):
|
|
|
|
"""
|
|
|
|
Returns a list of additional (.gypi) files to include, without
|
|
|
|
duplicating ones that are already specified on the command line.
|
|
|
|
"""
|
|
|
|
# Determine the include files specified on the command line.
|
|
|
|
# This doesn't cover all the different option formats you can use,
|
|
|
|
# but it's mainly intended to avoid duplicating flags on the automatic
|
|
|
|
# makefile regeneration which only uses this format.
|
|
|
|
specified_includes = set()
|
|
|
|
for arg in args:
|
|
|
|
if arg.startswith('-I') and len(arg) > 2:
|
|
|
|
specified_includes.add(os.path.realpath(arg[2:]))
|
|
|
|
|
|
|
|
result = []
|
|
|
|
def AddInclude(path):
|
|
|
|
if os.path.realpath(path) not in specified_includes:
|
|
|
|
result.append(path)
|
|
|
|
|
2011-08-25 14:50:09 +00:00
|
|
|
# Always include standalone.gypi
|
2016-04-29 10:08:53 +00:00
|
|
|
AddInclude(os.path.join(v8_root, 'gypfiles', 'standalone.gypi'))
|
2010-12-14 08:16:39 +00:00
|
|
|
|
|
|
|
# Optionally add supplemental .gypi files if present.
|
|
|
|
supplements = glob.glob(os.path.join(v8_root, '*', 'supplement.gypi'))
|
|
|
|
for supplement in supplements:
|
|
|
|
AddInclude(supplement)
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
2011-06-09 15:51:08 +00:00
|
|
|
|
|
|
|
def run_gyp(args):
|
|
|
|
rc = gyp.main(args)
|
2014-07-22 15:06:18 +00:00
|
|
|
|
2015-11-02 10:40:16 +00:00
|
|
|
vs2013_runtime_dll_dirs = vs_toolchain.SetEnvironmentAndGetRuntimeDllDirs()
|
|
|
|
if vs2013_runtime_dll_dirs:
|
|
|
|
x64_runtime, x86_runtime = vs2013_runtime_dll_dirs
|
|
|
|
vs_toolchain.CopyVsRuntimeDlls(
|
|
|
|
os.path.join(v8_root, GetOutputDirectory()),
|
|
|
|
(x86_runtime, x64_runtime))
|
|
|
|
|
2011-06-09 15:51:08 +00:00
|
|
|
if rc != 0:
|
|
|
|
print 'Error running GYP'
|
|
|
|
sys.exit(rc)
|
|
|
|
|
|
|
|
|
2010-12-14 08:16:39 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
args = sys.argv[1:]
|
|
|
|
|
2016-06-09 12:47:15 +00:00
|
|
|
if int(os.environ.get('GYP_CHROMIUM_NO_ACTION', 0)):
|
|
|
|
print 'Skipping gyp_v8 due to GYP_CHROMIUM_NO_ACTION env var.'
|
|
|
|
sys.exit(0)
|
|
|
|
|
2015-02-24 16:57:37 +00:00
|
|
|
gyp_environment.set_environment()
|
2010-12-14 08:16:39 +00:00
|
|
|
|
|
|
|
# This could give false positives since it doesn't actually do real option
|
|
|
|
# parsing. Oh well.
|
|
|
|
gyp_file_specified = False
|
|
|
|
for arg in args:
|
|
|
|
if arg.endswith('.gyp'):
|
|
|
|
gyp_file_specified = True
|
|
|
|
break
|
|
|
|
|
|
|
|
# If we didn't get a file, check an env var, and then fall back to
|
|
|
|
# assuming 'all.gyp' from the same directory as the script.
|
|
|
|
if not gyp_file_specified:
|
|
|
|
gyp_file = os.environ.get('V8_GYP_FILE')
|
|
|
|
if gyp_file:
|
|
|
|
# Note that V8_GYP_FILE values can't have backslashes as
|
|
|
|
# path separators even on Windows due to the use of shlex.split().
|
|
|
|
args.extend(shlex.split(gyp_file))
|
|
|
|
else:
|
2014-01-02 13:50:50 +00:00
|
|
|
args.append(os.path.join(script_dir, 'all.gyp'))
|
2010-12-14 08:16:39 +00:00
|
|
|
|
|
|
|
args.extend(['-I' + i for i in additional_include_files(args)])
|
|
|
|
|
|
|
|
# There shouldn't be a circular dependency relationship between .gyp files
|
|
|
|
args.append('--no-circular-check')
|
|
|
|
|
|
|
|
# Set the GYP DEPTH variable to the root of the V8 project.
|
2014-01-02 14:35:32 +00:00
|
|
|
args.append('--depth=' + os.path.relpath(v8_root))
|
2010-12-14 08:16:39 +00:00
|
|
|
|
|
|
|
# If V8_GYP_SYNTAX_CHECK is set to 1, it will invoke gyp with --check
|
|
|
|
# to enfore syntax checking.
|
|
|
|
syntax_check = os.environ.get('V8_GYP_SYNTAX_CHECK')
|
|
|
|
if syntax_check and int(syntax_check):
|
|
|
|
args.append('--check')
|
|
|
|
|
|
|
|
print 'Updating projects from gyp files...'
|
|
|
|
sys.stdout.flush()
|
|
|
|
|
2011-06-09 15:51:08 +00:00
|
|
|
# Generate for the architectures supported on the given platform.
|
|
|
|
gyp_args = list(args)
|
2015-11-02 10:40:16 +00:00
|
|
|
gyp_args.extend(['-D', 'gyp_output_dir=' + GetOutputDirectory()])
|
2015-06-29 10:47:20 +00:00
|
|
|
gyp_generators = os.environ.get('GYP_GENERATORS', '')
|
2014-04-03 07:40:32 +00:00
|
|
|
if platform.system() == 'Linux' and gyp_generators != 'ninja':
|
2014-01-07 09:09:24 +00:00
|
|
|
# Work around for crbug.com/331475.
|
|
|
|
for f in glob.glob(os.path.join(v8_root, 'out', 'Makefile.*')):
|
|
|
|
os.unlink(f)
|
2013-12-05 11:19:10 +00:00
|
|
|
# --generator-output defines where the Makefile goes.
|
2012-05-11 12:18:09 +00:00
|
|
|
gyp_args.append('--generator-output=out')
|
2013-12-05 11:19:10 +00:00
|
|
|
# -Goutput_dir defines where the build output goes, relative to the
|
|
|
|
# Makefile. Set it to . so that the build output doesn't end up in out/out.
|
|
|
|
gyp_args.append('-Goutput_dir=.')
|
2015-06-29 10:47:20 +00:00
|
|
|
|
|
|
|
gyp_defines = os.environ.get('GYP_DEFINES', '')
|
|
|
|
|
|
|
|
# Automatically turn on crosscompile support for platforms that need it.
|
|
|
|
if all(('ninja' in gyp_generators,
|
|
|
|
'OS=android' in gyp_defines,
|
|
|
|
'GYP_CROSSCOMPILE' not in os.environ)):
|
|
|
|
os.environ['GYP_CROSSCOMPILE'] = '1'
|
|
|
|
|
2011-06-09 15:51:08 +00:00
|
|
|
run_gyp(gyp_args)
|