[email protected] | abab8d7 | 2012-11-14 04:59:48 | [diff] [blame] | 1 | # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
| 5 | # This file helps gyp_chromium and landmines correctly set up the gyp |
| 6 | # environment from chromium.gyp_env on disk |
| 7 | |
| 8 | import os |
| 9 | |
| 10 | SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__)) |
| 11 | CHROME_SRC = os.path.dirname(SCRIPT_DIR) |
| 12 | |
| 13 | |
| 14 | def apply_gyp_environment_from_file(file_path): |
| 15 | """Reads in a *.gyp_env file and applies the valid keys to os.environ.""" |
| 16 | if not os.path.exists(file_path): |
| 17 | return |
[email protected] | 107e33a | 2012-11-15 01:51:54 | [diff] [blame] | 18 | with open(file_path, 'rU') as f: |
[email protected] | abab8d7 | 2012-11-14 04:59:48 | [diff] [blame] | 19 | file_contents = f.read() |
| 20 | try: |
| 21 | file_data = eval(file_contents, {'__builtins__': None}, None) |
| 22 | except SyntaxError, e: |
| 23 | e.filename = os.path.abspath(file_path) |
| 24 | raise |
| 25 | supported_vars = ( |
| 26 | 'CC', |
[email protected] | 68294fd | 2013-04-17 21:15:27 | [diff] [blame] | 27 | 'CC_wrapper', |
[email protected] | abab8d7 | 2012-11-14 04:59:48 | [diff] [blame] | 28 | 'CHROMIUM_GYP_FILE', |
| 29 | 'CHROMIUM_GYP_SYNTAX_CHECK', |
| 30 | 'CXX', |
[email protected] | 68294fd | 2013-04-17 21:15:27 | [diff] [blame] | 31 | 'CXX_wrapper', |
[email protected] | abab8d7 | 2012-11-14 04:59:48 | [diff] [blame] | 32 | 'GYP_DEFINES', |
| 33 | 'GYP_GENERATOR_FLAGS', |
[email protected] | ba203410 | 2013-05-07 21:05:39 | [diff] [blame] | 34 | 'GYP_CROSSCOMPILE', |
[email protected] | abab8d7 | 2012-11-14 04:59:48 | [diff] [blame] | 35 | 'GYP_GENERATOR_OUTPUT', |
| 36 | 'GYP_GENERATORS', |
justsomeguy | cec083d3 | 2014-11-05 18:57:15 | [diff] [blame] | 37 | 'GYP_INCLUDE_FIRST', |
| 38 | 'GYP_INCLUDE_LAST', |
[email protected] | dcd6d6e | 2014-01-13 21:29:34 | [diff] [blame] | 39 | 'GYP_MSVS_VERSION', |
[email protected] | abab8d7 | 2012-11-14 04:59:48 | [diff] [blame] | 40 | ) |
| 41 | for var in supported_vars: |
| 42 | file_val = file_data.get(var) |
| 43 | if file_val: |
| 44 | if var in os.environ: |
dongseong.hwang | ce4b0d1 | 2015-03-05 07:08:15 | [diff] [blame] | 45 | behavior = 'replaces' |
| 46 | if var == 'GYP_DEFINES': |
scheib | eedc9ac | 2015-03-14 00:14:01 | [diff] [blame^] | 47 | result = file_val + ' ' + os.environ[var] |
| 48 | behavior = 'merges with, and individual components override,' |
| 49 | else: |
| 50 | result = os.environ[var] |
dongseong.hwang | ce4b0d1 | 2015-03-05 07:08:15 | [diff] [blame] | 51 | print 'INFO: Environment value for "%s" %s value in %s' % ( |
| 52 | var, behavior, os.path.abspath(file_path) |
[email protected] | abab8d7 | 2012-11-14 04:59:48 | [diff] [blame] | 53 | ) |
scheib | eedc9ac | 2015-03-14 00:14:01 | [diff] [blame^] | 54 | string_padding = max(len(var), len(file_path), len('result')) |
| 55 | print ' %s: %s' % (var.rjust(string_padding), os.environ[var]) |
| 56 | print ' %s: %s' % (file_path.rjust(string_padding), file_val) |
| 57 | os.environ[var] = result |
[email protected] | abab8d7 | 2012-11-14 04:59:48 | [diff] [blame] | 58 | else: |
| 59 | os.environ[var] = file_val |
| 60 | |
| 61 | |
| 62 | def apply_chromium_gyp_env(): |
| 63 | if 'SKIP_CHROMIUM_GYP_ENV' not in os.environ: |
| 64 | # Update the environment based on chromium.gyp_env |
| 65 | path = os.path.join(os.path.dirname(CHROME_SRC), 'chromium.gyp_env') |
| 66 | apply_gyp_environment_from_file(path) |