media/webrtc/trunk/build/gyp_chromium

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rwxr-xr-x

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 #!/usr/bin/env python
     3 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
     4 # Use of this source code is governed by a BSD-style license that can be
     5 # found in the LICENSE file.
     7 # This script is wrapper for Chromium that adds some support for how GYP
     8 # is invoked by Chromium beyond what can be done in the gclient hooks.
    10 import glob
    11 import os
    12 import shlex
    13 import subprocess
    14 import sys
    16 script_dir = os.path.dirname(os.path.realpath(__file__))
    17 chrome_src = os.path.abspath(os.path.join(script_dir, os.pardir))
    19 sys.path.insert(0, os.path.join(chrome_src, 'tools', 'gyp', 'pylib'))
    20 import gyp
    22 # Add paths so that pymod_do_main(...) can import files.
    23 sys.path.insert(1, os.path.join(chrome_src, 'tools', 'grit'))
    24 sys.path.insert(1, os.path.join(chrome_src, 'chrome', 'tools', 'build'))
    25 sys.path.insert(1, os.path.join(chrome_src, 'native_client', 'build'))
    28 # On Windows, Psyco shortens warm runs of build/gyp_chromium by about
    29 # 20 seconds on a z600 machine with 12 GB of RAM, from 90 down to 70
    30 # seconds.  Conversely, memory usage of build/gyp_chromium with Psyco
    31 # maxes out at about 158 MB vs. 132 MB without it.
    32 #
    33 # Psyco uses native libraries, so we need to load a different
    34 # installation depending on which OS we are running under. It has not
    35 # been tested whether using Psyco on our Mac and Linux builds is worth
    36 # it (the GYP running time is a lot shorter, so the JIT startup cost
    37 # may not be worth it).
    38 if sys.platform == 'win32':
    39   try:
    40     sys.path.insert(0, os.path.join(chrome_src, 'third_party', 'psyco_win32'))
    41     import psyco
    42   except:
    43     psyco = None
    44 else:
    45   psyco = None
    47 def apply_gyp_environment(file_path=None):
    48   """
    49   Reads in a *.gyp_env file and applies the valid keys to os.environ.
    50   """
    51   if not file_path or not os.path.exists(file_path):
    52     return
    53   file_contents = open(file_path).read()
    54   try:
    55     file_data = eval(file_contents, {'__builtins__': None}, None)
    56   except SyntaxError, e:
    57     e.filename = os.path.abspath(file_path)
    58     raise
    59   supported_vars = ( 'CC',
    60                      'CHROMIUM_GYP_FILE',
    61                      'CHROMIUM_GYP_SYNTAX_CHECK',
    62                      'CXX',
    63                      'GYP_DEFINES',
    64                      'GYP_GENERATOR_FLAGS',
    65                      'GYP_GENERATOR_OUTPUT',
    66                      'GYP_GENERATORS', )
    67   for var in supported_vars:
    68     val = file_data.get(var)
    69     if val:
    70       if var in os.environ:
    71         print 'INFO: Environment value for "%s" overrides value in %s.' % (
    72             var, os.path.abspath(file_path)
    73         )
    74       else:
    75         os.environ[var] = val
    77 def additional_include_files(args=[]):
    78   """
    79   Returns a list of additional (.gypi) files to include, without
    80   duplicating ones that are already specified on the command line.
    81   """
    82   # Determine the include files specified on the command line.
    83   # This doesn't cover all the different option formats you can use,
    84   # but it's mainly intended to avoid duplicating flags on the automatic
    85   # makefile regeneration which only uses this format.
    86   specified_includes = set()
    87   for arg in args:
    88     if arg.startswith('-I') and len(arg) > 2:
    89       specified_includes.add(os.path.realpath(arg[2:]))
    91   result = []
    92   def AddInclude(path):
    93     if os.path.realpath(path) not in specified_includes:
    94       result.append(path)
    96   # Always include common.gypi.
    97   AddInclude(os.path.join(script_dir, 'common.gypi'))
    99   # Optionally add supplemental .gypi files if present.
   100   supplements = glob.glob(os.path.join(chrome_src, '*', 'supplement.gypi'))
   101   for supplement in supplements:
   102     AddInclude(supplement)
   104   return result
   106 if __name__ == '__main__':
   107   args = sys.argv[1:]
   109   # Use the Psyco JIT if available.
   110   if psyco:
   111     psyco.profile()
   112     print "Enabled Psyco JIT."
   114   # Fall back on hermetic python if we happen to get run under cygwin.
   115   # TODO(bradnelson): take this out once this issue is fixed:
   116   #    http://code.google.com/p/gyp/issues/detail?id=177
   117   if sys.platform == 'cygwin':
   118     python_dir = os.path.join(chrome_src, 'third_party', 'python_26')
   119     env = os.environ.copy()
   120     env['PATH'] = python_dir + os.pathsep + env.get('PATH', '')
   121     p = subprocess.Popen(
   122        [os.path.join(python_dir, 'python.exe')] + sys.argv,
   123        env=env, shell=False)
   124     p.communicate()
   125     sys.exit(p.returncode)
   127   if 'SKIP_CHROMIUM_GYP_ENV' not in os.environ:
   128     # Update the environment based on chromium.gyp_env
   129     gyp_env_path = os.path.join(os.path.dirname(chrome_src), 'chromium.gyp_env')
   130     apply_gyp_environment(gyp_env_path)
   132   # This could give false positives since it doesn't actually do real option
   133   # parsing.  Oh well.
   134   gyp_file_specified = False
   135   for arg in args:
   136     if arg.endswith('.gyp'):
   137       gyp_file_specified = True
   138       break
   140   # If we didn't get a file, check an env var, and then fall back to
   141   # assuming 'all.gyp' from the same directory as the script.
   142   if not gyp_file_specified:
   143     gyp_file = os.environ.get('CHROMIUM_GYP_FILE')
   144     if gyp_file:
   145       # Note that CHROMIUM_GYP_FILE values can't have backslashes as
   146       # path separators even on Windows due to the use of shlex.split().
   147       args.extend(shlex.split(gyp_file))
   148     else:
   149       args.append(os.path.join(script_dir, 'all.gyp'))
   151   args.extend(['-I' + i for i in additional_include_files(args)])
   153   # There shouldn't be a circular dependency relationship between .gyp files,
   154   # but in Chromium's .gyp files, on non-Mac platforms, circular relationships
   155   # currently exist.  The check for circular dependencies is currently
   156   # bypassed on other platforms, but is left enabled on the Mac, where a
   157   # violation of the rule causes Xcode to misbehave badly.
   158   # TODO(mark): Find and kill remaining circular dependencies, and remove this
   159   # option.  http://crbug.com/35878.
   160   # TODO(tc): Fix circular dependencies in ChromiumOS then add linux2 to the
   161   # list.
   162   if sys.platform not in ('darwin',):
   163     args.append('--no-circular-check')
   165   # If CHROMIUM_GYP_SYNTAX_CHECK is set to 1, it will invoke gyp with --check
   166   # to enfore syntax checking.
   167   syntax_check = os.environ.get('CHROMIUM_GYP_SYNTAX_CHECK')
   168   if syntax_check and int(syntax_check):
   169     args.append('--check')
   171   print 'Updating projects from gyp files...'
   172   sys.stdout.flush()
   174   # Off we go...
   175   sys.exit(gyp.main(args))

mercurial