Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enabled build from source dir/tarball via to --openjdk-source-location/-l #3737

Merged
merged 49 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
a635458
enabled build from source dir/tarball via to --openjdk-source
judovana Mar 27, 2024
b375a2a
not excluding build from tarballs extraction, rmeoving instead
judovana Mar 28, 2024
70278b4
removed debug
judovana Mar 28, 2024
bf63854
Fixing issues found during review
judovana Mar 28, 2024
d7a1ef3
Quoting few variables to prevent globbing and word splitting
judovana Apr 1, 2024
433ea0f
Replaced `pwd` by $(pwd)
judovana Apr 2, 2024
0620e50
Update makejdk-any-platform.1
judovana Apr 3, 2024
8cb6d80
Update makejdk-any-platform.1
judovana Apr 3, 2024
e0ccb12
Update makejdk-any-platform.1
judovana Apr 3, 2024
6c1bafb
Update sbin/prepareWorkspace.sh
judovana Apr 3, 2024
7030bcd
Update sbin/prepareWorkspace.sh
judovana Apr 3, 2024
eabc2c2
Update sbin/prepareWorkspace.sh
judovana Apr 3, 2024
5aa6407
Update sbin/prepareWorkspace.sh
judovana Apr 3, 2024
8c2753c
Update makejdk-any-platform.1
judovana Apr 3, 2024
d1de822
removed useless --strip-components 0 to help a it non posix systems
judovana Apr 3, 2024
8f8bc10
be specific on on kind of git ops hidden below magic
judovana Apr 3, 2024
176ee8a
Using verbose sleep instead of jsut sleep
judovana Apr 5, 2024
742b05a
Returned globing for $files, disable=SC2086 for that line
judovana Apr 5, 2024
38e318f
Merge branch 'master' into localBuild3
karianna Apr 5, 2024
c8c32da
sed "s/OPENJDK_FOREST_DIR/OPENJDK_FOREST_SOURCE_ARCHIVE/g" -i {prepar…
judovana Apr 6, 2024
fd8f48e
Update makejdk-any-platform.1
judovana Apr 6, 2024
6b71133
Update sbin/build.sh
judovana Apr 6, 2024
e954eb5
Update sbin/build.sh
judovana Apr 6, 2024
098aacd
Update sbin/build.sh
judovana Apr 6, 2024
d661188
Update sbin/common/config_init.sh
judovana Apr 6, 2024
4c06221
Update sbin/common/config_init.sh
judovana Apr 6, 2024
d84c039
Update sbin/prepareWorkspace.sh
judovana Apr 6, 2024
b459e69
Update sbin/common/config_init.sh
judovana Apr 6, 2024
194aabb
Update sbin/prepareWorkspace.sh
judovana Apr 6, 2024
6b342d2
Fixed last ;shift; to ; shift;
judovana Apr 6, 2024
9ed221a
Update sbin/prepareWorkspace.sh
judovana Apr 6, 2024
57dda8a
Update sbin/prepareWorkspace.sh
judovana Apr 6, 2024
519c528
Extracting OpenJDK source tarball ... to build the binary
judovana Apr 6, 2024
c3cc00f
Update sbin/prepareWorkspace.sh
judovana Apr 6, 2024
79bf173
You have specified ... does not exist
judovana Apr 6, 2024
43b5c93
using OPENJDK_LOCAL_SOURCE_ARCHIVE instead of OPENJDK_FOREST_SOURCE_A…
judovana Apr 23, 2024
45e4efb
Merge branch 'master' into localBuild3
karianna Apr 23, 2024
23454cc
Merge branch 'master' into localBuild3
karianna May 1, 2024
5e857d3
Update sbin/common/config_init.sh
judovana May 10, 2024
d8304b9
Update sbin/build.sh
judovana May 10, 2024
faf2bea
Update makejdk-any-platform.1
judovana May 10, 2024
72d3ed9
Update makejdk-any-platform.1
judovana May 10, 2024
a399523
Update makejdk-any-platform.1
judovana May 10, 2024
22299e6
Made tar --exclude check nonfatal
judovana May 10, 2024
9140925
SC2126 Considered using 'grep -c' instead of 'grep|wc -l'.
judovana May 10, 2024
7edc874
Workaroudned usage of --strip-components 1 by custom function
judovana May 10, 2024
5dcb140
renamed from "--openjdk-source" | "-o" to "--openjdk-source-locatio…
judovana May 10, 2024
385bfc3
Using $() isntead of backticks
judovana May 10, 2024
793fcad
Moved -l/openjdk-source-location to proper palce in man after rename…
judovana May 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions makejdk-any-platform.1
Original file line number Diff line number Diff line change
Expand Up @@ -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 the latest Java 22 Temurin binary from your local sources
judovana marked this conversation as resolved.
Show resolved Hide resolved

Please visit https://www.adoptium.net for further support

.SH VERSIONS
Expand Down Expand Up @@ -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<dir/archive>\fR
judovana marked this conversation as resolved.
Show resolved Hide resolved
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 have to set main argument though, and it is recommended that you add \-\-tag too.
judovana marked this conversation as resolved.
Show resolved Hide resolved
.TP
.BR \-p ", " \-\-processors " " \fI<args>\fR
specify the number of processors to use for the docker build.
.TP
Expand Down Expand Up @@ -190,6 +199,8 @@ specify the vendor vm bug url
.TP
.BR \-v ", " \-\-version " " \fI<version>\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 argument),
judovana marked this conversation as resolved.
Show resolved Hide resolved
to tell the build that you are effectively building a jdk8u binary.
.TP
.BR \-V ", " \-\-jvm-variant " " \fI<jvm_variant>\fR
specify the JVM variant (server or client), defaults to server.
Expand Down
32 changes: 22 additions & 10 deletions sbin/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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_FOREST_SOURCE_ARCHIVE]}" == "true" ]; then
echo "Version: local dir; OPENJDK_BUILD_NUMBER set as ${BUILD_CONFIG[OPENJDK_BUILD_NUMBER]}"
judovana marked this conversation as resolved.
Show resolved Hide resolved
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
Expand Down Expand Up @@ -232,7 +233,9 @@ patchFreetypeWindows() {
getOpenJdkVersion() {
local version

if [ "${BUILD_CONFIG[BUILD_VARIANT]}" == "${BUILD_VARIANT_CORRETTO}" ]; then
if [ "${BUILD_CONFIG[OPENJDK_FOREST_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}")"
Expand Down Expand Up @@ -1801,10 +1804,25 @@ getLatestTagJDK11plus() {
fi
}

createDefaultTag() {
judovana marked this conversation as resolved.
Show resolved Hide resolved
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_FOREST_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().
Expand Down Expand Up @@ -1848,13 +1866,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
Expand Down
30 changes: 29 additions & 1 deletion sbin/common/config_init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ OPENJDK_BUILD_NUMBER
OPENJDK_CORE_VERSION
OPENJDK_FEATURE_NUMBER
OPENJDK_FOREST_NAME
OPENJDK_FOREST_SOURCE_ARCHIVE
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Archive to me usually means .zip or .tar etc. Is OPENJDK_FOREST_SOURCE or something OPENJDK_LOCAL_SOURCE a better name?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can be archive archive. You can build local directory and tarball (both with sources) in same way.
As i replied to @sxa #3737 (comment) the proepr name aka OPENJDK_LOCAL_SOURCE_DIR_OR_ARCHIVE is terrible, but why not.

sh makejdk-any-platform.sh  -o ~/git/java-21-openjdk-portable/openjdk-21.0.2+13.tar.xz  jdk21u

and

 sh makejdk-any-platform.sh -o  ~/git/jdk21u/ jdk21u

both do same job.

Copy link
Contributor Author

@judovana judovana Apr 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually, OPENJDK_LOCAL_SOURCE and OPENJDK_LOCAL_SOURCE_ABSPATH are generic enough. @sxa , I will use that.

OPENJDK_FOREST_SOURCE_ARCHIVE_ABSPATH
OPENJDK_SOURCE_DIR
OPENJDK_UPDATE_VERSION
OS_KERNEL_NAME
Expand Down Expand Up @@ -304,7 +306,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;;
Expand All @@ -315,6 +317,9 @@ function parseConfigurationArguments() {
"--no-adopt-patches" )
BUILD_CONFIG[ADOPT_PATCHES]=false;;

"--openjdk-source" | "-o" )
setOpenjdkSourceDir "${1}"; shift;;

"--patches" )
BUILD_CONFIG[PATCHES]="$1"; shift;;

Expand Down Expand Up @@ -413,6 +418,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 -o/--openjdk-source, but '${1}' does not exist"
exit 1
fi
BUILD_CONFIG[OPENJDK_FOREST_SOURCE_ARCHIVE_ABSPATH]=$(readlink -f "$1");
if [ ! -e "${BUILD_CONFIG[OPENJDK_FOREST_SOURCE_ARCHIVE_ABSPATH]}" ] ; then
echo "You have specified -o/--openjdk-source, but '${BUILD_CONFIG[OPENJDK_FOREST_SOURCE_ARCHIVE_ABSPATH]}' does not exist"
exit 1
fi
BUILD_CONFIG[OPENJDK_FOREST_SOURCE_ARCHIVE]="true";
if [ -z "${BUILD_CONFIG[TAG]}" ] ; then
echo "You have not yet specified --tag. It is strongly recommended you do so, otherwise a default one will be provided."
judovana marked this conversation as resolved.
Show resolved Hide resolved
fi
}

# Set the config defaults
function configDefaults() {

Expand Down Expand Up @@ -460,6 +482,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_SOURCE_ARCHIVE]="false"

# whether the forest is local directory or not
BUILD_CONFIG[OPENJDK_FOREST_SOURCE_ARCHIVE_ABSPATH]=""

# The abridged openjdk core version name, e.g. jdk8, jdk9, etc.
BUILD_CONFIG[OPENJDK_CORE_VERSION]=""

Expand Down
65 changes: 61 additions & 4 deletions sbin/prepareWorkspace.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
################################################################################

set -eu

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

# shellcheck source=sbin/common/constants.sh
Expand All @@ -38,14 +37,58 @@ 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_FOREST_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_FOREST_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]}/"
}

unpackFromArchive() {
echo "Extracting OpenJDK source tarball ${BUILD_CONFIG[OPENJDK_FOREST_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_FOREST_SOURCE_ARCHIVE_ABSPATH]}" | wc -l)
if [ "$topLevelItems" -eq "1" ] ; then
echo "Source tarball contains exactly one directory"
tar --strip-components 1 -xf "${BUILD_CONFIG[OPENJDK_FOREST_SOURCE_ARCHIVE_ABSPATH]}"
else
echo "Source tarball does not contain a top level directory"
tar -xf "${BUILD_CONFIG[OPENJDK_FOREST_SOURCE_ARCHIVE_ABSPATH]}"
fi
rm -rf "build"
popd
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
popd
popd

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello! Not following this one unless you insists. If you look carefully the block in pushd/popd is indented:

unpackFromArchive() {
  echo "Extracting OpenJDK source tarbal ${BUILD_CONFIG[OPENJDK_FOREST_SOURCE_ARCHIVE_ABSPATH]} to $(pwd)/${BUILD_CONFIG[OPENJDK_SOURCE_DIR]} to be built"
  # 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_FOREST_SOURCE_ARCHIVE_ABSPATH]}" | wc -l)
    if [ "$topLevelItems" -eq "1" ] ; then
      echo "Source tarball contains exaclty one directory, using"
      tar --strip-components 1 -xf "${BUILD_CONFIG[OPENJDK_FOREST_SOURCE_ARCHIVE_ABSPATH]}"
    else
      echo "Source tarball does not contain a top level directory, using"
      tar -xf "${BUILD_CONFIG[OPENJDK_FOREST_SOURCE_ARCHIVE_ABSPATH]}"
    fi
    rm -rf "build"
  popd
}

I don't know how global this habit is, but its usefulness proved over years

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not seen that before, but I'm ok with it :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indentation or popd itself? The indentation of insides of pushd/popd block is quite good habbit.

}

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_FOREST_SOURCE_ARCHIVE_ABSPATH]}" ] ; then
copyFromDir
elif [ -f "${BUILD_CONFIG[OPENJDK_FOREST_SOURCE_ARCHIVE_ABSPATH]}" ] ; then
unpackFromArchive
else
echo "${BUILD_CONFIG[OPENJDK_FOREST_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() {

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_SOURCE_ARCHIVE]}" == "false" ]; then
set +e
git --git-dir "${BUILD_CONFIG[OPENJDK_SOURCE_DIR]}/.git" remote -v
echo "${BUILD_CONFIG[OPENJDK_CORE_VERSION]}"
Expand Down Expand Up @@ -79,6 +122,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_SOURCE_ARCHIVE]}" == "true" ]; then
copyFromDirOrUnpackFromArchive
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels a little odd to be calling this from within checkoutAndCloneOpenJDKGitRepo - perhaps we could invoke it from the higher level configureWorkspace` instead as an alternative. I guess it depends how much of the extra logic in this function we'd need to duplicate or abstract out.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok. let me try.

Copy link
Contributor Author

@judovana judovana May 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see. There is

  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" ] && [ "${BUILD_CONFIG[OPENJDK_LOCAL_SOURCE_ARCHIVE]}" == "false" ]; then

So the change of control dir, which is pretty important for any future steps would need to be handled.
And the main if is still using the [ "${BUILD_CONFIG[OPENJDK_LOCAL_SOURCE_ARCHIVE]}" == "false" ]

becasue of the change of the dir, I would rather not chnage the location of the call, unless yo really insists.

In that case it will go :

function configureWorkspace() {
  if [[ "${BUILD_CONFIG[ASSEMBLE_EXPLODED_IMAGE]}" != "true" ]]; then
    createWorkspace
    downloadingRequiredDependencies
    downloadDevkit
    relocateToTmpIfNeeded
+if [ "${BUILD_CONFIG[OPENJDK_LOCAL_SOURCE_ARCHIVE]}" == "true" ]; then
+    copyFromDirOrUnpackFromArchiveWrapper
+else 
    checkoutAndCloneOpenJDKGitRepo
+fi
    applyPatches
    if [ "${BUILD_CONFIG[CUSTOM_CACERTS]}" = "true" ] ; then
      prepareMozillaCacerts
    fi
  fi
  writeDockerImageSHA
}

where the wrapper:

function   copyFromDirOrUnpackFromArchiveWrapper() {
   cd "${BUILD_CONFIG[WORKSPACE_DIR]}/${BUILD_CONFIG[WORKING_DIR]}"
   copyFromDirOrUnpackFromArchive
    cd "${BUILD_CONFIG[WORKSPACE_DIR]}"
}

IN addition the method of checkoutAndCloneOpenJDKGitRepo is doing a bit more before cd "${BUILD_CONFIG[WORKSPACE_DIR]}" Although it seems those lines looks oook to omit (temurin exit, update openj9 and createSourceTagFile ) I'm not sure If I feel safe to omit them

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah agree that the safest option is to leave it as-is although putting it in the configureWorkspace function as per your example does look a lot nicer. But I won't insist on it :-)

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]}"
Expand Down Expand Up @@ -107,8 +152,9 @@ checkoutAndCloneOpenJDKGitRepo() {
fi
fi

git clean -ffdx

if [ "${BUILD_CONFIG[OPENJDK_FOREST_SOURCE_ARCHIVE]}" == "false" ]; then
git clean -ffdx
fi
updateOpenj9Sources

createSourceTagFile
Expand All @@ -119,6 +165,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_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]}"
Expand Down
Loading