Skip to content

Commit

Permalink
Fix warnings with Bazel 0.19
Browse files Browse the repository at this point in the history
Using :java and :jar now results in warnings like:

```
in alias rule @bazel_tools//tools/jdk:jar: target
'@bazel_tools//tools/jdk:jar' depends on deprecated target
'@local_jdk//:jar': Don't depend on targets in the JDK workspace; use
@bazel_tools//tools/jdk:current_java_runtime instead (see
bazelbuild/bazel#5594)
```

This approach is based on the following commit to the Bazel source:
bazelbuild/bazel@200819d

:current_java_runtime appears to have been present since ~0.10.0, so
this shouldn't cause any compatibility issues.
  • Loading branch information
drigz committed Oct 30, 2018
1 parent e8a2d11 commit 5e454dc
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions openapi/openapi.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ def _comma_separated_pairs(pairs):
])

def _new_generator_command(ctx, gen_dir, rjars):
gen_cmd = ctx.executable._java.path
java_runtime = ctx.attr._jdk[java_common.JavaRuntimeInfo]
gen_cmd = str(java_runtime.java_executable_exec_path)

gen_cmd += " -cp {cli_jar}:{jars} io.swagger.codegen.SwaggerCodegen generate -i {spec} -l {language} -o {output}".format(
java = ctx.executable._java.path,
cli_jar = ctx.file._codegen_cli.path,
jars = ":".join([j.path for j in rjars]),
spec = ctx.file.spec.path,
Expand Down Expand Up @@ -65,6 +65,9 @@ def _new_generator_command(ctx, gen_dir, rjars):
return gen_cmd

def _impl(ctx):
java_runtime = ctx.attr._jdk[java_common.JavaRuntimeInfo]
jar_path = "%s/bin/jar" % java_runtime.java_home

jars = _collect_jars(ctx.attr.deps)
(cjars, rjars) = (jars.compiletime, jars.runtime)
gen_dir = "{out}-tmp".format(
Expand All @@ -80,14 +83,13 @@ def _impl(ctx):
gen_dir=gen_dir
),
"{jar} cMf {target} -C {srcs} .".format(
jar=ctx.file._jar.path,
jar=jar_path,
target=ctx.outputs.codegen.path,
srcs=gen_dir
)
]

inputs = ctx.files._jdk + [
ctx.executable._java,
ctx.file._codegen_cli,
ctx.file.spec
] + list(cjars) + list(rjars)
Expand Down Expand Up @@ -149,18 +151,9 @@ openapi_gen = rule(
"additional_properties": attr.string_dict(),
"system_properties": attr.string_dict(),
"type_mappings": attr.string_dict(),
"_java": attr.label(
executable = True,
cfg = "host",
default = Label("@bazel_tools//tools/jdk:java"),
single_file = True,
allow_files = True,
),
"_jdk": attr.label(default=Label("//tools/defaults:jdk"), allow_files=True),
"_jar": attr.label(
default=Label("@bazel_tools//tools/jdk:jar"),
allow_files=True,
single_file=True
"_jdk": attr.label(
default = Label("@bazel_tools//tools/jdk:current_java_runtime"),
providers = [java_common.JavaRuntimeInfo],
),
"_codegen_cli": attr.label(
cfg = "host",
Expand Down

0 comments on commit 5e454dc

Please sign in to comment.