|
| 1 | +# Generate a toolchain ID. |
| 2 | +# This should identify the product, and where the build came from. |
| 3 | + |
| 4 | +# The ID begins with a product code (e.g. E for Embedded), followed |
| 5 | +# by build identifier. The build identifier will depend on the |
| 6 | +# build environment: for Jenkins builds, the pipeline and build |
| 7 | +# number will be sufficient. |
| 8 | + |
| 9 | +if(NOT DEFINED LLVM_TOOLCHAIN_PROJECT_CODE) |
| 10 | + message(FATAL_ERROR "LLVM_TOOLCHAIN_PROJECT_CODE must be set before including generate_toolchain_id.cmake") |
| 11 | +endif() |
| 12 | + |
| 13 | +# JENKINS_URL, BUILD_URL and BUILD_NUMBER will be set in a Jenkins environment. |
| 14 | +if(DEFINED ENV{JENKINS_URL} AND DEFINED ENV{BUILD_URL} AND DEFINED ENV{BUILD_NUMBER}) |
| 15 | + set(builder_name $ENV{BUILD_URL}) |
| 16 | + set(build_number $ENV{BUILD_NUMBER}) |
| 17 | + # BUILD_URL also contains the build number, which is not needed. |
| 18 | + string(REGEX REPLACE "/${build_number}/$" "/" builder_name ${builder_name}) |
| 19 | +else() |
| 20 | + # Use HOSTNAME if nothing else is available. |
| 21 | + cmake_host_system_information(RESULT builder_name QUERY HOSTNAME) |
| 22 | + set(build_number 0) |
| 23 | +endif() |
| 24 | + |
| 25 | +# Version suffix should be optional. |
| 26 | +if(DEFINED LLVM_TOOLCHAIN_VERSION_SUFFIX) |
| 27 | + set(ID_SUFFIX "-${LLVM_TOOLCHAIN_VERSION_SUFFIX}") |
| 28 | +else() |
| 29 | + set(ID_SUFFIX "") |
| 30 | +endif() |
| 31 | + |
| 32 | +string(SHA256 builder_name_hash ${builder_name}) |
| 33 | +string(SUBSTRING ${builder_name_hash} 0 8 builder_name_hash) |
| 34 | +set(ARM_TOOLCHAIN_ID |
| 35 | + "${LLVM_TOOLCHAIN_PROJECT_CODE}${build_number}${ID_SUFFIX} (${builder_name_hash})" CACHE STRING |
| 36 | + "Toolchain ID to identify product." |
| 37 | +) |
0 commit comments