Skip to content

Commit

Permalink
Added support for zipped sources (#3842)
Browse files Browse the repository at this point in the history
* Added support for zipped sources

* Update sbin/prepareWorkspace.sh

Co-authored-by: Martijn Verburg <martijnverburg@gmail.com>

* dangling space before |

Co-authored-by: Martijn Verburg <martijnverburg@gmail.com>

* Renamed from *GnuAbsPathWithStripComponents1 to *GnuAbsPathWithStrip1Component

added warning about issue with merge

---------

Co-authored-by: Martijn Verburg <martijnverburg@gmail.com>
  • Loading branch information
judovana and karianna authored Jun 20, 2024
1 parent be1dc31 commit 0545121
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions sbin/prepareWorkspace.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,29 +51,42 @@ copyFromDir() {
# 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() {
# warning! this method do not merge if (parts of!) destination exists.
unpackGnuAbsPathWithStrip1Component() {
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"
}

untarGnuAbsPathWithStrip1Component() {
unpackGnuAbsPathWithStrip1Component tar -xf "$@"
}

unzipGnuAbsPathWithStrip1Component() {
unpackGnuAbsPathWithStrip1Component unzip "$@"
}

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]}"
if [ "${BUILD_CONFIG[OPENJDK_LOCAL_SOURCE_ARCHIVE_ABSPATH]: -4}" == ".zip" ] ; then
echo "Source zip unpacked as if it contains exactly one directory"
unzipGnuAbsPathWithStrip1Component "${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]}"
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"
untarGnuAbsPathWithStrip1Component "${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
fi
rm -rf "build"
popd
Expand Down

0 comments on commit 0545121

Please sign in to comment.