Skip to content

Commit fde07e3

Browse files
judovanakarianna
authored andcommitted
adaptation of JDK-8 to build with in-tree freetype (adoptium#4287)
* Initial minimalistic adaptation of 8 to build with in-tree freetype * Determining free type absed on jdk's 8 tag the if is to long, will refactor * Simplified the condition * The in-tree freetype will appear in 482-b02 * Update sbin/build.sh Co-authored-by: Martijn Verburg <martijnverburg@gmail.com> * No longer building freetype if it exists in sources * Get rid of relative path * Aligned modified block to two spaces * Enforced the freetype switches checks * Update sbin/prepareWorkspace.sh Co-authored-by: Martijn Verburg <martijnverburg@gmail.com> * Update sbin/prepareWorkspace.sh Co-authored-by: Martijn Verburg <martijnverburg@gmail.com> * Update sbin/prepareWorkspace.sh Co-authored-by: Martijn Verburg <martijnverburg@gmail.com> * Small rephrasing ow errors * Renamed main freetype methods to match theirs real meaning setDefaultFreeType->setBundledFreeType setFreeTypeFromSrcs->setFreeTypeFromExternalSrcs --------- Co-authored-by: Martijn Verburg <martijnverburg@gmail.com>
1 parent c5c2e0b commit fde07e3

File tree

2 files changed

+164
-25
lines changed

2 files changed

+164
-25
lines changed

sbin/build.sh

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -552,23 +552,46 @@ configureDebugParameters() {
552552
fi
553553
}
554554

555+
configureAlsaLocation() {
556+
if [[ ! "${CONFIGURE_ARGS}" =~ "--with-alsa" ]]; then
557+
if [[ "${BUILD_CONFIG[ALSA]}" == "true" ]]; then
558+
# Only use the Adoptium downloaded ALSA if not using a DevKit, which already has a sysroot ALSA
559+
if [[ ${BUILD_CONFIG[USER_SUPPLIED_CONFIGURE_ARGS]} != *"--with-devkit="* ]] && [[ ${CONFIGURE_ARGS} != *"--with-devkit="* ]]; then
560+
addConfigureArg "--with-alsa=" "${BUILD_CONFIG[WORKSPACE_DIR]}/${BUILD_CONFIG[WORKING_DIR]}/installedalsa"
561+
fi
562+
fi
563+
fi
564+
}
565+
566+
setBundledFreeType() {
567+
echo "Freetype set from bundled in jdk"
568+
freetypeDir=${BUILD_CONFIG[FREETYPE_DIRECTORY]:-bundled}
569+
}
570+
571+
setFreeTypeFromExternalSrcs() {
572+
echo "Freetype set from local sources"
573+
addConfigureArg "--with-freetype-src=" "${BUILD_CONFIG[WORKSPACE_DIR]}/libs/freetype"
574+
}
575+
576+
setFreeTypeFromInstalled() {
577+
echo "Freetype set from installed binary"
578+
freetypeDir=${BUILD_CONFIG[FREETYPE_DIRECTORY]:-"${BUILD_CONFIG[WORKSPACE_DIR]}/${BUILD_CONFIG[WORKING_DIR]}/installedfreetype"}
579+
}
580+
555581
configureFreetypeLocation() {
556582
if [[ ! "${CONFIGURE_ARGS}" =~ "--with-freetype" ]]; then
557583
if [[ "${BUILD_CONFIG[FREETYPE]}" == "true" ]]; then
558584
local freetypeDir="${BUILD_CONFIG[FREETYPE_DIRECTORY]}"
559-
if [[ "$OSTYPE" == "cygwin" ]] || [[ "$OSTYPE" == "msys" ]]; then
560-
case "${BUILD_CONFIG[OPENJDK_CORE_VERSION]}" in
561-
jdk9* | jdk10*) addConfigureArg "--with-freetype-src=" "${BUILD_CONFIG[WORKSPACE_DIR]}/libs/freetype" ;;
562-
*) freetypeDir=${BUILD_CONFIG[FREETYPE_DIRECTORY]:-bundled} ;;
563-
esac
585+
if isFreeTypeInSources ; then
586+
setBundledFreeType
564587
else
565-
case "${BUILD_CONFIG[OPENJDK_CORE_VERSION]}" in
566-
jdk9* | jdk10*) freetypeDir=${BUILD_CONFIG[FREETYPE_DIRECTORY]:-"${BUILD_CONFIG[WORKSPACE_DIR]}/${BUILD_CONFIG[WORKING_DIR]}/installedfreetype"} ;;
567-
*) freetypeDir=${BUILD_CONFIG[FREETYPE_DIRECTORY]:-bundled} ;;
568-
esac
588+
if [[ "$OSTYPE" == "cygwin" ]] || [[ "$OSTYPE" == "msys" ]]; then
589+
setFreeTypeFromExternalSrcs
590+
else
591+
setFreeTypeFromInstalled
592+
fi
569593
fi
570-
571-
if [[ -n "$freetypeDir" ]]; then
594+
if [[ -n "$freetypeDir" ]]; then
572595
echo "setting freetype dir to ${freetypeDir}"
573596
addConfigureArg "--with-freetype=" "${freetypeDir}"
574597
fi

sbin/prepareWorkspace.sh

Lines changed: 130 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,121 @@ FREETYPE_LIB_CHECKSUM=${FREETYPE_LIB_CHECKSUM:-ec391504e55498adceb30baceebd147a6
4040
FREETYPE_FONT_SHARED_OBJECT_FILENAME="libfreetype.so*"
4141
FREEMARKER_LIB_VERSION=${FREEMARKER_LIB_VERSION:-2.3.31}
4242

43+
# sha256 of https://github.com/adoptium/devkit-binaries/releases/tag/vs2022_redist_14.40.33807_10.0.26100.1742
44+
WINDOWS_REDIST_CHECKSUM="ac6060f5f8a952f59faef20e53d124c2c267264109f3f6fabeb2b7aefb3e3c62"
45+
46+
47+
checkBundledFreetypeJdkConfig() {
48+
if [ "${BUILD_CONFIG[FREETYPE_DIRECTORY]}" = "bundled" ] ; then
49+
if [ "${BUILD_CONFIG[FREETYPE]}" = "false" ] ; then
50+
echo "--freetype-dir 'bundled' is in contradiction with -skip-freetype"
51+
exit 1
52+
fi
53+
echo "--freetype-dir is set to 'bundled' which is unusual, but accepted. It should be default."
54+
elif [ "${BUILD_CONFIG[FREETYPE_DIRECTORY]}" = "system" ] ; then
55+
echo "--freetype-dir is set to 'system' which is unusual, but accepted. Use --skip-freetype instead."
56+
elif [ -n "${BUILD_CONFIG[FREETYPE_DIRECTORY]}" ] ; then
57+
echo "--freetype-dir is not accepted for JDK with bundled freetype."
58+
exit 1
59+
fi
60+
}
61+
62+
checkNoBundledFreetypeJdkConfig() {
63+
if [ "${BUILD_CONFIG[FREETYPE]}" = "false" ] && [ -n "${BUILD_CONFIG[FREETYPE_DIRECTORY]}" ] ; then
64+
echo "--freetype-dir is declared together with --skip-freetype, that is invalid, as JDK would build against system freetype anyway."
65+
exit 1
66+
fi
67+
}
68+
69+
isFreeTypeInSources() {
70+
local libfreetypeid="libfreetype/src"
71+
local location="${BUILD_CONFIG[WORKSPACE_DIR]}/${BUILD_CONFIG[WORKING_DIR]}/${BUILD_CONFIG[OPENJDK_SOURCE_DIR]}"
72+
if [ ! -e "$location" ] ; then
73+
echo "No jdk sources exists to to determine $libfreetypeid presence"
74+
exit 1
75+
fi
76+
local found=0
77+
find "$location" | grep -q "$libfreetypeid" || found=$?
78+
if [ $found -eq 0 ] ; then
79+
echo "$libfreetypeid found in $location"
80+
checkBundledFreetypeJdkConfig
81+
else
82+
echo "$libfreetypeid not found in $location"
83+
checkNoBundledFreetypeJdkConfig
84+
fi
85+
return $found
86+
}
87+
88+
copyFromDir() {
89+
echo "Copying OpenJDK source from ${BUILD_CONFIG[OPENJDK_LOCAL_SOURCE_ARCHIVE_ABSPATH]} to $(pwd)/${BUILD_CONFIG[OPENJDK_SOURCE_DIR]} to be built"
90+
# We really do not want to use .git for dirs, as we expect user have them set up, ignoring them
91+
local files=$(find "${BUILD_CONFIG[OPENJDK_LOCAL_SOURCE_ARCHIVE_ABSPATH]}" -maxdepth 1 -mindepth 1 | grep -v -e "/workspace$" -e "/build$" -e "/.git" -e -"/build/")
92+
# SC2086 (info): Double quote to prevent globbing and word splitting.
93+
# globbing is intentional here
94+
# shellcheck disable=SC2086
95+
cp -rf $files "./${BUILD_CONFIG[OPENJDK_SOURCE_DIR]}/"
96+
}
97+
98+
# this is workarounding --strip-components 1 missing on gnu tar
99+
# it requires absolute tar-filepath as it changes dir and is hardcoded to one
100+
# similar approach can be used also for zip in future
101+
# warning! this method do not merge if (parts of!) destination exists.
102+
unpackGnuAbsPathWithStrip1Component() {
103+
local tmp=$(mktemp -d)
104+
pushd "$tmp" > /dev/null
105+
"$@"
106+
popd > /dev/null
107+
mv "$tmp"/*/* .
108+
mv "$tmp"/*/.* . || echo "no hidden files in tarball"
109+
rmdir "$tmp"/*
110+
rmdir "$tmp"
111+
}
112+
113+
untarGnuAbsPathWithStrip1Component() {
114+
unpackGnuAbsPathWithStrip1Component tar -xf "$@"
115+
}
116+
117+
unzipGnuAbsPathWithStrip1Component() {
118+
unpackGnuAbsPathWithStrip1Component unzip "$@"
119+
}
120+
121+
unpackFromArchive() {
122+
echo "Extracting OpenJDK source tarball ${BUILD_CONFIG[OPENJDK_LOCAL_SOURCE_ARCHIVE_ABSPATH]} to $(pwd)/${BUILD_CONFIG[OPENJDK_SOURCE_DIR]} to build the binary"
123+
# If the tarball contains .git files, they should be ignored later
124+
pushd "./${BUILD_CONFIG[OPENJDK_SOURCE_DIR]}"
125+
if [ "${BUILD_CONFIG[OPENJDK_LOCAL_SOURCE_ARCHIVE_ABSPATH]: -4}" == ".zip" ] ; then
126+
echo "Source zip unpacked as if it contains exactly one directory"
127+
unzipGnuAbsPathWithStrip1Component "${BUILD_CONFIG[OPENJDK_LOCAL_SOURCE_ARCHIVE_ABSPATH]}"
128+
else
129+
local topLevelItems=$(tar --exclude='*/*' -tf "${BUILD_CONFIG[OPENJDK_LOCAL_SOURCE_ARCHIVE_ABSPATH]}" | grep "/$" -c) || local topLevelItems=1
130+
if [ "$topLevelItems" -eq "1" ] ; then
131+
echo "Source tarball contains exactly one directory"
132+
untarGnuAbsPathWithStrip1Component "${BUILD_CONFIG[OPENJDK_LOCAL_SOURCE_ARCHIVE_ABSPATH]}"
133+
else
134+
echo "Source tarball does not contain a top level directory"
135+
tar -xf "${BUILD_CONFIG[OPENJDK_LOCAL_SOURCE_ARCHIVE_ABSPATH]}"
136+
fi
137+
fi
138+
rm -rf "build"
139+
popd
140+
}
141+
142+
copyFromDirOrUnpackFromArchive() {
143+
echo "Cleaning the copy of OpenJDK source repository from $(pwd)/${BUILD_CONFIG[OPENJDK_SOURCE_DIR]} and replacing with a fresh copy in 10 seconds..."
144+
verboseSleep 10
145+
rm -rf "./${BUILD_CONFIG[OPENJDK_SOURCE_DIR]}"
146+
mkdir "./${BUILD_CONFIG[OPENJDK_SOURCE_DIR]}"
147+
# Note that we are not persisting the build directory
148+
if [ -d "${BUILD_CONFIG[OPENJDK_LOCAL_SOURCE_ARCHIVE_ABSPATH]}" ] ; then
149+
copyFromDir
150+
elif [ -f "${BUILD_CONFIG[OPENJDK_LOCAL_SOURCE_ARCHIVE_ABSPATH]}" ] ; then
151+
unpackFromArchive
152+
else
153+
echo "${BUILD_CONFIG[OPENJDK_LOCAL_SOURCE_ARCHIVE_ABSPATH]} is not a directory or a file "
154+
exit 1
155+
fi
156+
}
157+
43158
# Create a new clone or update the existing clone of the OpenJDK source repo
44159
# TODO refactor this for Single Responsibility Principle (SRP)
45160
checkoutAndCloneOpenJDKGitRepo() {
@@ -565,6 +680,8 @@ prepareMozillaCacerts() {
565680

566681
# Download all of the dependencies for OpenJDK (Alsa, FreeType, FreeMarker etc.)
567682
downloadingRequiredDependencies() {
683+
local freeTypeInSources=0
684+
isFreeTypeInSources || freeTypeInSources="$?"
568685
if [[ "${BUILD_CONFIG[CLEAN_LIBS]}" == "true" ]]; then
569686
rm -rf "${BUILD_CONFIG[WORKSPACE_DIR]}/libs/freetype" || true
570687

@@ -592,19 +709,18 @@ downloadingRequiredDependencies() {
592709
fi
593710

594711
if [[ "${BUILD_CONFIG[FREETYPE]}" == "true" ]]; then
595-
case "${BUILD_CONFIG[OPENJDK_CORE_VERSION]}" in
596-
jdk8* | jdk9* | jdk10*)
597-
if [ -z "${BUILD_CONFIG[FREETYPE_DIRECTORY]}" ]; then
598-
echo "Checking and download FreeType Font dependency"
599-
checkingAndDownloadingFreeType
600-
else
601-
echo ""
602-
echo "---> Skipping the process of checking and downloading the FreeType Font dependency, a pre-built version provided at ${BUILD_CONFIG[FREETYPE_DIRECTORY]} <---"
603-
echo ""
604-
fi
605-
;;
606-
*) echo "Using bundled Freetype" ;;
607-
esac
712+
if [ "0${freeTypeInSources}" -ne 0 ] ; then
713+
if [ -z "${BUILD_CONFIG[FREETYPE_DIRECTORY]}" ]; then
714+
echo "Checking and downloading FreeType Font dependency"
715+
checkingAndDownloadingFreeType
716+
else
717+
echo ""
718+
echo "---> Skipping the process of checking and downloading the FreeType Font dependency, a pre-built version is provided at ${BUILD_CONFIG[FREETYPE_DIRECTORY]} <---"
719+
echo ""
720+
fi
721+
else
722+
echo "Using bundled Freetype"
723+
fi
608724
else
609725
echo "Skipping Freetype"
610726
fi
@@ -689,9 +805,9 @@ createSourceTagFile(){
689805
function configureWorkspace() {
690806
if [[ "${BUILD_CONFIG[ASSEMBLE_EXPLODED_IMAGE]}" != "true" ]]; then
691807
createWorkspace
808+
checkoutAndCloneOpenJDKGitRepo
692809
downloadingRequiredDependencies
693810
relocateToTmpIfNeeded
694-
checkoutAndCloneOpenJDKGitRepo
695811
applyPatches
696812
if [ "${BUILD_CONFIG[CUSTOM_CACERTS]}" = "true" ] ; then
697813
prepareMozillaCacerts

0 commit comments

Comments
 (0)