From 37c60080ddedb339089e7bccaf25e360c7b3ebb8 Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Tue, 25 Feb 2025 18:08:35 +0100 Subject: [PATCH] CMake: Handle installing files with same name during SBOM generation It's possible for a project to install a custom file with the same name into different destination directories, and want to include them in the SBOM. Previously this failed at CMake generation time with an error like: CMake Error: Files to be generated by multiple different commands: qt_sbom/SPDXRef-PackagedFile-foo-bar.cmake This happened due to using a non-unique filename for the generated SBOM building file, as well as the spdx id the file name is based on. Include a short hash based on the installed relative path of the file to avoid spdx id clashes, and thus generated file name clashes. Pick-to: 6.8 Task-number: QTBUG-122899 Change-Id: I4c2ecd4652708504ef299af9b6f53d680d542382 Reviewed-by: Alexey Edelev Reviewed-by: Joerg Bornemann (cherry picked from commit 9245d0a0f0761364e7b5b3d1c5c96cba16522820) Reviewed-by: Qt Cherry-pick Bot --- cmake/QtPublicSbomFileHelpers.cmake | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cmake/QtPublicSbomFileHelpers.cmake b/cmake/QtPublicSbomFileHelpers.cmake index 3d47ac174a6..db9ee95499c 100644 --- a/cmake/QtPublicSbomFileHelpers.cmake +++ b/cmake/QtPublicSbomFileHelpers.cmake @@ -677,7 +677,12 @@ function(_qt_internal_sbom_add_custom_file target installed_file_relative_path) set(file_type "OTHER") endif() + # Append a short hash based on the installed relative path of the file, to avoid spdx id + # clashes for files with the same name installed into different dirs. get_filename_component(file_name "${installed_file_relative_path}" NAME) + string(SHA1 rel_path_hash "${installed_file_relative_path}") + string(SUBSTRING "${rel_path_hash}" 0 4 short_hash) + set(file_name "${file_name}-${short_hash}") _qt_internal_sbom_get_package_infix("${arg_PACKAGE_TYPE}" package_infix)