Use commit_id.py on Windows, and handle missing git.

This allows us to delete the Windows batch file.

Changes the commit_id script to take the working directory so that it
can be called from a different working directory than the angle
repository is in.

Renames the generated commit header to angle_commit.h. This is being
written to the shared generated code directory for the entire build,
and "commit.h" is insufficiently unique.

BUG=angle:669

Change-Id: I35e80411a7e8ba1e02ce3f6a4fc54ed4dbc918f3
Reviewed-on: https://chromium-review.googlesource.com/202048
Reviewed-by: Geoff Lang <geofflang@chromium.org>
Tested-by: Jamie Madill <jmadill@chromium.org>
diff --git a/src/commit_id.py b/src/commit_id.py
index 6339cca..7f711e7 100644
--- a/src/commit_id.py
+++ b/src/commit_id.py
@@ -1,19 +1,35 @@
 import subprocess as sp
 import sys
+import os
 
-def grab_output(*command):
-    return sp.Popen(command, stdout=sp.PIPE).communicate()[0].strip()
+# Usage: commit_id.py check <angle_dir> (checks if git is present)
+# Usage: commit_id.py gen <angle_dir> <file_to_write> (generates commit id)
 
+def grab_output(command, cwd):
+    return sp.Popen(command, stdout=sp.PIPE, shell=True, cwd=cwd).communicate()[0].strip()
+
+operation = sys.argv[1]
+cwd = sys.argv[2]
+
+if operation == 'check':
+    index_path = os.path.join(cwd, '.git', 'index')
+    if os.path.exists(index_path):
+        print("1")
+    else:
+        print("0")
+    sys.exit(0)
+
+output_file = sys.argv[3]
 commit_id_size = 12
 
 try:
-    commit_id = grab_output('git', 'rev-parse', '--short=%d' % commit_id_size, 'HEAD')
-    commit_date = grab_output('git', 'show', '-s', '--format=%ci', 'HEAD')
+    commit_id = grab_output('git rev-parse --short=%d HEAD' % commit_id_size, cwd)
+    commit_date = grab_output('git show -s --format=%ci HEAD', cwd)
 except:
     commit_id = 'invalid-hash'
     commit_date = 'invalid-date'
 
-hfile = open(sys.argv[1], 'w')
+hfile = open(output_file, 'w')
 
 hfile.write('#define ANGLE_COMMIT_HASH "%s"\n'    % commit_id)
 hfile.write('#define ANGLE_COMMIT_HASH_SIZE %d\n' % commit_id_size)