Skip to content

Commit 188ac70

Browse files
committed
[Comgr] Reduce device_libs_id.py invocation command line lenght
On windows, cmd.exe has a ~8k characters command line lenght. When above this limit, some characters are silently removed to fit the appropiate lenght... <3 To work around this limitation, we pass separately the file names and the parent directory, instead of passing the list of headers as a list of full paths.
1 parent 8bbf7e3 commit 188ac70

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

amd/comgr/cmake/DeviceLibs.cmake

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ foreach(AMDGCN_LIB_TARGET ${AMD_DEVICE_LIBS_TARGETS})
5959
add_dependencies(amd_comgr ${AMDGCN_LIB_TARGET}_header)
6060

6161
list(APPEND TARGETS_INCLUDES "#include \"${header}\"")
62-
list(APPEND TARGETS_HEADERS "${INC_DIR}/${header}")
62+
list(APPEND TARGETS_HEADERS_FILENAME "${header}")
63+
list(APPEND TARGETS_HEADERS_REALPATH "${INC_DIR}/${header}")
6364
endforeach()
6465

6566
list(JOIN TARGETS_INCLUDES "\n" TARGETS_INCLUDES)
@@ -113,8 +114,8 @@ find_package(Python3 REQUIRED Interpreter)
113114
set(DEVICE_LIBS_ID_SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/cmake/device-libs-id.py")
114115
set(DEVICE_LIBS_ID_HEADER ${INC_DIR}/libraries_sha.inc)
115116
add_custom_command(OUTPUT ${DEVICE_LIBS_ID_HEADER}
116-
COMMAND ${Python3_EXECUTABLE} ${DEVICE_LIBS_ID_SCRIPT} --varname DEVICE_LIBS_ID --output ${DEVICE_LIBS_ID_HEADER} ${TARGETS_HEADERS}
117-
DEPENDS ${DEVICE_LIBS_ID_SCRIPT} ${TARGETS_HEADERS}
117+
COMMAND ${Python3_EXECUTABLE} ${DEVICE_LIBS_ID_SCRIPT} --varname DEVICE_LIBS_ID --output ${DEVICE_LIBS_ID_HEADER} --parent-directory ${INC_DIR} ${TARGETS_HEADERS_FILENAME}
118+
DEPENDS ${DEVICE_LIBS_ID_SCRIPT} ${TARGETS_HEADERS_REALPATH}
118119
COMMENT "Generating ${INC_DIR}/libraries_sha.inc"
119120
)
120121
set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${INC_DIR}/libraries_sha.inc)

amd/comgr/cmake/device-libs-id.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,23 @@
44

55
from argparse import ArgumentParser
66
from hashlib import sha256
7-
from functools import reduce
7+
from os.path import join as join_path
88

99
if __name__ == "__main__":
1010
parser = ArgumentParser(description='Generate id by computing a hash of the generated headers')
1111
parser.add_argument("headers", nargs='+', help='List of headers to generate id from')
12+
# On Windows, we cannot list the realpath for every individual header since we hit cmd.exe's
13+
# maximum command line lenght. As a workaround, we pass the pwd and the headers separately.
14+
parser.add_argument("--parent-directory", help='Parent directory for the headers', required=True)
1215
parser.add_argument("--varname", help='Name of the variable to generate', required=True)
1316
parser.add_argument("--output", help='Name of the header to generate', required=True)
1417

1518
args = parser.parse_args()
1619
args.headers.sort()
1720

1821
hash = sha256()
19-
for x in args.headers:
20-
hash.update(open(x, 'rb').read())
22+
for header in args.headers:
23+
hash.update(open(join_path(args.parent_directory, header), 'rb').read())
2124
digest_uchar = hash.digest()
2225
digest_elts = ", ".join(map(str, digest_uchar))
2326
print(f"static const unsigned char {args.varname}[] = {{{digest_elts}, 0}};", file=open(args.output, 'w'))

0 commit comments

Comments
 (0)