bazel: Fix java tests/samples run

* remove: code_samples_java_test
* Fix jvm library path on windows
This commit is contained in:
Corentin Le Molgat
2023-03-01 18:32:07 +01:00
parent 76b72ce5fa
commit 1e0f4027e2
10 changed files with 48 additions and 134 deletions

View File

@@ -33,22 +33,18 @@ def code_sample_cc(name):
)
def code_sample_java(name):
native.java_binary(
name = name + "_java",
native.java_test(
name = name + "_java_test",
size = "small",
srcs = [name + ".java"],
main_class = "com.google.ortools.algorithms.samples." + name,
test_class = "com.google.ortools.algorithms.samples." + name,
jvm_flags = select({
"@platforms//os:windows": ["-Djava.library.path=../../../../java/com/google/ortools"],
"//conditions:default": ["-Djava.library.path=ortools/java/com/google/ortools"],
}),
deps = [
"//ortools/algorithms/java:knapsacksolver",
"//ortools/java/com/google/ortools:Loader",
],
)
native.sh_test(
name = name + "_java_test",
size = "small",
srcs = ["code_samples_java_test.sh"],
args = [name],
data = [
":" + name + "_java",
],
)

View File

@@ -1,21 +0,0 @@
#!/usr/bin/env bash
# Copyright 2010-2022 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
declare -r DIR="${TEST_SRCDIR}/com_google_ortools/ortools/algorithms/samples"
function test::ortools::code_samples_algorithms_java() {
"${DIR}/$1_java"
}
test::ortools::code_samples_algorithms_java $1

View File

@@ -38,6 +38,10 @@ java_junit5_test(
size= "small",
srcs = ["FlowTest.java"],
test_class = "com.google.ortools.graph.FlowTest",
jvm_flags = select({
"@platforms//os:windows": ["-Djava.library.path=../../../../java/com/google/ortools"],
"//conditions:default": ["-Djava.library.path=ortools/java/com/google/ortools"],
}),
deps = [
"//ortools/java/com/google/ortools:Loader",
"//ortools/graph/java:graph",

View File

@@ -83,22 +83,18 @@ def code_sample_cc_py(name):
code_sample_py(name = name)
def code_sample_java(name):
native.java_binary(
name = name + "_java",
native.java_test(
name = name + "_java_test",
size = "small",
srcs = [name + ".java"],
main_class = "com.google.ortools.graph.samples." + name,
test_class = "com.google.ortools.graph.samples." + name,
jvm_flags = select({
"@platforms//os:windows": ["-Djava.library.path=../../../../java/com/google/ortools"],
"//conditions:default": ["-Djava.library.path=ortools/java/com/google/ortools"],
}),
deps = [
"//ortools/graph/java:graph",
"//ortools/java/com/google/ortools:Loader",
],
)
native.sh_test(
name = name + "_java_test",
size = "small",
srcs = ["code_samples_java_test.sh"],
args = [name],
data = [
":" + name + "_java",
],
)

View File

@@ -1,21 +0,0 @@
#!/usr/bin/env bash
# Copyright 2010-2022 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
declare -r DIR="${TEST_SRCDIR}/com_google_ortools/ortools/graph/samples"
function test::ortools::code_samples_graph_java() {
"${DIR}/$1_java"
}
test::ortools::code_samples_graph_java $1

View File

@@ -69,23 +69,19 @@ def code_sample_py(name):
)
def code_sample_java(name):
native.java_binary(
name = name + "_java",
native.java_test(
name = name + "_java_test",
size = "small",
srcs = [name + ".java"],
main_class = "com.google.ortools.linearsolver.samples." + name,
test_class = "com.google.ortools.linearsolver.samples." + name,
jvm_flags = select({
"@platforms//os:windows": ["-Djava.library.path=../../../../java/com/google/ortools"],
"//conditions:default": ["-Djava.library.path=ortools/java/com/google/ortools"],
}),
deps = [
"//ortools/linear_solver/java:modelbuilder",
"//ortools/java/com/google/ortools/modelbuilder",
"//ortools/java/com/google/ortools:Loader",
],
)
native.sh_test(
name = name + "_java_test",
size = "small",
srcs = ["code_samples_java_test.sh"],
args = [name],
data = [
":" + name + "_java",
],
)

View File

@@ -1,22 +0,0 @@
#!/usr/bin/env bash
# Copyright 2010-2022 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
declare -r DIR="${TEST_SRCDIR}/com_google_ortools/ortools/linear_solver/samples"
function test::ortools::code_samples_linear_solver_java() {
"${DIR}/$1_java"
}
test::ortools::code_samples_linear_solver_java $1

View File

@@ -45,6 +45,10 @@ java_junit5_test(
name = "CpModelTest",
srcs = ["CpModelTest.java"],
test_class = "com.google.ortools.sat.CpModelTest",
jvm_flags = select({
"@platforms//os:windows": ["-Djava.library.path=../../../../java/com/google/ortools"],
"//conditions:default": ["-Djava.library.path=ortools/java/com/google/ortools"],
}),
deps = [
"//ortools/java/com/google/ortools:Loader",
"//ortools/java/com/google/ortools/sat",
@@ -65,6 +69,10 @@ java_junit5_test(
name = "CpSolverTest",
srcs = ["CpSolverTest.java"],
test_class = "com.google.ortools.sat.CpSolverTest",
jvm_flags = select({
"@platforms//os:windows": ["-Djava.library.path=../../../../java/com/google/ortools"],
"//conditions:default": ["-Djava.library.path=ortools/java/com/google/ortools"],
}),
deps = [
"//ortools/java/com/google/ortools:Loader",
"//ortools/java/com/google/ortools/sat",
@@ -85,6 +93,10 @@ java_junit5_test(
name = "LinearExprTest",
srcs = ["LinearExprTest.java"],
test_class = "com.google.ortools.sat.LinearExprTest",
jvm_flags = select({
"@platforms//os:windows": ["-Djava.library.path=../../../../java/com/google/ortools"],
"//conditions:default": ["-Djava.library.path=ortools/java/com/google/ortools"],
}),
deps = [
"//ortools/java/com/google/ortools:Loader",
"//ortools/java/com/google/ortools/sat",

View File

@@ -75,10 +75,16 @@ def code_sample_cc_py(name):
code_sample_py(name = name)
def code_sample_java(name):
native.java_binary(
name = name + "_java",
native.java_test(
name = name + "_java_test",
size = "small",
srcs = [name + ".java"],
main_class = "com.google.ortools.sat.samples." + name,
test_class = "com.google.ortools.sat.samples." + name,
jvm_flags = select({
"@platforms//os:windows": ["-Djava.library.path=../../../../java/com/google/ortools"],
"//conditions:default": ["-Djava.library.path=ortools/java/com/google/ortools"],
}),
deps = [
"//ortools/sat/java:sat",
"//ortools/java/com/google/ortools:Loader",
@@ -88,13 +94,3 @@ def code_sample_java(name):
"//ortools/util/java:sorted_interval_list",
],
)
native.sh_test(
name = name + "_java_test",
size = "small",
srcs = ["code_samples_java_test.sh"],
args = [name],
data = [
":" + name + "_java",
],
)

View File

@@ -1,22 +0,0 @@
#!/usr/bin/env bash
# Copyright 2010-2022 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
declare -r DIR="${TEST_SRCDIR}/com_google_ortools/ortools/sat/samples"
function test::ortools::code_samples_sat_java() {
"${DIR}/$1_java"
}
test::ortools::code_samples_sat_java $1