Fix gen_build_version on Windows (#4780)

* Fix gen_build_version on Windows

The paths used in the gen_build_version script are causing some failures
in downstream builds. Switch to using the location of the CHANGES file
rather than the ".." parent directory workaround.

* Update other build files
diff --git a/Android.mk b/Android.mk
index e7616f9..b9fbcc8 100644
--- a/Android.mk
+++ b/Android.mk
@@ -302,7 +302,7 @@
         $(LOCAL_PATH)/utils/update_build_version.py \
         $(LOCAL_PATH)/CHANGES
 		@$(HOST_PYTHON) $(LOCAL_PATH)/utils/update_build_version.py \
-		                $(LOCAL_PATH) $(1)/build-version.inc
+		                $(LOCAL_PATH)/CHANGES $(1)/build-version.inc
 		@echo "[$(TARGET_ARCH_ABI)] Generate       : build-version.inc <= CHANGES"
 $(LOCAL_PATH)/source/software_version.cpp: $(1)/build-version.inc
 endef
diff --git a/BUILD.bazel b/BUILD.bazel
index c86ebbe..914619a 100644
--- a/BUILD.bazel
+++ b/BUILD.bazel
@@ -94,8 +94,8 @@
     name = "gen_build_version",
     srcs = ["CHANGES"],
     outs = ["build-version.inc"],
-    cmd = "SOURCE_DATE_EPOCH=0 $(location update_build_version) $$(dirname $(location CHANGES)) $(location build-version.inc)",
-    cmd_bat = "set SOURCE_DATE_EPOCH=0  && $(location //:update_build_version) \"$(location CHANGES)\\..\" $(location build-version.inc)",
+    cmd = "SOURCE_DATE_EPOCH=0 $(location update_build_version) $(location CHANGES) $(location build-version.inc)",
+    cmd_bat = "set SOURCE_DATE_EPOCH=0  && $(location //:update_build_version) $(location CHANGES) $(location build-version.inc)",
     tools = [":update_build_version"],
 )
 
diff --git a/BUILD.gn b/BUILD.gn
index 0ce6c35..ba05497 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -256,12 +256,12 @@
 action("spvtools_build_version") {
   script = "utils/update_build_version.py"
 
-  src_dir = "."
+  changes_file = "CHANGES"
   inc_file = "${target_gen_dir}/build-version.inc"
 
   outputs = [ inc_file ]
   args = [
-    rebase_path(src_dir, root_build_dir),
+    rebase_path(changes_file, root_build_dir),
     rebase_path(inc_file, root_build_dir),
   ]
 }
diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt
index f0dcadd..ab41173 100644
--- a/source/CMakeLists.txt
+++ b/source/CMakeLists.txt
@@ -197,7 +197,7 @@
 add_custom_command(OUTPUT ${SPIRV_TOOLS_BUILD_VERSION_INC}
    COMMAND ${PYTHON_EXECUTABLE}
            ${SPIRV_TOOLS_BUILD_VERSION_INC_GENERATOR}
-           ${spirv-tools_SOURCE_DIR} ${SPIRV_TOOLS_BUILD_VERSION_INC}
+           ${SPIRV_TOOLS_CHANGES_FILE} ${SPIRV_TOOLS_BUILD_VERSION_INC}
    DEPENDS ${SPIRV_TOOLS_BUILD_VERSION_INC_GENERATOR}
            ${SPIRV_TOOLS_CHANGES_FILE}
    COMMENT "Update build-version.inc in the SPIRV-Tools build directory (if necessary).")
diff --git a/utils/update_build_version.py b/utils/update_build_version.py
index 321de74..2a1ca60 100755
--- a/utils/update_build_version.py
+++ b/utils/update_build_version.py
@@ -17,16 +17,16 @@
 # Updates an output file with version info unless the new content is the same
 # as the existing content.
 #
-# Args: <spirv-tools_dir> <output-file>
+# Args: <changes-file> <output-file>
 #
 # The output file will contain a line of text consisting of two C source syntax
 # string literals separated by a comma:
-#  - The software version deduced from the CHANGES file in the given directory.
+#  - The software version deduced from the given CHANGES file.
 #  - A longer string with the project name, the software version number, and
-#    git commit information for the directory.  The commit information
-#    is the output of "git describe" if that succeeds, or "git rev-parse HEAD"
-#    if that succeeds, or otherwise a message containing the phrase
-#    "unknown hash".
+#    git commit information for the CHANGES file's directory.  The commit
+#    information is the output of "git describe" if that succeeds, or "git
+#    rev-parse HEAD" if that succeeds, or otherwise a message containing the
+#    phrase "unknown hash".
 # The string contents are escaped as necessary.
 
 import datetime
@@ -73,9 +73,8 @@
     return stdout
 
 
-def deduce_software_version(directory):
-    """Returns a software version number parsed from the CHANGES file
-    in the given directory.
+def deduce_software_version(changes_file):
+    """Returns a software version number parsed from the given CHANGES file.
 
     The CHANGES file describes most recent versions first.
     """
@@ -85,7 +84,6 @@
     # unexpected carriage returns on a linefeed-only system such as
     # Linux.
     pattern = re.compile(r'^(v\d+\.\d+(-dev)?) \d\d\d\d-\d\d-\d\d\s*$')
-    changes_file = os.path.join(directory, 'CHANGES')
     with open(changes_file, mode='r') as f:
         for line in f.readlines():
             match = pattern.match(line)
@@ -125,16 +123,17 @@
 
 def main():
     if len(sys.argv) != 3:
-        print('usage: {} <spirv-tools-dir> <output-file>'.format(sys.argv[0]))
+        print('usage: {} <changes-files> <output-file>'.format(sys.argv[0]))
         sys.exit(1)
 
     output_file = sys.argv[2]
     mkdir_p(os.path.dirname(output_file))
 
     software_version = deduce_software_version(sys.argv[1])
+    directory = os.path.dirname(sys.argv[1])
     new_content = '"{}", "SPIRV-Tools {} {}"\n'.format(
         software_version, software_version,
-        describe(sys.argv[1]).replace('"', '\\"'))
+        describe(directory).replace('"', '\\"'))
 
     if os.path.isfile(output_file):
         with open(output_file, 'r') as f: