1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
|
#!/usr/bin/env zsh
#
# Script to generate GraalVM native-image metadata and a native binary for junixsocket-selftest.
#
# junixsocket
# Copyright 2009-2022 Christian Kohlschütter
# SPDX-License-Identifier: Apache-2.0
#
cd "$(dirname $0)/../"
java -version 2>&1 | grep -q GraalVM
if [[ $? -ne 0 ]]; then
echo Error: JVM is not a GraalVM. >&2
echo Make sure that GraalVM is in PATH -- run with bin/graalvm bin/build-selftest
exit 1
fi
outputDir="output"
mkdir -p "$outputDir" "${outputDir}/bin" "${outputDir}/tmp"
cd "$outputDir"
outputDir="$(pwd)"
tmpDir=$(pwd)/tmp/junixsocket-selftest
rm -rf "$tmpDir"
mkdir -p "$tmpDir"
echo Checking presence of required commands
which which >/dev/null
if [[ $? -ne 0 ]]; then
echo "Error: \"which\" command not found" >&2
exit 1
fi
hasGraalVM=$(java -version 2>&1 | grep GraalVM)
[[ -n "$hasGraalVM" ]] && echo Java: $hasGraalVM
if [[ -z "$hasGraalVM" ]]; then
echo "Error: java/GraalVM not in PATH" >&2
exit 1
fi
hasNativeImage=$(which native-image)
if [[ $? -ne 0 || -z "$hasNativeImage" ]]; then
( set -x ; gu install native-image )
fi
hasNativeImage=$(which native-image)
if [[ $? -ne 0 || -z "$hasNativeImage" ]]; then
echo "Error: Could not find \"native-image\" command in PATH" >&2
exit 1
fi
echo native-image: $hasNativeImage
hasNativeImageConfigure=$(which native-image-configure)
if [[ $? -ne 0 || -z "$hasNativeImageConfigure" ]]; then
( set -x ; native-image --macro:native-image-configure-launcher )
fi
hasNativeImageConfigure=$(which native-image-configure)
if [[ $? -ne 0 || -z "$hasNativeImageConfigure" ]]; then
echo "Error: Could not find \"native-image-configure\" command in PATH" >&2
exit 1
fi
echo native-image-configure: $hasNativeImageConfigure
echo
echo Finding junixsocket-selftest jar
jar=$(find ../../junixsocket-selftest/target -maxdepth 1 -name "junixsocket-selftest-*-jar-with-dependencies.jar")
if [[ -z "$jar" ]]; then
echo "Error: Could not find junixsocket-selftest jar" >&2
echo "Please run \"mvn clean install\" (or similar) from the junixsocket project directory" >&2
exit 1
fi
jar=$(cd $(dirname "$jar"); pwd)/$(basename "$jar")
echo jar: $jar
echo
echo Running junixsocket-selftest with GraalVM native-image-agent...
( set -x ; java -agentlib:native-image-agent=config-output-dir=${tmpDir}/native-image.{pid} -Dselftest.skip.junixsocket-rmi=force -jar "$jar" >/dev/null )
if [[ $? -ne 0 ]]; then
echo "Error: junixsocket-selftest failed" >&2
exit 1
fi
echo
echo Combining native-image configs...
combinedDir="${outputDir}/META-INF/native-image/com.kohlschutter.junixsocket/junixsocket-native-graalvm"
mkdir -p "$combinedDir"
( set -x ; native-image-configure generate $(find "$tmpDir" -maxdepth 1 -type d -name "native-image.*" -exec echo "--input-dir={}" \;) --output-dir="$combinedDir" )
cd bin
echo
echo Running native-image...
( set -x ; native-image -cp "$tmpDir" --initialize-at-build-time=sun.rmi.transport.GC --report-unsupported-elements-at-runtime --no-fallback -jar "$jar" )
if [[ $? -ne 0 ]]; then
echo "Error: Failed to run native-image" >&2
exit 1
fi
nativeBinary="$(pwd)/${$(basename "$jar")%%.jar}"
if [[ ! -e "$nativeBinary" ]]; then
echo "Error: Native binary expected but not found at: $nativeBinary" >&2
exit 1
fi
echo
echo Native binary created successfully: $nativeBinary
changes=$(git status -s "$combinedDir")
if [[ -n "$changes" ]]; then
echo "Metadata changes detected:"
git status -s "$combinedDir"
fi
|