Skip to content

Commit

Permalink
Retire some pre-skylark machinery for accessing the contents of java_…
Browse files Browse the repository at this point in the history
…toolchain

and replace the only use with java_common.default_javac_opts.

PiperOrigin-RevId: 179571481
  • Loading branch information
cushon authored and Copybara-Service committed Dec 19, 2017
1 parent 741dbc0 commit 56d5ba1
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 247 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ package(
default_visibility = ["//src:__subpackages__"],
)

load(":build_defs.bzl", "default_javacopts")

# Exports the canonical javac bootclasspath artifact locations
genrule(
name = "javac-bootclasspath-locations",
Expand Down Expand Up @@ -46,38 +48,18 @@ java_library(
)

# Exports javacopts from the current java toolchain
java_binary(
name = "JavaBuilderConfigGenerator",
srcs = ["JavaBuilderConfigGenerator.java"],
main_class = "com.google.devtools.build.java.bazel.JavaBuilderConfigGenerator",
deps = [
"//src/main/java/com/google/devtools/build/lib:java-toolchain-parser",
"//third_party:guava",
],
)

# Exports javacopts from the current java toolchain
genquery(
name = "java_toolchain_content",
expression = "kind(java_toolchain, deps(//tools/defaults:java_toolchain))",
opts = ["--output=proto"],
scope = ["//tools/defaults:java_toolchain"],
)

genrule(
name = "javabuilder-javacopts",
srcs = [":java_toolchain_content"],
outs = ["JavaBuilderJavacOpts.java"],
cmd = "$(location :JavaBuilderConfigGenerator) $< > $@",
tools = [":JavaBuilderConfigGenerator"],
default_javacopts(
name = "gen_default_javacopts",
out = "JavaBuilderJavacOpts.java",
template = "JavaBuilderJavacOpts.java.template",
)

# Provides java-level access to the javacopts in the current java toolchain
java_library(
name = "JavaBuilderConfig",
srcs = [
"JavaBuilderConfig.java",
":javabuilder-javacopts",
"JavaBuilderJavacOpts.java",
],
deps = [
"//src/java_tools/buildjar/java/com/google/devtools/build/buildjar:javac_options",
Expand Down Expand Up @@ -120,5 +102,9 @@ filegroup(
srcs = glob([
"*.java",
"*.sh",
]) + ["BUILD"],
]) + [
"BUILD",
"JavaBuilderJavacOpts.java.template",
"build_defs.bzl",
],
)

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2017 The Bazel Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.devtools.build.java.bazel;

/**
* This class is used by {@link JavaBuilderConfig} to provide Java-level access to the blessed
* JavaBuilder javacopts.
*/
public class JavaBuilderJavacOpts {
public static final String[] DEFAULT_JAVACOPTS = {
%javacopts%
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Copyright 2017 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Rules to make the default javacopts available as a Java API."""

def _default_javacopts(ctx):
javacopts = java_common.default_javac_opts(
ctx, java_toolchain_attr = "_java_toolchain")
ctx.template_action(
template = ctx.file.template,
output = ctx.outputs.out,
substitutions = {
"%javacopts%": '"%s"' % '", "'.join(javacopts),
}
)

default_javacopts = rule(
implementation=_default_javacopts,
attrs={
"template": attr.label(
mandatory=True,
allow_files=True,
single_file=True,
),
"out": attr.output(mandatory=True),
"_java_toolchain": attr.label(
default = Label("//tools/jdk:current_java_toolchain"),
),
},
)
"""Makes the default javacopts available as a Java API.
Args:
template: The template file to expand, replacing %javacopts% with a quoted
comma-separated list of the default javac flags.
out: The destination of the expanded file.
"""
17 changes: 1 addition & 16 deletions src/main/java/com/google/devtools/build/lib/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -348,22 +348,6 @@ java_library(
],
)

java_library(
name = "java-toolchain-parser",
srcs = [
"rules/java/JavaToolchainData.java",
"rules/java/JavaToolchainDataParser.java",
],
deps = [
"//src/main/java/com/google/devtools/build/lib/concurrent",
"//src/main/java/com/google/devtools/build/lib/shell",
"//src/main/protobuf:build_java_proto",
"//third_party:guava",
"//third_party:jsr305",
"//third_party/protobuf:protobuf_java",
],
)

java_library(
name = "transitive-info-provider",
srcs = ["analysis/TransitiveInfoProvider.java"],
Expand Down Expand Up @@ -743,6 +727,7 @@ java_library(
"rules/java/JavaSourceInfoProvider.java",
"rules/java/JavaToolchain.java",
"rules/java/JavaToolchainAlias.java",
"rules/java/JavaToolchainData.java",
"rules/java/JavaToolchainRule.java",
"rules/java/JavaToolchainSkylarkApiProvider.java",
"rules/java/JvmConfigurationLoader.java",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
/**
* Information about the JDK used by the <code>java_*</code> rules.
*
* <p>This class contains the data of the {@code java_toolchain} rules, it is a separate object so
* it can be shared with other tools.
* <p>This class contains the data of the {@code java_toolchain} rules.
*/
// TODO(cushon): inline this into JavaToolchainProvider (it used to be shared with other tools).
@Immutable
public class JavaToolchainData {

Expand Down

This file was deleted.

0 comments on commit 56d5ba1

Please sign in to comment.