aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java4
-rw-r--r--src/main/java/com/google/devtools/build/lib/ideinfo/AndroidStudioInfoAspect.java64
-rw-r--r--src/main/java/com/google/devtools/build/lib/ideinfo/AndroidStudioInfoSemantics.java37
-rw-r--r--src/main/java/com/google/devtools/build/lib/ideinfo/BazelAndroidStudioInfoSemantics.java42
-rw-r--r--src/test/java/com/google/devtools/build/lib/ideinfo/intellij_info.bzl4
5 files changed, 129 insertions, 22 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java
index 84fb20a167..986e31c2c2 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java
@@ -69,6 +69,7 @@ import com.google.devtools.build.lib.bazel.rules.workspace.NewGitRepositoryRule;
import com.google.devtools.build.lib.bazel.rules.workspace.NewHttpArchiveRule;
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.ideinfo.AndroidStudioInfoAspect;
+import com.google.devtools.build.lib.ideinfo.BazelAndroidStudioInfoSemantics;
import com.google.devtools.build.lib.packages.Attribute;
import com.google.devtools.build.lib.packages.PackageGroup;
import com.google.devtools.build.lib.packages.Rule;
@@ -268,7 +269,8 @@ public class BazelRuleClassProvider {
JackAspect jackAspect = new JackAspect(TOOLS_REPOSITORY);
BazelJ2ObjcProtoAspect bazelJ2ObjcProtoAspect = new BazelJ2ObjcProtoAspect(TOOLS_REPOSITORY);
J2ObjcAspect j2ObjcAspect = new J2ObjcAspect(TOOLS_REPOSITORY, bazelJ2ObjcProtoAspect);
- AndroidStudioInfoAspect androidStudioInfoAspect = new AndroidStudioInfoAspect(TOOLS_REPOSITORY);
+ AndroidStudioInfoAspect androidStudioInfoAspect =
+ new AndroidStudioInfoAspect(TOOLS_REPOSITORY, new BazelAndroidStudioInfoSemantics());
builder.addNativeAspectClass(androidNeverlinkAspect);
builder.addNativeAspectClass(dexArchiveAspect);
diff --git a/src/main/java/com/google/devtools/build/lib/ideinfo/AndroidStudioInfoAspect.java b/src/main/java/com/google/devtools/build/lib/ideinfo/AndroidStudioInfoAspect.java
index 39dfff6ffc..56f917640c 100644
--- a/src/main/java/com/google/devtools/build/lib/ideinfo/AndroidStudioInfoAspect.java
+++ b/src/main/java/com/google/devtools/build/lib/ideinfo/AndroidStudioInfoAspect.java
@@ -82,7 +82,6 @@ import java.util.List;
import javax.annotation.Nullable;
-
/**
* Generates ide-build information for Android Studio.
*/
@@ -94,13 +93,28 @@ public class AndroidStudioInfoAspect extends NativeAspectClass implements Config
public static final String IDE_INFO = "ide-info";
public static final String IDE_INFO_TEXT = "ide-info-text";
public static final String IDE_RESOLVE = "ide-resolve";
+
private final String toolsRepository;
+ private final AndroidStudioInfoSemantics androidStudioInfoSemantics;
+ private final ImmutableList<PrerequisiteAttr> prerequisiteAttrs;
- public AndroidStudioInfoAspect(String toolsRepository) {
+ public AndroidStudioInfoAspect(
+ String toolsRepository,
+ AndroidStudioInfoSemantics androidStudioInfoSemantics) {
this.toolsRepository = toolsRepository;
+ this.androidStudioInfoSemantics = androidStudioInfoSemantics;
+ this.prerequisiteAttrs = buildPrerequisiteAttrs();
+ }
+
+ @Override
+ public String getName() {
+ return NAME;
}
- private static class PrerequisiteAttr {
+ /**
+ * Attribute to propagate dependencies along.
+ */
+ public static class PrerequisiteAttr {
public final String name;
public final Type<?> type;
public PrerequisiteAttr(String name, Type<?> type) {
@@ -108,17 +122,20 @@ public class AndroidStudioInfoAspect extends NativeAspectClass implements Config
this.type = type;
}
}
- public static final PrerequisiteAttr[] PREREQUISITE_ATTRS = {
- new PrerequisiteAttr("deps", BuildType.LABEL_LIST),
- new PrerequisiteAttr("exports", BuildType.LABEL_LIST),
- new PrerequisiteAttr("$robolectric", BuildType.LABEL_LIST), // From android_robolectric_test
- new PrerequisiteAttr("$junit", BuildType.LABEL), // From android_robolectric_test
- new PrerequisiteAttr("binary_under_test", BuildType.LABEL), // From android_test
- new PrerequisiteAttr("java_lib", BuildType.LABEL), // From proto_library
- new PrerequisiteAttr("$proto1_java_lib", BuildType.LABEL), // From proto_library
- new PrerequisiteAttr(":cc_toolchain", BuildType.LABEL), // from cc_* rules
- new PrerequisiteAttr("module_target", BuildType.LABEL)
- };
+
+ private ImmutableList<PrerequisiteAttr> buildPrerequisiteAttrs() {
+ ImmutableList.Builder<PrerequisiteAttr> builder = ImmutableList.builder();
+ builder.add(new PrerequisiteAttr("deps", BuildType.LABEL_LIST));
+ builder.add(new PrerequisiteAttr("exports", BuildType.LABEL_LIST));
+ // From android_test
+ builder.add(new PrerequisiteAttr("binary_under_test", BuildType.LABEL));
+ // from cc_* rules
+ builder.add(new PrerequisiteAttr(":cc_toolchain", BuildType.LABEL));
+
+ androidStudioInfoSemantics.augmentPrerequisiteAttrs(builder);
+
+ return builder.build();
+ }
// File suffixes.
public static final String ASWB_BUILD_SUFFIX = ".aswb-build";
@@ -140,7 +157,7 @@ public class AndroidStudioInfoAspect extends NativeAspectClass implements Config
.value(Label.parseAbsoluteUnchecked(
toolsRepository + "//tools/android:PackageParser")));
- for (PrerequisiteAttr prerequisiteAttr : PREREQUISITE_ATTRS) {
+ for (PrerequisiteAttr prerequisiteAttr : prerequisiteAttrs) {
builder.attributeAspect(prerequisiteAttr.name, this);
}
@@ -196,7 +213,7 @@ public class AndroidStudioInfoAspect extends NativeAspectClass implements Config
// Calculate direct dependencies
ImmutableList.Builder<TransitiveInfoCollection> directDepsBuilder = ImmutableList.builder();
- for (PrerequisiteAttr prerequisiteAttr : PREREQUISITE_ATTRS) {
+ for (PrerequisiteAttr prerequisiteAttr : prerequisiteAttrs) {
if (ruleContext.attributes().has(prerequisiteAttr.name, prerequisiteAttr.type)) {
directDepsBuilder.addAll(ruleContext.getPrerequisites(prerequisiteAttr.name, Mode.TARGET));
}
@@ -325,7 +342,8 @@ public class AndroidStudioInfoAspect extends NativeAspectClass implements Config
// C rules
CppCompilationContext cppCompilationContext = base.getProvider(CppCompilationContext.class);
if (cppCompilationContext != null) {
- CRuleIdeInfo cRuleIdeInfo = makeCRuleIdeInfo(base, ruleContext, cppCompilationContext);
+ CRuleIdeInfo cRuleIdeInfo =
+ makeCRuleIdeInfo(base, ruleContext, cppCompilationContext, ideResolveArtifacts);
outputBuilder.setCRuleIdeInfo(cRuleIdeInfo);
}
@@ -491,7 +509,7 @@ public class AndroidStudioInfoAspect extends NativeAspectClass implements Config
/*makeExecutable =*/ false);
}
- private static ArtifactLocation makeArtifactLocation(Artifact artifact) {
+ protected static ArtifactLocation makeArtifactLocation(Artifact artifact) {
return makeArtifactLocation(artifact.getRoot(), artifact.getRootRelativePath());
}
@@ -552,8 +570,11 @@ public class AndroidStudioInfoAspect extends NativeAspectClass implements Config
return builder.build();
}
- private static CRuleIdeInfo makeCRuleIdeInfo(ConfiguredTarget base,
- RuleContext ruleContext, CppCompilationContext cppCompilationContext) {
+ private CRuleIdeInfo makeCRuleIdeInfo(
+ ConfiguredTarget base,
+ RuleContext ruleContext,
+ CppCompilationContext cppCompilationContext,
+ NestedSetBuilder<Artifact> ideResolveArtifacts) {
CRuleIdeInfo.Builder builder = CRuleIdeInfo.newBuilder();
Collection<Artifact> sourceFiles = getSources(ruleContext);
@@ -591,6 +612,9 @@ public class AndroidStudioInfoAspect extends NativeAspectClass implements Config
builder.addTransitiveSystemIncludeDirectory(pathFragment.getSafePathString());
}
+ androidStudioInfoSemantics
+ .updateCppRuleInfo(builder, base, ruleContext, cppCompilationContext, ideResolveArtifacts);
+
return builder.build();
}
diff --git a/src/main/java/com/google/devtools/build/lib/ideinfo/AndroidStudioInfoSemantics.java b/src/main/java/com/google/devtools/build/lib/ideinfo/AndroidStudioInfoSemantics.java
new file mode 100644
index 0000000000..4e6639c966
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/ideinfo/AndroidStudioInfoSemantics.java
@@ -0,0 +1,37 @@
+// 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.ideinfo;
+
+import com.google.common.collect.ImmutableList.Builder;
+import com.google.devtools.build.lib.actions.Artifact;
+import com.google.devtools.build.lib.analysis.ConfiguredTarget;
+import com.google.devtools.build.lib.analysis.RuleContext;
+import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
+import com.google.devtools.build.lib.ideinfo.AndroidStudioInfoAspect.PrerequisiteAttr;
+import com.google.devtools.build.lib.ideinfo.androidstudio.AndroidStudioIdeInfo.CRuleIdeInfo;
+import com.google.devtools.build.lib.rules.cpp.CppCompilationContext;
+
+/**
+ * Methods to handle differences between blaze and bazel in the {@link AndroidStudioInfoAspect}.
+ */
+public interface AndroidStudioInfoSemantics {
+ void updateCppRuleInfo(
+ CRuleIdeInfo.Builder builder,
+ ConfiguredTarget base,
+ RuleContext ruleContext,
+ CppCompilationContext cppCompilationContext,
+ NestedSetBuilder<Artifact> ideResolveArtifacts);
+
+ void augmentPrerequisiteAttrs(Builder<PrerequisiteAttr> builder);
+}
diff --git a/src/main/java/com/google/devtools/build/lib/ideinfo/BazelAndroidStudioInfoSemantics.java b/src/main/java/com/google/devtools/build/lib/ideinfo/BazelAndroidStudioInfoSemantics.java
new file mode 100644
index 0000000000..f055405b48
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/ideinfo/BazelAndroidStudioInfoSemantics.java
@@ -0,0 +1,42 @@
+// 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.ideinfo;
+
+import com.google.common.collect.ImmutableList;
+import com.google.devtools.build.lib.actions.Artifact;
+import com.google.devtools.build.lib.analysis.ConfiguredTarget;
+import com.google.devtools.build.lib.analysis.RuleContext;
+import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
+import com.google.devtools.build.lib.ideinfo.AndroidStudioInfoAspect.PrerequisiteAttr;
+import com.google.devtools.build.lib.ideinfo.androidstudio.AndroidStudioIdeInfo.CRuleIdeInfo.Builder;
+import com.google.devtools.build.lib.rules.cpp.CppCompilationContext;
+
+/**
+ * Bazel specific semantics for the {@link AndroidStudioInfoAspect} aspect.
+ */
+public class BazelAndroidStudioInfoSemantics implements AndroidStudioInfoSemantics {
+
+ @Override
+ public void updateCppRuleInfo(
+ Builder builder,
+ ConfiguredTarget base,
+ RuleContext ruleContext,
+ CppCompilationContext cppCompilationContext,
+ NestedSetBuilder<Artifact> ideResolveArtifacts) {
+ }
+
+ @Override
+ public void augmentPrerequisiteAttrs(ImmutableList.Builder<PrerequisiteAttr> builder) {
+ }
+}
diff --git a/src/test/java/com/google/devtools/build/lib/ideinfo/intellij_info.bzl b/src/test/java/com/google/devtools/build/lib/ideinfo/intellij_info.bzl
index 5ebdb062b9..9cc0e22b63 100644
--- a/src/test/java/com/google/devtools/build/lib/ideinfo/intellij_info.bzl
+++ b/src/test/java/com/google/devtools/build/lib/ideinfo/intellij_info.bzl
@@ -183,6 +183,8 @@ def c_rule_ide_info(target, ctx):
cc_provider = target.cc
+ ide_resolve_files = set()
+
return (struct_omit_none(
source = sources,
exported_header = exported_headers,
@@ -194,7 +196,7 @@ def c_rule_ide_info(target, ctx):
transitive_define = cc_provider.defines,
transitive_system_include_directory = cc_provider.system_include_directories
),
- set())
+ ide_resolve_files)
def c_toolchain_ide_info(target, ctx):
""" Build CToolchainIdeInfo.