blob: c840f2d6dc258639631b9f8debe60f481e280d72 [file] [log] [blame]
iannucci@chromium.orgdccbcf12012-11-14 13:59:48 +09001# 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
8import os
9
10SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
11CHROME_SRC = os.path.dirname(SCRIPT_DIR)
12
13
14def 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.org48bf1d32012-11-15 10:51:54 +090018 with open(file_path, 'rU') as f:
iannucci@chromium.orgdccbcf12012-11-14 13:59:48 +090019 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.orgf7a39ab2013-04-18 06:15:27 +090027 'CC_wrapper',
cwgreene34eadbe2015-04-03 05:42:04 +090028 'CC.host_wrapper',
iannucci@chromium.orgdccbcf12012-11-14 13:59:48 +090029 'CHROMIUM_GYP_FILE',
30 'CHROMIUM_GYP_SYNTAX_CHECK',
31 'CXX',
scottmg@chromium.orgf7a39ab2013-04-18 06:15:27 +090032 'CXX_wrapper',
cwgreene34eadbe2015-04-03 05:42:04 +090033 'CXX.host_wrapper',
iannucci@chromium.orgdccbcf12012-11-14 13:59:48 +090034 'GYP_DEFINES',
35 'GYP_GENERATOR_FLAGS',
justincohen@google.comcac44b92013-05-08 06:05:39 +090036 'GYP_CROSSCOMPILE',
iannucci@chromium.orgdccbcf12012-11-14 13:59:48 +090037 'GYP_GENERATOR_OUTPUT',
38 'GYP_GENERATORS',
justsomeguy6386ebb2014-11-06 03:57:15 +090039 'GYP_INCLUDE_FIRST',
40 'GYP_INCLUDE_LAST',
jam@chromium.orgec69b0b2014-01-14 06:29:34 +090041 'GYP_MSVS_VERSION',
iannucci@chromium.orgdccbcf12012-11-14 13:59:48 +090042 )
43 for var in supported_vars:
44 file_val = file_data.get(var)
45 if file_val:
46 if var in os.environ:
dongseong.hwangb3afbf22015-03-05 16:08:15 +090047 behavior = 'replaces'
48 if var == 'GYP_DEFINES':
scheib6e9add82015-03-14 09:14:01 +090049 result = file_val + ' ' + os.environ[var]
50 behavior = 'merges with, and individual components override,'
51 else:
52 result = os.environ[var]
dongseong.hwangb3afbf22015-03-05 16:08:15 +090053 print 'INFO: Environment value for "%s" %s value in %s' % (
54 var, behavior, os.path.abspath(file_path)
iannucci@chromium.orgdccbcf12012-11-14 13:59:48 +090055 )
scheib6e9add82015-03-14 09:14:01 +090056 string_padding = max(len(var), len(file_path), len('result'))
57 print ' %s: %s' % (var.rjust(string_padding), os.environ[var])
58 print ' %s: %s' % (file_path.rjust(string_padding), file_val)
59 os.environ[var] = result
iannucci@chromium.orgdccbcf12012-11-14 13:59:48 +090060 else:
61 os.environ[var] = file_val
62
63
64def apply_chromium_gyp_env():
65 if 'SKIP_CHROMIUM_GYP_ENV' not in os.environ:
66 # Update the environment based on chromium.gyp_env
67 path = os.path.join(os.path.dirname(CHROME_SRC), 'chromium.gyp_env')
68 apply_gyp_environment_from_file(path)