forked from graalvm/mandrel-packaging
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildJDK.sh
executable file
·113 lines (95 loc) · 6.67 KB
/
buildJDK.sh
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
#!/usr/bin/env bash
set -e
if [[ "${VERBOSE}" == "true" ]]; then
set -x
VERBOSE_BUILD=--verbose
VERBOSE_MX=-v
fi
MX_HOME=${MX_HOME:-/opt/mx}
JAVA_HOME=${JAVA_HOME:-/opt/jdk}
JAVA_MAJOR=$(${JAVA_HOME}/bin/java --version | awk -F'[. ]' '/openjdk / {print $2}')
MANDREL_REPO=${MANDREL_REPO:-/tmp/mandrel}
MAVEN_REPO=${MAVEN_REPO:-~/.m2/repository}
MANDREL_VERSION=${MANDREL_VERSION:-$((git -C ${MANDREL_REPO} describe 2>/dev/null || git -C ${MANDREL_REPO} rev-parse --short HEAD) | sed 's/mandrel-//')}
MANDREL_VERSION_UNTIL_SPACE="$( echo ${MANDREL_VERSION} | sed -e 's/\([^ ]*\).*/\1/;t' )"
MANDREL_HOME=${MANDREL_HOME:-${PWD}/mandrel-java${JAVA_MAJOR}-${MANDREL_VERSION_UNTIL_SPACE}}
MAVEN_ARTIFACTS_VERSION="${MANDREL_VERSION_UNTIL_SPACE}.redhat-00001"
if [[ "${SKIP_CLEAN}" == "true" ]]; then
SKIP_CLEAN_FLAG=--skipClean
fi
# tarxz or tar.gz
TAR_SUFFIX=${TAR_SUFFIX:-tar.gz}
case $TAR_SUFFIX in
tar.gz | tarxz ) true ;;
* ) echo "Unknown archive suffix ${TAR_SUFFIX}"; exit 1 ;;
esac
# from https://stackoverflow.com/a/8597411/186429
PLATFORM="unknown"
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
PLATFORM="linux"
elif [[ "$OSTYPE" == "darwin"* ]]; then
PLATFORM="darwin"
fi
ARCHIVE_NAME="mandrel-java${JAVA_MAJOR}-${PLATFORM}-amd64-${MANDREL_VERSION_UNTIL_SPACE}.${TAR_SUFFIX}"
if [ -n "${MAVEN_HOME}" ]; then
MAVEN_HOME_ARGS="--maven-home ${MAVEN_HOME}"
fi
### Build Mandrel
basename="$(dirname $0)"
${JAVA_HOME}/bin/java -ea $basename/src/build.java ${VERBOSE_BUILD} --version "${MAVEN_ARTIFACTS_VERSION}" --maven-local-repository ${MAVEN_REPO} --mx-home ${MX_HOME} --mandrel-home ${MANDREL_REPO} ${SKIP_CLEAN_FLAG} ${MAVEN_HOME_ARGS}
### Copy default JDK
rm -rf ${MANDREL_HOME}
cp -R -L ${JAVA_HOME} ${MANDREL_HOME}
### Copy needed jars
mkdir -p ${MANDREL_HOME}/lib/svm/builder
cp ${MAVEN_REPO}/org/graalvm/nativeimage/svm/${MAVEN_ARTIFACTS_VERSION}/svm-${MAVEN_ARTIFACTS_VERSION}.jar ${MANDREL_HOME}/lib/svm/builder/svm.jar
cp ${MAVEN_REPO}/org/graalvm/nativeimage/svm/${MAVEN_ARTIFACTS_VERSION}/svm-${MAVEN_ARTIFACTS_VERSION}-sources.jar ${MANDREL_HOME}/lib/svm/builder/svm.src.zip
cp ${MAVEN_REPO}/org/graalvm/nativeimage/pointsto/${MAVEN_ARTIFACTS_VERSION}/pointsto-${MAVEN_ARTIFACTS_VERSION}.jar ${MANDREL_HOME}/lib/svm/builder/pointsto.jar
cp ${MAVEN_REPO}/org/graalvm/nativeimage/pointsto/${MAVEN_ARTIFACTS_VERSION}/pointsto-${MAVEN_ARTIFACTS_VERSION}-sources.jar ${MANDREL_HOME}/lib/svm/builder/pointsto.src.zip
cp ${MAVEN_REPO}/org/graalvm/nativeimage/objectfile/${MAVEN_ARTIFACTS_VERSION}/objectfile-${MAVEN_ARTIFACTS_VERSION}.jar ${MANDREL_HOME}/lib/svm/builder/objectfile.jar
cp ${MAVEN_REPO}/org/graalvm/nativeimage/objectfile/${MAVEN_ARTIFACTS_VERSION}/objectfile-${MAVEN_ARTIFACTS_VERSION}-sources.jar ${MANDREL_HOME}/lib/svm/builder/objectfile.src.zip
mkdir ${MANDREL_HOME}/lib/graalvm
cp ${MAVEN_REPO}/org/graalvm/nativeimage/svm-driver/${MAVEN_ARTIFACTS_VERSION}/svm-driver-${MAVEN_ARTIFACTS_VERSION}.jar ${MANDREL_HOME}/lib/graalvm/svm-driver.jar
cp ${MAVEN_REPO}/org/graalvm/nativeimage/svm-driver/${MAVEN_ARTIFACTS_VERSION}/svm-driver-${MAVEN_ARTIFACTS_VERSION}-sources.jar ${MANDREL_HOME}/lib/graalvm/svm-driver.src.zip
## The following jars are not included in the GraalJDK created by `mx --components="Native Image" build`
mkdir ${MANDREL_HOME}/lib/jvmci
cp ${MAVEN_REPO}/org/graalvm/sdk/graal-sdk/${MAVEN_ARTIFACTS_VERSION}/graal-sdk-${MAVEN_ARTIFACTS_VERSION}.jar ${MANDREL_HOME}/lib/jvmci/graal-sdk.jar
cp ${MAVEN_REPO}/org/graalvm/sdk/graal-sdk/${MAVEN_ARTIFACTS_VERSION}/graal-sdk-${MAVEN_ARTIFACTS_VERSION}-sources.jar ${MANDREL_HOME}/lib/jvmci/graal-sdk.src.zip
cp ${MAVEN_REPO}/org/graalvm/compiler/compiler/${MAVEN_ARTIFACTS_VERSION}/compiler-${MAVEN_ARTIFACTS_VERSION}.jar ${MANDREL_HOME}/lib/jvmci/graal.jar
cp ${MAVEN_REPO}/org/graalvm/compiler/compiler/${MAVEN_ARTIFACTS_VERSION}/compiler-${MAVEN_ARTIFACTS_VERSION}-sources.jar ${MANDREL_HOME}/lib/jvmci/graal.src.zip
mkdir ${MANDREL_HOME}/lib/truffle
cp ${MAVEN_REPO}/org/graalvm/truffle/truffle-api/${MAVEN_ARTIFACTS_VERSION}/truffle-api-${MAVEN_ARTIFACTS_VERSION}.jar ${MANDREL_HOME}/lib/truffle/truffle-api.jar
cp ${MAVEN_REPO}/org/graalvm/truffle/truffle-api/${MAVEN_ARTIFACTS_VERSION}/truffle-api-${MAVEN_ARTIFACTS_VERSION}-sources.jar ${MANDREL_HOME}/lib/truffle/truffle-api.src.zip
### Docs
cp ${MANDREL_REPO}/LICENSE ${MANDREL_HOME}
cp ${MANDREL_REPO}/THIRD_PARTY_LICENSE.txt ${MANDREL_HOME}
if [ -e ${MANDREL_REPO}/README-Mandrel.md ]
then
cp ${MANDREL_REPO}/README-Mandrel.md ${MANDREL_HOME}/README.md
else
cp ${MANDREL_REPO}/README.md ${MANDREL_HOME}/README.md
fi
cp ${MANDREL_REPO}/SECURITY.md ${MANDREL_HOME}
### Copy native bits
mkdir -p ${MANDREL_HOME}/lib/svm/clibraries/${PLATFORM}-amd64/include
cp ${MANDREL_REPO}/substratevm/src/com.oracle.svm.native.libchelper/include/amd64cpufeatures.h ${MANDREL_HOME}/lib/svm/clibraries/${PLATFORM}-amd64/include
cp ${MANDREL_REPO}/substratevm/src/com.oracle.svm.native.libchelper/include/aarch64cpufeatures.h ${MANDREL_HOME}/lib/svm/clibraries/${PLATFORM}-amd64/include
cp ${MANDREL_REPO}/substratevm/src/com.oracle.svm.libffi/include/svm_libffi.h ${MANDREL_HOME}/lib/svm/clibraries/${PLATFORM}-amd64/include
cp ${MANDREL_REPO}/truffle/src/com.oracle.truffle.nfi.native/include/trufflenfi.h ${MANDREL_HOME}/lib/svm/clibraries/${PLATFORM}-amd64/include
cp ${MANDREL_REPO}/substratevm/mxbuild/${PLATFORM}-amd64/src/com.oracle.svm.native.libchelper/amd64/liblibchelper.a ${MANDREL_HOME}/lib/svm/clibraries/${PLATFORM}-amd64
cp ${MANDREL_REPO}/substratevm/mxbuild/${PLATFORM}-amd64/src/com.oracle.svm.native.jvm.posix/amd64/libjvm.a ${MANDREL_HOME}/lib/svm/clibraries/${PLATFORM}-amd64
mkdir ${MANDREL_HOME}/lib/svm/bin
cp ${MANDREL_REPO}/sdk/mxbuild/${PLATFORM}-amd64/native-image.image-bash/native-image ${MANDREL_HOME}/lib/svm/bin/native-image
## Create symbolic link in bin
ln -s ../lib/svm/bin/native-image ${MANDREL_HOME}/bin/native-image
### Fix native-image launcher
sed -i -e "s!EnableJVMCI!EnableJVMCI -Dorg.graalvm.version=\"${MANDREL_VERSION}\" -Dorg.graalvm.config=\"(Mandrel Distribution)\" --upgrade-module-path \${location}/../../jvmci/graal.jar --add-modules \"org.graalvm.truffle,org.graalvm.sdk\" --module-path \${location}/../../truffle/truffle-api.jar:\${location}/../../jvmci/graal-sdk.jar!" \
"${MANDREL_HOME}/lib/svm/bin/native-image"
## Explicitly export jdk.vm.ci.code to jdk.internal.vm.compiler
sed -i -e "s!JDK9Plus'!JDK9Plus' -J--add-exports=jdk.internal.vm.ci/jdk.vm.ci.code=jdk.internal.vm.compiler!" \
"${MANDREL_HOME}/lib/svm/bin/native-image"
### Create tarball
case $TAR_SUFFIX in
tar.gz ) tar -czf "${ARCHIVE_NAME}" -C $(dirname ${MANDREL_HOME}) $(basename ${MANDREL_HOME}) ;;
tarxz ) Z_OPT=-9e tar cJf "${ARCHIVE_NAME}" -C $(dirname ${MANDREL_HOME}) $(basename ${MANDREL_HOME}) ;;
esac