-
Notifications
You must be signed in to change notification settings - Fork 4
/
BUILD.bazel
151 lines (142 loc) · 3.51 KB
/
BUILD.bazel
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
149
150
151
java_binary(
name = "HelloFromJava",
srcs = ["src/test/java/com/example/HelloFromJava.java"],
create_executable = False,
)
# A library that wraps a Java method into a C++ method by starting a JVM and
# executing the method in it. It has access to the usual jni.h header via the
# dependency on @fmeum_rules_jni//jni, but does not require any code specific
# to rules_jni.
cc_library(
name = "hello_from_java",
srcs = ["hello_from_java.cpp"],
hdrs = ["hello_from_java.h"],
data = [
":HelloFromJava_deploy.jar",
],
deps = [
"@bazel_tools//tools/cpp/runfiles",
"@fmeum_rules_jni//jni",
],
)
# A program that uses :hello_from_java. It depends on
# @fmeum_rules_jni//jni:libjvm to link in the logic that finds and loads libjvm
# at runtime. The only rules_jni-specific part of the code is a call to
# rules_jni_init, which ensures that rules_jni can use the Bazel-provided JDK.
cc_library(
name = "libjvm_test_lib",
srcs = ["libjvm_test.cpp"],
deps = [
":hello_from_java",
"@bazel_tools//tools/cpp/runfiles",
"@fmeum_rules_jni//jni:libjvm",
],
)
cc_library(
name = "libjvm_release_test_lib",
srcs = ["libjvm_test.cpp"],
deps = [
":hello_from_java",
"@bazel_tools//tools/cpp/runfiles",
"@fmeum_rules_jni//jni:libjvm_lite",
],
)
cc_test(
name = "hermetic_test",
size = "small",
env = {
"HERMETIC": "1",
# Setting PATH in env directly does not work, so we let the test
# override it with this value.
"PATH_OVERRIDE": "",
"RULES_JNI_TRACE": "1",
},
deps = [
":libjvm_test_lib",
],
)
cc_test(
name = "java_home_release_test",
size = "small",
env = {
# Setting PATH in env directly does not work, so we let the test
# override it with this value.
"PATH_OVERRIDE": "",
"RULES_JNI_TRACE": "1",
},
env_inherit = [
"JAVA_HOME",
],
tags = [
"no-coverage",
],
deps = [
":libjvm_release_test_lib",
],
)
cc_test(
name = "java_home_test",
size = "small",
env = {
# Setting PATH in env directly does not work, so we let the test
# override it with this value.
"PATH_OVERRIDE": "",
"RULES_JNI_TRACE": "1",
},
env_inherit = [
"JAVA_HOME",
],
deps = [
":libjvm_test_lib",
],
)
cc_test(
name = "path_release_test",
size = "small",
env = {
"RULES_JNI_TRACE": "1",
},
env_inherit = [
"PATH",
],
tags = [
"no-coverage",
],
deps = [
":libjvm_release_test_lib",
],
)
cc_test(
name = "path_test",
size = "small",
env = {
"RULES_JNI_TRACE": "1",
},
env_inherit = [
"PATH",
],
deps = [
":libjvm_test_lib",
],
)
cc_test(
name = "hermetic_release_failure_test",
size = "small",
srcs = ["hermetic_release_failure_test.c"],
env = {
"HERMETIC": "1",
# Setting PATH in env directly does not work, so we let the test
# override it with this value.
"PATH_OVERRIDE": "",
"RULES_JNI_TRACE": "1",
},
target_compatible_with = select({
# Skip on macOS since the /usr/libexec/java_home fallback means that
# a JDK will still be found without PATH and JAVA_HOME.
"@platforms//os:macos": ["@platforms//:incompatible"],
"//conditions:default": [],
}),
deps = [
"@fmeum_rules_jni//jni:libjvm_lite",
],
)