From f01d684ec3fd48d410830cf1b2ae71544f3105f9 Mon Sep 17 00:00:00 2001 From: Jiri Date: Wed, 27 Mar 2024 11:24:13 +0100 Subject: [PATCH] enabled build from source dir/tarball via to --openjdk-source --- makejdk-any-platform.1 | 11 +++++++ sbin/build.sh | 54 ++++++++++++++++++++++----------- sbin/common/config_init.sh | 28 +++++++++++++++++ sbin/prepareWorkspace.sh | 62 +++++++++++++++++++++++++++++++++++--- 4 files changed, 133 insertions(+), 22 deletions(-) diff --git a/makejdk-any-platform.1 b/makejdk-any-platform.1 index f52f95f31d..6841e82b86 100755 --- a/makejdk-any-platform.1 +++ b/makejdk-any-platform.1 @@ -27,6 +27,10 @@ that you are building for further details. This will start a Docker container and build you the latest Java 8 Temurin binary from the source at https://github.com/adoptium/openjdk-jdk8u +"./makejdk-any-platform.sh -o my/dir/or/archive.tar.gz jdk22u" + +This will start a build of your local sources as Temurin 22. + Please visit https://www.adoptium.net for further support .SH VERSIONS @@ -128,6 +132,11 @@ specify any custom user make arguments. .BR \-\-no\-adopt\-patches This indicates to the build script that the build does not have Temurin's additional patches applied. .TP +.BR \-o ", " \-\-openjdk\-source " " \fI\fR +If set, must point to directory or archive with sources. +Those will be used instead of cloning without any .git magic. +You have to set main argument though, and you should use \-\-tag too. +.TP .BR \-p ", " \-\-processors " " \fI\fR specify the number of processors to use for the docker build. .TP @@ -190,6 +199,8 @@ specify the vendor vm bug url .TP .BR \-v ", " \-\-version " " \fI\fR specify the OpenJDK version to build e.g. jdk8u. Left for backwards compatibility. +Useful, when cloning repo of weird name, eg shenandoah-jdk8u (main argument), +to tell system that it is jdk8u .TP .BR \-V ", " \-\-jvm-variant " " \fI\fR specify the JVM variant (server or client), defaults to server. diff --git a/sbin/build.sh b/sbin/build.sh index cb27358e27..c3005165c0 100755 --- a/sbin/build.sh +++ b/sbin/build.sh @@ -178,8 +178,9 @@ configureMacOSCodesignParameter() { # Get the OpenJDK update version and build version getOpenJDKUpdateAndBuildVersion() { cd "${BUILD_CONFIG[WORKSPACE_DIR]}/${BUILD_CONFIG[WORKING_DIR]}" - - if [ -d "${BUILD_CONFIG[OPENJDK_SOURCE_DIR]}/.git" ]; then + if [ "${BUILD_CONFIG[OPENJDK_FOREST_DIR]}" == "true" ]; then + echo "Version: local dir; OPENJDK_BUILD_NUMBER set as ${BUILD_CONFIG[OPENJDK_BUILD_NUMBER]}" + elif [ -d "${BUILD_CONFIG[OPENJDK_SOURCE_DIR]}/.git" ]; then # It does exist and it's a repo other than the Temurin one cd "${BUILD_CONFIG[OPENJDK_SOURCE_DIR]}" || return @@ -227,7 +228,9 @@ patchFreetypeWindows() { getOpenJdkVersion() { local version - if [ "${BUILD_CONFIG[BUILD_VARIANT]}" == "${BUILD_VARIANT_CORRETTO}" ]; then + if [ "${BUILD_CONFIG[OPENJDK_FOREST_DIR]}" == "true" ]; then + version=${BUILD_CONFIG[TAG]:-$(createDefaultTag)} + elif [ "${BUILD_CONFIG[BUILD_VARIANT]}" == "${BUILD_VARIANT_CORRETTO}" ]; then local corrVerFile=${BUILD_CONFIG[WORKSPACE_DIR]}/${BUILD_CONFIG[WORKING_DIR]}/${BUILD_CONFIG[OPENJDK_SOURCE_DIR]}/version.txt local corrVersion="$(cut -d'.' -f 1 <"${corrVerFile}")" @@ -1771,10 +1774,25 @@ getLatestTagJDK11plus() { fi } +createDefaultTag() { + if [ "${BUILD_CONFIG[OPENJDK_FEATURE_NUMBER]}" == "8" ]; then + echo "WARNING: Could not identify latest tag but the ADOPT_BRANCH_SAFETY flag is off so defaulting to 8u000-b00" 1>&2 + echo "8u000-b00" + else + echo "WARNING: Could not identify latest tag but the ADOPT_BRANCH_SAFETY flag is off so defaulting to jdk-${BUILD_CONFIG[OPENJDK_FEATURE_NUMBER]}.0.0+0" 1>&2 + echo "jdk-${BUILD_CONFIG[OPENJDK_FEATURE_NUMBER]}.0.0+0" + fi +} + # Get the tags from the git repo and choose the latest numerically ordered tag for the given JDK version. # getFirstTagFromOpenJDKGitRepo() { + if [ "${BUILD_CONFIG[OPENJDK_FOREST_DIR]}" == "true" ]; then + echo "you are building froum source snapshot. getFirstTagFromOpenJDKGitRepo is not allowed" 1>&2 + exit 1 + fi + # Save current directory of caller so we can return to that directory at the end of this function. # Some callers are not in the git repo root, but instead build root sub-directory like the archive functions # and any function called after cleanAndMoveArchiveFiles(). @@ -1802,15 +1820,20 @@ getFirstTagFromOpenJDKGitRepo() { TAG_SEARCH="aarch64-shenandoah-jdk8u*-b*" fi - # If openj9 and the closed/openjdk-tag.gmk file exists which specifies what level the openj9 jdk code is based upon, - # read OPENJDK_TAG value from that file. - local openj9_openjdk_tag_file="${BUILD_CONFIG[WORKSPACE_DIR]}/${BUILD_CONFIG[WORKING_DIR]}/${BUILD_CONFIG[OPENJDK_SOURCE_DIR]}/closed/openjdk-tag.gmk" - if [[ "${BUILD_CONFIG[BUILD_VARIANT]}" == "${BUILD_VARIANT_OPENJ9}" ]] && [[ -f "${openj9_openjdk_tag_file}" ]]; then - firstMatchingNameFromRepo=$(grep OPENJDK_TAG ${openj9_openjdk_tag_file} | awk 'BEGIN {FS = "[ :=]+"} {print $2}') + if [ "${BUILD_CONFIG[OPENJDK_FOREST_DIR]}" == "true" ]; then + echo "Skipping tag reading from local dir. You shoud have set up TAG" 1>&2 + firstMatchingNameFromRepo="" else - git fetch --tags "${BUILD_CONFIG[WORKSPACE_DIR]}/${BUILD_CONFIG[WORKING_DIR]}/${BUILD_CONFIG[OPENJDK_SOURCE_DIR]}" - firstMatchingNameFromRepo=$(git tag --list "$TAG_SEARCH" | "$get_tag_cmd") - fi + # If openj9 and the closed/openjdk-tag.gmk file exists which specifies what level the openj9 jdk code is based upon, + # read OPENJDK_TAG value from that file. + local openj9_openjdk_tag_file="${BUILD_CONFIG[WORKSPACE_DIR]}/${BUILD_CONFIG[WORKING_DIR]}/${BUILD_CONFIG[OPENJDK_SOURCE_DIR]}/closed/openjdk-tag.gmk" + if [[ "${BUILD_CONFIG[BUILD_VARIANT]}" == "${BUILD_VARIANT_OPENJ9}" ]] && [[ -f "${openj9_openjdk_tag_file}" ]]; then + firstMatchingNameFromRepo=$(grep OPENJDK_TAG ${openj9_openjdk_tag_file} | awk 'BEGIN {FS = "[ :=]+"} {print $2}') + else + git fetch --tags "${BUILD_CONFIG[WORKSPACE_DIR]}/${BUILD_CONFIG[WORKING_DIR]}/${BUILD_CONFIG[OPENJDK_SOURCE_DIR]}" + firstMatchingNameFromRepo=$(git tag --list "$TAG_SEARCH" | "$get_tag_cmd") + fi + fi if [ -z "$firstMatchingNameFromRepo" ]; then echo "WARNING: Failed to identify latest tag in the repository" 1>&2 @@ -1818,13 +1841,7 @@ getFirstTagFromOpenJDKGitRepo() { # repository that doesn't have the same tags, so allow defaults. For a better # options see https://github.com/adoptium/temurin-build/issues/2671 if [ "${BUILD_CONFIG[DISABLE_ADOPT_BRANCH_SAFETY]}" == "true" ]; then - if [ "${BUILD_CONFIG[OPENJDK_FEATURE_NUMBER]}" == "8" ]; then - echo "WARNING: Could not identify latest tag but the ADOPT_BRANCH_SAFETY flag is off so defaulting to 8u000-b00" 1>&2 - echo "8u000-b00" - else - echo "WARNING: Could not identify latest tag but the ADOPT_BRANCH_SAFETY flag is off so defaulting to jdk-${BUILD_CONFIG[OPENJDK_FEATURE_NUMBER]}.0.0+0" 1>&2 - echo "jdk-${BUILD_CONFIG[OPENJDK_FEATURE_NUMBER]}.0.0+0" - fi + createDefaultTag else echo "WARNING: Failed to identify latest tag in the repository" 1>&2 fi @@ -2241,6 +2258,7 @@ echo "build.sh : $(date +%T) : Configuring workspace inc. clone and cacerts gene configureWorkspace echo "build.sh : $(date +%T) : Initiating build ..." +set -x getOpenJDKUpdateAndBuildVersion if [[ "$OSTYPE" == "cygwin" ]] || [[ "$OSTYPE" == "msys" ]]; then patchFreetypeWindows diff --git a/sbin/common/config_init.sh b/sbin/common/config_init.sh index 3ee88244fe..2c8afb54cf 100755 --- a/sbin/common/config_init.sh +++ b/sbin/common/config_init.sh @@ -83,6 +83,8 @@ OPENJDK_BUILD_NUMBER OPENJDK_CORE_VERSION OPENJDK_FEATURE_NUMBER OPENJDK_FOREST_NAME +OPENJDK_FOREST_DIR +OPENJDK_FOREST_DIR_ABSPATH OPENJDK_SOURCE_DIR OPENJDK_UPDATE_VERSION OS_KERNEL_NAME @@ -315,6 +317,9 @@ function parseConfigurationArguments() { "--no-adopt-patches" ) BUILD_CONFIG[ADOPT_PATCHES]=false;; + "--openjdk-source" | "-o" ) + setLocalDir "${1}";shift;; + "--patches" ) BUILD_CONFIG[PATCHES]="$1"; shift;; @@ -410,6 +415,23 @@ function setBranch() { BUILD_CONFIG[BRANCH]=${BUILD_CONFIG[BRANCH]:-$branch} } +# Set the local dir if used +function setLocalDir() { + if [ ! -e "${1}" ] ; then + echo "you have specified -o/--openjdk-source, but '${1}' do not exists" + exit 1 + fi + BUILD_CONFIG[OPENJDK_FOREST_DIR_ABSPATH]=$(readlink -f "$1"); + if [ ! -e "${BUILD_CONFIG[OPENJDK_FOREST_DIR_ABSPATH]}" ] ; then + echo "you have specified -o/--openjdk-source, but '${BUILD_CONFIG[OPENJDK_FOREST_DIR_ABSPATH]}' do not exists" + exit 1 + fi + BUILD_CONFIG[OPENJDK_FOREST_DIR]="true"; + if [ -z "${BUILD_CONFIG[TAG]}" ] ; then + echo "You have not yet specified --tag. It is strongly recommended you do so, otherwise default one will be provided" + fi +} + # Set the config defaults function configDefaults() { @@ -457,6 +479,12 @@ function configDefaults() { # The full forest name, e.g. jdk8, jdk8u, jdk9, jdk9u, etc. BUILD_CONFIG[OPENJDK_FOREST_NAME]="" + # whether the forest is local directory or not + BUILD_CONFIG[OPENJDK_FOREST_DIR]="false" + + # whether the forest is local directory or not + BUILD_CONFIG[OPENJDK_FOREST_DIR_ABSPATH]="" + # The abridged openjdk core version name, e.g. jdk8, jdk9, etc. BUILD_CONFIG[OPENJDK_CORE_VERSION]="" diff --git a/sbin/prepareWorkspace.sh b/sbin/prepareWorkspace.sh index 022a0b297b..bc03581fc3 100644 --- a/sbin/prepareWorkspace.sh +++ b/sbin/prepareWorkspace.sh @@ -24,7 +24,7 @@ ################################################################################ set -eu - +set -x SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # shellcheck source=sbin/common/constants.sh @@ -37,6 +37,46 @@ ALSA_LIB_CHECKSUM=${ALSA_LIB_CHECKSUM:-5f2cd274b272cae0d0d111e8a9e363f0878332915 ALSA_LIB_GPGKEYID=${ALSA_LIB_GPGKEYID:-A6E59C91} FREETYPE_FONT_SHARED_OBJECT_FILENAME="libfreetype.so*" + +copyFromDir() { + echo "Copyng existing ${BUILD_CONFIG[OPENJDK_FOREST_DIR_ABSPATH]} to `pwd`/${BUILD_CONFIG[OPENJDK_SOURCE_DIR]} to be built" + # we really do not want to use .git for dirs, as we expect user have them set up, ignoring them + local files=$(find ${BUILD_CONFIG[OPENJDK_FOREST_DIR_ABSPATH]} -maxdepth 1 -mindepth 1 | grep -v -e "/workspace$" -e "/build$" -e "/.git" -e -"/build/") + cp -rf $files "./${BUILD_CONFIG[OPENJDK_SOURCE_DIR]}/" +} + +unpackFromArchive() { + echo "Extracting source tarball ${BUILD_CONFIG[OPENJDK_FOREST_DIR_ABSPATH]} to $(pwd)/${BUILD_CONFIG[OPENJDK_SOURCE_DIR]} to be built" + # if the tarball contains .git files, they should be ignored later withut shame + # todo, support also zips? + pushd "./${BUILD_CONFIG[OPENJDK_SOURCE_DIR]}" + local topLevelItems=$(tar --exclude='*/*' -tf "${BUILD_CONFIG[OPENJDK_FOREST_DIR_ABSPATH]}" | wc -l) + if [ "$topLevelItems" -eq "1" ] ; then + echo "Source tarball contans exaclty one directory, using" + tar --exclude='*/build' --strip-components 1 -xf "${BUILD_CONFIG[OPENJDK_FOREST_DIR_ABSPATH]}" + else + echo "Source tarball do not contains top level directory, using" + tar --exclude='*/build' --strip-components 0 -xf "${BUILD_CONFIG[OPENJDK_FOREST_DIR_ABSPATH]}" + fi + popd +} + +copyFromDirOrUnpackFromArchive() { + echo "Removing copy of openjdk source repository of $(pwd)/${BUILD_CONFIG[OPENJDK_SOURCE_DIR]} in 10 seconds..." + sleep 10 + rm -rf "./${BUILD_CONFIG[OPENJDK_SOURCE_DIR]}" + mkdir "./${BUILD_CONFIG[OPENJDK_SOURCE_DIR]}" + # note, that we are not persisting build directory + if [ -d "${BUILD_CONFIG[OPENJDK_FOREST_DIR_ABSPATH]}" ] ; then + copyFromDir + elif [ -f "${BUILD_CONFIG[OPENJDK_FOREST_DIR_ABSPATH]}" ] ; then + unpackFromArchive + else + echo "Not directory nor file ${BUILD_CONFIG[OPENJDK_FOREST_DIR_ABSPATH]}" + exit 1 + fi +} + # Create a new clone or update the existing clone of the OpenJDK source repo # TODO refactor this for Single Responsibility Principle (SRP) checkoutAndCloneOpenJDKGitRepo() { @@ -44,7 +84,7 @@ checkoutAndCloneOpenJDKGitRepo() { cd "${BUILD_CONFIG[WORKSPACE_DIR]}/${BUILD_CONFIG[WORKING_DIR]}" # Check that we have a git repo, we assume that it is a repo that contains openjdk source - if [ -d "${BUILD_CONFIG[OPENJDK_SOURCE_DIR]}/.git" ]; then + if [ -d "${BUILD_CONFIG[OPENJDK_SOURCE_DIR]}/.git" ] && [ "${BUILD_CONFIG[OPENJDK_FOREST_DIR]}" == "false" ]; then set +e git --git-dir "${BUILD_CONFIG[OPENJDK_SOURCE_DIR]}/.git" remote -v echo "${BUILD_CONFIG[OPENJDK_CORE_VERSION]}" @@ -78,6 +118,8 @@ checkoutAndCloneOpenJDKGitRepo() { echo "If this is inside a docker you can purge the existing source by passing --clean-docker-build" exit 1 fi + elif [ "${BUILD_CONFIG[OPENJDK_FOREST_DIR]}" == "true" ]; then + copyFromDirOrUnpackFromArchive elif [ ! -d "${BUILD_CONFIG[OPENJDK_SOURCE_DIR]}/.git" ]; then echo "Could not find a valid openjdk git repository at $(pwd)/${BUILD_CONFIG[OPENJDK_SOURCE_DIR]} so re-cloning the source to openjdk" rm -rf "${BUILD_CONFIG[WORKSPACE_DIR]:?}/${BUILD_CONFIG[WORKING_DIR]}/${BUILD_CONFIG[OPENJDK_SOURCE_DIR]}" @@ -106,8 +148,9 @@ checkoutAndCloneOpenJDKGitRepo() { fi fi - git clean -ffdx - + if [ ! "${BUILD_CONFIG[OPENJDK_FOREST_DIR]}" == "true" ]; then + git clean -ffdx + fi updateOpenj9Sources createSourceTagFile @@ -118,6 +161,17 @@ checkoutAndCloneOpenJDKGitRepo() { # Checkout the required code to build from the given cached git repo # Set checkoutRc to result so we can retry checkoutRequiredCodeToBuild() { + + if [ "${BUILD_CONFIG[OPENJDK_FOREST_DIR]}" == "true" ]; then + echo "skipping checkoutRequiredCodeToBuild - local directory under processing:" + echo " workspace = ${BUILD_CONFIG[WORKSPACE_DIR]}/${BUILD_CONFIG[WORKING_DIR]}/${BUILD_CONFIG[OPENJDK_SOURCE_DIR]}" + echo " BUILD_VARIANT = ${BUILD_CONFIG[BUILD_VARIANT]}" + echo " TAG = ${BUILD_CONFIG[TAG]} - Used only in name, if at all" + echo " BRANCH = ${BUILD_CONFIG[BRANCH]} - UNUSED!" + checkoutRc=0 + return + fi + checkoutRc=1 cd "${BUILD_CONFIG[WORKSPACE_DIR]}/${BUILD_CONFIG[WORKING_DIR]}/${BUILD_CONFIG[OPENJDK_SOURCE_DIR]}"