aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com
diff options
context:
space:
mode:
authorGravatar Dmitry Lomov <dslomov@google.com>2016-02-11 15:59:05 +0000
committerGravatar David Chen <dzc@google.com>2016-02-11 22:22:20 +0000
commitff9d02c66704f53b1dc5b7436977e440f288cfc4 (patch)
treefa19a1eda942ce76296b415dec95396076f5a2b0 /src/main/java/com
parent60434dae746ed61f025fdfd0464993fa6a0ff1d2 (diff)
Expose some information about Java compilation to Skylark.
-- MOS_MIGRATED_REVID=114438050
Diffstat (limited to 'src/main/java/com')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/java/JavaCommon.java12
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/java/JavaCompilationInfoProvider.java116
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/java/JavaSkylarkApiProvider.java17
3 files changed, 141 insertions, 4 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaCommon.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaCommon.java
index 0839da12c2..0b310b7dd9 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaCommon.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaCommon.java
@@ -572,7 +572,8 @@ public class JavaCommon {
builder
.add(JavaExportsProvider.class, new JavaExportsProvider(collectTransitiveExports()))
.addSkylarkTransitiveInfo(JavaSkylarkApiProvider.NAME, new JavaSkylarkApiProvider())
- .addOutputGroup(OutputGroupProvider.FILES_TO_COMPILE, getFilesToCompile(classJar));
+ .addOutputGroup(OutputGroupProvider.FILES_TO_COMPILE, getFilesToCompile(classJar))
+ .add(JavaCompilationInfoProvider.class, createCompilationInfoProvider());
}
private void addInstrumentationFilesProvider(RuleConfiguredTargetBuilder builder,
@@ -755,4 +756,13 @@ public class JavaCommon {
public RuleContext getRuleContext() {
return ruleContext;
}
+
+ private JavaCompilationInfoProvider createCompilationInfoProvider() {
+ return new JavaCompilationInfoProvider.Builder()
+ .setJavacOpts(javacOpts)
+ .setBootClasspath(getBootClasspath())
+ .setCompilationClasspath(getCompileTimeClasspath())
+ .setRuntimeClasspath(getRuntimeClasspath())
+ .build();
+ }
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaCompilationInfoProvider.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaCompilationInfoProvider.java
new file mode 100644
index 0000000000..76750e72ea
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaCompilationInfoProvider.java
@@ -0,0 +1,116 @@
+// Copyright 2016 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.devtools.build.lib.actions.Artifact;
+import com.google.devtools.build.lib.analysis.TransitiveInfoProvider;
+import com.google.devtools.build.lib.collect.nestedset.NestedSet;
+import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
+import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable;
+import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
+
+/**
+ * A class that provides compilation information in Java rules, for perusal of aspects and tools.
+ */
+@SkylarkModule(
+ name = "JavaCompilationInfo",
+ doc = "Provides access to compilation information for Java rules"
+)
+@Immutable
+public class JavaCompilationInfoProvider implements TransitiveInfoProvider {
+ private final ImmutableList<String> javacOpts;
+ private final NestedSet<Artifact> runtimeClasspath;
+ private final NestedSet<Artifact> compilationClasspath;
+ private final ImmutableList<Artifact> bootClasspath;
+
+ /**
+ * Builder for {@link JavaCompilationInfoProvider}.
+ */
+ public static class Builder {
+ private ImmutableList<String> javacOpts;
+ private NestedSet<Artifact> runtimeClasspath;
+ private NestedSet<Artifact> compilationClasspath;
+ private ImmutableList<Artifact> bootClasspath;
+
+ public Builder setJavacOpts(ImmutableList<String> javacOpts) {
+ this.javacOpts = javacOpts;
+ return this;
+ }
+
+ public Builder setRuntimeClasspath(NestedSet<Artifact> runtimeClasspath) {
+ this.runtimeClasspath = runtimeClasspath;
+ return this;
+ }
+
+ public Builder setCompilationClasspath(NestedSet<Artifact> compilationClasspath) {
+ this.compilationClasspath = compilationClasspath;
+ return this;
+ }
+
+ public Builder setBootClasspath(ImmutableList<Artifact> bootClasspath) {
+ this.bootClasspath = bootClasspath;
+ return this;
+ }
+
+ public JavaCompilationInfoProvider build() {
+ return new JavaCompilationInfoProvider(
+ javacOpts, runtimeClasspath, compilationClasspath, bootClasspath);
+ }
+ }
+
+ @SkylarkCallable(name = "javac_options", structField = true, doc = "Options to java compiler")
+ public ImmutableList<String> getJavacOpts() {
+ return javacOpts;
+ }
+
+ @SkylarkCallable(
+ name = "runtime_classpath",
+ structField = true,
+ doc = "Run-time classpath for this Java target"
+ )
+ public NestedSet<Artifact> getRuntimeClasspath() {
+ return runtimeClasspath;
+ }
+
+ @SkylarkCallable(
+ name = "compilation_classpath",
+ structField = true,
+ doc = "Compilation classpath for this Java target"
+ )
+ public NestedSet<Artifact> getCompilationClasspath() {
+ return compilationClasspath;
+ }
+
+ @SkylarkCallable(
+ name = "boot_classpath",
+ structField = true,
+ doc = "Boot classpath for this Java target"
+ )
+ public ImmutableList<Artifact> getBootClasspath() {
+ return bootClasspath;
+ }
+
+ private JavaCompilationInfoProvider(
+ ImmutableList<String> javacOpts,
+ NestedSet<Artifact> runtimeClasspath,
+ NestedSet<Artifact> compileTimeClasspath,
+ ImmutableList<Artifact> bootClasspath) {
+ this.javacOpts = javacOpts;
+ this.runtimeClasspath = runtimeClasspath;
+ this.compilationClasspath = compileTimeClasspath;
+ this.bootClasspath = bootClasspath;
+ }
+}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaSkylarkApiProvider.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaSkylarkApiProvider.java
index 48d4056e4e..98cff71e15 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaSkylarkApiProvider.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaSkylarkApiProvider.java
@@ -72,7 +72,7 @@ public final class JavaSkylarkApiProvider extends SkylarkApiProvider {
@SkylarkCallable(
name = "outputs",
- doc = "Returns information about outputs of this Java rule",
+ doc = "Returns information about outputs of this Java target",
structField = true
)
public JavaRuleOutputJarsProvider getOutputJars() {
@@ -81,11 +81,22 @@ public final class JavaSkylarkApiProvider extends SkylarkApiProvider {
@SkylarkCallable(
name = "annotation_processing",
- structField = true, allowReturnNones = true,
- doc = "Returns information about annotation processing for this Java rule"
+ structField = true,
+ allowReturnNones = true,
+ doc = "Returns information about annotation processing for this Java target"
)
public JavaGenJarsProvider getGenJarsProvider() {
return getInfo().getProvider(JavaGenJarsProvider.class);
}
+ @SkylarkCallable(
+ name = "compilation_info",
+ structField = true,
+ allowReturnNones = true,
+ doc = "Returns compilation information for this Java target"
+ )
+ public JavaCompilationInfoProvider getCompilationInfoProvider() {
+ return getInfo().getProvider(JavaCompilationInfoProvider.class);
+ }
+
}