Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up jmh rule a bit #811

Merged
merged 1 commit into from
Aug 12, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions jmh/jmh.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,22 @@ def jmh_repositories(maven_servers = ["http://central.maven.org/maven2"]):
actual = "@io_bazel_rules_scala_org_apache_commons_commons_math3//jar",
)

def _scala_construct_runtime_classpath(deps):
files = []
[files.append(target[JavaInfo].transitive_runtime_deps) for target in deps if JavaInfo in target]

return depset(transitive = files)

def _scala_generate_benchmark(ctx):
class_jar = ctx.attr.src.scala.outputs.class_jar
classpath = _scala_construct_runtime_classpath([ctx.attr.src])
# we use required providers to ensure JavaInfo exists
info = ctx.attr.src[JavaInfo]
# TODO, if we emit more than one jar, which scala_library does not,
# this might fail. We could possibly extend the BenchmarkGenerator
# to accept more than one jar to scan, and then allow multiple labels
# in ctx.attr.src
outs = info.outputs.jars
if len(outs) != 1:
print("expected exactly 1 output jar in: " + ctx.label)
# just try to take the first one and see if that works
class_jar = outs[0].class_jar
classpath = info.transitive_runtime_deps
ctx.actions.run(
outputs = [ctx.outputs.src_jar, ctx.outputs.resource_jar],
inputs = depset([class_jar], transitive = [classpath]),
inputs = classpath,
executable = ctx.executable._generator,
arguments = [ctx.attr.generator_type] + [
f.path
Expand All @@ -99,7 +103,7 @@ def _scala_generate_benchmark(ctx):
scala_generate_benchmark = rule(
implementation = _scala_generate_benchmark,
attrs = {
"src": attr.label(allow_single_file = True, mandatory = True),
"src": attr.label(mandatory = True, providers = [[JavaInfo]]),
"generator_type": attr.string(
default = "reflection",
mandatory = False,
Expand Down