blob: 9543ed3f681de6c1edbf0f66f6d7d108f5da52b5 [file] [log] [blame]
# 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):
with open(file_path, 'rU') as f:
file_contents =
file_data = eval(file_contents, {'__builtins__': None}, None)
except SyntaxError as e:
e.filename = os.path.abspath(file_path)
supported_vars = (
for var in supported_vars:
file_val = file_data.get(var)
if file_val:
if var in os.environ:
behavior = 'replaces'
if var == 'GYP_DEFINES':
result = file_val + ' ' + os.environ[var]
behavior = 'merges with, and individual components override,'
result = os.environ[var]
print('INFO: Environment value for "%s" %s value in %s' % (
var, behavior, os.path.abspath(file_path)
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
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')