From 78a0f075ac851e64502bc09098b7ebb4c8748d2e Mon Sep 17 00:00:00 2001 From: Natalie Chouinard <1953083+sudonatalie@users.noreply.github.com> Date: Thu, 7 Apr 2022 06:19:05 -0700 Subject: [PATCH] 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 --- Android.mk | 2 +- BUILD.bazel | 4 ++-- BUILD.gn | 4 ++-- source/CMakeLists.txt | 2 +- utils/update_build_version.py | 23 +++++++++++------------ 5 files changed, 17 insertions(+), 18 deletions(-) diff --git a/Android.mk b/Android.mk index e7616f95..b9fbcc83 100644 --- a/Android.mk +++ b/Android.mk @@ -302,7 +302,7 @@ $(1)/build-version.inc: \ $(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 c86ebbef..914619af 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -94,8 +94,8 @@ genrule( 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 0ce6c350..ba054978 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -256,12 +256,12 @@ action("spvtools_generators_inc") { 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 f0dcaddd..ab411737 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -197,7 +197,7 @@ set(SPIRV_TOOLS_CHANGES_FILE 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 321de74b..2a1ca600 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: +# Args: # # 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 @@ def command_output(cmd, directory): 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 @@ def deduce_software_version(directory): # 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 describe(directory): def main(): if len(sys.argv) != 3: - print('usage: {} '.format(sys.argv[0])) + print('usage: {} '.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: