From bd5da15e472f5c4654898f715c8832cc1d530173 Mon Sep 17 00:00:00 2001 From: James Judd Date: Tue, 7 May 2019 16:22:37 -0600 Subject: [PATCH] Update the _java attribute to use current_java_runtime and get rid of 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 https://github.com/bazelbuild/bazel/issues/5594). Resolves #122 --- rules/common/private/utils.bzl | 13 ++++++++++--- rules/private/phases/phase_binary_launcher.bzl | 3 +-- rules/private/phases/phase_bootstrap_compile.bzl | 6 +++--- rules/scala.bzl | 12 ++++++------ rules/scala/private/repl.bzl | 2 +- 5 files changed, 21 insertions(+), 15 deletions(-) diff --git a/rules/common/private/utils.bzl b/rules/common/private/utils.bzl index 655d6eb5..7da75fbd 100644 --- a/rules/common/private/utils.bzl +++ b/rules/common/private/utils.bzl @@ -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 @@ -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 "", @@ -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, ) diff --git a/rules/private/phases/phase_binary_launcher.bzl b/rules/private/phases/phase_binary_launcher.bzl index 6e175aac..dab2a918 100644 --- a/rules/private/phases/phase_binary_launcher.bzl +++ b/rules/private/phases/phase_binary_launcher.bzl @@ -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, ), diff --git a/rules/private/phases/phase_bootstrap_compile.bzl b/rules/private/phases/phase_bootstrap_compile.bzl index c4534d3d..b50ab072 100644 --- a/rules/private/phases/phase_bootstrap_compile.bzl +++ b/rules/private/phases/phase_bootstrap_compile.bzl @@ -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()]) @@ -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, diff --git a/rules/scala.bzl b/rules/scala.bzl index 610e2a80..4de80e01 100644 --- a/rules/scala.bzl +++ b/rules/scala.bzl @@ -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( @@ -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( diff --git a/rules/scala/private/repl.bzl b/rules/scala/private/repl.bzl index f3d346a9..00291bef 100644 --- a/rules/scala/private/repl.bzl +++ b/rules/scala/private/repl.bzl @@ -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, ), ),