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

Update getjdkbinary to correctly handle Temurin debugimage and static-libs folders #5750

Merged
merged 16 commits into from
Nov 20, 2024
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
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
67 changes: 55 additions & 12 deletions get.sh
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,36 @@ parseCommandLineArgs()
echo "TESTDIR: $TESTDIR"
}

# If the current directory contains only a single directory then squash that directory into the current directory
squashSingleFolderContentsToCurrentDir()
andrew-m-leonard marked this conversation as resolved.
Show resolved Hide resolved
{
# Does current directory contain one and ONLY one directory?
if [[ $(ls -1 | wc -l) -eq 1 ]]; then
folder=$(ls -d */)
if [ -d "$folder" ]; then
echo "Removing top-level folder ${folder}"
mv ${folder}* .
rmdir "${folder}"
fi
fi
}

# Moves the given directory safely, ensuring the target does not exist, fail with error if it does exist
moveDirectorySafely()
{
if [ $# -lt 2 ]; then
echo "Syntax: moveDirectorySafely <sourceDirectory> <targetDirectory>"
exit 1
fi
if [ -d "$2" ]; then
echo "ERROR: moveDirectorySafely $1 $2 : target directory $2 already exists"
exit 1
else
echo "Moving directory $1 to $2"
mv "$1" "$2"
fi
}

getBinaryOpenjdk()
{
echo "get jdk binary..."
Expand Down Expand Up @@ -375,16 +405,25 @@ getBinaryOpenjdk()
extract_dir="./j2sdk-image/jre"
fi
echo "Uncompressing $file_name over $extract_dir..."

# Debug image tarballs vary in top-level folders between Vendors, eg.location of bin folder
# temurin: jdk-21.0.5+11-debug-image/jdk-21.0.5+11/bin
# semeru: jdk-21.0.4+7-debug-image/bin

# Unpack into a temp directory, remove 1 or maybe 2 top-level single folders, then copy over extract_dir
mkdir dir.$$ && cd dir.$$
if [[ $file_name == *zip ]] || [[ $file_name == *jar ]]; then
unzip -q $file_name -d $extract_dir
unzip -q ../$file_name
else
# some debug-image tar has parent folder ... strip it
if tar --version 2>&1 | grep GNU 2>&1; then
gzip -cd $file_name | tar xof - -C $extract_dir --strip 1
else
mkdir dir.$$ && cd dir.$$ && gzip -cd ../$file_name | tar xof - && cd * && tar cf - . | (cd ../../$extract_dir && tar xpf -) && cd ../.. && rm -rf dir.$$
fi
gzip -cd ../$file_name | tar xof -
fi

# Remove 1 possibly 2 top-level folders (debugimage has 2)
squashSingleFolderContentsToCurrentDir
squashSingleFolderContentsToCurrentDir

# Copy to extract_dir
cp -R * "../${extract_dir}" && cd .. && rm -rf dir.$$
else
if [ -d "$SDKDIR/jdkbinary/tmp" ]; then
rm -rf $SDKDIR/jdkbinary/tmp/*
Expand Down Expand Up @@ -413,10 +452,14 @@ getBinaryOpenjdk()
jar_dir_name=${jar_dir_array[0]}
if [[ "$jar_dir_name" =~ "test-image" ]] || [[ "$jar_dir_name" =~ "tests-" ]]; then
if [ "$jar_dir_name" != "openjdk-test-image" ]; then
mv $jar_dir_name ../openjdk-test-image
moveDirectorySafely $jar_dir_name ../openjdk-test-image
andrew-m-leonard marked this conversation as resolved.
Show resolved Hide resolved
fi
elif [[ "$jar_dir_name" =~ "static-libs" ]]; then
moveDirectorySafely $jar_dir_name ../static-libs
elif [[ "$jar_dir_name" =~ jdk.*-src/ ]]; then
moveDirectorySafely $jar_dir_name ../source-image
elif [[ "$jar_dir_name" =~ jre* ]] && [ "$jar_dir_name" != "j2re-image" ]; then
mv $jar_dir_name ../j2re-image
moveDirectorySafely $jar_dir_name ../j2re-image
elif [[ "$jar_dir_name" =~ jdk* ]] && [ "$jar_dir_name" != "j2sdk-image" ]; then
# If test sdk has already been expanded, this one must be the additional sdk
isAdditional=0
Expand Down Expand Up @@ -448,14 +491,14 @@ getBinaryOpenjdk()
echo "RI JDK version:"
$SDKDIR/additionaljdkbinary/bin/java -version
else
mv $jar_dir_name ../j2sdk-image
moveDirectorySafely $jar_dir_name ../j2sdk-image
fi
# The following only needed if openj9 has a different image name convention
elif [ "$jar_dir_name" != "j2sdk-image" ]; then
mv $jar_dir_name ../j2sdk-image
moveDirectorySafely $jar_dir_name ../j2sdk-image
fi
elif [ "$len" -gt 1 ]; then
mv ../tmp ../j2sdk-image
moveDirectorySafely ../tmp ../j2sdk-image
fi
cd $SDKDIR/jdkbinary
fi
Expand Down