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.

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

mercurial