gclient: predefine host_os

Bug: 570091
Change-Id: Ib2606fcc7251221ae10a0ef18b6585841d18eef4
Reviewed-on: https://chromium-review.googlesource.com/641750
Commit-Queue: Paweł Hajdan Jr. <phajdan.jr@chromium.org>
Reviewed-by: Michael Moss <mmoss@chromium.org>
Reviewed-by: Dirk Pranke <dpranke@chromium.org>
diff --git a/gclient.py b/gclient.py
index 89fbc27..a45d0af 100755
--- a/gclient.py
+++ b/gclient.py
@@ -1150,11 +1150,28 @@
   def get_vars(self):
     """Returns a dictionary of effective variable values
     (DEPS file contents with applied custom_vars overrides)."""
-    result = dict(self._vars)
+    # Provide some built-in variables.
+    result = {
+        'host_os': repr(_detect_host_os()),
+    }
+    # Variables defined in DEPS file override built-in ones.
+    result.update(self._vars)
     result.update(self.custom_vars or {})
     return result
 
 
+_PLATFORM_MAPPING = {
+  'cygwin': 'win',
+  'darwin': 'mac',
+  'linux2': 'linux',
+  'win32': 'win',
+}
+
+
+def _detect_host_os():
+  return _PLATFORM_MAPPING[sys.platform]
+
+
 class GClient(Dependency):
   """Object that represent a gclient checkout. A tree of Dependency(), one per
   solution or DEPS entry."""
@@ -1841,7 +1858,8 @@
 
     self._allowed_hosts.update(dep.allowed_hosts)
 
-    for key, value in dep.get_vars().iteritems():
+    # Only include vars listed in the DEPS files, not possible local overrides.
+    for key, value in dep._vars.iteritems():
       # Make sure there are no conflicting variables. It is fine however
       # to use same variable name, as long as the value is consistent.
       assert key not in self._vars or self._vars[key][1] == value