Skip to content

Commit

Permalink
Added feature to download boot jdk on demand
Browse files Browse the repository at this point in the history
currenlty only dne for linux, shoudl be easy to extend for windows, not
sure what whith other platfroms.

Is done via magic parameter of `download` for -J: -J download
  • Loading branch information
judovana committed Mar 23, 2024
1 parent 119bc1e commit 95385f4
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 65 deletions.
84 changes: 84 additions & 0 deletions build-farm/platform-specific-configurations/downloaders.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/bin/bash
# shellcheck disable=SC1091

################################################################################
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
################################################################################

DOWLOADERS_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

# this one should be swithing per (supported) oses in future
function downloadBootJDK() {
downloadLinuxBootJDK "$@"
}

function downloadLinuxBootJDK() {
ARCH=$1
VER=$2
export downloadArch
case "$ARCH" in
"riscv64") downloadArch="$NATIVE_API_ARCH";;
*) downloadArch="$ARCH";;
esac
releaseType="ga"
vendor="eclipse"
apiUrlTemplate="https://api.adoptium.net/v3/binary/latest/\${VER}/\${releaseType}/linux/\${downloadArch}/jdk/hotspot/normal/\${vendor}"
apiURL=$(eval echo "${apiUrlTemplate}")
echo "Downloading GA release of boot JDK version ${VER} from ${apiURL}"
# make-adopt-build-farm.sh has 'set -e'. We need to disable that for
# the fallback mechanism, as downloading of the GA binary might fail.
set +e
curl -L -o bootjdk.tar.gz "${apiURL}"
apiSigURL=$(curl -v "${apiURL}" 2>&1 | tr -d \\r | awk '/^< Location:/{print $3 ".sig"}')
if ! grep "No releases match the request" bootjdk.tar.gz; then
curl -L -o bootjdk.tar.gz.sig "${apiSigURL}"
gpg --keyserver keyserver.ubuntu.com --recv-keys 3B04D753C9050D9A5D343F39843C48A565F8F04B
echo -e "5\ny\n" | gpg --batch --command-fd 0 --expert --edit-key 3B04D753C9050D9A5D343F39843C48A565F8F04B trust;
gpg --verify bootjdk.tar.gz.sig bootjdk.tar.gz || exit 1
mkdir "$bootDir"
tar xpzf bootjdk.tar.gz --strip-components=1 -C "$bootDir"
set -e
else
# We must be a JDK HEAD build for which no boot JDK exists other than
# nightlies?
echo "Downloading GA release of boot JDK version ${VER} failed."
# shellcheck disable=SC2034
releaseType="ea"
# shellcheck disable=SC2034
vendor="adoptium"
apiURL=$(eval echo ${apiUrlTemplate})
echo "Attempting to download EA release of boot JDK version ${VER} from ${apiURL}"
set +e
curl -L -o bootjdk.tar.gz "${apiURL}"
if ! grep "No releases match the request" bootjdk.tar.gz; then
apiSigURL=$(curl -v "${apiURL}" 2>&1 | tr -d \\r | awk '/^< Location:/{print $3 ".sig"}')
curl -L -o bootjdk.tar.gz.sig "${apiSigURL}"
gpg --keyserver keyserver.ubuntu.com --recv-keys 3B04D753C9050D9A5D343F39843C48A565F8F04B
echo -e "5\ny\n" | gpg --batch --command-fd 0 --expert --edit-key 3B04D753C9050D9A5D343F39843C48A565F8F04B trust;
gpg --verify bootjdk.tar.gz.sig bootjdk.tar.gz || exit 1
mkdir "$bootDir"
tar xpzf bootjdk.tar.gz --strip-components=1 -C "$bootDir"
else
# If no binaries are available then try from adoptopenjdk
echo "Downloading Temurin release of boot JDK version ${VER} failed."
# shellcheck disable=SC2034
releaseType="ga"
# shellcheck disable=SC2034
vendor="adoptium"
apiURL=$(eval echo ${apiUrlTemplate})
echo "Attempting to download GA release of boot JDK version ${VER} from ${apiURL}"
curl -L "${apiURL}" | tar xpzf - --strip-components=1 -C "$bootDir"
fi
fi
}

64 changes: 2 additions & 62 deletions build-farm/platform-specific-configurations/linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# shellcheck source=sbin/common/constants.sh
source "$SCRIPT_DIR/../../sbin/common/constants.sh"
source "$SCRIPT_DIR/downloaders.sh"

if [[ "$JAVA_FEATURE_VERSION" -ge 21 ]]; then
# jdk-21+ uses "bundled" FreeType
Expand Down Expand Up @@ -145,67 +146,6 @@ function setCrossCompilerEnvironment()
fi
}

function downloadBootJDK()
{
ARCH=$1
VER=$2
export downloadArch
case "$ARCH" in
"riscv64") downloadArch="$NATIVE_API_ARCH";;
*) downloadArch="$ARCH";;
esac
releaseType="ga"
vendor="eclipse"
apiUrlTemplate="https://api.adoptium.net/v3/binary/latest/\${VER}/\${releaseType}/linux/\${downloadArch}/jdk/hotspot/normal/\${vendor}"
apiURL=$(eval echo "${apiUrlTemplate}")
echo "Downloading GA release of boot JDK version ${VER} from ${apiURL}"
# make-adopt-build-farm.sh has 'set -e'. We need to disable that for
# the fallback mechanism, as downloading of the GA binary might fail.
set +e
curl -L -o bootjdk.tar.gz "${apiURL}"
apiSigURL=$(curl -v "${apiURL}" 2>&1 | tr -d \\r | awk '/^< Location:/{print $3 ".sig"}')
if ! grep "No releases match the request" bootjdk.tar.gz; then
curl -L -o bootjdk.tar.gz.sig "${apiSigURL}"
gpg --keyserver keyserver.ubuntu.com --recv-keys 3B04D753C9050D9A5D343F39843C48A565F8F04B
echo -e "5\ny\n" | gpg --batch --command-fd 0 --expert --edit-key 3B04D753C9050D9A5D343F39843C48A565F8F04B trust;
gpg --verify bootjdk.tar.gz.sig bootjdk.tar.gz || exit 1
mkdir "$bootDir"
tar xpzf bootjdk.tar.gz --strip-components=1 -C "$bootDir"
set -e
else
# We must be a JDK HEAD build for which no boot JDK exists other than
# nightlies?
echo "Downloading GA release of boot JDK version ${VER} failed."
# shellcheck disable=SC2034
releaseType="ea"
# shellcheck disable=SC2034
vendor="adoptium"
apiURL=$(eval echo ${apiUrlTemplate})
echo "Attempting to download EA release of boot JDK version ${VER} from ${apiURL}"
set +e
curl -L -o bootjdk.tar.gz "${apiURL}"
if ! grep "No releases match the request" bootjdk.tar.gz; then
apiSigURL=$(curl -v "${apiURL}" 2>&1 | tr -d \\r | awk '/^< Location:/{print $3 ".sig"}')
curl -L -o bootjdk.tar.gz.sig "${apiSigURL}"
gpg --keyserver keyserver.ubuntu.com --recv-keys 3B04D753C9050D9A5D343F39843C48A565F8F04B
echo -e "5\ny\n" | gpg --batch --command-fd 0 --expert --edit-key 3B04D753C9050D9A5D343F39843C48A565F8F04B trust;
gpg --verify bootjdk.tar.gz.sig bootjdk.tar.gz || exit 1
mkdir "$bootDir"
tar xpzf bootjdk.tar.gz --strip-components=1 -C "$bootDir"
else
# If no binaries are available then try from adoptopenjdk
echo "Downloading Temurin release of boot JDK version ${VER} failed."
# shellcheck disable=SC2034
releaseType="ga"
# shellcheck disable=SC2034
vendor="adoptium"
apiURL=$(eval echo ${apiUrlTemplate})
echo "Attempting to download GA release of boot JDK version ${VER} from ${apiURL}"
curl -L "${apiURL}" | tar xpzf - --strip-components=1 -C "$bootDir"
fi
fi
}

if [ "${ARCHITECTURE}" == "x64" ]
then
export PATH=/opt/rh/devtoolset-2/root/usr/bin:$PATH
Expand Down Expand Up @@ -317,7 +257,7 @@ if [ ! -d "$(eval echo "\$$BOOT_JDK_VARIABLE")" ]; then
# shellcheck disable=SC2140
export "${BOOT_JDK_VARIABLE}"="/usr/lib/jvm/jdk-${JDK_BOOT_VERSION}"
elif [ "$JDK_BOOT_VERSION" -ge 8 ]; then # Adoptium has no build pre-8
downloadBootJDK "${ARCHITECTURE}" "${JDK_BOOT_VERSION}"
downloadLinuxBootJDK "${ARCHITECTURE}" "${JDK_BOOT_VERSION}"
fi
fi
fi
Expand Down
4 changes: 3 additions & 1 deletion makejdk-any-platform.1
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ ignore the existing docker container if you have one already.
specify the JDK boot dir.
For reference, OpenJDK needs the previous version of a JDK in order to build
itself. You should select the path to a JDK install that is N-1 versions below
the one you are trying to build.
the one you are trying to build. On some platforms, you can use magic keyword
of `download`, and boot jdk will be downloaded for you in best attempt. It will
be reused as long as you keep workspace or clean libs.
.TP
.BR \-k ", " \-\-keep
if using docker, keep the container after the build.
Expand Down
22 changes: 20 additions & 2 deletions sbin/prepareWorkspace.sh
Original file line number Diff line number Diff line change
Expand Up @@ -577,15 +577,33 @@ prepareMozillaCacerts() {
fi
}

# Download all of the dependencies for OpenJDK (Alsa, FreeType etc.)
downloadBootJdkIfNeeded () {
if [[ "${BUILD_CONFIG[JDK_BOOT_DIR]}" == "download" ]]; then
# the bootDir is used by refactored downloaders.sh methods; it would benice to change in future
bootDir="${BUILD_CONFIG[WORKSPACE_DIR]}/downloaded-boot-jdk-${BUILD_CONFIG[OPENJDK_FEATURE_NUMBER]}"
if [ -e "$bootDir" ] ; then
echo "Reusing $bootDir"
else
source "$SCRIPT_DIR/../build-farm/platform-specific-configurations/downloaders.sh"
echo "Downloading to $bootDir"
downloadBootJDK $(uname -m) ${BUILD_CONFIG[OPENJDK_FEATURE_NUMBER]}
fi
BUILD_CONFIG[JDK_BOOT_DIR]="${bootDir}"
fi
}

# Download all of the dependencies for OpenJDK (Alsa, FreeType, boot-jdk etc.)
downloadingRequiredDependencies() {

if [[ "${BUILD_CONFIG[CLEAN_LIBS]}" == "true" ]]; then
rm -rf "${BUILD_CONFIG[WORKSPACE_DIR]}/libs/freetype" || true

rm -rf "${BUILD_CONFIG[WORKSPACE_DIR]}/${BUILD_CONFIG[WORKING_DIR]}/installedalsa" || true
rm -rf "${BUILD_CONFIG[WORKSPACE_DIR]}/${BUILD_CONFIG[WORKING_DIR]}/installedfreetype" || true
rm -rf "${BUILD_CONFIG[WORKSPACE_DIR]}/downloaded-boot-jdk-${BUILD_CONFIG[OPENJDK_FEATURE_NUMBER]}" || true
fi

downloadBootJdkIfNeeded

mkdir -p "${BUILD_CONFIG[WORKSPACE_DIR]}/libs/" || exit
cd "${BUILD_CONFIG[WORKSPACE_DIR]}/libs/" || exit

Expand Down

0 comments on commit 95385f4

Please sign in to comment.