-
Notifications
You must be signed in to change notification settings - Fork 115
/
Copy pathbuild-selftest
executable file
·148 lines (127 loc) · 4.54 KB
/
build-selftest
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/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)/../"
nativeGraalVmDir="$(pwd)"
[[ -n "$GRAALVM_HOME" ]] && export PATH="$GRAALVM_HOME"/bin:$PATH
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 Checking availability of additional dependencies required for coverage
mysqlDepVersion=$(grep -A2 mysql-connector "${nativeGraalVmDir}/../pom.xml" | grep '<version>' | grep '</version>' | tr -d ' ' | sed -E 's|</?version>||g')
if [[ -n "$mysqlDepVersion" ]]; then
echo "Detected version for mysql-connector-j dependency: $mysqlDepVersion"
else
mysqlDepVersion=8.3.0
echo "[WARNING] could not detect version for mysql-connector-j dependency, using ${mysqlDepVersion}"
fi
mysqlDep="$HOME/.m2/repository/com/mysql/mysql-connector-j/8.3.0/mysql-connector-j-8.3.0.jar"
if [[ -f "$mysqlDep" ]]; then
echo "Using mysql-connector-j dependency from: $mysqlDep"
else
echo "[WARNING] mysql-connector-j dependency is missing: $mysqlDep" >&2
fi
selftestArgs=(
-Dselftest.enable-module.junixsocket-common.JavaInet=true
-Dselftest.enable-module.junixsocket-common.JEP380=true
-cp "$jar":"$mysqlDep"
)
echo
echo Running junixsocket-selftest with GraalVM native-image-agent...
(
set -x
java -agentlib:native-image-agent=config-output-dir=${tmpDir}/native-image.{pid} \
${selftestArgs[@]} org.newsclub.net.unix.selftest.Selftest
)
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 \
${selftestArgs[@]} org.newsclub.net.unix.selftest.Selftest
)
if [[ $? -ne 0 ]]; then
echo "Error: Failed to run native-image" >&2
exit 1
fi
#nativeBinary="$(pwd)/${$(basename "$jar")%%.jar}"
nativeBinary="$(pwd)/org.newsclub.net.unix.selftest.selftest"
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