Skip to content

Commit

Permalink
Update the _java attribute to use current_java_runtime and get rid of…
Browse files Browse the repository at this point in the history
… warnings.

The current code with more recent versions of Bazel causes a warning about
using the deprecated target '@local_jdk//:java' and to use use
@bazel_tools//tools/jdk:current_java_runtime instead (see
bazelbuild/bazel#5594).

Resolves higherkindness#122
  • Loading branch information
James Judd committed May 7, 2019
1 parent 250d883 commit 0332e8a
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 15 deletions.
13 changes: 10 additions & 3 deletions rules/common/private/utils.bzl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("@bazel_skylib//lib:dicts.bzl", _dicts = "dicts")
load("@bazel_skylib//lib:dicts.bzl", "dicts")
load("@bazel_skylib//lib:paths.bzl", "paths")

#
# Helper utilities
Expand Down Expand Up @@ -60,9 +61,15 @@ def write_launcher(
template = ctx.file._java_stub_template
runfiles_enabled = False

java_path = str(ctx.attr._jdk[java_common.JavaRuntimeInfo].java_executable_runfiles_path)
if paths.is_absolute(java_path):
javabin = java_path
else:
javabin = "$JAVA_RUNFILES/{}/{}".format(ctx.workspace_name, ctx.attr._jdk[java_common.JavaRuntimeInfo].java_executable_runfiles_path)

base_substitutions = {
"%classpath%": classpath,
"%javabin%": "JAVABIN=\"$JAVA_RUNFILES/{}/{}\"\n{}".format(ctx.workspace_name, ctx.executable._java.short_path, extra),
"%javabin%": "JAVABIN=\"{}\"\n{}".format(javabin, extra),
"%jvm_flags%": jvm_flags,
"%needs_runfiles%": "1" if runfiles_enabled else "",
"%runfiles_manifest_only%": "1" if runfiles_enabled else "",
Expand Down Expand Up @@ -96,7 +103,7 @@ def write_launcher(
ctx.actions.expand_template(
template = template,
output = output,
substitutions = _dicts.add(base_substitutions, more_substitutions),
substitutions = dicts.add(base_substitutions, more_substitutions),
is_executable = True,
)

Expand Down
3 changes: 1 addition & 2 deletions rules/private/phases/phase_binary_launcher.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ def phase_binary_launcher(ctx, g):
runfiles = ctx.runfiles(
files = inputs + files,
transitive_files = depset(
direct = [ctx.executable._java],
order = "default",
transitive = [g.javainfo.java_info.transitive_runtime_deps],
transitive = [ctx.attr._jdk[java_common.JavaRuntimeInfo].files, g.javainfo.java_info.transitive_runtime_deps],
),
collect_default = True,
),
Expand Down
6 changes: 3 additions & 3 deletions rules/private/phases/phase_bootstrap_compile.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ def phase_bootstrap_compile(ctx, g):
fail("source jars supported for bootstrap_scala rules")

inputs = depset(
[ctx.executable._java] + ctx.files.srcs,
transitive = [g.classpaths.compile, g.classpaths.compiler],
ctx.files.srcs,
transitive = [ctx.attr._jdk[java_common.JavaRuntimeInfo].files, g.classpaths.compile, g.classpaths.compiler],
)

compiler_classpath = ":".join([f.path for f in g.classpaths.compiler.to_list()])
Expand All @@ -43,7 +43,7 @@ def phase_bootstrap_compile(ctx, g):
|
|{jar_creator} {output_jar} tmp/classes 2> /dev/null
|""".format(
java = ctx.executable._java.path,
java = ctx.attr._jdk[java_common.JavaRuntimeInfo].java_executable_exec_path,
jar_creator = ctx.executable._jar_creator.path,
compiler_classpath = compiler_classpath,
compile_classpath = compile_classpath,
Expand Down
12 changes: 6 additions & 6 deletions rules/scala.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ _compile_private_attributes = {

# TODO: push java and jar_creator into a provider for the
# bootstrap compile phase
"_java": attr.label(
default = Label("@bazel_tools//tools/jdk:java"),
executable = True,
"_jdk": attr.label(
default = Label("@bazel_tools//tools/jdk:current_java_runtime"),
providers = [java_common.JavaRuntimeInfo],
cfg = "host",
),
"_jar_creator": attr.label(
Expand Down Expand Up @@ -167,9 +167,9 @@ _runtime_attributes = {
}

_runtime_private_attributes = {
"_java": attr.label(
default = Label("@bazel_tools//tools/jdk:java"),
executable = True,
"_jdk": attr.label(
default = Label("@bazel_tools//tools/jdk:current_java_runtime"),
providers = [java_common.JavaRuntimeInfo],
cfg = "host",
),
"_java_stub_template": attr.label(
Expand Down
2 changes: 1 addition & 1 deletion rules/scala/private/repl.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def scala_repl_implementation(ctx):
runfiles = ctx.runfiles(
collect_default = True,
collect_data = True,
files = [ctx.executable._java],
files = [ctx.attr._jdk[java_common.JavaRuntimeInfo].java_executable_exec_path],
transitive_files = files,
),
),
Expand Down

0 comments on commit 0332e8a

Please sign in to comment.