1 |
1 |
# Copyright 1999-2022 Gentoo Authors
|
2 |
2 |
# Distributed under the terms of the GNU General Public License v2
|
3 |
3 |
|
4 |
|
# Skeleton command:
|
5 |
|
# java-ebuilder --generate-ebuild --workdir . --pom antlr-runtime-3.5.3.pom --download-uri https://repo1.maven.org/maven2/org/antlr/antlr-runtime/3.5.3/antlr-runtime-3.5.3-sources.jar --slot 3.5 --keywords "~amd64 ~arm ~arm64~ppc64 ~x86" --ebuild antlr-runtime-3.5.3.ebuild
|
6 |
|
|
7 |
4 |
EAPI=8
|
8 |
5 |
|
9 |
|
JAVA_PKG_IUSE="doc source"
|
10 |
|
MAVEN_ID="org.antlr:antlr-runtime:3.5.3"
|
|
6 |
JAVA_PKG_IUSE="doc source test"
|
|
7 |
MAVEN_ID="org.antlr:antlr4-runtime:4.9.3"
|
|
8 |
JAVA_TESTING_FRAMEWORKS="junit-4"
|
11 |
9 |
|
12 |
10 |
inherit java-pkg-2 java-pkg-simple
|
13 |
11 |
|
14 |
|
DESCRIPTION="ANTLR 3 Runtime"
|
15 |
|
HOMEPAGE="https://www.antlr3.org/"
|
16 |
|
SRC_URI="https://repo1.maven.org/maven2/org/antlr/${PN}/${PV}/${P}-sources.jar"
|
|
12 |
MY_PN="${PN%-runtime}"
|
|
13 |
MY_P="${MY_PN}-${PV}"
|
|
14 |
|
|
15 |
DESCRIPTION="ANTLR 4 Runtime"
|
|
16 |
HOMEPAGE="https://www.antlr.org/"
|
|
17 |
SRC_URI="https://github.com/antlr/antlr4/archive/${PV}.tar.gz -> ${MY_P}.tar.gz"
|
17 |
18 |
|
18 |
19 |
LICENSE="BSD"
|
19 |
|
SLOT="3.5"
|
|
20 |
SLOT="4"
|
20 |
21 |
KEYWORDS="amd64 ~arm arm64 ppc64 x86"
|
21 |
22 |
|
22 |
|
# Common dependencies
|
23 |
|
# POM: ${P}.pom
|
24 |
|
# org.antlr:stringtemplate:3.2.1 -> >=dev-java/stringtemplate-3.2.1:0
|
|
23 |
DEPEND="
|
|
24 |
>=virtual/jdk-1.8:*
|
|
25 |
test? (
|
|
26 |
~dev-java/antlr-tool-${PV}:${SLOT}
|
|
27 |
dev-java/jol-core:0
|
|
28 |
)
|
|
29 |
"
|
25 |
30 |
|
26 |
|
CP_DEPEND="
|
27 |
|
>=dev-java/stringtemplate-3.2.1:0
|
|
31 |
RDEPEND="
|
|
32 |
>=virtual/jre-1.8:*
|
28 |
33 |
"
|
29 |
34 |
|
30 |
|
DEPEND="${CP_DEPEND}
|
31 |
|
>=virtual/jdk-1.8:*"
|
|
35 |
S="${WORKDIR}/${MY_PN}4-${PV}"
|
32 |
36 |
|
33 |
|
RDEPEND="${CP_DEPEND}
|
34 |
|
>=virtual/jre-1.8:*"
|
|
37 |
JAVA_SRC_DIR="runtime/Java/src"
|
35 |
38 |
|
36 |
|
BDEPEND="app-arch/unzip"
|
|
39 |
JAVA_TEST_GENTOO_CLASSPATH="
|
|
40 |
junit-4
|
|
41 |
antlr-tool-${SLOT}
|
|
42 |
jol-core
|
|
43 |
"
|
|
44 |
JAVA_TEST_SRC_DIR=(
|
|
45 |
runtime-testsuite/test
|
|
46 |
runtime-testsuite/annotations
|
|
47 |
)
|
|
48 |
JAVA_TEST_RESOURCE_DIRS=(
|
|
49 |
runtime-testsuite/resources
|
|
50 |
)
|
|
51 |
|
|
52 |
src_prepare() {
|
|
53 |
java-pkg_clean
|
|
54 |
eapply "${FILESDIR}/${PV}-test-fixes.patch"
|
|
55 |
java-pkg-2_src_prepare
|
|
56 |
}
|
|
57 |
|
|
58 |
src_test() {
|
|
59 |
# Build classpath for tests
|
|
60 |
# The JAR created during src_compile must appear in the classpath *before*
|
|
61 |
# any dependencies to ensure that *it* is the JAR being tested; otherwise,
|
|
62 |
# because the test suite depends on antlr-tool, which depends on this
|
|
63 |
# package, the copy of this package's JAR installed on the system would be
|
|
64 |
# tested instead when it appears earlier in the classpath, which might
|
|
65 |
# cause test failures when the version being built differs from the version
|
|
66 |
# already installed on the system, like https://bugs.gentoo.org/834138
|
|
67 |
local CP="${S}/${JAVA_JAR_FILENAME}"
|
|
68 |
local test_dep res_dir
|
|
69 |
for test_dep in ${JAVA_TEST_GENTOO_CLASSPATH}; do
|
|
70 |
CP+=":$(java-pkg_getjars --with-dependencies "${test_dep}")"
|
|
71 |
done
|
|
72 |
for res_dir in "${JAVA_TEST_RESOURCE_DIRS[@]}"; do
|
|
73 |
CP+=":${res_dir}"
|
|
74 |
done
|
|
75 |
|
|
76 |
pushd "${JAVA_TEST_SRC_DIR[0]}" > /dev/null ||
|
|
77 |
die "Failed to enter test source directory for ${PN}"
|
|
78 |
|
|
79 |
einfo "Removing tests for non-Java runtimes ..."
|
|
80 |
find org/antlr/v4/test/runtime/* -maxdepth 0 -type d \
|
|
81 |
-not -name category -not -name descriptors -not -name java \
|
|
82 |
-exec einfo " {}" \; -exec rm -r "{}" + ||
|
|
83 |
die "Failed to remove tests for non-Java runtimes"
|
|
84 |
|
|
85 |
einfo "Generating ANTLR 4 parsers for tests ..."
|
|
86 |
local java_exe="$(java-config -J)"
|
|
87 |
local g4_files=( $(find * -name "*.g4") )
|
|
88 |
local file
|
|
89 |
for file in "${g4_files[@]}"; do
|
|
90 |
local java_pkg="${file%/*.g4}"
|
|
91 |
java_pkg="${java_pkg//\//.}"
|
|
92 |
"${java_exe}" -cp "${CP}" org.antlr.v4.Tool \
|
|
93 |
-visitor -package "${java_pkg}" "${file}" ||
|
|
94 |
die "Failed to generate ANTLR 4 parser from ${file}"
|
|
95 |
done
|
|
96 |
|
|
97 |
# Create a list of tests to run
|
|
98 |
# https://github.com/antlr/antlr4/blob/4.9.3/runtime-testsuite/pom.xml#L100
|
|
99 |
# Excluding classes with "No runnable methods"
|
|
100 |
local TESTS=$(find * -type f -name "Test*.java" \
|
|
101 |
-not -name "TestContext.java" \
|
|
102 |
-not -name "TestOutputReading.java"
|
|
103 |
)
|
|
104 |
TESTS="${TESTS//.java}"
|
|
105 |
TESTS="${TESTS//\//.}"
|
|
106 |
|
|
107 |
popd > /dev/null || die "Failed to leave test source directory for ${PN}"
|
|
108 |
|
|
109 |
local classes="target/classes"
|
|
110 |
|
|
111 |
# Compile the annotation processor of @CommentHasStringValue
|
|
112 |
# before the test sources (requires tools.jar)
|
|
113 |
ejavac -d "${classes}" -cp "${CP}:$(java-config -t)" \
|
|
114 |
$(find runtime-testsuite/{annotations,processors} -name "*.java")
|
|
115 |
local processor_cp="${classes}:runtime-testsuite/processors/resources"
|
|
116 |
|
|
117 |
# Compile Java test sources, and process @CommentHasStringValue
|
|
118 |
# annotations at the same time
|
|
119 |
local javac_extra_args=()
|
|
120 |
if ver_test "$(java-config -g PROVIDES_VERSION)" -ge 17; then
|
|
121 |
javac_extra_args+=(
|
|
122 |
-J--add-opens=jdk.compiler/com.sun.tools.javac.{main,model,tree,util}=ALL-UNNAMED
|
|
123 |
)
|
|
124 |
fi
|
|
125 |
ejavac -d "${classes}" -cp "${CP}:${processor_cp}" \
|
|
126 |
"${javac_extra_args[@]}" \
|
|
127 |
$(find "${JAVA_TEST_SRC_DIR[@]}" -name "*.java")
|
37 |
128 |
|
38 |
|
S="${WORKDIR}"
|
|
129 |
ejunit4 -classpath "${classes}:${CP}" ${TESTS}
|
|
130 |
}
|