Skip to content

Commit 7fd142c

Browse files
authored
Clean up jmh rule a bit (#811)
1 parent b30f2cb commit 7fd142c

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

jmh/jmh.bzl

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,18 +75,22 @@ def jmh_repositories(maven_servers = ["http://central.maven.org/maven2"]):
7575
actual = "@io_bazel_rules_scala_org_apache_commons_commons_math3//jar",
7676
)
7777

78-
def _scala_construct_runtime_classpath(deps):
79-
files = []
80-
[files.append(target[JavaInfo].transitive_runtime_deps) for target in deps if JavaInfo in target]
81-
82-
return depset(transitive = files)
83-
8478
def _scala_generate_benchmark(ctx):
85-
class_jar = ctx.attr.src.scala.outputs.class_jar
86-
classpath = _scala_construct_runtime_classpath([ctx.attr.src])
79+
# we use required providers to ensure JavaInfo exists
80+
info = ctx.attr.src[JavaInfo]
81+
# TODO, if we emit more than one jar, which scala_library does not,
82+
# this might fail. We could possibly extend the BenchmarkGenerator
83+
# to accept more than one jar to scan, and then allow multiple labels
84+
# in ctx.attr.src
85+
outs = info.outputs.jars
86+
if len(outs) != 1:
87+
print("expected exactly 1 output jar in: " + ctx.label)
88+
# just try to take the first one and see if that works
89+
class_jar = outs[0].class_jar
90+
classpath = info.transitive_runtime_deps
8791
ctx.actions.run(
8892
outputs = [ctx.outputs.src_jar, ctx.outputs.resource_jar],
89-
inputs = depset([class_jar], transitive = [classpath]),
93+
inputs = classpath,
9094
executable = ctx.executable._generator,
9195
arguments = [ctx.attr.generator_type] + [
9296
f.path
@@ -99,7 +103,7 @@ def _scala_generate_benchmark(ctx):
99103
scala_generate_benchmark = rule(
100104
implementation = _scala_generate_benchmark,
101105
attrs = {
102-
"src": attr.label(allow_single_file = True, mandatory = True),
106+
"src": attr.label(mandatory = True, providers = [[JavaInfo]]),
103107
"generator_type": attr.string(
104108
default = "reflection",
105109
mandatory = False,

0 commit comments

Comments
 (0)