deps: update v8 to 4.3.61.21
[platform/upstream/nodejs.git] / deps / v8 / build / gyp_environment.py
1 # Copyright 2015 the V8 project 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 """
6 Sets up various automatic gyp environment variables. These are used by
7 gyp_v8 and landmines.py which run at different stages of runhooks. To
8 make sure settings are consistent between them, all setup should happen here.
9 """
10
11 import os
12 import sys
13
14 SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
15 V8_ROOT = os.path.abspath(os.path.join(SCRIPT_DIR, os.pardir))
16
17
18 def apply_gyp_environment(file_path=None):
19   """
20   Reads in a *.gyp_env file and applies the valid keys to os.environ.
21   """
22   if not file_path or not os.path.exists(file_path):
23     return
24   file_contents = open(file_path).read()
25   try:
26     file_data = eval(file_contents, {'__builtins__': None}, None)
27   except SyntaxError, e:
28     e.filename = os.path.abspath(file_path)
29     raise
30   supported_vars = ( 'V8_GYP_FILE',
31                      'V8_GYP_SYNTAX_CHECK',
32                      'GYP_DEFINES',
33                      'GYP_GENERATOR_FLAGS',
34                      'GYP_GENERATOR_OUTPUT', )
35   for var in supported_vars:
36     val = file_data.get(var)
37     if val:
38       if var in os.environ:
39         print 'INFO: Environment value for "%s" overrides value in %s.' % (
40             var, os.path.abspath(file_path)
41         )
42       else:
43         os.environ[var] = val
44
45
46 def set_environment():
47   """Sets defaults for GYP_* variables."""
48
49   if 'SKIP_V8_GYP_ENV' not in os.environ:
50     # Update the environment based on v8.gyp_env
51     gyp_env_path = os.path.join(os.path.dirname(V8_ROOT), 'v8.gyp_env')
52     apply_gyp_environment(gyp_env_path)