media/webrtc/trunk/build/gyp_chromium

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/media/webrtc/trunk/build/gyp_chromium	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,175 @@
     1.4 +#!/usr/bin/env python
     1.5 +
     1.6 +# Copyright (c) 2012 The Chromium Authors. All rights reserved.
     1.7 +# Use of this source code is governed by a BSD-style license that can be
     1.8 +# found in the LICENSE file.
     1.9 +
    1.10 +# This script is wrapper for Chromium that adds some support for how GYP
    1.11 +# is invoked by Chromium beyond what can be done in the gclient hooks.
    1.12 +
    1.13 +import glob
    1.14 +import os
    1.15 +import shlex
    1.16 +import subprocess
    1.17 +import sys
    1.18 +
    1.19 +script_dir = os.path.dirname(os.path.realpath(__file__))
    1.20 +chrome_src = os.path.abspath(os.path.join(script_dir, os.pardir))
    1.21 +
    1.22 +sys.path.insert(0, os.path.join(chrome_src, 'tools', 'gyp', 'pylib'))
    1.23 +import gyp
    1.24 +
    1.25 +# Add paths so that pymod_do_main(...) can import files.
    1.26 +sys.path.insert(1, os.path.join(chrome_src, 'tools', 'grit'))
    1.27 +sys.path.insert(1, os.path.join(chrome_src, 'chrome', 'tools', 'build'))
    1.28 +sys.path.insert(1, os.path.join(chrome_src, 'native_client', 'build'))
    1.29 +
    1.30 +
    1.31 +# On Windows, Psyco shortens warm runs of build/gyp_chromium by about
    1.32 +# 20 seconds on a z600 machine with 12 GB of RAM, from 90 down to 70
    1.33 +# seconds.  Conversely, memory usage of build/gyp_chromium with Psyco
    1.34 +# maxes out at about 158 MB vs. 132 MB without it.
    1.35 +#
    1.36 +# Psyco uses native libraries, so we need to load a different
    1.37 +# installation depending on which OS we are running under. It has not
    1.38 +# been tested whether using Psyco on our Mac and Linux builds is worth
    1.39 +# it (the GYP running time is a lot shorter, so the JIT startup cost
    1.40 +# may not be worth it).
    1.41 +if sys.platform == 'win32':
    1.42 +  try:
    1.43 +    sys.path.insert(0, os.path.join(chrome_src, 'third_party', 'psyco_win32'))
    1.44 +    import psyco
    1.45 +  except:
    1.46 +    psyco = None
    1.47 +else:
    1.48 +  psyco = None
    1.49 +
    1.50 +def apply_gyp_environment(file_path=None):
    1.51 +  """
    1.52 +  Reads in a *.gyp_env file and applies the valid keys to os.environ.
    1.53 +  """
    1.54 +  if not file_path or not os.path.exists(file_path):
    1.55 +    return
    1.56 +  file_contents = open(file_path).read()
    1.57 +  try:
    1.58 +    file_data = eval(file_contents, {'__builtins__': None}, None)
    1.59 +  except SyntaxError, e:
    1.60 +    e.filename = os.path.abspath(file_path)
    1.61 +    raise
    1.62 +  supported_vars = ( 'CC',
    1.63 +                     'CHROMIUM_GYP_FILE',
    1.64 +                     'CHROMIUM_GYP_SYNTAX_CHECK',
    1.65 +                     'CXX',
    1.66 +                     'GYP_DEFINES',
    1.67 +                     'GYP_GENERATOR_FLAGS',
    1.68 +                     'GYP_GENERATOR_OUTPUT',
    1.69 +                     'GYP_GENERATORS', )
    1.70 +  for var in supported_vars:
    1.71 +    val = file_data.get(var)
    1.72 +    if val:
    1.73 +      if var in os.environ:
    1.74 +        print 'INFO: Environment value for "%s" overrides value in %s.' % (
    1.75 +            var, os.path.abspath(file_path)
    1.76 +        )
    1.77 +      else:
    1.78 +        os.environ[var] = val
    1.79 +
    1.80 +def additional_include_files(args=[]):
    1.81 +  """
    1.82 +  Returns a list of additional (.gypi) files to include, without
    1.83 +  duplicating ones that are already specified on the command line.
    1.84 +  """
    1.85 +  # Determine the include files specified on the command line.
    1.86 +  # This doesn't cover all the different option formats you can use,
    1.87 +  # but it's mainly intended to avoid duplicating flags on the automatic
    1.88 +  # makefile regeneration which only uses this format.
    1.89 +  specified_includes = set()
    1.90 +  for arg in args:
    1.91 +    if arg.startswith('-I') and len(arg) > 2:
    1.92 +      specified_includes.add(os.path.realpath(arg[2:]))
    1.93 +
    1.94 +  result = []
    1.95 +  def AddInclude(path):
    1.96 +    if os.path.realpath(path) not in specified_includes:
    1.97 +      result.append(path)
    1.98 +
    1.99 +  # Always include common.gypi.
   1.100 +  AddInclude(os.path.join(script_dir, 'common.gypi'))
   1.101 +
   1.102 +  # Optionally add supplemental .gypi files if present.
   1.103 +  supplements = glob.glob(os.path.join(chrome_src, '*', 'supplement.gypi'))
   1.104 +  for supplement in supplements:
   1.105 +    AddInclude(supplement)
   1.106 +
   1.107 +  return result
   1.108 +
   1.109 +if __name__ == '__main__':
   1.110 +  args = sys.argv[1:]
   1.111 +
   1.112 +  # Use the Psyco JIT if available.
   1.113 +  if psyco:
   1.114 +    psyco.profile()
   1.115 +    print "Enabled Psyco JIT."
   1.116 +
   1.117 +  # Fall back on hermetic python if we happen to get run under cygwin.
   1.118 +  # TODO(bradnelson): take this out once this issue is fixed:
   1.119 +  #    http://code.google.com/p/gyp/issues/detail?id=177
   1.120 +  if sys.platform == 'cygwin':
   1.121 +    python_dir = os.path.join(chrome_src, 'third_party', 'python_26')
   1.122 +    env = os.environ.copy()
   1.123 +    env['PATH'] = python_dir + os.pathsep + env.get('PATH', '')
   1.124 +    p = subprocess.Popen(
   1.125 +       [os.path.join(python_dir, 'python.exe')] + sys.argv,
   1.126 +       env=env, shell=False)
   1.127 +    p.communicate()
   1.128 +    sys.exit(p.returncode)
   1.129 +
   1.130 +  if 'SKIP_CHROMIUM_GYP_ENV' not in os.environ:
   1.131 +    # Update the environment based on chromium.gyp_env
   1.132 +    gyp_env_path = os.path.join(os.path.dirname(chrome_src), 'chromium.gyp_env')
   1.133 +    apply_gyp_environment(gyp_env_path)
   1.134 +
   1.135 +  # This could give false positives since it doesn't actually do real option
   1.136 +  # parsing.  Oh well.
   1.137 +  gyp_file_specified = False
   1.138 +  for arg in args:
   1.139 +    if arg.endswith('.gyp'):
   1.140 +      gyp_file_specified = True
   1.141 +      break
   1.142 +
   1.143 +  # If we didn't get a file, check an env var, and then fall back to
   1.144 +  # assuming 'all.gyp' from the same directory as the script.
   1.145 +  if not gyp_file_specified:
   1.146 +    gyp_file = os.environ.get('CHROMIUM_GYP_FILE')
   1.147 +    if gyp_file:
   1.148 +      # Note that CHROMIUM_GYP_FILE values can't have backslashes as
   1.149 +      # path separators even on Windows due to the use of shlex.split().
   1.150 +      args.extend(shlex.split(gyp_file))
   1.151 +    else:
   1.152 +      args.append(os.path.join(script_dir, 'all.gyp'))
   1.153 +
   1.154 +  args.extend(['-I' + i for i in additional_include_files(args)])
   1.155 +
   1.156 +  # There shouldn't be a circular dependency relationship between .gyp files,
   1.157 +  # but in Chromium's .gyp files, on non-Mac platforms, circular relationships
   1.158 +  # currently exist.  The check for circular dependencies is currently
   1.159 +  # bypassed on other platforms, but is left enabled on the Mac, where a
   1.160 +  # violation of the rule causes Xcode to misbehave badly.
   1.161 +  # TODO(mark): Find and kill remaining circular dependencies, and remove this
   1.162 +  # option.  http://crbug.com/35878.
   1.163 +  # TODO(tc): Fix circular dependencies in ChromiumOS then add linux2 to the
   1.164 +  # list.
   1.165 +  if sys.platform not in ('darwin',):
   1.166 +    args.append('--no-circular-check')
   1.167 +
   1.168 +  # If CHROMIUM_GYP_SYNTAX_CHECK is set to 1, it will invoke gyp with --check
   1.169 +  # to enfore syntax checking.
   1.170 +  syntax_check = os.environ.get('CHROMIUM_GYP_SYNTAX_CHECK')
   1.171 +  if syntax_check and int(syntax_check):
   1.172 +    args.append('--check')
   1.173 +
   1.174 +  print 'Updating projects from gyp files...'
   1.175 +  sys.stdout.flush()
   1.176 +
   1.177 +  # Off we go...
   1.178 +  sys.exit(gyp.main(args))

mercurial