# Copyright 2014 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""A wrapper for the gyp_main that ensures the appropriate include directories
are brought in.
"""

import os
import sys


if __name__ == '__main__':
  # Get the path of the root 'src' directory.
  self_dir = os.path.abspath(os.path.dirname(__file__))
  src_dir = os.path.abspath(os.path.join(self_dir, '..', '..'))

  # Get the path to src/build. This contains a bunch of gyp
  # 'plugins' that get called by common.gypi and base.gyp.
  build_dir = os.path.join(src_dir, 'build')

  # Get the path to the downloaded version of gyp.
  gyp_dir = os.path.join(src_dir, 'tools', 'gyp')

  # Get the path to the gyp module directoy, and the gyp_main
  # that we'll defer to.
  gyp_pylib = os.path.join(gyp_dir, 'pylib')
  gyp_main = os.path.join(gyp_dir, 'gyp_main.py')

  # Ensure the gyp plugin and module directories are in the module path
  # before passing execution to gyp_main.
  sys.path.append(gyp_pylib)
  sys.path.append(build_dir)
  execfile(gyp_main)

@@ -713,16 +713,1060 @@
 t sys%0A%0A%0A
+def apply_gyp_environment_from_file(file_path):%0A  %22%22%22Reads in a *.gyp_env file and applies the valid keys to os.environ.%22%22%22%0A  if not os.path.exists(file_path):%0A    return%0A  with open(file_path, 'rU') as f:%0A    file_contents = f.read()%0A  try:%0A    file_data = eval(file_contents, %7B'__builtins__': None%7D, None)%0A  except SyntaxError, e:%0A    e.filename = os.path.abspath(file_path)%0A    raise%0A  supported_vars = (%0A      'GYP_DEFINES',%0A      'GYP_GENERATOR_FLAGS',%0A      'GYP_GENERATORS',%0A      'GYP_MSVS_VERSION',%0A  )%0A  for var in supported_vars:%0A    file_val = file_data.get(var)%0A    if file_val:%0A      if var in os.environ:%0A        print 'INFO: Environment value for %22%25s%22 overrides value in %25s.' %25 (%0A            var, os.path.abspath(file_path)%0A        )%0A      else:%0A        os.environ%5Bvar%5D = file_val%0A%0A%0Adef apply_syzygy_gyp_env(syzygy_src_path):%0A  if 'SKIP_SYZYGY_GYP_ENV' not in os.environ:%0A    # Update the environment based on syzygy.gyp_env%0A    path = os.path.join(syzygy_src_path, 'syzygy.gyp_env')%0A    apply_gyp_environment_from_file(path)%0A%0A%0A
 if __nam
@@ -1951,16 +1951,49 @@
 '..'))%0A%0A
+  apply_syzygy_gyp_env(src_dir)%0A%0A
   # Get 

Add support for the syzygy.gyp_env files.