2012-11-14 08:59:48 +04:00
|
|
|
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
|
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
|
|
# found in the LICENSE file.
|
|
|
|
|
|
|
|
# This file helps gyp_chromium and landmines correctly set up the gyp
|
|
|
|
# environment from chromium.gyp_env on disk
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
|
|
|
SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
CHROME_SRC = os.path.dirname(SCRIPT_DIR)
|
|
|
|
|
|
|
|
|
|
|
|
def apply_gyp_environment_from_file(file_path):
|
|
|
|
"""Reads in a *.gyp_env file and applies the valid keys to os.environ."""
|
|
|
|
if not os.path.exists(file_path):
|
|
|
|
return
|
2012-11-15 05:51:54 +04:00
|
|
|
with open(file_path, 'rU') as f:
|
2012-11-14 08:59:48 +04:00
|
|
|
file_contents = f.read()
|
|
|
|
try:
|
|
|
|
file_data = eval(file_contents, {'__builtins__': None}, None)
|
|
|
|
except SyntaxError, e:
|
|
|
|
e.filename = os.path.abspath(file_path)
|
|
|
|
raise
|
|
|
|
supported_vars = (
|
|
|
|
'CC',
|
2013-04-18 01:15:27 +04:00
|
|
|
'CC_wrapper',
|
2015-04-02 23:42:04 +03:00
|
|
|
'CC.host_wrapper',
|
2012-11-14 08:59:48 +04:00
|
|
|
'CHROMIUM_GYP_FILE',
|
|
|
|
'CHROMIUM_GYP_SYNTAX_CHECK',
|
|
|
|
'CXX',
|
2013-04-18 01:15:27 +04:00
|
|
|
'CXX_wrapper',
|
2015-04-02 23:42:04 +03:00
|
|
|
'CXX.host_wrapper',
|
2012-11-14 08:59:48 +04:00
|
|
|
'GYP_DEFINES',
|
|
|
|
'GYP_GENERATOR_FLAGS',
|
2013-05-08 01:05:39 +04:00
|
|
|
'GYP_CROSSCOMPILE',
|
2012-11-14 08:59:48 +04:00
|
|
|
'GYP_GENERATOR_OUTPUT',
|
|
|
|
'GYP_GENERATORS',
|
2014-11-05 21:57:15 +03:00
|
|
|
'GYP_INCLUDE_FIRST',
|
|
|
|
'GYP_INCLUDE_LAST',
|
2014-01-14 01:29:34 +04:00
|
|
|
'GYP_MSVS_VERSION',
|
2012-11-14 08:59:48 +04:00
|
|
|
)
|
|
|
|
for var in supported_vars:
|
|
|
|
file_val = file_data.get(var)
|
|
|
|
if file_val:
|
|
|
|
if var in os.environ:
|
2015-03-05 10:08:15 +03:00
|
|
|
behavior = 'replaces'
|
|
|
|
if var == 'GYP_DEFINES':
|
2015-03-14 03:14:01 +03:00
|
|
|
result = file_val + ' ' + os.environ[var]
|
|
|
|
behavior = 'merges with, and individual components override,'
|
|
|
|
else:
|
|
|
|
result = os.environ[var]
|
2015-03-05 10:08:15 +03:00
|
|
|
print 'INFO: Environment value for "%s" %s value in %s' % (
|
|
|
|
var, behavior, os.path.abspath(file_path)
|
2012-11-14 08:59:48 +04:00
|
|
|
)
|
2015-03-14 03:14:01 +03:00
|
|
|
string_padding = max(len(var), len(file_path), len('result'))
|
|
|
|
print ' %s: %s' % (var.rjust(string_padding), os.environ[var])
|
|
|
|
print ' %s: %s' % (file_path.rjust(string_padding), file_val)
|
|
|
|
os.environ[var] = result
|
2012-11-14 08:59:48 +04:00
|
|
|
else:
|
|
|
|
os.environ[var] = file_val
|
|
|
|
|
|
|
|
|
|
|
|
def apply_chromium_gyp_env():
|
|
|
|
if 'SKIP_CHROMIUM_GYP_ENV' not in os.environ:
|
|
|
|
# Update the environment based on chromium.gyp_env
|
|
|
|
path = os.path.join(os.path.dirname(CHROME_SRC), 'chromium.gyp_env')
|
|
|
|
apply_gyp_environment_from_file(path)
|