niklase@google.com | da159d6 | 2011-05-30 11:51:34 +0000 | [diff] [blame^] | 1 | #!/usr/bin/python
|
| 2 |
|
| 3 | # Copyright (c) 2009 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.
|
| 6 |
|
| 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.
|
| 9 |
|
| 10 | import glob
|
| 11 | import os
|
| 12 | import shlex
|
| 13 | import sys
|
| 14 |
|
| 15 | script_dir = os.path.dirname(__file__)
|
| 16 | chrome_src = '../..';#os.path.normpath(os.path.join(script_dir, os.pardir))
|
| 17 |
|
| 18 | sys.path.insert(0, os.path.join(chrome_src, 'tools', 'gyp', 'pylib'))
|
| 19 | import gyp
|
| 20 |
|
| 21 | def apply_gyp_environment(file_path=None):
|
| 22 | """
|
| 23 | Reads in a *.gyp_env file and applies the valid keys to os.environ.
|
| 24 | """
|
| 25 | if not file_path or not os.path.exists(file_path):
|
| 26 | return
|
| 27 | file_contents = open(file_path).read()
|
| 28 | try:
|
| 29 | file_data = eval(file_contents, {'__builtins__': None}, None)
|
| 30 | except SyntaxError, e:
|
| 31 | e.filename = os.path.abspath(file_path)
|
| 32 | raise
|
| 33 | supported_vars = ( 'CHROMIUM_GYP_FILE',
|
| 34 | 'CHROMIUM_GYP_SYNTAX_CHECK',
|
| 35 | 'GYP_DEFINES',
|
| 36 | 'GYP_GENERATOR_FLAGS',
|
| 37 | 'GYP_GENERATOR_OUTPUT', )
|
| 38 | for var in supported_vars:
|
| 39 | val = file_data.get(var)
|
| 40 | if val:
|
| 41 | if var in os.environ:
|
| 42 | print 'INFO: Environment value for "%s" overrides value in %s.' % (
|
| 43 | var, os.path.abspath(file_path)
|
| 44 | )
|
| 45 | else:
|
| 46 | os.environ[var] = val
|
| 47 |
|
| 48 | def additional_include_files(args=[]):
|
| 49 | """
|
| 50 | Returns a list of additional (.gypi) files to include, without
|
| 51 | duplicating ones that are already specified on the command line.
|
| 52 | """
|
| 53 | # Determine the include files specified on the command line.
|
| 54 | # This doesn't cover all the different option formats you can use,
|
| 55 | # but it's mainly intended to avoid duplicating flags on the automatic
|
| 56 | # makefile regeneration which only uses this format.
|
| 57 | specified_includes = set()
|
| 58 | for arg in args:
|
| 59 | if arg.startswith('-I') and len(arg) > 2:
|
| 60 | specified_includes.add(os.path.realpath(arg[2:]))
|
| 61 |
|
| 62 | result = []
|
| 63 | def AddInclude(path):
|
| 64 | if os.path.realpath(path) not in specified_includes:
|
| 65 | result.append(path)
|
| 66 |
|
| 67 | # Always include common.gypi & features_override.gypi
|
| 68 | AddInclude(os.path.join(script_dir, '../../build/common.gypi'))
|
| 69 | AddInclude(os.path.join(script_dir, '../../build/features_override.gypi'))
|
| 70 |
|
| 71 | # Optionally add supplemental .gypi files if present.
|
| 72 | supplements = glob.glob(os.path.join(chrome_src, '*', 'supplement.gypi'))
|
| 73 | for supplement in supplements:
|
| 74 | AddInclude(supplement)
|
| 75 |
|
| 76 | return result
|
| 77 |
|
| 78 | if __name__ == '__main__':
|
| 79 | args = sys.argv[1:]
|
| 80 |
|
| 81 | if 'SKIP_CHROMIUM_GYP_ENV' not in os.environ:
|
| 82 | # Update the environment based on chromium.gyp_env
|
| 83 | gyp_env_path = os.path.join(os.path.dirname(chrome_src), 'chromium.gyp_env')
|
| 84 | apply_gyp_environment(gyp_env_path)
|
| 85 |
|
| 86 | # This could give false positives since it doesn't actually do real option
|
| 87 | # parsing. Oh well.
|
| 88 | gyp_file_specified = False
|
| 89 | for arg in args:
|
| 90 | if arg.endswith('.gyp'):
|
| 91 | gyp_file_specified = True
|
| 92 | break
|
| 93 |
|
| 94 | # If we didn't get a file, check an env var, and then fall back to
|
| 95 | # assuming 'all.gyp' from the same directory as the script.
|
| 96 | if not gyp_file_specified:
|
| 97 | gyp_file = os.environ.get('CHROMIUM_GYP_FILE')
|
| 98 | if gyp_file:
|
| 99 | # Note that CHROMIUM_GYP_FILE values can't have backslashes as
|
| 100 | # path separators even on Windows due to the use of shlex.split().
|
| 101 | args.extend(shlex.split(gyp_file))
|
| 102 | else:
|
| 103 | args.append(os.path.join(script_dir, 'video_engine.gyp'))
|
| 104 |
|
| 105 | args.extend(['-I' + i for i in additional_include_files(args)])
|
| 106 |
|
| 107 | # There shouldn't be a circular dependency relationship between .gyp files,
|
| 108 | # but in Chromium's .gyp files, on non-Mac platforms, circular relationships
|
| 109 | # currently exist. The check for circular dependencies is currently
|
| 110 | # bypassed on other platforms, but is left enabled on the Mac, where a
|
| 111 | # violation of the rule causes Xcode to misbehave badly.
|
| 112 | # TODO(mark): Find and kill remaining circular dependencies, and remove this
|
| 113 | # option. http://crbug.com/35878.
|
| 114 | # TODO(tc): Fix circular dependencies in ChromiumOS then add linux2 to the
|
| 115 | # list.
|
| 116 | if sys.platform not in ('darwin',):
|
| 117 | args.append('--no-circular-check')
|
| 118 |
|
| 119 | # If CHROMIUM_GYP_SYNTAX_CHECK is set to 1, it will invoke gyp with --check
|
| 120 | # to enfore syntax checking.
|
| 121 | syntax_check = os.environ.get('CHROMIUM_GYP_SYNTAX_CHECK')
|
| 122 | if syntax_check and int(syntax_check):
|
| 123 | args.append('--check')
|
| 124 |
|
| 125 | print 'Updating projects from gyp files...'
|
| 126 | sys.stdout.flush()
|
| 127 |
|
| 128 | # Off we go...
|
| 129 | sys.exit(gyp.main(args))
|