@@ -105,7 +105,7 @@ configureDevKitConfigureParameter() {
105105 addConfigureArg " --with-devkit=" " ${BUILD_CONFIG[ADOPTIUM_DEVKIT_LOCATION]} "
106106 fi
107107 fi
108- }
108+ }
109109
110110# Configure the boot JDK
111111configureBootJDKConfigureParameter () {
@@ -253,6 +253,98 @@ patchFreetypeWindows() {
253253 fi
254254}
255255
256+ # Returns the version numbers in version-numbers.conf as a space-seperated list of integers.
257+ # e.g. 17 0 1 5
258+ # or 8 0 0 432
259+ # Build number will not be included, as that is not stored in this file.
260+ versionNumbersFileParser () {
261+ funcName=" versionNumbersFileParser"
262+ buildSrc=" ${BUILD_CONFIG[WORKSPACE_DIR]} /${BUILD_CONFIG[WORKING_DIR]} /${BUILD_CONFIG[OPENJDK_SOURCE_DIR]} "
263+ jdkVersion=" ${BUILD_CONFIG[OPENJDK_FEATURE_NUMBER]} "
264+
265+ # Find version-numbers.conf (or equivalent) and confirm we can read it.
266+ numbersFile=" ${buildSrc} /common/autoconf/version-numbers"
267+ [ " $jdkVersion " -eq 11 ] && numbersFile=" ${buildSrc} /make/autoconf/version-numbers"
268+ [ " $jdkVersion " -ge 17 ] && numbersFile=" ${buildSrc} /make/conf/version-numbers.conf"
269+ [ ! -r " ${numbersFile} " ] && echo " ERROR: build.sh: ${funcName} : JDK version file not found: ${numbersFile} " >&2 && exit 1
270+
271+ fileVersionString=" "
272+ error=" "
273+ if [ " $jdkVersion " -eq 8 ]; then
274+ # jdk8 uses this format: jdk8u482-b01
275+ fileVersionString=" jdk8u$( grep " JDK_UPDATE_VERSION" " ${numbersFile} " | head -1 | grep -Eo ' [0-9]+' ) " || error=" true"
276+ [[ ! " ${fileVersionString} " =~ ^jdk8u[0-9]+$ || $error ]] && echo " ERROR: build.sh: ${funcName} : version file could not be parsed." >&2 && exit 1
277+ else
278+ # File parsing logic for jdk11+.
279+ patchNo=" $( grep " DEFAULT_VERSION_PATCH" " ${numbersFile} " | head -1 | grep -Eo ' [0-9]+' ) " || error=" true"
280+ updateNo=" $( grep " DEFAULT_VERSION_UPDATE" " ${numbersFile} " | head -1 | grep -Eo ' [0-9]+' ) " || error=" true"
281+ interimNo=" $( grep " DEFAULT_VERSION_INTERIM" " ${numbersFile} " | head -1 | grep -Eo ' [0-9]+' ) " || error=" true"
282+ featureNo=" $( grep " DEFAULT_VERSION_FEATURE" " ${numbersFile} " | head -1 | grep -Eo ' [0-9]+' ) " || error=" true"
283+
284+ [[ ! " ${patchNo} " =~ ^0$ ]] && fileVersionString=" .${patchNo} "
285+ [[ ! " ${updateNo} .${fileVersionString} " =~ ^[0\. ]+$ ]] && fileVersionString=" .${updateNo}${fileVersionString} "
286+ [[ ! " ${interimNo} .${fileVersionString} " =~ ^[0\. ]+$ ]] && fileVersionString=" .${interimNo}${fileVersionString} "
287+ fileVersionString=" jdk-${featureNo}${fileVersionString} "
288+
289+ [[ ! " ${fileVersionString} " =~ ^jdk\- [0-9]+[0-9\. ]* $ || $error ]] && echo " ERROR: build.sh: ${funcName} : version file could not be parsed." >&2 && exit 1
290+ fi
291+
292+ # Returning the formatted jdk version string.
293+ echo " ${fileVersionString} "
294+ }
295+
296+ # This function attempts to compare the jdk version from version-numbers.conf with arg 1.
297+ # We will then return whichever version is bigger/later.
298+ # e.g. 17.0.1+32 > 17.0.0+64
299+ # If any errors or unusual circumstances are detected, we simply return arg1 to avoid destabilising the build.
300+ # Note: For error messages, use 'echo message >&2' to ensure the error isn't intercepted by the subshell.
301+ compareToOpenJDKFileVersion () {
302+ funcName=" compareToOpenJDKFileVersion"
303+ # First, sanity checking on the arg.
304+ if [ $# -eq 0 ]; then
305+ echo " compareToOpenJDKFileVersion_was_called_with_no_args"
306+ exit 1
307+ elif [ $# -gt 1 ]; then
308+ echo " ERROR: build.sh: ${funcName} : Too many arguments (>1) were passed to this function." >&2
309+ echo " $1 "
310+ exit 1
311+ fi
312+
313+ # Check if arg 1 looks like a jdk version string.
314+ # Example: JDK11+: jdk-21.0.10+2
315+ # Example: JDK8 : jdk8u482-b01
316+ if [[ ! " $1 " =~ ^jdk\- [0-9]+[0-9\. ]* (\+ [0-9]+)? $ ]]; then
317+ if [[ ! " $1 " =~ ^jdk8u[0-9]+ (\- b[0-9][0-9]+)? $ ]]; then
318+ echo " ERROR: build.sh: ${funcName} : The JDK version passed to this function did not match the expected format." >&2
319+ echo " $1 "
320+ exit 1
321+ fi
322+ fi
323+
324+ # Retrieve the jdk version from version-numbers.conf (minus the build number).
325+ if ! fileVersionString=" $( versionNumbersFileParser) " ; then
326+ # This is to catch versionNumbersFileParser failures.
327+ echo " ERROR: build.sh: ${funcName} : versionNumbersFileParser has failed." >&2
328+ echo " $1 "
329+ exit 1
330+ fi
331+
332+ if [[ " $1 " =~ ^${fileVersionString} .* $ ]]; then
333+ # The file version matches the function argument.
334+ echo " $1 "
335+ return
336+ fi
337+
338+ # The file version does not match the function argument.
339+ # Returning the file version.
340+ [ " ${BUILD_CONFIG[OPENJDK_FEATURE_NUMBER]} " -eq 8 ] && fileVersionString+=" -b00"
341+ [ " ${BUILD_CONFIG[OPENJDK_FEATURE_NUMBER]} " -gt 8 ] && fileVersionString+=" +0"
342+
343+ echo " WARNING: build.sh: ${funcName} : JDK version in source does not match the supplied version (likely the latest git tag)." >&2
344+ echo " WARNING: The JDK version in source will be used instead." >&2
345+ echo " ${fileVersionString} "
346+ }
347+
256348getOpenJdkVersion () {
257349 local version
258350
@@ -548,22 +640,34 @@ configureAlsaLocation() {
548640 fi
549641}
550642
643+ setBundledFreeType () {
644+ echo " Freetype set from bundled in jdk"
645+ freetypeDir=${BUILD_CONFIG[FREETYPE_DIRECTORY]:- bundled}
646+ }
647+
648+ setFreeTypeFromExternalSrcs () {
649+ echo " Freetype set from local sources"
650+ addConfigureArg " --with-freetype-src=" " ${BUILD_CONFIG[WORKSPACE_DIR]} /libs/freetype"
651+ }
652+
653+ setFreeTypeFromInstalled () {
654+ echo " Freetype set from installed binary"
655+ freetypeDir=${BUILD_CONFIG[FREETYPE_DIRECTORY]:- " ${BUILD_CONFIG[WORKSPACE_DIR]} /${BUILD_CONFIG[WORKING_DIR]} /installedfreetype" }
656+ }
657+
551658configureFreetypeLocation () {
552659 if [[ ! " ${CONFIGURE_ARGS} " =~ " --with-freetype" ]]; then
553660 if [[ " ${BUILD_CONFIG[FREETYPE]} " == " true" ]]; then
554661 local freetypeDir=" ${BUILD_CONFIG[FREETYPE_DIRECTORY]} "
555- if [[ " $OSTYPE " == " cygwin" ]] || [[ " $OSTYPE " == " msys" ]]; then
556- case " ${BUILD_CONFIG[OPENJDK_CORE_VERSION]} " in
557- jdk8* | jdk9* | jdk10* ) addConfigureArg " --with-freetype-src=" " ${BUILD_CONFIG[WORKSPACE_DIR]} /libs/freetype" ;;
558- * ) freetypeDir=${BUILD_CONFIG[FREETYPE_DIRECTORY]:- bundled} ;;
559- esac
662+ if isFreeTypeInSources ; then
663+ setBundledFreeType
560664 else
561- case " ${BUILD_CONFIG[OPENJDK_CORE_VERSION]} " in
562- jdk8* | jdk9* | jdk10* ) freetypeDir=${BUILD_CONFIG[FREETYPE_DIRECTORY]:- " ${BUILD_CONFIG[WORKSPACE_DIR]} /${BUILD_CONFIG[WORKING_DIR]} /installedfreetype" } ;;
563- * ) freetypeDir=${BUILD_CONFIG[FREETYPE_DIRECTORY]:- bundled} ;;
564- esac
665+ if [[ " $OSTYPE " == " cygwin" ]] || [[ " $OSTYPE " == " msys" ]]; then
666+ setFreeTypeFromExternalSrcs
667+ else
668+ setFreeTypeFromInstalled
669+ fi
565670 fi
566-
567671 if [[ -n " $freetypeDir " ]]; then
568672 echo " setting freetype dir to ${freetypeDir} "
569673 addConfigureArg " --with-freetype=" " ${freetypeDir} "
@@ -2074,7 +2178,14 @@ getOpenJDKTag() {
20742178 echo " ${BUILD_CONFIG[BRANCH]} "
20752179 else
20762180 echo " getOpenJDKTag(): Determining tag from checked out repository.." 1>&2
2077- getFirstTagFromOpenJDKGitRepo
2181+ tagString=$( getFirstTagFromOpenJDKGitRepo)
2182+ # Now we check if the version in the code is later than the version we have so far.
2183+ # This prevents an issue where the git repo tags do not match the version string in the source.
2184+ # Without this code, we can create builds where half of the version strings do not match.
2185+ # This results in nonsensical -version output, incorrect folder names, and lots of failures
2186+ # relating to those two factors.
2187+ tagString=$( compareToOpenJDKFileVersion " $tagString " )
2188+ echo " ${tagString} "
20782189 fi
20792190}
20802191
0 commit comments