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
This commit is contained in:
Natalie Chouinard 2022-04-07 06:19:05 -07:00 коммит произвёл GitHub
Родитель eed5c76a57
Коммит 78a0f075ac
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
5 изменённых файлов: 17 добавлений и 18 удалений

Просмотреть файл

@ -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

Просмотреть файл

@ -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"],
)

Просмотреть файл

@ -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),
]
}

Просмотреть файл

@ -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).")

Просмотреть файл

@ -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 @@ 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: {} <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: