Fix not supplying environment to ninja step for Windows

Change-Id: Icc0c16c4a5d5e63885ed5419bb417bceb6a2ee04
Reviewed-on: https://gn-review.googlesource.com/1640
Reviewed-by: Petr Hosek <phosek@google.com>
Commit-Queue: Scott Graham <scottmg@chromium.org>
diff --git a/infra/recipes/gn.expected/ci_linux.json b/infra/recipes/gn.expected/ci_linux.json
index d725497..01f95ba 100644
--- a/infra/recipes/gn.expected/ci_linux.json
+++ b/infra/recipes/gn.expected/ci_linux.json
@@ -109,6 +109,13 @@
       "-C",
       "[START_DIR]/gn/out"
     ],
+    "cwd": "[START_DIR]/gn",
+    "env": {
+      "AR": "[START_DIR]/cipd/bin/llvm-ar",
+      "CC": "[START_DIR]/cipd/bin/clang",
+      "CXX": "[START_DIR]/cipd/bin/clang++",
+      "LDFLAGS": "-static-libstdc++ -ldl -lpthread"
+    },
     "name": "debug.build.ninja",
     "~followup_annotations": [
       "@@@STEP_NEST_LEVEL@2@@@"
@@ -118,10 +125,9 @@
     "cmd": [
       "[START_DIR]/gn/out/gn_unittests"
     ],
-    "cwd": "[START_DIR]/gn",
-    "name": "debug.test",
+    "name": "debug.build.test",
     "~followup_annotations": [
-      "@@@STEP_NEST_LEVEL@1@@@"
+      "@@@STEP_NEST_LEVEL@2@@@"
     ]
   },
   {
@@ -159,6 +165,13 @@
       "-C",
       "[START_DIR]/gn/out"
     ],
+    "cwd": "[START_DIR]/gn",
+    "env": {
+      "AR": "[START_DIR]/cipd/bin/llvm-ar",
+      "CC": "[START_DIR]/cipd/bin/clang",
+      "CXX": "[START_DIR]/cipd/bin/clang++",
+      "LDFLAGS": "-static-libstdc++ -ldl -lpthread"
+    },
     "name": "release.build.ninja",
     "~followup_annotations": [
       "@@@STEP_NEST_LEVEL@2@@@"
@@ -168,10 +181,9 @@
     "cmd": [
       "[START_DIR]/gn/out/gn_unittests"
     ],
-    "cwd": "[START_DIR]/gn",
-    "name": "release.test",
+    "name": "release.build.test",
     "~followup_annotations": [
-      "@@@STEP_NEST_LEVEL@1@@@"
+      "@@@STEP_NEST_LEVEL@2@@@"
     ]
   },
   {
diff --git a/infra/recipes/gn.expected/ci_mac.json b/infra/recipes/gn.expected/ci_mac.json
index 8f39168..89db3b6 100644
--- a/infra/recipes/gn.expected/ci_mac.json
+++ b/infra/recipes/gn.expected/ci_mac.json
@@ -99,6 +99,7 @@
       "-C",
       "[START_DIR]/gn/out"
     ],
+    "cwd": "[START_DIR]/gn",
     "name": "debug.build.ninja",
     "~followup_annotations": [
       "@@@STEP_NEST_LEVEL@2@@@"
@@ -108,10 +109,9 @@
     "cmd": [
       "[START_DIR]/gn/out/gn_unittests"
     ],
-    "cwd": "[START_DIR]/gn",
-    "name": "debug.test",
+    "name": "debug.build.test",
     "~followup_annotations": [
-      "@@@STEP_NEST_LEVEL@1@@@"
+      "@@@STEP_NEST_LEVEL@2@@@"
     ]
   },
   {
@@ -143,6 +143,7 @@
       "-C",
       "[START_DIR]/gn/out"
     ],
+    "cwd": "[START_DIR]/gn",
     "name": "release.build.ninja",
     "~followup_annotations": [
       "@@@STEP_NEST_LEVEL@2@@@"
@@ -152,10 +153,9 @@
     "cmd": [
       "[START_DIR]/gn/out/gn_unittests"
     ],
-    "cwd": "[START_DIR]/gn",
-    "name": "release.test",
+    "name": "release.build.test",
     "~followup_annotations": [
-      "@@@STEP_NEST_LEVEL@1@@@"
+      "@@@STEP_NEST_LEVEL@2@@@"
     ]
   },
   {
diff --git a/infra/recipes/gn.expected/ci_win.json b/infra/recipes/gn.expected/ci_win.json
index ddcdc94..cb832c3 100644
--- a/infra/recipes/gn.expected/ci_win.json
+++ b/infra/recipes/gn.expected/ci_win.json
@@ -49,7 +49,7 @@
       "-root",
       "[START_DIR]\\cipd",
       "-ensure-file",
-      "chrome_internal/third_party/sdk/windows latest\ninfra/ninja/${platform} version:1.8.2",
+      "chrome_internal/third_party/sdk/windows uploaded:2018-06-13\ninfra/ninja/${platform} version:1.8.2",
       "-json-output",
       "/path/to/tmp/json"
     ],
@@ -60,7 +60,7 @@
       "@@@STEP_LOG_LINE@json.output@  \"result\": {@@@",
       "@@@STEP_LOG_LINE@json.output@    \"\": [@@@",
       "@@@STEP_LOG_LINE@json.output@      {@@@",
-      "@@@STEP_LOG_LINE@json.output@        \"instance_id\": \"resolved-instance_id-of-latest----------\", @@@",
+      "@@@STEP_LOG_LINE@json.output@        \"instance_id\": \"resolved-instance_id-of-uploaded:2018-06\", @@@",
       "@@@STEP_LOG_LINE@json.output@        \"package\": \"chrome_internal/third_party/sdk/windows\"@@@",
       "@@@STEP_LOG_LINE@json.output@      }, @@@",
       "@@@STEP_LOG_LINE@json.output@      {@@@",
@@ -183,6 +183,17 @@
       "-C",
       "[START_DIR]\\gn\\out"
     ],
+    "cwd": "[START_DIR]\\gn",
+    "env": {
+      "INCLUDE": "[START_DIR]\\cipd\\win_sdk\\Include\\10.0.17134.0\\um;[START_DIR]\\cipd\\win_sdk\\Include\\10.0.17134.0\\shared;[START_DIR]\\cipd\\win_sdk\\Include\\10.0.17134.0\\winrt",
+      "VSINSTALLDIR": "[START_DIR]\\cipd"
+    },
+    "env_prefixes": {
+      "PATH": [
+        "[START_DIR]\\cipd\\win_sdk\\bin\\10.0.17134.0\\x64",
+        "[START_DIR]\\cipd\\VC\\Tools\\MSVC\\14.14.26428\\bin\\HostX64\\x64"
+      ]
+    },
     "name": "debug.build.ninja",
     "~followup_annotations": [
       "@@@STEP_NEST_LEVEL@2@@@"
@@ -192,10 +203,9 @@
     "cmd": [
       "[START_DIR]\\gn\\out\\gn_unittests"
     ],
-    "cwd": "[START_DIR]\\gn",
-    "name": "debug.test",
+    "name": "debug.build.test",
     "~followup_annotations": [
-      "@@@STEP_NEST_LEVEL@1@@@"
+      "@@@STEP_NEST_LEVEL@2@@@"
     ]
   },
   {
@@ -237,6 +247,17 @@
       "-C",
       "[START_DIR]\\gn\\out"
     ],
+    "cwd": "[START_DIR]\\gn",
+    "env": {
+      "INCLUDE": "[START_DIR]\\cipd\\win_sdk\\Include\\10.0.17134.0\\um;[START_DIR]\\cipd\\win_sdk\\Include\\10.0.17134.0\\shared;[START_DIR]\\cipd\\win_sdk\\Include\\10.0.17134.0\\winrt",
+      "VSINSTALLDIR": "[START_DIR]\\cipd"
+    },
+    "env_prefixes": {
+      "PATH": [
+        "[START_DIR]\\cipd\\win_sdk\\bin\\10.0.17134.0\\x64",
+        "[START_DIR]\\cipd\\VC\\Tools\\MSVC\\14.14.26428\\bin\\HostX64\\x64"
+      ]
+    },
     "name": "release.build.ninja",
     "~followup_annotations": [
       "@@@STEP_NEST_LEVEL@2@@@"
@@ -246,10 +267,9 @@
     "cmd": [
       "[START_DIR]\\gn\\out\\gn_unittests"
     ],
-    "cwd": "[START_DIR]\\gn",
-    "name": "release.test",
+    "name": "release.build.test",
     "~followup_annotations": [
-      "@@@STEP_NEST_LEVEL@1@@@"
+      "@@@STEP_NEST_LEVEL@2@@@"
     ]
   },
   {
diff --git a/infra/recipes/gn.expected/cq_linux.json b/infra/recipes/gn.expected/cq_linux.json
index b810ef3..33d30ba 100644
--- a/infra/recipes/gn.expected/cq_linux.json
+++ b/infra/recipes/gn.expected/cq_linux.json
@@ -136,6 +136,13 @@
       "-C",
       "[START_DIR]/gn/out"
     ],
+    "cwd": "[START_DIR]/gn",
+    "env": {
+      "AR": "[START_DIR]/cipd/bin/llvm-ar",
+      "CC": "[START_DIR]/cipd/bin/clang",
+      "CXX": "[START_DIR]/cipd/bin/clang++",
+      "LDFLAGS": "-static-libstdc++ -ldl -lpthread"
+    },
     "name": "debug.build.ninja",
     "~followup_annotations": [
       "@@@STEP_NEST_LEVEL@2@@@"
@@ -145,10 +152,9 @@
     "cmd": [
       "[START_DIR]/gn/out/gn_unittests"
     ],
-    "cwd": "[START_DIR]/gn",
-    "name": "debug.test",
+    "name": "debug.build.test",
     "~followup_annotations": [
-      "@@@STEP_NEST_LEVEL@1@@@"
+      "@@@STEP_NEST_LEVEL@2@@@"
     ]
   },
   {
@@ -186,6 +192,13 @@
       "-C",
       "[START_DIR]/gn/out"
     ],
+    "cwd": "[START_DIR]/gn",
+    "env": {
+      "AR": "[START_DIR]/cipd/bin/llvm-ar",
+      "CC": "[START_DIR]/cipd/bin/clang",
+      "CXX": "[START_DIR]/cipd/bin/clang++",
+      "LDFLAGS": "-static-libstdc++ -ldl -lpthread"
+    },
     "name": "release.build.ninja",
     "~followup_annotations": [
       "@@@STEP_NEST_LEVEL@2@@@"
@@ -195,10 +208,9 @@
     "cmd": [
       "[START_DIR]/gn/out/gn_unittests"
     ],
-    "cwd": "[START_DIR]/gn",
-    "name": "release.test",
+    "name": "release.build.test",
     "~followup_annotations": [
-      "@@@STEP_NEST_LEVEL@1@@@"
+      "@@@STEP_NEST_LEVEL@2@@@"
     ]
   },
   {
diff --git a/infra/recipes/gn.expected/cq_mac.json b/infra/recipes/gn.expected/cq_mac.json
index 8630599..600c99a 100644
--- a/infra/recipes/gn.expected/cq_mac.json
+++ b/infra/recipes/gn.expected/cq_mac.json
@@ -126,6 +126,7 @@
       "-C",
       "[START_DIR]/gn/out"
     ],
+    "cwd": "[START_DIR]/gn",
     "name": "debug.build.ninja",
     "~followup_annotations": [
       "@@@STEP_NEST_LEVEL@2@@@"
@@ -135,10 +136,9 @@
     "cmd": [
       "[START_DIR]/gn/out/gn_unittests"
     ],
-    "cwd": "[START_DIR]/gn",
-    "name": "debug.test",
+    "name": "debug.build.test",
     "~followup_annotations": [
-      "@@@STEP_NEST_LEVEL@1@@@"
+      "@@@STEP_NEST_LEVEL@2@@@"
     ]
   },
   {
@@ -170,6 +170,7 @@
       "-C",
       "[START_DIR]/gn/out"
     ],
+    "cwd": "[START_DIR]/gn",
     "name": "release.build.ninja",
     "~followup_annotations": [
       "@@@STEP_NEST_LEVEL@2@@@"
@@ -179,10 +180,9 @@
     "cmd": [
       "[START_DIR]/gn/out/gn_unittests"
     ],
-    "cwd": "[START_DIR]/gn",
-    "name": "release.test",
+    "name": "release.build.test",
     "~followup_annotations": [
-      "@@@STEP_NEST_LEVEL@1@@@"
+      "@@@STEP_NEST_LEVEL@2@@@"
     ]
   },
   {
diff --git a/infra/recipes/gn.expected/cq_win.json b/infra/recipes/gn.expected/cq_win.json
index b3f46ba..3329ec0 100644
--- a/infra/recipes/gn.expected/cq_win.json
+++ b/infra/recipes/gn.expected/cq_win.json
@@ -76,7 +76,7 @@
       "-root",
       "[START_DIR]\\cipd",
       "-ensure-file",
-      "chrome_internal/third_party/sdk/windows latest\ninfra/ninja/${platform} version:1.8.2",
+      "chrome_internal/third_party/sdk/windows uploaded:2018-06-13\ninfra/ninja/${platform} version:1.8.2",
       "-json-output",
       "/path/to/tmp/json"
     ],
@@ -87,7 +87,7 @@
       "@@@STEP_LOG_LINE@json.output@  \"result\": {@@@",
       "@@@STEP_LOG_LINE@json.output@    \"\": [@@@",
       "@@@STEP_LOG_LINE@json.output@      {@@@",
-      "@@@STEP_LOG_LINE@json.output@        \"instance_id\": \"resolved-instance_id-of-latest----------\", @@@",
+      "@@@STEP_LOG_LINE@json.output@        \"instance_id\": \"resolved-instance_id-of-uploaded:2018-06\", @@@",
       "@@@STEP_LOG_LINE@json.output@        \"package\": \"chrome_internal/third_party/sdk/windows\"@@@",
       "@@@STEP_LOG_LINE@json.output@      }, @@@",
       "@@@STEP_LOG_LINE@json.output@      {@@@",
@@ -210,6 +210,17 @@
       "-C",
       "[START_DIR]\\gn\\out"
     ],
+    "cwd": "[START_DIR]\\gn",
+    "env": {
+      "INCLUDE": "[START_DIR]\\cipd\\win_sdk\\Include\\10.0.17134.0\\um;[START_DIR]\\cipd\\win_sdk\\Include\\10.0.17134.0\\shared;[START_DIR]\\cipd\\win_sdk\\Include\\10.0.17134.0\\winrt",
+      "VSINSTALLDIR": "[START_DIR]\\cipd"
+    },
+    "env_prefixes": {
+      "PATH": [
+        "[START_DIR]\\cipd\\win_sdk\\bin\\10.0.17134.0\\x64",
+        "[START_DIR]\\cipd\\VC\\Tools\\MSVC\\14.14.26428\\bin\\HostX64\\x64"
+      ]
+    },
     "name": "debug.build.ninja",
     "~followup_annotations": [
       "@@@STEP_NEST_LEVEL@2@@@"
@@ -219,10 +230,9 @@
     "cmd": [
       "[START_DIR]\\gn\\out\\gn_unittests"
     ],
-    "cwd": "[START_DIR]\\gn",
-    "name": "debug.test",
+    "name": "debug.build.test",
     "~followup_annotations": [
-      "@@@STEP_NEST_LEVEL@1@@@"
+      "@@@STEP_NEST_LEVEL@2@@@"
     ]
   },
   {
@@ -264,6 +274,17 @@
       "-C",
       "[START_DIR]\\gn\\out"
     ],
+    "cwd": "[START_DIR]\\gn",
+    "env": {
+      "INCLUDE": "[START_DIR]\\cipd\\win_sdk\\Include\\10.0.17134.0\\um;[START_DIR]\\cipd\\win_sdk\\Include\\10.0.17134.0\\shared;[START_DIR]\\cipd\\win_sdk\\Include\\10.0.17134.0\\winrt",
+      "VSINSTALLDIR": "[START_DIR]\\cipd"
+    },
+    "env_prefixes": {
+      "PATH": [
+        "[START_DIR]\\cipd\\win_sdk\\bin\\10.0.17134.0\\x64",
+        "[START_DIR]\\cipd\\VC\\Tools\\MSVC\\14.14.26428\\bin\\HostX64\\x64"
+      ]
+    },
     "name": "release.build.ninja",
     "~followup_annotations": [
       "@@@STEP_NEST_LEVEL@2@@@"
@@ -273,10 +294,9 @@
     "cmd": [
       "[START_DIR]\\gn\\out\\gn_unittests"
     ],
-    "cwd": "[START_DIR]\\gn",
-    "name": "release.test",
+    "name": "release.build.test",
     "~followup_annotations": [
-      "@@@STEP_NEST_LEVEL@1@@@"
+      "@@@STEP_NEST_LEVEL@2@@@"
     ]
   },
   {
diff --git a/infra/recipes/gn.py b/infra/recipes/gn.py
index 212cd96..f234e27 100644
--- a/infra/recipes/gn.py
+++ b/infra/recipes/gn.py
@@ -124,9 +124,9 @@
                      src_dir.join('build', 'gen.py'),
                      args=config['args'])
 
-        api.step('ninja', [cipd_dir.join('ninja'), '-C', src_dir.join('out')])
+          # Windows requires the environment modifications when building too.
+          api.step('ninja', [cipd_dir.join('ninja'), '-C', src_dir.join('out')])
 
-      with api.context(cwd=src_dir):
         api.step('test', [src_dir.join('out', 'gn_unittests')])