Make check_gn_headers.py run on Windows

BUG=661774

Review-Url: https://codereview.chromium.org/2914323002
Cr-Commit-Position: refs/heads/master@{#478848}
diff --git a/build/check_gn_headers.py b/build/check_gn_headers.py
index 2c3a51a1..9164de1 100755
--- a/build/check_gn_headers.py
+++ b/build/check_gn_headers.py
@@ -52,7 +52,8 @@
   """Parse ninja output and get the header files"""
   all_headers = set()
 
-  prefix = '..' + os.sep + '..' + os.sep
+  # Ninja always uses "/", even on Windows.
+  prefix = '../../'
 
   is_valid = False
   for line in ninja_out:
@@ -82,12 +83,15 @@
   tmp = None
   ans, err = set(), None
   try:
-    tmp = tempfile.mkdtemp()
+    # Argument |dir| is needed to make sure it's on the same drive on Windows.
+    # dir='' means dir='.', but doesn't introduce an unneeded prefix.
+    tmp = tempfile.mkdtemp(dir='')
     shutil.copy2(os.path.join(out_dir, 'args.gn'),
                  os.path.join(tmp, 'args.gn'))
     # Do "gn gen" in a temp dir to prevent dirtying |out_dir|.
+    gn_exe = 'gn.bat' if sys.platform == 'win32' else 'gn'
     subprocess.check_call([
-      os.path.join(DEPOT_TOOLS_DIR, 'gn'), 'gen', tmp, '--ide=json', '-q'])
+      os.path.join(DEPOT_TOOLS_DIR, gn_exe), 'gen', tmp, '--ide=json', '-q'])
     gn_json = json.load(open(os.path.join(tmp, 'project.json')))
     ans = ParseGNProjectJSON(gn_json, out_dir, tmp)
   except Exception as e:
@@ -123,10 +127,12 @@
   """Return all the folders controlled by DEPS file"""
   prefixes, err = set(), None
   try:
+    gclient_exe = 'gclient.bat' if sys.platform == 'win32' else 'gclient'
     gclient_out = subprocess.check_output([
-      os.path.join(DEPOT_TOOLS_DIR, 'gclient'),
-      'recurse', '--no-progress', '-j1',
-      'python', '-c', 'import os;print os.environ["GCLIENT_DEP_PATH"]'])
+        os.path.join(DEPOT_TOOLS_DIR, gclient_exe),
+        'recurse', '--no-progress', '-j1',
+        'python', '-c', 'import os;print os.environ["GCLIENT_DEP_PATH"]'],
+        universal_newlines=True)
     for i in gclient_out.split('\n'):
       if i.startswith('src/'):
         i = i[4:]