From df3711942bff12598cf5907af2709578dc232278 Mon Sep 17 00:00:00 2001 From: Andrew Leonard Date: Thu, 5 Oct 2023 12:02:05 +0100 Subject: [PATCH] Obtain FreeType version being used for the build from freetype.h Signed-off-by: Andrew Leonard --- sbin/build.sh | 52 ++++++++++++++++++++++++++++++++++++++-- sbin/prepareWorkspace.sh | 7 ------ 2 files changed, 50 insertions(+), 9 deletions(-) diff --git a/sbin/build.sh b/sbin/build.sh index 4fde12786..8502f0123 100755 --- a/sbin/build.sh +++ b/sbin/build.sh @@ -890,8 +890,8 @@ generateSBoM() { # Add ALSA 3rd party addSBOMMetadataTools "${javaHome}" "${classpath}" "${sbomJson}" "ALSA" "$(cat ${BUILD_CONFIG[WORKSPACE_DIR]}/${BUILD_CONFIG[TARGET_DIR]}/metadata/dependency_version_alsa.txt)" - # Add FreeType 3rd party (windows + macOS) - addSBOMMetadataTools "${javaHome}" "${classpath}" "${sbomJson}" "FreeType" "$(cat ${BUILD_CONFIG[WORKSPACE_DIR]}/${BUILD_CONFIG[TARGET_DIR]}/metadata/dependency_version_freetype.txt)" + # Add FreeType 3rd party + addFreeTypeVersionInfo # Add FreeMarker 3rd party (openj9) addSBOMMetadataTools "${javaHome}" "${classpath}" "${sbomJson}" "FreeMarker" "$(cat ${BUILD_CONFIG[WORKSPACE_DIR]}/${BUILD_CONFIG[TARGET_DIR]}/metadata/dependency_version_freemarker.txt)" @@ -920,6 +920,54 @@ checkingToolSummary() { sed -n '/^Tools summary:$/,$p' "${inputConfigFile}" > "${outputConfigFile}" } +# Determine FreeType version being used in the build from either the system or bundled freetype.h definition +addFreeTypeVersionInfo() { + # Default to "system" the jdk8 only value + local FREETYPE_TO_USE="system" + if [ "${BUILD_CONFIG[OPENJDK_CORE_VERSION]}" != "${JDK8_CORE_VERSION}" ]; then + # Get FreeType used from build spec.gmk, "bundled" or "system" + FREETYPE_TO_USE="$(grep "^FREETYPE_TO_USE[ ]*:=" ${BUILD_CONFIG[WORKSPACE_DIR]}/${BUILD_CONFIG[WORKING_DIR]}/${BUILD_CONFIG[OPENJDK_SOURCE_DIR]}/build/*/spec.gmk | sed "s/^FREETYPE_TO_USE[ ]*:=[ ]*//")" + fi + + local version="Unknown" + local freetypeInclude="" + if [ "${FREETYPE_TO_USE}" == "system" ]; then + local FREETYPE_CFLAGS="$(grep "^FREETYPE_CFLAGS[ ]*:=" ${BUILD_CONFIG[WORKSPACE_DIR]}/${BUILD_CONFIG[WORKING_DIR]}/${BUILD_CONFIG[OPENJDK_SOURCE_DIR]}/build/*/spec.gmk | sed "s/^FREETYPE_CFLAGS[ ]*:=[ ]*//" | sed "s/\-I//")" + echo "FREETYPE_CFLAGS paths=${FREETYPE_CFLAGS}" + + # Search freetype include path for freetype.h + local freetypeIncludeDirs=(${FREETYPE_CFLAGS}) + for i in "${!freetypeIncludeDirs[@]}" + do + local include="${freetypeIncludeDirs[i]}/freetype/freetype.h" + echo "Checking for FreeType include ${include}" + if [[ -f "${include}" ]]; then + echo "Found ${include}" + freetypeInclude="${include}" + fi + done + elif [ "${FREETYPE_TO_USE}" == "bundled" ]; then + # jdk-11+ supports "bundled" + # freetype.h location for jdk-11+ + local include="src/java.desktop/share/native/libfreetype/include/freetype/freetype.h" + echo "Checking for FreeType include ${include}" + if [[ -f "${include}" ]]; then + echo "Found ${include}" + freetypeInclude="${include}" + fi + fi + + # Obtain FreeType version from freetype.h + if [[ "x${freetypeInclude}" != "x" ]]; then + local ver_major="$(grep "FREETYPE_MAJOR" "${freetypeInclude}" | grep "#define" | tr -s " " | cut -d" " -f3)" + local ver_minor="$(grep "FREETYPE_MINOR" "${freetypeInclude}" | grep "#define" | tr -s " " | cut -d" " -f3)" + local ver_patch="$(grep "FREETYPE_PATCH" "${freetypeInclude}" | grep "#define" | tr -s " " | cut -d" " -f3)" + version="${ver_major}.${ver_minor}.${ver_patch}" + fi + + addSBOMMetadataTools "${javaHome}" "${classpath}" "${sbomJson}" "FreeType" "${version}" +} + # Below add versions to sbom | Facilitate reproducible builds addGLIBCforLinux() { diff --git a/sbin/prepareWorkspace.sh b/sbin/prepareWorkspace.sh index f73b1bef6..393328b6e 100644 --- a/sbin/prepareWorkspace.sh +++ b/sbin/prepareWorkspace.sh @@ -450,7 +450,6 @@ checkingAndDownloadingFreeType() { FOUND_FREETYPE=$(find "${BUILD_CONFIG[WORKSPACE_DIR]}/${BUILD_CONFIG[WORKING_DIR]}/installedfreetype/lib/" -name "${FREETYPE_FONT_SHARED_OBJECT_FILENAME}" || true) - FREETYPE_BUILD_INFO="Unknown" if [[ -n "$FOUND_FREETYPE" ]]; then echo "Skipping FreeType download" else @@ -475,11 +474,8 @@ checkingAndDownloadingFreeType() { # Fetch the sha for the commit we just cloned cd freetype || exit FREETYPE_SHA=$(git rev-parse HEAD) || exit - FREETYPE_BUILD_INFO="https://github.com/freetype/freetype/commit/${FREETYPE_SHA}" if [[ "$OSTYPE" == "cygwin" ]] || [[ "$OSTYPE" == "msys" ]]; then - # Record buildinfo version - echo "${FREETYPE_BUILD_INFO}" > "${BUILD_CONFIG[WORKSPACE_DIR]}/${BUILD_CONFIG[TARGET_DIR]}/metadata/dependency_version_freetype.txt" return fi @@ -534,9 +530,6 @@ checkingAndDownloadingFreeType() { fi fi fi - - # Record buildinfo version - echo "${FREETYPE_BUILD_INFO}" > "${BUILD_CONFIG[WORKSPACE_DIR]}/${BUILD_CONFIG[TARGET_DIR]}/metadata/dependency_version_freetype.txt" } # Recording Build image SHA into docker.txt