diff --git a/build-farm/platform-specific-configurations/downloaders.sh b/build-farm/platform-specific-configurations/downloaders.sh new file mode 100755 index 000000000..2b29e4fa8 --- /dev/null +++ b/build-farm/platform-specific-configurations/downloaders.sh @@ -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 +} + diff --git a/build-farm/platform-specific-configurations/linux.sh b/build-farm/platform-specific-configurations/linux.sh index 5125c9c09..669271bb1 100755 --- a/build-farm/platform-specific-configurations/linux.sh +++ b/build-farm/platform-specific-configurations/linux.sh @@ -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 @@ -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 @@ -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 diff --git a/makejdk-any-platform.1 b/makejdk-any-platform.1 index f52f95f31..bdf8dfd23 100755 --- a/makejdk-any-platform.1 +++ b/makejdk-any-platform.1 @@ -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. diff --git a/sbin/prepareWorkspace.sh b/sbin/prepareWorkspace.sh index 022a0b297..15a532a29 100644 --- a/sbin/prepareWorkspace.sh +++ b/sbin/prepareWorkspace.sh @@ -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