iannucci@chromium.org | dccbcf1 | 2012-11-14 13:59:48 +0900 | [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 |
iannucci@chromium.org | 48bf1d3 | 2012-11-15 10:51:54 +0900 | [diff] [blame] | 18 | with open(file_path, 'rU') as f: |
iannucci@chromium.org | dccbcf1 | 2012-11-14 13:59:48 +0900 | [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', |
scottmg@chromium.org | f7a39ab | 2013-04-18 06:15:27 +0900 | [diff] [blame] | 27 | 'CC_wrapper', |
iannucci@chromium.org | dccbcf1 | 2012-11-14 13:59:48 +0900 | [diff] [blame] | 28 | 'CHROMIUM_GYP_FILE', |
| 29 | 'CHROMIUM_GYP_SYNTAX_CHECK', |
| 30 | 'CXX', |
scottmg@chromium.org | f7a39ab | 2013-04-18 06:15:27 +0900 | [diff] [blame] | 31 | 'CXX_wrapper', |
iannucci@chromium.org | dccbcf1 | 2012-11-14 13:59:48 +0900 | [diff] [blame] | 32 | 'GYP_DEFINES', |
| 33 | 'GYP_GENERATOR_FLAGS', |
justincohen@google.com | cac44b9 | 2013-05-08 06:05:39 +0900 | [diff] [blame] | 34 | 'GYP_CROSSCOMPILE', |
iannucci@chromium.org | dccbcf1 | 2012-11-14 13:59:48 +0900 | [diff] [blame] | 35 | 'GYP_GENERATOR_OUTPUT', |
| 36 | 'GYP_GENERATORS', |
jam@chromium.org | ec69b0b | 2014-01-14 06:29:34 +0900 | [diff] [blame] | 37 | 'GYP_MSVS_VERSION', |
iannucci@chromium.org | dccbcf1 | 2012-11-14 13:59:48 +0900 | [diff] [blame] | 38 | ) |
| 39 | for var in supported_vars: |
| 40 | file_val = file_data.get(var) |
| 41 | if file_val: |
| 42 | if var in os.environ: |
| 43 | print 'INFO: Environment value for "%s" overrides value in %s.' % ( |
| 44 | var, os.path.abspath(file_path) |
| 45 | ) |
| 46 | else: |
| 47 | os.environ[var] = file_val |
| 48 | |
| 49 | |
| 50 | def apply_chromium_gyp_env(): |
| 51 | if 'SKIP_CHROMIUM_GYP_ENV' not in os.environ: |
| 52 | # Update the environment based on chromium.gyp_env |
| 53 | path = os.path.join(os.path.dirname(CHROME_SRC), 'chromium.gyp_env') |
| 54 | apply_gyp_environment_from_file(path) |