diff options
author | cushon <cushon@google.com> | 2017-12-19 10:23:53 -0800 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2017-12-19 10:25:51 -0800 |
commit | 56d5ba1ee89ac2dfb4eb5b2b8a076bb372258877 (patch) | |
tree | f13899ddc9cb4c1b9de4e91f6bcbb8e39ee6c59b /src/main/java/com/google | |
parent | 741dbc081e2479fd8b0b9c289802b8a0e4af7c06 (diff) |
Retire some pre-skylark machinery for accessing the contents of java_toolchain
and replace the only use with java_common.default_javac_opts.
PiperOrigin-RevId: 179571481
Diffstat (limited to 'src/main/java/com/google')
3 files changed, 3 insertions, 161 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/BUILD b/src/main/java/com/google/devtools/build/lib/BUILD index 3794ce1121..d16c7a4175 100644 --- a/src/main/java/com/google/devtools/build/lib/BUILD +++ b/src/main/java/com/google/devtools/build/lib/BUILD @@ -349,22 +349,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"], ) @@ -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", diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaToolchainData.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaToolchainData.java index fca7a9f440..68ff205676 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaToolchainData.java +++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaToolchainData.java @@ -24,9 +24,9 @@ import java.util.List; /** * 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 { diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaToolchainDataParser.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaToolchainDataParser.java deleted file mode 100644 index 4c1558fde4..0000000000 --- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaToolchainDataParser.java +++ /dev/null @@ -1,143 +0,0 @@ -// Copyright 2015 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.lib.rules.java; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.devtools.build.lib.query2.proto.proto2api.Build; -import com.google.devtools.build.lib.query2.proto.proto2api.Build.QueryResult; -import com.google.devtools.build.lib.rules.java.JavaToolchainData.SupportsWorkers; -import com.google.devtools.build.lib.shell.ShellUtils; -import com.google.protobuf.TextFormat; -import com.google.protobuf.TextFormat.ParseException; - -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.List; - -/** - * A class to parse a {@link JavaToolchainData} from the result of blaze query. It is used by - * {@link com.google.devtools.build.java.bazel.BazelJavaCompiler} to get default options. - */ -public class JavaToolchainDataParser { - - /** - * Parse a {@link com.google.devtools.build.lib.query2.proto.proto2api.Build.QueryResult} as - * returned by a bazel query and look for the list of target containing a {@code java_toolchain} - * rule. These rules are then parsed into {@link JavaToolchainData}'s and returned as map with the - * name of the target as key and the {@link JavaToolchainData} as value. - */ - public static ImmutableMap<String, JavaToolchainData> parse(QueryResult queryResult) { - ImmutableMap.Builder<String, JavaToolchainData> builder = ImmutableMap.builder(); - for (Build.Target target : queryResult.getTargetList()) { - Build.Rule rule = target.getRule(); - if (target.hasRule() && rule.getRuleClass().equals("java_toolchain")) { - builder.put(rule.getName(), parseBuildRuleProto(rule)); - } - } - return builder.build(); - } - - /** - * Parse a text serialization of a - * {@link com.google.devtools.build.lib.query2.proto.proto2api.Build.QueryResult}. See - * {@link #parse(QueryResult)} for the details of the result. - * - * @throws ParseException when the provided string does not corresponds to a bazel query output. - */ - public static ImmutableMap<String, JavaToolchainData> parse(String queryResult) - throws ParseException { - QueryResult.Builder builder = QueryResult.newBuilder(); - TextFormat.merge(queryResult, builder); - return parse(builder.build()); - } - /** - * Parse a {@link com.google.devtools.build.lib.query2.proto.proto2api.Build.QueryResult} from - * an input stream. See {@link #parse(QueryResult)} for the details of the result. - */ - public static ImmutableMap<String, JavaToolchainData> parse(InputStream queryResult) - throws IOException { - return parse(QueryResult.newBuilder().mergeFrom(queryResult).build()); - } - - private static JavaToolchainData parseBuildRuleProto(Build.Rule rule) { - String source = ""; - String target = ""; - ImmutableList<String> bootclasspath = ImmutableList.of(); - ImmutableList<String> extclasspath = ImmutableList.of(); - String encoding = ""; - ImmutableList<String> xlint = ImmutableList.of(); - ImmutableList<String> misc = ImmutableList.of(); - ImmutableList<String> jvmOpts = ImmutableList.of(); - SupportsWorkers javacSupportsWorkers = SupportsWorkers.NO; - for (Build.Attribute attribute : rule.getAttributeList()) { - switch (attribute.getName()) { - case "source_version": - source = attribute.getStringValue(); - break; - case "target_version": - target = attribute.getStringValue(); - break; - case "bootclasspath": - bootclasspath = ImmutableList.copyOf(attribute.getStringListValueList()); - break; - case "extclasspath": - extclasspath = ImmutableList.copyOf(attribute.getStringListValueList()); - break; - case "encoding": - encoding = attribute.getStringValue(); - break; - case "xlint": - xlint = ImmutableList.copyOf(attribute.getStringListValueList()); - break; - case "misc": - { - List<String> options = new ArrayList<>(); - for (String option : attribute.getStringListValueList()) { - try { - ShellUtils.tokenize(options, option); - } catch (ShellUtils.TokenizationException e) { - // Tokenization failed; this likely means that the user - // did not want tokenization to happen on the argument. - // (see JavaHelper.tokenizeJavaOptions) - options.add(option); - } - } - misc = ImmutableList.copyOf(options); - break; - } - case "jvm_opts": - jvmOpts = ImmutableList.copyOf(attribute.getStringListValueList()); - break; - case "javac_supports_workers": - if (attribute.getBooleanValue()) { - javacSupportsWorkers = SupportsWorkers.YES; - } - break; - } - } - return new JavaToolchainData( - source, - target, - bootclasspath, - extclasspath, - encoding, - xlint, - misc, - jvmOpts, - javacSupportsWorkers); - } -} |