diff --git a/makejdk-any-platform.1 b/makejdk-any-platform.1 index a052497ff..c16e838d9 100755 --- a/makejdk-any-platform.1 +++ b/makejdk-any-platform.1 @@ -30,6 +30,10 @@ Note that the main argument, in this case jdk8, is compared and enforced against an enumeration - jdk8, jdk8u, ... jdk21, jdk21u, ...jdk. Nothing else. You can workaround this by \-\-version switch. +"./makejdk-any-platform.sh -l my/dir/or/archive.tar.gz jdk22u" + +This will start a build of Java 22 from your local sources + Please visit https://www.adoptium.net for further support .SH VERSIONS @@ -131,6 +135,11 @@ the one you are trying to build. .BR \-k ", " \-\-keep if using docker, keep the container after the build. .TP +.BR \-l ", " \-\-openjdk\-source\-location " " \fI\fR +If set, must point to directory or archive with valid OpenJDK source code. +This local source code will be used instead of cloning from a git repository and without any git tag or git reset. +You still have to set the version argument though, and it is recommended that you add \-\-tag too so that the top level directory names in the output, as well as the details in "java -version" are created correctly. +.TP .BR \-\-make-args " " \fI\fR specify any custom user make arguments. .TP @@ -199,6 +208,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 a repo with a non-uniform name, e.g., shenandoah-jdk8u (main version argument), +to tell the build that you are effectively building a jdk8u binary. .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 172ede760..aa1b4e260 100755 --- a/sbin/build.sh +++ b/sbin/build.sh @@ -183,8 +183,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_LOCAL_SOURCE_ARCHIVE]}" == "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 @@ -232,7 +233,9 @@ patchFreetypeWindows() { getOpenJdkVersion() { local version - if [ "${BUILD_CONFIG[BUILD_VARIANT]}" == "${BUILD_VARIANT_CORRETTO}" ]; then + if [ "${BUILD_CONFIG[OPENJDK_LOCAL_SOURCE_ARCHIVE]}" == "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}")" @@ -1819,10 +1822,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 the 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_LOCAL_SOURCE_ARCHIVE]}" == "true" ]; then + echo "You are building from a local 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(). @@ -1866,13 +1884,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 diff --git a/sbin/common/config_init.sh b/sbin/common/config_init.sh index 79884278a..6a42ae274 100755 --- a/sbin/common/config_init.sh +++ b/sbin/common/config_init.sh @@ -82,6 +82,8 @@ OPENJDK_BUILD_NUMBER OPENJDK_CORE_VERSION OPENJDK_FEATURE_NUMBER OPENJDK_FOREST_NAME +OPENJDK_LOCAL_SOURCE_ARCHIVE +OPENJDK_LOCAL_SOURCE_ARCHIVE_ABSPATH OPENJDK_SOURCE_DIR OPENJDK_UPDATE_VERSION OS_KERNEL_NAME @@ -308,7 +310,7 @@ function parseConfigurationArguments() { BUILD_CONFIG[REUSE_CONTAINER]=false;; "--jdk-boot-dir" | "-J" ) - BUILD_CONFIG[JDK_BOOT_DIR]="$1";shift;; + BUILD_CONFIG[JDK_BOOT_DIR]="$1"; shift;; "--cross-compile" ) BUILD_CONFIG[CROSSCOMPILE]=true;; @@ -319,6 +321,9 @@ function parseConfigurationArguments() { "--no-adopt-patches" ) BUILD_CONFIG[ADOPT_PATCHES]=false;; + "--openjdk-source-location" | "-l" ) + setOpenjdkSourceDir "${1}"; shift;; + "--patches" ) BUILD_CONFIG[PATCHES]="$1"; shift;; @@ -417,6 +422,23 @@ function setBranch() { BUILD_CONFIG[BRANCH]=${BUILD_CONFIG[BRANCH]:-$branch} } +# Set the local dir if used +function setOpenjdkSourceDir() { + if [ ! -e "${1}" ] ; then + echo "You have specified -l/--openjdk-source-location, but '${1}' does not exist" + exit 1 + fi + BUILD_CONFIG[OPENJDK_LOCAL_SOURCE_ARCHIVE_ABSPATH]=$(readlink -f "$1"); + if [ ! -e "${BUILD_CONFIG[OPENJDK_LOCAL_SOURCE_ARCHIVE_ABSPATH]}" ] ; then + echo "You have specified -l/--openjdk-source-location, but '${BUILD_CONFIG[OPENJDK_LOCAL_SOURCE_ARCHIVE_ABSPATH]}' does not exist" + exit 1 + fi + BUILD_CONFIG[OPENJDK_LOCAL_SOURCE_ARCHIVE]="true"; + if [ -z "${BUILD_CONFIG[TAG]}" ] ; then + echo "WARNING: You have not yet specified --tag. It is strongly recommended you do so, otherwise a default one will be provided." + fi +} + # Set the config defaults function configDefaults() { @@ -464,6 +486,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_LOCAL_SOURCE_ARCHIVE]="false" + + # whether the forest is local directory or not + BUILD_CONFIG[OPENJDK_LOCAL_SOURCE_ARCHIVE_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 d2ad91dc8..79ed8acd1 100644 --- a/sbin/prepareWorkspace.sh +++ b/sbin/prepareWorkspace.sh @@ -22,7 +22,6 @@ ################################################################################ set -eu - SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # shellcheck source=sbin/common/constants.sh @@ -38,6 +37,64 @@ ALSA_LIB_CHECKSUM=${ALSA_LIB_CHECKSUM:-5f2cd274b272cae0d0d111e8a9e363f0878332915 ALSA_LIB_GPGKEYID=${ALSA_LIB_GPGKEYID:-A6E59C91} FREETYPE_FONT_SHARED_OBJECT_FILENAME="libfreetype.so*" + +copyFromDir() { + echo "Copying OpenJDK source from ${BUILD_CONFIG[OPENJDK_LOCAL_SOURCE_ARCHIVE_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_LOCAL_SOURCE_ARCHIVE_ABSPATH]}" -maxdepth 1 -mindepth 1 | grep -v -e "/workspace$" -e "/build$" -e "/.git" -e -"/build/") + # SC2086 (info): Double quote to prevent globbing and word splitting. + # globbing is intentional here + # shellcheck disable=SC2086 + cp -rf $files "./${BUILD_CONFIG[OPENJDK_SOURCE_DIR]}/" +} + +# this is workarounding --strip-components 1 missing on gnu tar +# it requires absolute tar-filepath as it changes dir and is hardcoded to one +# similar approach can be used also for zip in future +untarGnuAbsPathWithStripComponents1() { + local tmp=$(mktemp -d) + pushd "$tmp" > /dev/null + tar "$@" + popd > /dev/null + mv "$tmp"/*/* . + mv "$tmp"/*/.* . || echo "no hidden files in tarball" + rmdir "$tmp"/* + rmdir "$tmp" +} + +unpackFromArchive() { + echo "Extracting OpenJDK source tarball ${BUILD_CONFIG[OPENJDK_LOCAL_SOURCE_ARCHIVE_ABSPATH]} to $(pwd)/${BUILD_CONFIG[OPENJDK_SOURCE_DIR]} to build the binary" + # If the tarball contains .git files, they should be ignored later + # todo, support also zips? + pushd "./${BUILD_CONFIG[OPENJDK_SOURCE_DIR]}" + local topLevelItems=$(tar --exclude='*/*' -tf "${BUILD_CONFIG[OPENJDK_LOCAL_SOURCE_ARCHIVE_ABSPATH]}" | grep "/$" -c) || local topLevelItems=1 + if [ "$topLevelItems" -eq "1" ] ; then + echo "Source tarball contains exactly one directory" + untarGnuAbsPathWithStripComponents1 -xf "${BUILD_CONFIG[OPENJDK_LOCAL_SOURCE_ARCHIVE_ABSPATH]}" + else + echo "Source tarball does not contain a top level directory" + tar -xf "${BUILD_CONFIG[OPENJDK_LOCAL_SOURCE_ARCHIVE_ABSPATH]}" + fi + rm -rf "build" + popd +} + +copyFromDirOrUnpackFromArchive() { + echo "Cleaning the copy of OpenJDK source repository from $(pwd)/${BUILD_CONFIG[OPENJDK_SOURCE_DIR]} and replacing with a fresh copy in 10 seconds..." + verboseSleep 10 + rm -rf "./${BUILD_CONFIG[OPENJDK_SOURCE_DIR]}" + mkdir "./${BUILD_CONFIG[OPENJDK_SOURCE_DIR]}" + # Note that we are not persisting the build directory + if [ -d "${BUILD_CONFIG[OPENJDK_LOCAL_SOURCE_ARCHIVE_ABSPATH]}" ] ; then + copyFromDir + elif [ -f "${BUILD_CONFIG[OPENJDK_LOCAL_SOURCE_ARCHIVE_ABSPATH]}" ] ; then + unpackFromArchive + else + echo "${BUILD_CONFIG[OPENJDK_LOCAL_SOURCE_ARCHIVE_ABSPATH]} is not a directory or a file " + 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() { @@ -45,7 +102,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_LOCAL_SOURCE_ARCHIVE]}" == "false" ]; then set +e git --git-dir "${BUILD_CONFIG[OPENJDK_SOURCE_DIR]}/.git" remote -v echo "${BUILD_CONFIG[OPENJDK_CORE_VERSION]}" @@ -79,6 +136,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_LOCAL_SOURCE_ARCHIVE]}" == "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]}" @@ -107,8 +166,9 @@ checkoutAndCloneOpenJDKGitRepo() { fi fi - git clean -ffdx - + if [ "${BUILD_CONFIG[OPENJDK_LOCAL_SOURCE_ARCHIVE]}" == "false" ]; then + git clean -ffdx + fi updateOpenj9Sources createSourceTagFile @@ -119,6 +179,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_LOCAL_SOURCE_ARCHIVE]}" == "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]}"