Replace native AndroidStudioInfoAspect with an error message.
BUG=33295755
--
PiperOrigin-RevId: 150633735
MOS_MIGRATED_REVID=150633735
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 658285b..7e31c37 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
@@ -77,7 +77,6 @@
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.NonconfigurableAttributeMapper;
import com.google.devtools.build.lib.packages.PackageGroup;
@@ -729,9 +728,7 @@
new RuleSet() {
@Override
public void init(Builder builder) {
- String toolsRepository = checkNotNull(builder.getToolsRepository());
- AndroidStudioInfoAspect androidStudioInfoAspect =
- new AndroidStudioInfoAspect(toolsRepository, new BazelAndroidStudioInfoSemantics());
+ AndroidStudioInfoAspect androidStudioInfoAspect = new AndroidStudioInfoAspect();
builder.addNativeAspectClass(androidStudioInfoAspect);
}
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 a29dead..59c0fbf 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
@@ -14,952 +14,39 @@
package com.google.devtools.build.lib.ideinfo;
-import static com.google.common.collect.Iterables.transform;
-import static com.google.devtools.build.lib.packages.Attribute.ConfigurationTransition.HOST;
-import static com.google.devtools.build.lib.packages.Attribute.attr;
-import static com.google.devtools.build.lib.packages.BuildType.LABEL;
-
-import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Function;
-import com.google.common.base.Joiner;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Lists;
-import com.google.common.io.ByteSource;
-import com.google.devtools.build.lib.actions.Action;
-import com.google.devtools.build.lib.actions.ActionOwner;
-import com.google.devtools.build.lib.actions.Artifact;
-import com.google.devtools.build.lib.actions.ParameterFile.ParameterFileType;
-import com.google.devtools.build.lib.actions.Root;
-import com.google.devtools.build.lib.analysis.AnalysisUtils;
import com.google.devtools.build.lib.analysis.ConfiguredAspect;
import com.google.devtools.build.lib.analysis.ConfiguredAspect.Builder;
import com.google.devtools.build.lib.analysis.ConfiguredAspectFactory;
import com.google.devtools.build.lib.analysis.ConfiguredTarget;
-import com.google.devtools.build.lib.analysis.OutputGroupProvider;
-import com.google.devtools.build.lib.analysis.RuleConfiguredTarget.Mode;
import com.google.devtools.build.lib.analysis.RuleContext;
-import com.google.devtools.build.lib.analysis.TransitiveInfoCollection;
-import com.google.devtools.build.lib.analysis.actions.BinaryFileWriteAction;
-import com.google.devtools.build.lib.analysis.actions.CustomCommandLine;
-import com.google.devtools.build.lib.analysis.actions.SpawnAction;
-import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
-import com.google.devtools.build.lib.cmdline.Label;
-import com.google.devtools.build.lib.collect.nestedset.NestedSet;
-import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
import com.google.devtools.build.lib.packages.AspectDefinition;
import com.google.devtools.build.lib.packages.AspectParameters;
-import com.google.devtools.build.lib.packages.BuildType;
import com.google.devtools.build.lib.packages.NativeAspectClass;
-import com.google.devtools.build.lib.packages.NonconfigurableAttributeMapper;
-import com.google.devtools.build.lib.packages.Package;
-import com.google.devtools.build.lib.packages.TargetUtils;
-import com.google.devtools.build.lib.rules.android.AndroidIdeInfoProvider;
-import com.google.devtools.build.lib.rules.android.AndroidIdeInfoProvider.SourceDirectory;
-import com.google.devtools.build.lib.rules.cpp.CcToolchainProvider;
-import com.google.devtools.build.lib.rules.cpp.CppCompilationContext;
-import com.google.devtools.build.lib.rules.cpp.CppConfiguration;
-import com.google.devtools.build.lib.rules.java.JavaExportsProvider;
-import com.google.devtools.build.lib.rules.java.JavaGenJarsProvider;
-import com.google.devtools.build.lib.rules.java.JavaProvider;
-import com.google.devtools.build.lib.rules.java.JavaRuleOutputJarsProvider;
-import com.google.devtools.build.lib.rules.java.JavaRuleOutputJarsProvider.OutputJar;
-import com.google.devtools.build.lib.rules.java.JavaSourceInfoProvider;
-import com.google.devtools.build.lib.rules.java.JavaToolchainProvider;
-import com.google.devtools.build.lib.syntax.Type;
-import com.google.devtools.build.lib.vfs.PathFragment;
-import com.google.devtools.intellij.ideinfo.IntellijIdeInfo.AndroidIdeInfo;
-import com.google.devtools.intellij.ideinfo.IntellijIdeInfo.ArtifactLocation;
-import com.google.devtools.intellij.ideinfo.IntellijIdeInfo.CIdeInfo;
-import com.google.devtools.intellij.ideinfo.IntellijIdeInfo.CToolchainIdeInfo;
-import com.google.devtools.intellij.ideinfo.IntellijIdeInfo.JavaIdeInfo;
-import com.google.devtools.intellij.ideinfo.IntellijIdeInfo.JavaToolchainIdeInfo;
-import com.google.devtools.intellij.ideinfo.IntellijIdeInfo.LibraryArtifact;
-import com.google.devtools.intellij.ideinfo.IntellijIdeInfo.PyIdeInfo;
-import com.google.devtools.intellij.ideinfo.IntellijIdeInfo.TargetIdeInfo;
-import com.google.devtools.intellij.ideinfo.IntellijIdeInfo.TestInfo;
-import com.google.protobuf.MessageLite;
-import java.io.ByteArrayInputStream;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.charset.StandardCharsets;
-import java.util.Collection;
-import java.util.List;
-import javax.annotation.Nullable;
/** Generates ide-build information for Android Studio. */
public class AndroidStudioInfoAspect extends NativeAspectClass implements ConfiguredAspectFactory {
public static final String NAME = "AndroidStudioInfoAspect";
- // Output groups.
-
- static final String IDE_INFO = "ide-info";
- static final String IDE_INFO_TEXT = "ide-info-text";
- static final String IDE_RESOLVE = "ide-resolve";
- static final String IDE_COMPILE = "ide-compile";
-
- private final String toolsRepository;
- private final AndroidStudioInfoSemantics androidStudioInfoSemantics;
- private final ImmutableList<PrerequisiteAttr> prerequisiteAttrs;
-
- public AndroidStudioInfoAspect(
- String toolsRepository, AndroidStudioInfoSemantics androidStudioInfoSemantics) {
- this.toolsRepository = toolsRepository;
- this.androidStudioInfoSemantics = androidStudioInfoSemantics;
- this.prerequisiteAttrs = buildPrerequisiteAttrs();
- }
-
@Override
public String getName() {
return NAME;
}
- /** Attribute to propagate dependencies along. */
- public static class PrerequisiteAttr {
- public final String name;
- public final Type<?> type;
-
- public PrerequisiteAttr(String name, Type<?> type) {
- this.name = name;
- this.type = type;
- }
- }
-
- 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 java_* rules
- builder.add(new PrerequisiteAttr(":java_toolchain", 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";
- public static final String ASWB_BUILD_TEXT_SUFFIX = ".aswb-build.txt";
- public static final Function<Label, String> LABEL_TO_STRING =
- new Function<Label, String>() {
- @Nullable
- @Override
- public String apply(Label label) {
- return label.toString();
- }
- };
-
@Override
public AspectDefinition getDefinition(AspectParameters aspectParameters) {
- AspectDefinition.Builder builder =
- new AspectDefinition.Builder(this)
- .propagateAlongAttribute("runtime_deps")
- .propagateAlongAttribute("resources")
- .add(
- attr("$packageParser", LABEL)
- .cfg(HOST)
- .exec()
- .value(
- Label.parseAbsoluteUnchecked(
- toolsRepository + "//tools/android:PackageParser")))
- .add(
- attr("$jarFilter", LABEL)
- .cfg(HOST)
- .exec()
- .value(
- Label.parseAbsoluteUnchecked(
- toolsRepository + "//tools/android:JarFilter")));
-
- for (PrerequisiteAttr prerequisiteAttr : prerequisiteAttrs) {
- builder.propagateAlongAttribute(prerequisiteAttr.name);
- }
-
- return builder.build();
+ return new AspectDefinition.Builder(this).build();
}
@Override
public ConfiguredAspect create(
ConfiguredTarget base, RuleContext ruleContext, AspectParameters parameters) {
+ // Deprecated for bazel > 0.45
+ // Can be completely removed after a version or two
+ ruleContext.ruleError(
+ "AndroidStudioInfoAspect is deprecated. "
+ + "If you are using an IntelliJ bazel plugin, "
+ + "please update to the latest plugin version from the Jetbrains plugin repository.");
ConfiguredAspect.Builder builder = new Builder(this, parameters, ruleContext);
-
- AndroidStudioInfoFilesProvider.Builder providerBuilder =
- new AndroidStudioInfoFilesProvider.Builder();
-
- DependenciesResult dependenciesResult = processDependencies(base, ruleContext, providerBuilder);
-
- AndroidStudioInfoFilesProvider provider =
- createIdeBuildArtifact(base, ruleContext, dependenciesResult, providerBuilder);
-
- NestedSetBuilder<Artifact> ideCompileArtifacts = NestedSetBuilder.stableOrder();
- // Add artifacts required for compilation
- OutputGroupProvider outputGroupProvider = base.getProvider(OutputGroupProvider.class);
- if (outputGroupProvider != null) {
- ideCompileArtifacts.addTransitive(
- outputGroupProvider.getOutputGroup(OutputGroupProvider.FILES_TO_COMPILE));
- }
-
- builder
- .addOutputGroup(IDE_INFO, provider.getIdeInfoFiles())
- .addOutputGroup(IDE_INFO_TEXT, provider.getIdeInfoTextFiles())
- .addOutputGroup(IDE_RESOLVE, provider.getIdeResolveFiles())
- .addOutputGroup(IDE_COMPILE, ideCompileArtifacts.build())
- .addProvider(provider);
-
return builder.build();
}
-
- private static class DependenciesResult {
- private DependenciesResult(
- Iterable<Label> deps, Iterable<Label> runtimeDeps, @Nullable Label resources) {
- this.deps = deps;
- this.runtimeDeps = runtimeDeps;
- this.resources = resources;
- }
-
- final Iterable<Label> deps;
- final Iterable<Label> runtimeDeps;
- @Nullable final Label resources;
- }
-
- private DependenciesResult processDependencies(
- ConfiguredTarget base,
- RuleContext ruleContext,
- AndroidStudioInfoFilesProvider.Builder providerBuilder) {
-
- // Calculate direct dependencies
- ImmutableList.Builder<TransitiveInfoCollection> directDepsBuilder = ImmutableList.builder();
- for (PrerequisiteAttr prerequisiteAttr : prerequisiteAttrs) {
- if (ruleContext.attributes().has(prerequisiteAttr.name, prerequisiteAttr.type)) {
- Mode mode = ruleContext.getAttributeMode(prerequisiteAttr.name);
- if (mode == Mode.TARGET || mode == Mode.SPLIT) {
- directDepsBuilder.addAll(
- ruleContext.getPrerequisites(prerequisiteAttr.name, Mode.TARGET));
- }
- }
- }
- List<TransitiveInfoCollection> directDeps = directDepsBuilder.build();
-
- // Add exports from direct dependencies
- NestedSetBuilder<Label> dependenciesBuilder = NestedSetBuilder.stableOrder();
- for (AndroidStudioInfoFilesProvider depProvider :
- AnalysisUtils.getProviders(directDeps, AndroidStudioInfoFilesProvider.class)) {
- dependenciesBuilder.addTransitive(depProvider.getExportedDeps());
- }
- for (TransitiveInfoCollection dep : directDeps) {
- dependenciesBuilder.add(dep.getLabel());
- }
- NestedSet<Label> dependencies = dependenciesBuilder.build();
-
- // Propagate my own exports
- JavaExportsProvider javaExportsProvider = base.getProvider(JavaExportsProvider.class);
- if (javaExportsProvider != null) {
- providerBuilder
- .exportedDepsBuilder()
- .addTransitive(javaExportsProvider.getTransitiveExports());
- }
- // android_library without sources exports all its deps
- if (ruleContext.getRule().getRuleClass().equals("android_library")) {
- JavaSourceInfoProvider sourceInfoProvider = base.getProvider(JavaSourceInfoProvider.class);
- boolean hasSources =
- sourceInfoProvider != null && !sourceInfoProvider.getSourceFiles().isEmpty();
- if (!hasSources) {
- for (TransitiveInfoCollection dep : directDeps) {
- providerBuilder.exportedDepsBuilder().add(dep.getLabel());
- }
- }
- }
-
- // runtime_deps
- List<? extends TransitiveInfoCollection> runtimeDeps = ImmutableList.of();
- NestedSetBuilder<Label> runtimeDepsBuilder = NestedSetBuilder.stableOrder();
- if (ruleContext.attributes().has("runtime_deps", BuildType.LABEL_LIST)) {
- runtimeDeps = ruleContext.getPrerequisites("runtime_deps", Mode.TARGET);
- for (TransitiveInfoCollection dep : runtimeDeps) {
- runtimeDepsBuilder.add(dep.getLabel());
- }
- }
-
- // resources
- @Nullable
- TransitiveInfoCollection resources =
- ruleContext.attributes().has("resources", BuildType.LABEL)
- ? ruleContext.getPrerequisite("resources", Mode.TARGET)
- : null;
-
- // Propagate providers from all prerequisites (deps + runtime_deps)
- ImmutableList.Builder<TransitiveInfoCollection> prerequisitesBuilder = ImmutableList.builder();
- prerequisitesBuilder.addAll(directDeps);
- prerequisitesBuilder.addAll(runtimeDeps);
- if (resources != null) {
- prerequisitesBuilder.add(resources);
- }
-
- List<TransitiveInfoCollection> prerequisites = prerequisitesBuilder.build();
-
- for (AndroidStudioInfoFilesProvider depProvider :
- AnalysisUtils.getProviders(prerequisites, AndroidStudioInfoFilesProvider.class)) {
- providerBuilder.ideInfoFilesBuilder().addTransitive(depProvider.getIdeInfoFiles());
- providerBuilder.ideInfoTextFilesBuilder().addTransitive(depProvider.getIdeInfoTextFiles());
- providerBuilder.ideResolveFilesBuilder().addTransitive(depProvider.getIdeResolveFiles());
- }
-
- return new DependenciesResult(
- dependencies, runtimeDepsBuilder.build(), resources != null ? resources.getLabel() : null);
- }
-
- private AndroidStudioInfoFilesProvider createIdeBuildArtifact(
- ConfiguredTarget base,
- RuleContext ruleContext,
- DependenciesResult dependenciesResult,
- AndroidStudioInfoFilesProvider.Builder providerBuilder) {
-
- Artifact ideInfoFile = derivedArtifact(base, ruleContext, ASWB_BUILD_SUFFIX);
- Artifact ideInfoTextFile = derivedArtifact(base, ruleContext, ASWB_BUILD_TEXT_SUFFIX);
- providerBuilder.ideInfoFilesBuilder().add(ideInfoFile);
- providerBuilder.ideInfoTextFilesBuilder().add(ideInfoTextFile);
- NestedSetBuilder<Artifact> ideResolveArtifacts = providerBuilder.ideResolveFilesBuilder();
-
- TargetIdeInfo.Builder outputBuilder = TargetIdeInfo.newBuilder();
-
- outputBuilder.setLabel(base.getLabel().toString());
-
- outputBuilder.setBuildFileArtifactLocation(
- makeArtifactLocation(ruleContext.getRule().getPackage(), ruleContext.getLabel()));
-
- outputBuilder.setKindString(ruleContext.getRule().getRuleClass());
-
- // Java rules
- JavaRuleOutputJarsProvider outputJarsProvider =
- JavaProvider.getProvider(JavaRuleOutputJarsProvider.class, base);
- if (outputJarsProvider != null && !androidStudioInfoSemantics.suppressJavaRuleInfo(base)) {
- JavaIdeInfo javaIdeInfo =
- makeJavaIdeInfo(base, ruleContext, outputJarsProvider, providerBuilder);
- outputBuilder.setJavaIdeInfo(javaIdeInfo);
- }
-
- // C rules
- if (isCppRule(base)) {
- CppCompilationContext cppCompilationContext = base.getProvider(CppCompilationContext.class);
- if (cppCompilationContext != null) {
- CIdeInfo cIdeInfo =
- makeCIdeInfo(base, ruleContext, cppCompilationContext, ideResolveArtifacts);
- outputBuilder.setCIdeInfo(cIdeInfo);
- }
- }
-
- // CCToolchain rule
- CcToolchainProvider ccToolchainProvider = base.getProvider(CcToolchainProvider.class);
- if (ccToolchainProvider != null) {
- CppConfiguration cppConfiguration = ccToolchainProvider.getCppConfiguration();
- if (cppConfiguration != null) {
- CToolchainIdeInfo cToolchainIdeInfo = makeCToolchainIdeInfo(ruleContext, cppConfiguration);
- if (cToolchainIdeInfo != null) {
- outputBuilder.setCToolchainIdeInfo(cToolchainIdeInfo);
- }
- }
- }
-
- // Android rules
- AndroidIdeInfoProvider androidIdeInfoProvider = base.getProvider(AndroidIdeInfoProvider.class);
- if (androidIdeInfoProvider != null) {
- outputBuilder.setAndroidIdeInfo(
- makeAndroidIdeInfo(androidIdeInfoProvider, dependenciesResult, ideResolveArtifacts));
- }
-
- // Python rules
- if (isPythonRule(base)) {
- outputBuilder.setPyIdeInfo(makePyIdeInfo(base, ruleContext, ideResolveArtifacts));
- }
-
- // Test rules
- if (TargetUtils.isTestRule(base.getTarget())) {
- TestInfo.Builder builder = TestInfo.newBuilder();
- String attr =
- NonconfigurableAttributeMapper.of(base.getTarget().getAssociatedRule())
- .get("size", Type.STRING);
- if (attr != null) {
- builder.setSize(attr);
- }
- outputBuilder.setTestInfo(builder);
- }
-
- // Java toolchain rule
- JavaToolchainProvider javaToolchainProvider = base.getProvider(JavaToolchainProvider.class);
- if (javaToolchainProvider != null) {
- outputBuilder.setJavaToolchainIdeInfo(
- JavaToolchainIdeInfo.newBuilder()
- .setSourceVersion(javaToolchainProvider.getSourceVersion())
- .setTargetVersion(javaToolchainProvider.getTargetVersion()));
- }
-
- androidStudioInfoSemantics.augmentRuleInfo(
- outputBuilder, base, ruleContext, ideResolveArtifacts);
-
- AndroidStudioInfoFilesProvider provider = providerBuilder.build();
-
- outputBuilder.addAllDependencies(transform(dependenciesResult.deps, LABEL_TO_STRING));
- outputBuilder.addAllRuntimeDeps(transform(dependenciesResult.runtimeDeps, LABEL_TO_STRING));
- outputBuilder.addAllTags(base.getTarget().getAssociatedRule().getRuleTags());
-
- final TargetIdeInfo targetIdeInfo = outputBuilder.build();
-
- ruleContext.registerAction(
- makeProtoWriteAction(ruleContext.getActionOwner(), targetIdeInfo, ideInfoFile));
- ruleContext.registerAction(
- makeProtoTextWriteAction(ruleContext.getActionOwner(), targetIdeInfo, ideInfoTextFile));
-
- return provider;
- }
-
- private boolean isCppRule(ConfiguredTarget base) {
- String ruleClass = base.getTarget().getAssociatedRule().getRuleClass();
- switch (ruleClass) {
- case "cc_library":
- case "cc_binary":
- case "cc_test":
- case "cc_inc_library:":
- return true;
- default:
- // Fall through
- }
- return androidStudioInfoSemantics.checkForAdditionalCppRules(ruleClass);
- }
-
- private boolean isPythonRule(ConfiguredTarget base) {
- String ruleClass = base.getTarget().getAssociatedRule().getRuleClass();
- switch (ruleClass) {
- case "py_library":
- case "py_binary":
- case "py_test":
- return true;
- default:
- // Fall through
- }
- return androidStudioInfoSemantics.checkForAdditionalPythonRules(ruleClass);
- }
-
- private static Action[] makePackageManifestAction(
- RuleContext ruleContext, Artifact packageManifest, Collection<Artifact> sourceFiles) {
-
- return new SpawnAction.Builder()
- .addInputs(sourceFiles)
- .addOutput(packageManifest)
- .setExecutable(ruleContext.getExecutablePrerequisite("$packageParser", Mode.HOST))
- .setCommandLine(
- CustomCommandLine.builder()
- .addExecPath("--output_manifest", packageManifest)
- .addJoinStrings("--sources", ":", toSerializedArtifactLocations(sourceFiles))
- .build())
- .useParameterFile(ParameterFileType.SHELL_QUOTED)
- .setProgressMessage("Parsing java package strings for " + ruleContext.getRule())
- .setMnemonic("JavaPackageManifest")
- .build(ruleContext);
- }
-
- private static Iterable<String> toSerializedArtifactLocations(Iterable<Artifact> artifacts) {
- return Iterables.transform(
- Iterables.filter(artifacts, Artifact.MIDDLEMAN_FILTER), PACKAGE_PARSER_SERIALIZER);
- }
-
- private static final Function<Artifact, String> PACKAGE_PARSER_SERIALIZER =
- new Function<Artifact, String>() {
- @Override
- public String apply(Artifact artifact) {
- Root root = artifact.getRoot();
- return Joiner.on(",")
- .join(root.getExecPath().toString(), artifact.getRootRelativePath().toString());
- }
- };
-
- private static Action[] makeFilteredJarAction(
- RuleContext ruleContext,
- List<Artifact> filterJars,
- List<Artifact> filterSourceJars,
- List<Artifact> keepJavaFiles,
- List<Artifact> keepSourceJars,
- Artifact filteredJar,
- Artifact filteredSrcJar) {
-
- CustomCommandLine.Builder commandLine =
- CustomCommandLine.builder()
- .addJoinExecPaths("--filter_jars", File.pathSeparator, filterJars)
- .addJoinExecPaths("--filter_source_jars", File.pathSeparator, filterSourceJars)
- .addExecPath("--filtered_jar", filteredJar)
- .addExecPath("--filtered_source_jar", filteredSrcJar);
-
- if (!keepJavaFiles.isEmpty()) {
- commandLine.addJoinExecPaths("--keep_java_files", File.pathSeparator, keepJavaFiles);
- }
- if (!keepSourceJars.isEmpty()) {
- commandLine.addJoinExecPaths("--keep_source_jars", File.pathSeparator, keepSourceJars);
- }
-
- return new SpawnAction.Builder()
- .addInputs(filterJars)
- .addInputs(filterSourceJars)
- .addInputs(keepJavaFiles)
- .addInputs(keepSourceJars)
- .addOutput(filteredJar)
- .addOutput(filteredSrcJar)
- .setExecutable(ruleContext.getExecutablePrerequisite("$jarFilter", Mode.HOST))
- .setCommandLine(commandLine.build())
- .useParameterFile(ParameterFileType.SHELL_QUOTED)
- .setProgressMessage("Filtering generated code for " + ruleContext.getRule())
- .setMnemonic("JarFilter")
- .build(ruleContext);
- }
-
- private static Artifact derivedArtifact(
- ConfiguredTarget base, RuleContext ruleContext, String suffix) {
- BuildConfiguration configuration = ruleContext.getConfiguration();
- assert configuration != null;
- Root binDirectory = configuration.getBinDirectory(ruleContext.getRule().getRepository());
-
- PathFragment derivedFilePath = getOutputFilePath(base, ruleContext, suffix);
-
- return ruleContext.getAnalysisEnvironment().getDerivedArtifact(derivedFilePath, binDirectory);
- }
-
- private static AndroidIdeInfo makeAndroidIdeInfo(
- AndroidIdeInfoProvider androidIdeInfoProvider,
- DependenciesResult dependenciesResult,
- NestedSetBuilder<Artifact> ideResolveArtifacts) {
- AndroidIdeInfo.Builder builder = AndroidIdeInfo.newBuilder();
- if (androidIdeInfoProvider.getSignedApk() != null) {
- builder.setApk(makeArtifactLocation(androidIdeInfoProvider.getSignedApk()));
- }
-
- Artifact manifest = androidIdeInfoProvider.getManifest();
- if (manifest != null) {
- builder.setManifest(makeArtifactLocation(manifest));
- addResolveArtifact(ideResolveArtifacts, manifest);
- }
-
- for (Artifact artifact : androidIdeInfoProvider.getApksUnderTest()) {
- builder.addDependencyApk(makeArtifactLocation(artifact));
- }
- for (SourceDirectory resourceDir : androidIdeInfoProvider.getResourceDirs()) {
- ArtifactLocation artifactLocation = makeArtifactLocation(resourceDir);
- builder.addResources(artifactLocation);
- }
-
- if (androidIdeInfoProvider.getJavaPackage() != null) {
- builder.setJavaPackage(androidIdeInfoProvider.getJavaPackage());
- }
-
- String idlImportRoot = androidIdeInfoProvider.getIdlImportRoot();
- if (idlImportRoot != null) {
- builder.setIdlImportRoot(idlImportRoot);
- }
- boolean hasIdlSources = !androidIdeInfoProvider.getIdlSrcs().isEmpty();
- builder.setHasIdlSources(hasIdlSources);
- if (hasIdlSources) {
- LibraryArtifact idlLibraryArtifact =
- makeLibraryArtifact(
- ideResolveArtifacts,
- androidIdeInfoProvider.getIdlClassJar(),
- null,
- androidIdeInfoProvider.getIdlSourceJar());
- if (idlLibraryArtifact != null) {
- builder.setIdlJar(idlLibraryArtifact);
- }
- }
-
- builder.setGenerateResourceClass(androidIdeInfoProvider.definesAndroidResources());
-
- if (dependenciesResult.resources != null) {
- builder.setLegacyResources(dependenciesResult.resources.toString());
- }
-
- OutputJar resourceJar = androidIdeInfoProvider.getResourceJar();
- if (resourceJar != null) {
- LibraryArtifact resourceLibraryArtifact =
- makeLibraryArtifact(
- ideResolveArtifacts,
- resourceJar.getClassJar(),
- resourceJar.getIJar(),
- resourceJar.getSrcJar());
- if (resourceLibraryArtifact != null) {
- builder.setResourceJar(resourceLibraryArtifact);
- }
- }
-
- return builder.build();
- }
-
- private static BinaryFileWriteAction makeProtoWriteAction(
- ActionOwner actionOwner, final MessageLite message, Artifact artifact) {
- return new BinaryFileWriteAction(
- actionOwner,
- artifact,
- new ByteSource() {
- @Override
- public InputStream openStream() throws IOException {
- return message.toByteString().newInput();
- }
- },
- /*makeExecutable =*/ false);
- }
-
- private static BinaryFileWriteAction makeProtoTextWriteAction(
- ActionOwner actionOwner, final MessageLite message, Artifact artifact) {
- return new BinaryFileWriteAction(
- actionOwner,
- artifact,
- new ByteSource() {
- @Override
- public InputStream openStream() throws IOException {
- return new ByteArrayInputStream(message.toString().getBytes(StandardCharsets.UTF_8));
- }
- },
- /*makeExecutable =*/ false);
- }
-
- public static ArtifactLocation makeArtifactLocation(Artifact artifact) {
- return makeArtifactLocation(
- artifact.getRoot(), artifact.getRootRelativePath(), isExternal(artifact.getOwner()));
- }
-
- private static ArtifactLocation makeArtifactLocation(Package pkg, Label label) {
- Root root =
- Root.asSourceRoot(pkg.getSourceRoot(), pkg.getPackageIdentifier().getRepository().isMain());
- PathFragment relativePath = pkg.getBuildFile().getPath().relativeTo(root.getPath());
- return makeArtifactLocation(root, relativePath, isExternal(label));
- }
-
- @VisibleForTesting
- static ArtifactLocation makeArtifactLocation(
- Root root, PathFragment relativePath, boolean isExternal) {
- return ArtifactLocation.newBuilder()
- .setRootExecutionPathFragment(root.getExecPath().toString())
- .setRelativePath(relativePath.toString())
- .setIsSource(root.isSourceRoot())
- .setIsExternal(isExternal)
- .build();
- }
-
- private static ArtifactLocation makeArtifactLocation(SourceDirectory resourceDir) {
- return ArtifactLocation.newBuilder()
- .setRootExecutionPathFragment(resourceDir.getRootExecutionPathFragment().toString())
- .setRelativePath(resourceDir.getRelativePath().toString())
- .setIsSource(resourceDir.isSource())
- .setIsExternal(false)
- .build();
- }
-
- /** Returns whether this {@link Label} refers to an external repository. */
- private static boolean isExternal(Label label) {
- return label.getWorkspaceRoot().startsWith("external");
- }
-
- private JavaIdeInfo makeJavaIdeInfo(
- ConfiguredTarget base,
- RuleContext ruleContext,
- JavaRuleOutputJarsProvider outputJarsProvider,
- AndroidStudioInfoFilesProvider.Builder providerBuilder) {
- NestedSetBuilder<Artifact> ideResolveArtifacts = providerBuilder.ideResolveFilesBuilder();
- JavaIdeInfo.Builder builder = JavaIdeInfo.newBuilder();
-
- List<Artifact> javaSources = Lists.newArrayList();
- List<Artifact> generatedJavaSources = Lists.newArrayList();
- List<Artifact> srcjars = Lists.newArrayList();
- divideJavaSources(ruleContext, javaSources, generatedJavaSources, srcjars);
-
- if (!javaSources.isEmpty()) {
- Artifact packageManifest = derivedArtifact(base, ruleContext, ".manifest");
- providerBuilder.ideInfoFilesBuilder().add(packageManifest);
- ruleContext.registerAction(
- makePackageManifestAction(ruleContext, packageManifest, javaSources));
- builder.setPackageManifest(makeArtifactLocation(packageManifest));
- }
-
- // HACK -- android_library rules with the resources attribute do not support srcjar inputs
- // to the filtered gen jar generation, because we don't want all resource classes in this jar.
- // This can be removed once android_resources is deleted
- if (ruleContext.attributes().has("resources", BuildType.LABEL)
- && ruleContext.getRule().getRuleClass().startsWith("android_")) {
- srcjars = ImmutableList.of();
- }
-
- if (!javaSources.isEmpty() && (!generatedJavaSources.isEmpty() || !srcjars.isEmpty())) {
- Artifact filteredGenJar = derivedArtifact(base, ruleContext, "-filtered-gen.jar");
- Artifact filteredGenSrcJar = derivedArtifact(base, ruleContext, "-filtered-gen-src.jar");
- List<Artifact> jars = Lists.newArrayList();
- List<Artifact> sourceJars = Lists.newArrayList();
- for (OutputJar outputJar : outputJarsProvider.getOutputJars()) {
- Artifact jar = outputJar.getIJar();
- if (jar == null) {
- jar = outputJar.getClassJar();
- }
- if (jar != null) {
- jars.add(jar);
- }
- if (outputJar.getSrcJar() != null) {
- sourceJars.add(outputJar.getSrcJar());
- }
- }
- ruleContext.registerAction(
- makeFilteredJarAction(
- ruleContext,
- jars,
- sourceJars,
- generatedJavaSources,
- srcjars,
- filteredGenJar,
- filteredGenSrcJar));
- ideResolveArtifacts.add(filteredGenJar);
- ideResolveArtifacts.add(filteredGenSrcJar);
- builder.setFilteredGenJar(
- makeLibraryArtifact(ideResolveArtifacts, filteredGenJar, null, filteredGenSrcJar));
- }
-
- collectJarsFromOutputJarsProvider(builder, ideResolveArtifacts, outputJarsProvider);
-
- Artifact jdeps = outputJarsProvider.getJdeps();
- if (jdeps != null) {
- builder.setJdeps(makeArtifactLocation(jdeps));
- }
-
- JavaGenJarsProvider genJarsProvider = base.getProvider(JavaGenJarsProvider.class);
- if (genJarsProvider != null) {
- collectGenJars(builder, ideResolveArtifacts, genJarsProvider);
- }
-
- Collection<Artifact> sourceFiles = getSources(ruleContext);
-
- for (Artifact sourceFile : sourceFiles) {
- builder.addSources(makeArtifactLocation(sourceFile));
- }
-
- return builder.build();
- }
-
- private CIdeInfo makeCIdeInfo(
- ConfiguredTarget base,
- RuleContext ruleContext,
- CppCompilationContext cppCompilationContext,
- NestedSetBuilder<Artifact> ideResolveArtifacts) {
- CIdeInfo.Builder builder = CIdeInfo.newBuilder();
-
- Collection<Artifact> sourceFiles = getSources(ruleContext);
- for (Artifact sourceFile : sourceFiles) {
- builder.addSource(makeArtifactLocation(sourceFile));
- }
-
- ideResolveArtifacts.addTransitive(cppCompilationContext.getDeclaredIncludeSrcs());
-
- builder.addAllTargetInclude(getIncludes(ruleContext));
- builder.addAllTargetDefine(getDefines(ruleContext));
- builder.addAllTargetCopt(getCopts(ruleContext));
-
- // Get information about from the transitive closure
- ImmutableList<PathFragment> transitiveIncludeDirectories =
- cppCompilationContext.getIncludeDirs();
- for (PathFragment pathFragment : transitiveIncludeDirectories) {
- builder.addTransitiveIncludeDirectory(pathFragment.getSafePathString());
- }
- ImmutableList<PathFragment> transitiveQuoteIncludeDirectories =
- cppCompilationContext.getQuoteIncludeDirs();
- for (PathFragment pathFragment : transitiveQuoteIncludeDirectories) {
- builder.addTransitiveQuoteIncludeDirectory(pathFragment.getSafePathString());
- }
- ImmutableList<String> transitiveDefines = cppCompilationContext.getDefines();
- for (String transitiveDefine : transitiveDefines) {
- builder.addTransitiveDefine(transitiveDefine);
- }
- ImmutableList<PathFragment> transitiveSystemIncludeDirectories =
- cppCompilationContext.getSystemIncludeDirs();
- for (PathFragment pathFragment : transitiveSystemIncludeDirectories) {
- builder.addTransitiveSystemIncludeDirectory(pathFragment.getSafePathString());
- }
-
- androidStudioInfoSemantics.augmentCppRuleInfo(
- builder, base, ruleContext, cppCompilationContext, ideResolveArtifacts);
-
- return builder.build();
- }
-
- private static CToolchainIdeInfo makeCToolchainIdeInfo(
- RuleContext ruleContext, CppConfiguration cppConfiguration) {
- CToolchainIdeInfo.Builder builder = CToolchainIdeInfo.newBuilder();
- ImmutableSet<String> features = ruleContext.getFeatures();
- builder.setTargetName(cppConfiguration.getTargetGnuSystemName());
-
- builder.addAllBaseCompilerOption(cppConfiguration.getCompilerOptions(features));
- builder.addAllCOption(cppConfiguration.getCOptions());
- builder.addAllCppOption(cppConfiguration.getCxxOptions(features));
- builder.addAllLinkOption(cppConfiguration.getLinkOptions());
-
- // This includes options such as system includes from toolchains.
- builder.addAllUnfilteredCompilerOption(cppConfiguration.getUnfilteredCompilerOptions(features));
-
- builder.setPreprocessorExecutable(
- cppConfiguration.getCpreprocessorExecutable().getSafePathString());
- builder.setCppExecutable(cppConfiguration.getCppExecutable().getSafePathString());
-
- List<PathFragment> builtInIncludeDirectories = cppConfiguration.getBuiltInIncludeDirectories();
- for (PathFragment builtInIncludeDirectory : builtInIncludeDirectories) {
- builder.addBuiltInIncludeDirectory(builtInIncludeDirectory.getSafePathString());
- }
- return builder.build();
- }
-
- private static PyIdeInfo makePyIdeInfo(
- ConfiguredTarget base,
- RuleContext ruleContext,
- NestedSetBuilder<Artifact> ideResolveArtifacts) {
- PyIdeInfo.Builder builder = PyIdeInfo.newBuilder();
-
- Collection<Artifact> sourceFiles = getSources(ruleContext);
- for (Artifact sourceFile : sourceFiles) {
- builder.addSources(makeArtifactLocation(sourceFile));
- }
-
- // Ensure we add all generated sources to the ide-resolve output group.
- // See {@link PyCommon#collectTransitivePythonSources}.
- OutputGroupProvider outputGroupProvider = base.getProvider(OutputGroupProvider.class);
- if (outputGroupProvider != null) {
- ideResolveArtifacts.addTransitive(
- outputGroupProvider.getOutputGroup(OutputGroupProvider.FILES_TO_COMPILE));
- }
- return builder.build();
- }
-
- private static void collectJarsFromOutputJarsProvider(
- JavaIdeInfo.Builder builder,
- NestedSetBuilder<Artifact> ideResolveArtifacts,
- JavaRuleOutputJarsProvider outputJarsProvider) {
- for (OutputJar outputJar : outputJarsProvider.getOutputJars()) {
- LibraryArtifact libraryArtifact =
- makeLibraryArtifact(
- ideResolveArtifacts,
- outputJar.getClassJar(),
- outputJar.getIJar(),
- outputJar.getSrcJar());
-
- if (libraryArtifact != null) {
- builder.addJars(libraryArtifact);
- }
- }
- }
-
- @Nullable
- private static LibraryArtifact makeLibraryArtifact(
- NestedSetBuilder<Artifact> ideResolveArtifacts,
- @Nullable Artifact classJar,
- @Nullable Artifact iJar,
- @Nullable Artifact sourceJar) {
- // We don't want to add anything that doesn't have a class jar
- if (classJar == null) {
- return null;
- }
- LibraryArtifact.Builder jarsBuilder = LibraryArtifact.newBuilder();
- jarsBuilder.setJar(makeArtifactLocation(classJar));
- addResolveArtifact(ideResolveArtifacts, classJar);
-
- if (iJar != null) {
- jarsBuilder.setInterfaceJar(makeArtifactLocation(iJar));
- addResolveArtifact(ideResolveArtifacts, iJar);
- }
- if (sourceJar != null) {
- jarsBuilder.setSourceJar(makeArtifactLocation(sourceJar));
- addResolveArtifact(ideResolveArtifacts, sourceJar);
- }
-
- return jarsBuilder.build();
- }
-
- private static void collectGenJars(
- JavaIdeInfo.Builder builder,
- NestedSetBuilder<Artifact> ideResolveArtifacts,
- JavaGenJarsProvider genJarsProvider) {
- LibraryArtifact.Builder genjarsBuilder = LibraryArtifact.newBuilder();
-
- if (genJarsProvider.usesAnnotationProcessing()) {
- Artifact genClassJar = genJarsProvider.getGenClassJar();
- if (genClassJar != null) {
- genjarsBuilder.setJar(makeArtifactLocation(genClassJar));
- addResolveArtifact(ideResolveArtifacts, genClassJar);
- }
- Artifact gensrcJar = genJarsProvider.getGenSourceJar();
- if (gensrcJar != null) {
- genjarsBuilder.setSourceJar(makeArtifactLocation(gensrcJar));
- addResolveArtifact(ideResolveArtifacts, gensrcJar);
- }
- if (genjarsBuilder.hasJar()) {
- builder.addGeneratedJars(genjarsBuilder.build());
- }
- }
- }
-
- private static void divideJavaSources(
- RuleContext ruleContext,
- List<Artifact> javaSources,
- List<Artifact> generatedSources,
- List<Artifact> srcjars) {
- Collection<Artifact> srcs = getSources(ruleContext);
- for (Artifact src : srcs) {
- if (src.getRootRelativePathString().endsWith(".java")) {
- if (src.isSourceArtifact()) {
- javaSources.add(src);
- } else {
- generatedSources.add(src);
- }
- } else if (src.getRootRelativePathString().endsWith(".srcjar")) {
- srcjars.add(src);
- }
- }
- }
-
- private static Collection<Artifact> getSources(RuleContext ruleContext) {
- return getTargetListAttribute(ruleContext, "srcs");
- }
-
- private static Collection<String> getIncludes(RuleContext ruleContext) {
- return getStringListAttribute(ruleContext, "includes");
- }
-
- private static Collection<String> getDefines(RuleContext ruleContext) {
- return getStringListAttribute(ruleContext, "defines");
- }
-
- private static Collection<String> getCopts(RuleContext ruleContext) {
- return getStringListAttribute(ruleContext, "copts");
- }
-
- private static Collection<Artifact> getTargetListAttribute(
- RuleContext ruleContext, String attributeName) {
- return (ruleContext.attributes().has(attributeName, BuildType.LABEL_LIST)
- && ruleContext.getAttributeMode(attributeName) == Mode.TARGET)
- ? ruleContext.getPrerequisiteArtifacts(attributeName, Mode.TARGET).list()
- : ImmutableList.<Artifact>of();
- }
-
- private static Collection<String> getStringListAttribute(
- RuleContext ruleContext, String attributeName) {
- return ruleContext.attributes().has(attributeName, Type.STRING_LIST)
- ? ruleContext.attributes().get(attributeName, Type.STRING_LIST)
- : ImmutableList.<String>of();
- }
-
- private static PathFragment getOutputFilePath(
- ConfiguredTarget base, RuleContext ruleContext, String suffix) {
- PathFragment packagePathFragment =
- ruleContext.getLabel().getPackageIdentifier().getSourceRoot();
- String name = base.getLabel().getName();
- return new PathFragment(packagePathFragment, new PathFragment(name + suffix));
- }
-
- private static void addResolveArtifact(
- NestedSetBuilder<Artifact> ideResolveArtifacts, Artifact artifact) {
- if (!artifact.isSourceArtifact()) {
- ideResolveArtifacts.add(artifact);
- }
- }
}
diff --git a/src/main/java/com/google/devtools/build/lib/ideinfo/AndroidStudioInfoFilesProvider.java b/src/main/java/com/google/devtools/build/lib/ideinfo/AndroidStudioInfoFilesProvider.java
deleted file mode 100644
index 8f57d96..0000000
--- a/src/main/java/com/google/devtools/build/lib/ideinfo/AndroidStudioInfoFilesProvider.java
+++ /dev/null
@@ -1,102 +0,0 @@
-// Copyright 2014 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.devtools.build.lib.actions.Artifact;
-import com.google.devtools.build.lib.analysis.TransitiveInfoProvider;
-import com.google.devtools.build.lib.cmdline.Label;
-import com.google.devtools.build.lib.collect.nestedset.NestedSet;
-import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
-import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
-
-/**
- * File provider for Android Studio ide build files.
- */
-@Immutable
-public final class AndroidStudioInfoFilesProvider implements TransitiveInfoProvider {
- private final NestedSet<Artifact> ideInfoFiles;
- private final NestedSet<Artifact> ideInfoTextFiles;
- private final NestedSet<Artifact> ideResolveFiles;
- private final NestedSet<Label> exportedDeps;
-
- /**
- * Builder class for {@link AndroidStudioInfoFilesProvider}
- */
- public static class Builder {
- private final NestedSetBuilder<Artifact> ideInfoFilesBuilder;
- private final NestedSetBuilder<Artifact> ideInfoTextFilesBuilder;
- private final NestedSetBuilder<Artifact> ideResolveFilesBuilder;
- private NestedSetBuilder<Label> exportedDepsBuilder;
-
- public Builder() {
- ideInfoFilesBuilder = NestedSetBuilder.stableOrder();
- ideInfoTextFilesBuilder = NestedSetBuilder.stableOrder();
- ideResolveFilesBuilder = NestedSetBuilder.stableOrder();
- exportedDepsBuilder = NestedSetBuilder.stableOrder();
- }
-
- public NestedSetBuilder<Artifact> ideInfoFilesBuilder() {
- return ideInfoFilesBuilder;
- }
-
- public NestedSetBuilder<Artifact> ideInfoTextFilesBuilder() {
- return ideInfoTextFilesBuilder;
- }
-
- public NestedSetBuilder<Artifact> ideResolveFilesBuilder() {
- return ideResolveFilesBuilder;
- }
-
- public NestedSetBuilder<Label> exportedDepsBuilder() {
- return exportedDepsBuilder;
- }
-
- public AndroidStudioInfoFilesProvider build() {
- return new AndroidStudioInfoFilesProvider(
- ideInfoFilesBuilder.build(),
- ideInfoTextFilesBuilder.build(),
- ideResolveFilesBuilder.build(),
- exportedDepsBuilder.build()
- );
- }
- }
-
- private AndroidStudioInfoFilesProvider(
- NestedSet<Artifact> ideInfoFiles,
- NestedSet<Artifact> ideInfoTextFiles,
- NestedSet<Artifact> ideResolveFiles,
- NestedSet<Label> exportedDeps) {
- this.ideInfoFiles = ideInfoFiles;
- this.ideInfoTextFiles = ideInfoTextFiles;
- this.ideResolveFiles = ideResolveFiles;
- this.exportedDeps = exportedDeps;
- }
-
- public NestedSet<Artifact> getIdeInfoFiles() {
- return ideInfoFiles;
- }
-
- public NestedSet<Artifact> getIdeInfoTextFiles() {
- return ideInfoTextFiles;
- }
-
- public NestedSet<Artifact> getIdeResolveFiles() {
- return ideResolveFiles;
- }
-
- public NestedSet<Label> getExportedDeps() {
- return exportedDeps;
- }
-}
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
deleted file mode 100644
index b40254c..0000000
--- a/src/main/java/com/google/devtools/build/lib/ideinfo/AndroidStudioInfoSemantics.java
+++ /dev/null
@@ -1,51 +0,0 @@
-// 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.rules.cpp.CppCompilationContext;
-import com.google.devtools.intellij.ideinfo.IntellijIdeInfo.CIdeInfo;
-import com.google.devtools.intellij.ideinfo.IntellijIdeInfo.TargetIdeInfo;
-
-/**
- * Methods to handle differences between blaze and bazel in the {@link AndroidStudioInfoAspect}.
- */
-public interface AndroidStudioInfoSemantics {
-
- void augmentPrerequisiteAttrs(ImmutableList.Builder<PrerequisiteAttr> builder);
-
- void augmentRuleInfo(
- TargetIdeInfo.Builder builder,
- ConfiguredTarget base,
- RuleContext ruleContext,
- NestedSetBuilder<Artifact> ideResolveArtifacts);
-
- boolean suppressJavaRuleInfo(ConfiguredTarget base);
-
- void augmentCppRuleInfo(
- CIdeInfo.Builder builder,
- ConfiguredTarget base,
- RuleContext ruleContext,
- CppCompilationContext cppCompilationContext,
- NestedSetBuilder<Artifact> ideResolveArtifacts);
-
- boolean checkForAdditionalCppRules(String ruleClass);
-
- boolean checkForAdditionalPythonRules(String ruleClass);
-}
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
deleted file mode 100644
index 4c851ad..0000000
--- a/src/main/java/com/google/devtools/build/lib/ideinfo/BazelAndroidStudioInfoSemantics.java
+++ /dev/null
@@ -1,66 +0,0 @@
-// 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.rules.cpp.CppCompilationContext;
-import com.google.devtools.intellij.ideinfo.IntellijIdeInfo.CIdeInfo.Builder;
-import com.google.devtools.intellij.ideinfo.IntellijIdeInfo.TargetIdeInfo;
-
-/**
- * Bazel specific semantics for the {@link AndroidStudioInfoAspect} aspect.
- */
-public class BazelAndroidStudioInfoSemantics implements AndroidStudioInfoSemantics {
-
- @Override
- public void augmentCppRuleInfo(
- Builder builder,
- ConfiguredTarget base,
- RuleContext ruleContext,
- CppCompilationContext cppCompilationContext,
- NestedSetBuilder<Artifact> ideResolveArtifacts) {
- }
-
- @Override
- public void augmentPrerequisiteAttrs(ImmutableList.Builder<PrerequisiteAttr> builder) {
- }
-
- @Override
- public void augmentRuleInfo(
- TargetIdeInfo.Builder builder,
- ConfiguredTarget base,
- RuleContext ruleContext,
- NestedSetBuilder<Artifact> ideResolveArtifacts) {}
-
- @Override
- public boolean suppressJavaRuleInfo(ConfiguredTarget base) {
- return false;
- }
-
- @Override
- public boolean checkForAdditionalCppRules(String ruleClass) {
- return false;
- }
-
-
- @Override
- public boolean checkForAdditionalPythonRules(String ruleClass) {
- return false;
- }
-}
diff --git a/src/test/java/com/google/devtools/build/android/BUILD b/src/test/java/com/google/devtools/build/android/BUILD
index 2a638e1..411d0f3 100644
--- a/src/test/java/com/google/devtools/build/android/BUILD
+++ b/src/test/java/com/google/devtools/build/android/BUILD
@@ -1,7 +1,6 @@
filegroup(
name = "srcs",
srcs = glob(["**"]) + [
- "//src/test/java/com/google/devtools/build/android/ideinfo:srcs",
"//src/test/java/com/google/devtools/build/android/idlclass:srcs",
"//src/test/java/com/google/devtools/build/android/resources:srcs",
"//src/test/java/com/google/devtools/build/android/ziputils:srcs",
diff --git a/src/test/java/com/google/devtools/build/android/ideinfo/ArtifactLocationConverterTest.java b/src/test/java/com/google/devtools/build/android/ideinfo/ArtifactLocationConverterTest.java
deleted file mode 100644
index 9fac92c..0000000
--- a/src/test/java/com/google/devtools/build/android/ideinfo/ArtifactLocationConverterTest.java
+++ /dev/null
@@ -1,106 +0,0 @@
-// 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.android.ideinfo;
-
-import static com.google.common.truth.Truth.assertThat;
-import static org.junit.Assert.fail;
-
-import com.google.common.base.Joiner;
-import com.google.devtools.build.lib.ideinfo.androidstudio.PackageManifestOuterClass.ArtifactLocation;
-import com.google.devtools.common.options.OptionsParsingException;
-import java.nio.file.Paths;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
-/**
- * Tests {@link ArtifactLocationConverter}.
- */
-@RunWith(JUnit4.class)
-public class ArtifactLocationConverterTest {
-
- private ArtifactLocationConverter converter;
-
- @Before
- public final void init() throws Exception {
- converter = new ArtifactLocationConverter();
- }
-
- @Test
- public void testConverterSourceArtifact() throws Exception {
- ArtifactLocation parsed = converter.convert(
- Joiner.on(',').join("", "test.java")
- );
- assertThat(parsed)
- .isEqualTo(
- ArtifactLocation.newBuilder()
- .setRelativePath(Paths.get("test.java").toString())
- .setIsSource(true)
- .build());
- }
-
- @Test
- public void testConverterDerivedArtifact() throws Exception {
- ArtifactLocation parsed = converter.convert(
- Joiner.on(',').join("bin", "java/com/test.java")
- );
- assertThat(parsed)
- .isEqualTo(
- ArtifactLocation.newBuilder()
- .setRootExecutionPathFragment(Paths.get("bin").toString())
- .setRelativePath(Paths.get("java/com/test.java").toString())
- .setIsSource(false)
- .build());
- }
-
- @Test
- public void testConverterExternal() throws Exception {
- ArtifactLocation externalArtifact =
- converter.convert(Joiner.on(',').join("", "test.java", "1"));
- assertThat(externalArtifact)
- .isEqualTo(
- ArtifactLocation.newBuilder()
- .setRelativePath(Paths.get("test.java").toString())
- .setIsSource(true)
- .setIsExternal(true)
- .build());
- ArtifactLocation nonExternalArtifact =
- converter.convert(Joiner.on(',').join("", "test.java", "0"));
- assertThat(nonExternalArtifact)
- .isEqualTo(
- ArtifactLocation.newBuilder()
- .setRelativePath(Paths.get("test.java").toString())
- .setIsSource(true)
- .setIsExternal(false)
- .build());
- }
-
- @Test
- public void testInvalidFormatFails() throws Exception {
- assertFails("/root", ArtifactLocationConverter.INVALID_FORMAT);
- assertFails("/root,exec,rel,extra", ArtifactLocationConverter.INVALID_FORMAT);
- }
-
- private void assertFails(String input, String expectedError) {
- try {
- new ArtifactLocationConverter().convert(input);
- fail();
- } catch (OptionsParsingException e) {
- assertThat(e).hasMessage(expectedError);
- }
- }
-}
-
diff --git a/src/test/java/com/google/devtools/build/android/ideinfo/BUILD b/src/test/java/com/google/devtools/build/android/ideinfo/BUILD
deleted file mode 100644
index 924ec5f..0000000
--- a/src/test/java/com/google/devtools/build/android/ideinfo/BUILD
+++ /dev/null
@@ -1,52 +0,0 @@
-filegroup(
- name = "srcs",
- srcs = glob(["**"]),
- visibility = ["//src/test/java/com/google/devtools/build/android:__pkg__"],
-)
-
-java_test(
- name = "JarFilterTest",
- size = "small",
- srcs = ["JarFilterTest.java"],
- deps = [
- "//src/main/java/com/google/devtools/common/options",
- "//src/main/protobuf:package_manifest_java_proto",
- "//src/tools/android/java/com/google/devtools/build/android/ideinfo:jar_filter_lib",
- "//third_party:guava",
- "//third_party:jsr305",
- "//third_party:junit4",
- "//third_party:truth",
- "//third_party/protobuf:protobuf_java",
- ],
-)
-
-java_test(
- name = "PackageParserTest",
- size = "small",
- srcs = ["PackageParserTest.java"],
- deps = [
- "//src/main/java/com/google/devtools/common/options",
- "//src/main/protobuf:package_manifest_java_proto",
- "//src/tools/android/java/com/google/devtools/build/android/ideinfo:package_parser_lib",
- "//third_party:guava",
- "//third_party:jsr305",
- "//third_party:junit4",
- "//third_party:truth",
- "//third_party/protobuf:protobuf_java",
- ],
-)
-
-java_test(
- name = "ArtifactLocationConverterTest",
- size = "small",
- srcs = ["ArtifactLocationConverterTest.java"],
- deps = [
- "//src/main/java/com/google/devtools/common/options",
- "//src/main/protobuf:package_manifest_java_proto",
- "//src/tools/android/java/com/google/devtools/build/android/ideinfo:package_parser_lib",
- "//third_party:guava",
- "//third_party:junit4",
- "//third_party:truth",
- "//third_party/protobuf:protobuf_java",
- ],
-)
diff --git a/src/test/java/com/google/devtools/build/android/ideinfo/JarFilterTest.java b/src/test/java/com/google/devtools/build/android/ideinfo/JarFilterTest.java
deleted file mode 100644
index a17048d..0000000
--- a/src/test/java/com/google/devtools/build/android/ideinfo/JarFilterTest.java
+++ /dev/null
@@ -1,252 +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.android.ideinfo;
-
-import static com.google.common.truth.Truth.assertThat;
-import static java.nio.charset.StandardCharsets.UTF_8;
-
-import com.google.common.base.Joiner;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Lists;
-import com.google.common.io.Files;
-import com.google.devtools.build.android.ideinfo.JarFilter.JarFilterOptions;
-import com.google.devtools.build.lib.ideinfo.androidstudio.PackageManifestOuterClass.ArtifactLocation;
-import com.google.devtools.build.lib.ideinfo.androidstudio.PackageManifestOuterClass.JavaSourcePackage;
-import com.google.devtools.build.lib.ideinfo.androidstudio.PackageManifestOuterClass.PackageManifest;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.util.Enumeration;
-import java.util.List;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipFile;
-import java.util.zip.ZipOutputStream;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
-/** Unit tests for {@link JarFilter} */
-@RunWith(JUnit4.class)
-public class JarFilterTest {
-
- @Rule public TemporaryFolder folder = new TemporaryFolder();
-
- @Test
- public void testFilterMethod() throws Exception {
- List<String> prefixes =
- ImmutableList.of("com/google/foo/Foo", "com/google/bar/Bar", "com/google/baz/Baz");
- assertThat(JarFilter.shouldKeepClass(prefixes, "com/google/foo/Foo.class")).isTrue();
- assertThat(JarFilter.shouldKeepClass(prefixes, "com/google/foo/Foo$Inner.class")).isTrue();
- assertThat(JarFilter.shouldKeepClass(prefixes, "com/google/bar/Bar.class")).isTrue();
- assertThat(JarFilter.shouldKeepClass(prefixes, "com/google/foo/Foo/NotFoo.class")).isFalse();
- assertThat(JarFilter.shouldKeepClass(prefixes, "wrong/com/google/foo/Foo.class")).isFalse();
- }
-
- @Test
- public void legacyIntegrationTest() throws Exception {
- PackageManifest packageManifest =
- PackageManifest.newBuilder()
- .addSources(
- JavaSourcePackage.newBuilder()
- .setArtifactLocation(
- ArtifactLocation.newBuilder()
- .setIsSource(true)
- .setRelativePath("com/google/foo/Foo.java"))
- .setPackageString("com.google.foo"))
- .addSources(
- JavaSourcePackage.newBuilder()
- .setArtifactLocation(
- ArtifactLocation.newBuilder()
- .setIsSource(true)
- .setRelativePath("com/google/bar/Bar.java"))
- .setPackageString("com.google.bar"))
- .addSources(
- JavaSourcePackage.newBuilder()
- .setArtifactLocation(
- ArtifactLocation.newBuilder()
- .setIsSource(true)
- .setRelativePath("some/path/Test.java"))
- .setPackageString("com.google.test"))
- .build();
- assertThat(JarFilter.parsePackageManifest(packageManifest))
- .containsExactly("com/google/foo/Foo", "com/google/bar/Bar", "com/google/test/Test");
- File manifest = folder.newFile("foo.manifest");
- try (FileOutputStream outputStream = new FileOutputStream(manifest)) {
- packageManifest.writeTo(outputStream);
- }
-
- File filterJar = folder.newFile("foo.jar");
- try (ZipOutputStream zo = new ZipOutputStream(new FileOutputStream(filterJar))) {
- zo.putNextEntry(new ZipEntry("com/google/foo/Foo.class"));
- zo.closeEntry();
- zo.putNextEntry(new ZipEntry("com/google/foo/Foo$Inner.class"));
- zo.closeEntry();
- zo.putNextEntry(new ZipEntry("com/google/bar/Bar.class"));
- zo.closeEntry();
- zo.putNextEntry(new ZipEntry("com/google/test/Test.class"));
- zo.closeEntry();
- zo.putNextEntry(new ZipEntry("com/google/foo/Foo2.class"));
- zo.closeEntry();
- }
-
- File outputJar = folder.newFile("foo-filtered-gen.jar");
-
- String[] args =
- new String[] {
- "--jars",
- filterJar.getPath(),
- "--output",
- outputJar.getPath(),
- "--manifest",
- manifest.getPath()
- };
- JarFilter.JarFilterOptions options = JarFilter.parseArgs(args);
- JarFilter.main(options);
-
- List<String> filteredJarNames = Lists.newArrayList();
- try (ZipFile zipFile = new ZipFile(outputJar)) {
- Enumeration<? extends ZipEntry> entries = zipFile.entries();
- while (entries.hasMoreElements()) {
- ZipEntry zipEntry = entries.nextElement();
- filteredJarNames.add(zipEntry.getName());
- }
- }
-
- assertThat(filteredJarNames)
- .containsExactly(
- "com/google/foo/Foo.class",
- "com/google/foo/Foo$Inner.class",
- "com/google/bar/Bar.class",
- "com/google/test/Test.class");
- }
-
- @Test
- public void fullIntegrationTest() throws Exception {
- File fooJava = folder.newFile("Foo.java");
- Files.write("package com.google.foo; class Foo { class Inner {} }".getBytes(UTF_8), fooJava);
-
- File barJava = folder.newFile("Bar.java");
- Files.write("package com.google.foo.bar; class Bar {}".getBytes(UTF_8), barJava);
-
- File srcJar = folder.newFile("gen.srcjar");
- try (ZipOutputStream zo = new ZipOutputStream(new FileOutputStream(srcJar))) {
- zo.putNextEntry(new ZipEntry("com/google/foo/gen/Gen.java"));
- zo.write("package gen; class Gen {}".getBytes(UTF_8));
- zo.closeEntry();
- zo.putNextEntry(new ZipEntry("com/google/foo/gen/Gen2.java"));
- zo.write("package gen; class Gen2 {}".getBytes(UTF_8));
- zo.closeEntry();
- }
-
- File src3Jar = folder.newFile("gen3.srcjar");
- try (ZipOutputStream zo = new ZipOutputStream(new FileOutputStream(src3Jar))) {
- zo.putNextEntry(new ZipEntry("com/google/foo/gen/Gen3.java"));
- zo.write("package gen; class Gen3 {}".getBytes(UTF_8));
- zo.closeEntry();
- }
-
- File filterJar = folder.newFile("foo.jar");
- try (ZipOutputStream zo = new ZipOutputStream(new FileOutputStream(filterJar))) {
- zo.putNextEntry(new ZipEntry("com/google/foo/Foo.class"));
- zo.closeEntry();
- zo.putNextEntry(new ZipEntry("com/google/foo/Foo$Inner.class"));
- zo.closeEntry();
- zo.putNextEntry(new ZipEntry("com/google/foo/bar/Bar.class"));
- zo.closeEntry();
- zo.putNextEntry(new ZipEntry("gen/Gen.class"));
- zo.closeEntry();
- zo.putNextEntry(new ZipEntry("gen/Gen2.class"));
- zo.closeEntry();
- zo.putNextEntry(new ZipEntry("gen/Gen3.class"));
- zo.closeEntry();
- zo.putNextEntry(new ZipEntry("com/google/foo/Foo2.class"));
- zo.closeEntry();
- }
- File filterSrcJar = folder.newFile("foo-src.jar");
- try (ZipOutputStream zo = new ZipOutputStream(new FileOutputStream(filterSrcJar))) {
- zo.putNextEntry(new ZipEntry("com/google/foo/Foo.java"));
- zo.closeEntry();
- zo.putNextEntry(new ZipEntry("com/google/foo/bar/Bar.java"));
- zo.closeEntry();
- zo.putNextEntry(new ZipEntry("gen/Gen.java"));
- zo.closeEntry();
- zo.putNextEntry(new ZipEntry("gen/Gen2.java"));
- zo.closeEntry();
- zo.putNextEntry(new ZipEntry("gen/Gen3.java"));
- zo.closeEntry();
- zo.putNextEntry(new ZipEntry("com/google/foo/Foo2.java"));
- zo.closeEntry();
- zo.putNextEntry(new ZipEntry("com/google/foo/bar/Bar2.java"));
- zo.closeEntry();
- }
-
- File filteredJar = folder.newFile("foo-filtered-gen.jar");
- File filteredSourceJar = folder.newFile("foo-filtered-gen-src.jar");
-
- String[] args =
- new String[] {
- "--keep_java_files",
- fooJava.getPath() + File.pathSeparator + barJava.getPath(),
- "--keep_source_jars",
- Joiner.on(File.pathSeparator).join(srcJar.getPath(), src3Jar.getPath()),
- "--filter_jars",
- filterJar.getPath(),
- "--filter_source_jars",
- filterSrcJar.getPath(),
- "--filtered_jar",
- filteredJar.getPath(),
- "--filtered_source_jar",
- filteredSourceJar.getPath()
- };
- JarFilterOptions options = JarFilter.parseArgs(args);
- JarFilter.main(options);
-
- List<String> filteredJarNames = Lists.newArrayList();
- try (ZipFile zipFile = new ZipFile(filteredJar)) {
- Enumeration<? extends ZipEntry> entries = zipFile.entries();
- while (entries.hasMoreElements()) {
- ZipEntry zipEntry = entries.nextElement();
- filteredJarNames.add(zipEntry.getName());
- }
- }
-
- List<String> filteredSourceJarNames = Lists.newArrayList();
- try (ZipFile zipFile = new ZipFile(filteredSourceJar)) {
- Enumeration<? extends ZipEntry> entries = zipFile.entries();
- while (entries.hasMoreElements()) {
- ZipEntry zipEntry = entries.nextElement();
- filteredSourceJarNames.add(zipEntry.getName());
- }
- }
-
- assertThat(filteredJarNames)
- .containsExactly(
- "com/google/foo/Foo.class",
- "com/google/foo/Foo$Inner.class",
- "com/google/foo/bar/Bar.class",
- "gen/Gen.class",
- "gen/Gen2.class",
- "gen/Gen3.class");
-
- assertThat(filteredSourceJarNames)
- .containsExactly(
- "com/google/foo/Foo.java",
- "com/google/foo/bar/Bar.java",
- "gen/Gen.java",
- "gen/Gen2.java",
- "gen/Gen3.java");
- }
-}
diff --git a/src/test/java/com/google/devtools/build/android/ideinfo/PackageParserTest.java b/src/test/java/com/google/devtools/build/android/ideinfo/PackageParserTest.java
deleted file mode 100644
index cfb8096..0000000
--- a/src/test/java/com/google/devtools/build/android/ideinfo/PackageParserTest.java
+++ /dev/null
@@ -1,276 +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.android.ideinfo;
-
-import static com.google.common.truth.Truth.assertThat;
-import static org.junit.Assert.fail;
-
-import com.google.common.base.Joiner;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-import com.google.devtools.build.lib.ideinfo.androidstudio.PackageManifestOuterClass.ArtifactLocation;
-import com.google.protobuf.MessageLite;
-import java.io.BufferedReader;
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.StringWriter;
-import java.io.UnsupportedEncodingException;
-import java.nio.charset.StandardCharsets;
-import java.nio.file.InvalidPathException;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.List;
-import java.util.Map;
-import javax.annotation.Nonnull;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
-/**
- * Unit tests for {@link PackageParser}
- */
-@RunWith(JUnit4.class)
-public class PackageParserTest {
-
- private static class MockPackageParserIoProvider extends PackageParserIoProvider {
- private final Map<Path, InputStream> sources = Maps.newHashMap();
- private final List<ArtifactLocation> sourceLocations = Lists.newArrayList();
- private StringWriter writer = new StringWriter();
-
- public MockPackageParserIoProvider addSource(ArtifactLocation source, String javaSrc) {
- try {
- Path path = Paths.get(source.getRootExecutionPathFragment(), source.getRelativePath());
- sources.put(path, new ByteArrayInputStream(javaSrc.getBytes("UTF-8")));
- sourceLocations.add(source);
-
- } catch (UnsupportedEncodingException | InvalidPathException e) {
- fail(e.getMessage());
- }
- return this;
- }
-
- public void reset() {
- sources.clear();
- sourceLocations.clear();
- writer = new StringWriter();
- }
-
- public List<ArtifactLocation> getSourceLocations() {
- return Lists.newArrayList(sourceLocations);
- }
-
- @Nonnull
- @Override
- public BufferedReader getReader(Path file) throws IOException {
- InputStream input = sources.get(file);
- return new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8));
- }
-
- @Override
- public void writeProto(@Nonnull MessageLite message, @Nonnull Path file) throws IOException {
- writer.write(message.toString());
- }
- }
-
- private static final ArtifactLocation DUMMY_SOURCE_ARTIFACT =
- ArtifactLocation.newBuilder()
- .setRelativePath("java/com/google/Foo.java")
- .setIsSource(true)
- .build();
-
- private static final ArtifactLocation DUMMY_DERIVED_ARTIFACT =
- ArtifactLocation.newBuilder()
- .setRootExecutionPathFragment("bin")
- .setRelativePath("java/com/google/Bla.java")
- .setIsSource(false)
- .build();
-
- private MockPackageParserIoProvider mockIoProvider;
- private PackageParser parser;
-
- @Before
- public void setUp() {
- mockIoProvider = new MockPackageParserIoProvider();
- parser = new PackageParser(mockIoProvider);
- }
-
- private Map<ArtifactLocation, String> parsePackageStrings() throws Exception {
- List<ArtifactLocation> sources = mockIoProvider.getSourceLocations();
- return parser.parsePackageStrings(sources);
- }
-
- @Test
- public void testParseCommandLineArguments() throws Exception {
- String[] args = new String[] {
- "--output_manifest",
- "/tmp/out.manifest",
- "--sources",
- Joiner.on(':').join(
- ",java/com/google/Foo.java",
- "bin/out,java/com/google/Bla.java")
- };
- PackageParser.PackageParserOptions options = PackageParser.parseArgs(args);
- assertThat(options.outputManifest.toString())
- .isEqualTo(Paths.get("/tmp/out.manifest").toString());
- assertThat(options.sources).hasSize(2);
- assertThat(options.sources.get(0))
- .isEqualTo(
- ArtifactLocation.newBuilder()
- .setRelativePath(Paths.get("java/com/google/Foo.java").toString())
- .setIsSource(true)
- .build());
- assertThat(options.sources.get(1))
- .isEqualTo(
- ArtifactLocation.newBuilder()
- .setRootExecutionPathFragment(Paths.get("bin/out").toString())
- .setRelativePath(Paths.get("java/com/google/Bla.java").toString())
- .setIsSource(false)
- .build());
- }
-
- @Test
- public void testReadNoSources() throws Exception {
- Map<ArtifactLocation, String> map = parsePackageStrings();
- assertThat(map).isEmpty();
- }
-
- @Test
- public void testSingleRead() throws Exception {
- mockIoProvider
- .addSource(
- DUMMY_SOURCE_ARTIFACT,
- "package com.google;\n public class Bla {}\"");
- Map<ArtifactLocation, String> map = parsePackageStrings();
- assertThat(map).hasSize(1);
- assertThat(map).containsEntry(
- DUMMY_SOURCE_ARTIFACT,
- "com.google");
- }
-
- @Test
- public void testMultiRead() throws Exception {
- mockIoProvider
- .addSource(
- DUMMY_SOURCE_ARTIFACT,
- "package com.test;\n public class Bla {}\"")
- .addSource(
- DUMMY_DERIVED_ARTIFACT,
- "package com.other;\n public class Foo {}\"");
- Map<ArtifactLocation, String> map = parsePackageStrings();
- assertThat(map).hasSize(2);
- assertThat(map).containsEntry(
- DUMMY_SOURCE_ARTIFACT,
- "com.test");
- assertThat(map).containsEntry(
- DUMMY_DERIVED_ARTIFACT,
- "com.other");
- }
-
- @Test
- public void testReadSomeInvalid() throws Exception {
- mockIoProvider
- .addSource(
- DUMMY_SOURCE_ARTIFACT,
- "package %com.test;\n public class Bla {}\"")
- .addSource(
- DUMMY_DERIVED_ARTIFACT,
- "package com.other;\n public class Foo {}\"");
- Map<ArtifactLocation, String> map = parsePackageStrings();
- assertThat(map).hasSize(1);
- assertThat(map).containsEntry(
- DUMMY_DERIVED_ARTIFACT,
- "com.other");
- }
-
- @Test
- public void testReadAllInvalid() throws Exception {
- mockIoProvider
- .addSource(
- DUMMY_SOURCE_ARTIFACT,
- "#package com.test;\n public class Bla {}\"")
- .addSource(
- DUMMY_DERIVED_ARTIFACT,
- "package com.other\n public class Foo {}\"");
- Map<ArtifactLocation, String> map = parsePackageStrings();
- assertThat(map).isEmpty();
- }
-
- @Test
- public void testWriteEmptyMap() throws Exception {
- parser.writeManifest(
- Maps.<ArtifactLocation, String> newHashMap(),
- Paths.get("/java/com/google/test.manifest"));
- assertThat(mockIoProvider.writer.toString()).isEmpty();
- }
-
- @Test
- public void testWriteMap() throws Exception {
- Map<ArtifactLocation, String> map = ImmutableMap.of(
- DUMMY_SOURCE_ARTIFACT,
- "com.google",
- DUMMY_DERIVED_ARTIFACT,
- "com.other"
- );
- parser.writeManifest(map, Paths.get("/java/com/google/test.manifest"));
-
- String writtenString = mockIoProvider.writer.toString();
- assertThat(writtenString).contains(String.format(
- "relative_path: \"%s\"",
- DUMMY_SOURCE_ARTIFACT.getRelativePath()));
- assertThat(writtenString).contains("package_string: \"com.google\"");
-
- assertThat(writtenString).contains(String.format(
- "root_execution_path_fragment: \"%s\"",
- DUMMY_DERIVED_ARTIFACT.getRootExecutionPathFragment()));
- assertThat(writtenString).contains(String.format(
- "relative_path: \"%s\"",
- DUMMY_DERIVED_ARTIFACT.getRelativePath()));
- assertThat(writtenString).contains("package_string: \"com.other\"");
- }
-
- @Test
- public void testHandlesOldFormat() throws Exception {
- String[] args = new String[] {
- "--output_manifest",
- "/tmp/out.manifest",
- "--sources",
- Joiner.on(':').join(
- ",java/com/google/Foo.java,/usr/local/google/code",
- "bin,java/com/google/Bla.java,/usr/local/_tmp/code/bin"
- )};
- PackageParser.PackageParserOptions options = PackageParser.parseArgs(args);
- assertThat(options.outputManifest.toString())
- .isEqualTo(Paths.get("/tmp/out.manifest").toString());
- assertThat(options.sources).hasSize(2);
- assertThat(options.sources.get(0))
- .isEqualTo(
- ArtifactLocation.newBuilder()
- .setRelativePath(Paths.get("java/com/google/Foo.java").toString())
- .setIsSource(true)
- .build());
- assertThat(options.sources.get(1))
- .isEqualTo(
- ArtifactLocation.newBuilder()
- .setRootExecutionPathFragment(Paths.get("bin").toString())
- .setRelativePath(Paths.get("java/com/google/Bla.java").toString())
- .setIsSource(false)
- .build());
- }
-
-}
diff --git a/src/test/java/com/google/devtools/build/lib/BUILD b/src/test/java/com/google/devtools/build/lib/BUILD
index 2aa95f5..f3c03d1 100644
--- a/src/test/java/com/google/devtools/build/lib/BUILD
+++ b/src/test/java/com/google/devtools/build/lib/BUILD
@@ -666,38 +666,6 @@
],
)
-java_test(
- name = "ideinfo_test",
- srcs = glob([
- "ideinfo/*.java",
- ]),
- tags = ["ideinfo"],
- test_class = "com.google.devtools.build.lib.AllTests",
- deps = [
- ":analysis_testutil",
- ":foundations_testutil",
- ":test_runner",
- ":testutil",
- "//src/main/java/com/google/devtools/build/lib:bazel-main",
- "//src/main/java/com/google/devtools/build/lib:bazel-rules",
- "//src/main/java/com/google/devtools/build/lib:build-base",
- "//src/main/java/com/google/devtools/build/lib:collect",
- "//src/main/java/com/google/devtools/build/lib:events",
- "//src/main/java/com/google/devtools/build/lib:ideinfo",
- "//src/main/java/com/google/devtools/build/lib:packages",
- "//src/main/java/com/google/devtools/build/lib:vfs",
- "//src/main/java/com/google/devtools/build/lib/actions",
- "//src/main/protobuf:intellij_ide_info_java_proto",
- "//third_party:guava",
- "//third_party:guava-testlib",
- "//third_party:jsr305",
- "//third_party:junit4",
- "//third_party:mockito",
- "//third_party:truth",
- "//third_party/protobuf:protobuf_java",
- ],
-)
-
cc_binary(
name = "shell/killmyself",
srcs = ["shell/killmyself.cc"],
@@ -1281,7 +1249,6 @@
"shell",
"server",
"skyframe",
- "ideinfo",
"exec",
]
diff --git a/src/test/java/com/google/devtools/build/lib/ideinfo/AndroidStudioInfoAspectTest.java b/src/test/java/com/google/devtools/build/lib/ideinfo/AndroidStudioInfoAspectTest.java
deleted file mode 100644
index 4a80886..0000000
--- a/src/test/java/com/google/devtools/build/lib/ideinfo/AndroidStudioInfoAspectTest.java
+++ /dev/null
@@ -1,1865 +0,0 @@
-// Copyright 2014 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 static com.google.common.collect.Iterables.transform;
-import static com.google.common.truth.Truth.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-import com.google.common.collect.Iterables;
-import com.google.common.collect.ObjectArrays;
-import com.google.devtools.build.lib.actions.Root;
-import com.google.devtools.build.lib.cmdline.RepositoryName;
-import com.google.devtools.build.lib.vfs.PathFragment;
-import com.google.devtools.intellij.ideinfo.IntellijIdeInfo.ArtifactLocation;
-import com.google.devtools.intellij.ideinfo.IntellijIdeInfo.CIdeInfo;
-import com.google.devtools.intellij.ideinfo.IntellijIdeInfo.CToolchainIdeInfo;
-import com.google.devtools.intellij.ideinfo.IntellijIdeInfo.JavaIdeInfo;
-import com.google.devtools.intellij.ideinfo.IntellijIdeInfo.TargetIdeInfo;
-import com.google.protobuf.ByteString;
-import com.google.protobuf.ProtocolStringList;
-import java.nio.file.Paths;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
-/** Tests for {@link AndroidStudioInfoAspect} validating proto's contents. */
-@RunWith(JUnit4.class)
-public class AndroidStudioInfoAspectTest extends AndroidStudioInfoAspectTestBase {
-
- @Override
- protected final void useConfiguration(String... args) throws Exception {
- super.useConfiguration(ObjectArrays.concat(args, "--java_header_compilation=true"));
- }
-
- @Test
- public void testSimpleJavaLibrary() throws Exception {
- scratch.file(
- "com/google/example/BUILD",
- "java_library(",
- " name = 'simple',",
- " srcs = ['simple/Simple.java']",
- ")");
- Map<String, TargetIdeInfo> targetIdeInfos = buildIdeInfo("//com/google/example:simple");
- TargetIdeInfo targetIdeInfo =
- getTargetIdeInfoAndVerifyLabel("//com/google/example:simple", targetIdeInfos);
- ArtifactLocation location = targetIdeInfo.getBuildFileArtifactLocation();
- assertThat(Paths.get(location.getRelativePath()).toString())
- .isEqualTo(Paths.get("com/google/example/BUILD").toString());
- assertThat(location.getIsSource()).isTrue();
- assertThat(location.getIsExternal()).isFalse();
- assertThat(targetIdeInfo.getKindString()).isEqualTo("java_library");
- assertThat(relativePathsForJavaSourcesOf(targetIdeInfo))
- .containsExactly("com/google/example/simple/Simple.java");
- assertThat(transform(targetIdeInfo.getJavaIdeInfo().getJarsList(), LIBRARY_ARTIFACT_TO_STRING))
- .containsExactly(
- jarString(
- "com/google/example", "libsimple.jar", "libsimple-hjar.jar", "libsimple-src.jar"));
-
- assertThat(getIdeResolveFiles())
- .containsExactly(
- "com/google/example/libsimple.jar",
- "com/google/example/libsimple-hjar.jar",
- "com/google/example/libsimple-src.jar");
- assertThat(targetIdeInfo.getJavaIdeInfo().getJdeps().getRelativePath())
- .isEqualTo("com/google/example/libsimple.jdeps");
- }
-
- @Test
- public void testPackageManifestCreated() throws Exception {
- scratch.file(
- "com/google/example/BUILD",
- "java_library(",
- " name = 'simple',",
- " srcs = ['simple/Simple.java']",
- ")");
- Map<String, TargetIdeInfo> targetIdeInfos = buildIdeInfo("//com/google/example:simple");
- TargetIdeInfo targetIdeInfo =
- getTargetIdeInfoAndVerifyLabel("//com/google/example:simple", targetIdeInfos);
-
- ArtifactLocation packageManifest = targetIdeInfo.getJavaIdeInfo().getPackageManifest();
- assertNotNull(packageManifest);
-
- assertEquals(packageManifest.getRelativePath(), "com/google/example/simple.manifest");
- }
-
- @Test
- public void testPackageManifestNotCreatedForOnlyGeneratedSources() throws Exception {
- scratch.file(
- "com/google/example/BUILD",
- "genrule(",
- " name = 'gen_sources',",
- " outs = ['Gen.java'],",
- " cmd = '',",
- ")",
- "java_library(",
- " name = 'simple',",
- " srcs = [':gen_sources']",
- ")");
- Map<String, TargetIdeInfo> targetIdeInfos = buildIdeInfo("//com/google/example:simple");
- TargetIdeInfo targetIdeInfo =
- getTargetIdeInfoAndVerifyLabel("//com/google/example:simple", targetIdeInfos);
- assertThat(targetIdeInfo.getJavaIdeInfo().hasPackageManifest()).isFalse();
- }
-
- @Test
- public void testFilteredGenJarNotCreatedForSourceOnlyRule() throws Exception {
- scratch.file(
- "com/google/example/BUILD",
- "java_library(",
- " name = 'simple',",
- " srcs = ['Test.java']",
- ")");
- Map<String, TargetIdeInfo> targetIdeInfos = buildIdeInfo("//com/google/example:simple");
- TargetIdeInfo targetIdeInfo =
- getTargetIdeInfoAndVerifyLabel("//com/google/example:simple", targetIdeInfos);
- assertThat(targetIdeInfo.getJavaIdeInfo().hasFilteredGenJar()).isFalse();
- }
-
- @Test
- public void testFilteredGenJarNotCreatedForOnlyGenRule() throws Exception {
- scratch.file(
- "com/google/example/BUILD",
- "genrule(",
- " name = 'gen_sources',",
- " outs = ['Gen.java'],",
- " cmd = '',",
- ")",
- "java_library(",
- " name = 'simple',",
- " srcs = [':gen_sources']",
- ")");
- Map<String, TargetIdeInfo> targetIdeInfos = buildIdeInfo("//com/google/example:simple");
- TargetIdeInfo targetIdeInfo =
- getTargetIdeInfoAndVerifyLabel("//com/google/example:simple", targetIdeInfos);
- assertThat(targetIdeInfo.getJavaIdeInfo().hasFilteredGenJar()).isFalse();
- }
-
- @Test
- public void testFilteredGenJar() throws Exception {
- scratch.file(
- "com/google/example/BUILD",
- "genrule(",
- " name = 'gen_sources',",
- " outs = ['Gen.java'],",
- " cmd = '',",
- ")",
- "genrule(",
- " name = 'gen_srcjar',",
- " outs = ['gen.srcjar'],",
- " cmd = '',",
- ")",
- "java_library(",
- " name = 'lib',",
- " srcs = [':gen_sources', ':gen_srcjar', 'Test.java']",
- ")");
- Map<String, TargetIdeInfo> targetIdeInfos = buildIdeInfo("//com/google/example:lib");
- TargetIdeInfo targetIdeInfo =
- getTargetIdeInfoAndVerifyLabel("//com/google/example:lib", targetIdeInfos);
- assertThat(targetIdeInfo.getJavaIdeInfo().hasFilteredGenJar()).isTrue();
- assertThat(targetIdeInfo.getJavaIdeInfo().getFilteredGenJar().getJar().getRelativePath())
- .isEqualTo("com/google/example/lib-filtered-gen.jar");
- assertThat(targetIdeInfo.getJavaIdeInfo().getFilteredGenJar().getSourceJar().getRelativePath())
- .isEqualTo("com/google/example/lib-filtered-gen-src.jar");
- }
-
- @Test
- public void testJavaLibraryWithDependencies() throws Exception {
- scratch.file(
- "com/google/example/BUILD",
- "java_library(",
- " name = 'simple',",
- " srcs = ['simple/Simple.java']",
- ")",
- "java_library(",
- " name = 'complex',",
- " srcs = ['complex/Complex.java'],",
- " deps = [':simple']",
- ")");
-
- Map<String, TargetIdeInfo> targetIdeInfos = buildIdeInfo("//com/google/example:complex");
-
- getTargetIdeInfoAndVerifyLabel("//com/google/example:simple", targetIdeInfos);
- TargetIdeInfo complexTarget =
- getTargetIdeInfoAndVerifyLabel("//com/google/example:complex", targetIdeInfos);
-
- assertThat(relativePathsForJavaSourcesOf(complexTarget))
- .containsExactly("com/google/example/complex/Complex.java");
- assertThat(complexTarget.getDependenciesList()).contains("//com/google/example:simple");
- }
-
- @Test
- public void testJavaLibraryWithTransitiveDependencies() throws Exception {
- scratch.file(
- "com/google/example/BUILD",
- "java_library(",
- " name = 'simple',",
- " srcs = ['simple/Simple.java']",
- ")",
- "java_library(",
- " name = 'complex',",
- " srcs = ['complex/Complex.java'],",
- " deps = [':simple']",
- ")",
- "java_library(",
- " name = 'extracomplex',",
- " srcs = ['extracomplex/ExtraComplex.java'],",
- " deps = [':complex']",
- ")");
- Map<String, TargetIdeInfo> targetIdeInfos = buildIdeInfo("//com/google/example:extracomplex");
-
- getTargetIdeInfoAndVerifyLabel("//com/google/example:simple", targetIdeInfos);
- getTargetIdeInfoAndVerifyLabel("//com/google/example:complex", targetIdeInfos);
-
- TargetIdeInfo extraComplexTarget =
- getTargetIdeInfoAndVerifyLabel("//com/google/example:extracomplex", targetIdeInfos);
-
- assertThat(relativePathsForJavaSourcesOf(extraComplexTarget))
- .containsExactly("com/google/example/extracomplex/ExtraComplex.java");
- assertThat(extraComplexTarget.getDependenciesList()).contains("//com/google/example:complex");
-
- assertThat(getIdeResolveFiles())
- .containsExactly(
- "com/google/example/libextracomplex.jar",
- "com/google/example/libextracomplex-hjar.jar",
- "com/google/example/libextracomplex-src.jar",
- "com/google/example/libcomplex.jar",
- "com/google/example/libcomplex-hjar.jar",
- "com/google/example/libcomplex-src.jar",
- "com/google/example/libsimple.jar",
- "com/google/example/libsimple-hjar.jar",
- "com/google/example/libsimple-src.jar");
- }
-
- @Test
- public void testJavaLibraryWithDiamondDependencies() throws Exception {
- scratch.file(
- "com/google/example/BUILD",
- "java_library(",
- " name = 'simple',",
- " srcs = ['simple/Simple.java']",
- ")",
- "java_library(",
- " name = 'complex',",
- " srcs = ['complex/Complex.java'],",
- " deps = [':simple']",
- ")",
- "java_library(",
- " name = 'complex1',",
- " srcs = ['complex1/Complex.java'],",
- " deps = [':simple']",
- ")",
- "java_library(",
- " name = 'extracomplex',",
- " srcs = ['extracomplex/ExtraComplex.java'],",
- " deps = [':complex', ':complex1']",
- ")");
- Map<String, TargetIdeInfo> targetIdeInfos = buildIdeInfo("//com/google/example:extracomplex");
-
- getTargetIdeInfoAndVerifyLabel("//com/google/example:simple", targetIdeInfos);
- getTargetIdeInfoAndVerifyLabel("//com/google/example:complex", targetIdeInfos);
- getTargetIdeInfoAndVerifyLabel("//com/google/example:complex1", targetIdeInfos);
-
- TargetIdeInfo extraComplexTarget =
- getTargetIdeInfoAndVerifyLabel("//com/google/example:extracomplex", targetIdeInfos);
-
- assertThat(relativePathsForJavaSourcesOf(extraComplexTarget))
- .containsExactly("com/google/example/extracomplex/ExtraComplex.java");
- assertThat(extraComplexTarget.getDependenciesList())
- .containsAllOf("//com/google/example:complex", "//com/google/example:complex1");
- }
-
- @Test
- public void testJavaLibraryWithExports() throws Exception {
- scratch.file(
- "com/google/example/BUILD",
- "java_library(",
- " name = 'simple',",
- " srcs = ['simple/Simple.java']",
- ")",
- "java_library(",
- " name = 'complex',",
- " srcs = ['complex/Complex.java'],",
- " exports = [':simple'],",
- ")",
- "java_library(",
- " name = 'extracomplex',",
- " srcs = ['extracomplex/ExtraComplex.java'],",
- " deps = [':complex']",
- ")");
- Map<String, TargetIdeInfo> targetIdeInfos = buildIdeInfo("//com/google/example:extracomplex");
-
- getTargetIdeInfoAndVerifyLabel("//com/google/example:simple", targetIdeInfos);
- getTargetIdeInfoAndVerifyLabel("//com/google/example:complex", targetIdeInfos);
-
- TargetIdeInfo complexTarget =
- getTargetIdeInfoAndVerifyLabel("//com/google/example:complex", targetIdeInfos);
- TargetIdeInfo extraComplexTarget =
- getTargetIdeInfoAndVerifyLabel("//com/google/example:extracomplex", targetIdeInfos);
-
- assertThat(complexTarget.getDependenciesList()).contains("//com/google/example:simple");
-
- assertThat(extraComplexTarget.getDependenciesList())
- .containsAllOf("//com/google/example:simple", "//com/google/example:complex");
- assertThat(getIdeResolveFiles())
- .containsExactly(
- "com/google/example/libextracomplex.jar",
- "com/google/example/libextracomplex-hjar.jar",
- "com/google/example/libextracomplex-src.jar",
- "com/google/example/libcomplex.jar",
- "com/google/example/libcomplex-hjar.jar",
- "com/google/example/libcomplex-src.jar",
- "com/google/example/libsimple.jar",
- "com/google/example/libsimple-hjar.jar",
- "com/google/example/libsimple-src.jar");
- }
-
- @Test
- public void testJavaLibraryWithTransitiveExports() throws Exception {
- scratch.file(
- "com/google/example/BUILD",
- "java_library(",
- " name = 'simple',",
- " srcs = ['simple/Simple.java']",
- ")",
- "java_library(",
- " name = 'complex',",
- " srcs = ['complex/Complex.java'],",
- " exports = [':simple'],",
- ")",
- "java_library(",
- " name = 'extracomplex',",
- " srcs = ['extracomplex/ExtraComplex.java'],",
- " exports = [':complex'],",
- ")",
- "java_library(",
- " name = 'megacomplex',",
- " srcs = ['megacomplex/MegaComplex.java'],",
- " deps = [':extracomplex'],",
- ")");
- Map<String, TargetIdeInfo> targetIdeInfos = buildIdeInfo("//com/google/example:megacomplex");
-
- getTargetIdeInfoAndVerifyLabel("//com/google/example:simple", targetIdeInfos);
- getTargetIdeInfoAndVerifyLabel("//com/google/example:complex", targetIdeInfos);
- getTargetIdeInfoAndVerifyLabel("//com/google/example:extracomplex", targetIdeInfos);
-
- TargetIdeInfo megaComplexTarget =
- getTargetIdeInfoAndVerifyLabel("//com/google/example:megacomplex", targetIdeInfos);
-
- assertThat(relativePathsForJavaSourcesOf(megaComplexTarget))
- .containsExactly("com/google/example/megacomplex/MegaComplex.java");
- assertThat(megaComplexTarget.getDependenciesList())
- .containsAllOf(
- "//com/google/example:simple",
- "//com/google/example:complex",
- "//com/google/example:extracomplex");
- }
-
- @Test
- public void testJavaImport() throws Exception {
- scratch.file(
- "com/google/example/BUILD",
- "java_import(",
- " name = 'imp',",
- " jars = ['a.jar', 'b.jar'],",
- " srcjar = 'impsrc.jar',",
- ")",
- "java_library(",
- " name = 'lib',",
- " srcs = ['Lib.java'],",
- " deps = [':imp'],",
- ")");
-
- Map<String, TargetIdeInfo> targetIdeInfos = buildIdeInfo("//com/google/example:lib");
- final TargetIdeInfo libInfo =
- getTargetIdeInfoAndVerifyLabel("//com/google/example:lib", targetIdeInfos);
- TargetIdeInfo impInfo =
- getTargetIdeInfoAndVerifyLabel("//com/google/example:imp", targetIdeInfos);
-
- assertThat(impInfo.getKindString()).isEqualTo("java_import");
- assertThat(libInfo.getDependenciesList()).contains("//com/google/example:imp");
-
- JavaIdeInfo javaIdeInfo = impInfo.getJavaIdeInfo();
- assertThat(javaIdeInfo).isNotNull();
- assertThat(transform(javaIdeInfo.getJarsList(), LIBRARY_ARTIFACT_TO_STRING))
- .containsExactly(
- jarString(
- "com/google/example",
- "a.jar",
- "_ijar/imp/com/google/example/a-ijar.jar",
- "impsrc.jar"),
- jarString(
- "com/google/example",
- "b.jar",
- "_ijar/imp/com/google/example/b-ijar.jar",
- "impsrc.jar"))
- .inOrder();
-
- assertThat(getIdeResolveFiles())
- .containsExactly(
- "com/google/example/_ijar/imp/com/google/example/a-ijar.jar",
- "com/google/example/_ijar/imp/com/google/example/b-ijar.jar",
- "com/google/example/liblib.jar",
- "com/google/example/liblib-hjar.jar",
- "com/google/example/liblib-src.jar");
- }
-
- @Test
- public void testJavaImportWithExports() throws Exception {
- scratch.file(
- "com/google/example/BUILD",
- "java_library(",
- " name = 'foobar',",
- " srcs = ['FooBar.java'],",
- ")",
- "java_import(",
- " name = 'imp',",
- " jars = ['a.jar', 'b.jar'],",
- " deps = [':foobar'],",
- " exports = [':foobar'],",
- ")",
- "java_library(",
- " name = 'lib',",
- " srcs = ['Lib.java'],",
- " deps = [':imp'],",
- ")");
-
- Map<String, TargetIdeInfo> targetIdeInfos = buildIdeInfo("//com/google/example:lib");
- TargetIdeInfo libInfo =
- getTargetIdeInfoAndVerifyLabel("//com/google/example:lib", targetIdeInfos);
- TargetIdeInfo impInfo =
- getTargetIdeInfoAndVerifyLabel("//com/google/example:imp", targetIdeInfos);
-
- assertThat(impInfo.getKindString()).isEqualTo("java_import");
- assertThat(impInfo.getDependenciesList()).contains("//com/google/example:foobar");
- assertThat(libInfo.getDependenciesList())
- .containsAllOf("//com/google/example:foobar", "//com/google/example:imp");
- }
-
- @Test
- public void testNoPackageManifestForExports() throws Exception {
- scratch.file(
- "com/google/example/BUILD",
- "java_library(",
- " name = 'foobar',",
- " srcs = ['FooBar.java'],",
- ")",
- "java_import(",
- " name = 'imp',",
- " jars = ['a.jar', 'b.jar'],",
- " deps = [':foobar'],",
- " exports = [':foobar'],",
- ")",
- "java_library(",
- " name = 'lib',",
- " srcs = ['Lib.java'],",
- " deps = [':imp'],",
- ")");
-
- Map<String, TargetIdeInfo> targetIdeInfos = buildIdeInfo("//com/google/example:lib");
- TargetIdeInfo libInfo =
- getTargetIdeInfoAndVerifyLabel("//com/google/example:lib", targetIdeInfos);
- TargetIdeInfo impInfo =
- getTargetIdeInfoAndVerifyLabel("//com/google/example:imp", targetIdeInfos);
-
- assertThat(!impInfo.getJavaIdeInfo().hasPackageManifest()).isTrue();
- assertThat(libInfo.getJavaIdeInfo().hasPackageManifest()).isTrue();
- }
-
- @Test
- public void testGeneratedJavaImportFilesAreAddedToOutputGroup() throws Exception {
- scratch.file(
- "com/google/example/BUILD",
- "java_import(",
- " name = 'imp',",
- " jars = [':gen_jar'],",
- " srcjar = ':gen_srcjar',",
- ")",
- "genrule(",
- " name = 'gen_jar',",
- " outs = ['gen_jar.jar'],",
- " cmd = '',",
- ")",
- "genrule(",
- " name = 'gen_srcjar',",
- " outs = ['gen_srcjar.jar'],",
- " cmd = '',",
- ")");
- buildIdeInfo("//com/google/example:imp");
- assertThat(getIdeResolveFiles())
- .containsExactly(
- "com/google/example/_ijar/imp/com/google/example/gen_jar-ijar.jar",
- "com/google/example/gen_jar.jar",
- "com/google/example/gen_srcjar.jar");
- }
-
- @Test
- public void testAspectIsPropagatedAcrossExports() throws Exception {
- scratch.file(
- "com/google/example/BUILD",
- "java_library(",
- " name = 'foobar',",
- " srcs = ['FooBar.java'],",
- ")",
- "java_library(",
- " name = 'lib',",
- " srcs = ['Lib.java'],",
- " exports = [':foobar'],",
- ")");
-
- Map<String, TargetIdeInfo> targetIdeInfos = buildIdeInfo("//com/google/example:lib");
- getTargetIdeInfoAndVerifyLabel("//com/google/example:foobar", targetIdeInfos);
- }
-
- @Test
- public void testJavaTest() throws Exception {
- scratch.file(
- "java/com/google/example/BUILD",
- "java_library(",
- " name = 'foobar',",
- " srcs = ['FooBar.java'],",
- ")",
- "java_test(",
- " name = 'FooBarTest',",
- " srcs = ['FooBarTest.java'],",
- " size = 'large',",
- " deps = [':foobar'],",
- ")");
- Map<String, TargetIdeInfo> targetIdeInfos =
- buildIdeInfo("//java/com/google/example:FooBarTest");
- TargetIdeInfo testInfo =
- getTargetIdeInfoAndVerifyLabel("//java/com/google/example:FooBarTest", targetIdeInfos);
- assertThat(testInfo.getKindString()).isEqualTo("java_test");
- assertThat(relativePathsForJavaSourcesOf(testInfo))
- .containsExactly("java/com/google/example/FooBarTest.java");
- assertThat(testInfo.getDependenciesList()).contains("//java/com/google/example:foobar");
- assertThat(transform(testInfo.getJavaIdeInfo().getJarsList(), LIBRARY_ARTIFACT_TO_STRING))
- .containsExactly(
- jarString("java/com/google/example", "FooBarTest.jar", null, "FooBarTest-src.jar"));
-
- assertThat(getIdeResolveFiles())
- .containsExactly(
- "java/com/google/example/libfoobar.jar",
- "java/com/google/example/libfoobar-hjar.jar",
- "java/com/google/example/libfoobar-src.jar",
- "java/com/google/example/FooBarTest.jar",
- "java/com/google/example/FooBarTest-src.jar");
- assertThat(testInfo.getJavaIdeInfo().getJdeps().getRelativePath())
- .isEqualTo("java/com/google/example/FooBarTest.jdeps");
-
- assertThat(testInfo.getTestInfo().getSize()).isEqualTo("large");
- }
-
- @Test
- public void testJavaBinary() throws Exception {
- scratch.file(
- "com/google/example/BUILD",
- "java_library(",
- " name = 'foobar',",
- " srcs = ['FooBar.java'],",
- ")",
- "java_binary(",
- " name = 'foobar-exe',",
- " main_class = 'MyMainClass',",
- " srcs = ['FooBarMain.java'],",
- " deps = [':foobar'],",
- ")");
- Map<String, TargetIdeInfo> targetIdeInfos = buildIdeInfo("//com/google/example:foobar-exe");
- TargetIdeInfo binaryInfo =
- getTargetIdeInfoAndVerifyLabel("//com/google/example:foobar-exe", targetIdeInfos);
-
- assertThat(binaryInfo.getKindString()).isEqualTo("java_binary");
- assertThat(relativePathsForJavaSourcesOf(binaryInfo))
- .containsExactly("com/google/example/FooBarMain.java");
- assertThat(binaryInfo.getDependenciesList()).contains("//com/google/example:foobar");
-
- assertThat(transform(binaryInfo.getJavaIdeInfo().getJarsList(), LIBRARY_ARTIFACT_TO_STRING))
- .containsExactly(
- jarString("com/google/example", "foobar-exe.jar", null, "foobar-exe-src.jar"));
-
- assertThat(getIdeResolveFiles())
- .containsExactly(
- "com/google/example/libfoobar.jar",
- "com/google/example/libfoobar-hjar.jar",
- "com/google/example/libfoobar-src.jar",
- "com/google/example/foobar-exe.jar",
- "com/google/example/foobar-exe-src.jar");
- assertThat(binaryInfo.getJavaIdeInfo().getJdeps().getRelativePath())
- .isEqualTo("com/google/example/foobar-exe.jdeps");
- }
-
- @Test
- public void testJavaToolchain() throws Exception {
- scratch.file(
- "com/google/example/BUILD",
- "java_library(",
- " name = 'a',",
- " srcs = ['A.java'],",
- " deps = [':b'],",
- ")",
- "java_library(",
- " name = 'b',",
- " srcs = ['B.java'],",
- ")");
-
- Map<String, TargetIdeInfo> targetIdeInfos = buildIdeInfo("//com/google/example:a");
-
- List<TargetIdeInfo> javaToolChainInfos = findJavaToolchain(targetIdeInfos);
- assertThat(javaToolChainInfos).hasSize(1); // Ensure we don't get one instance per java_library
- TargetIdeInfo toolChainInfo = Iterables.getOnlyElement(javaToolChainInfos);
- assertThat(toolChainInfo.getJavaToolchainIdeInfo().getSourceVersion()).isNotEmpty();
- assertThat(toolChainInfo.getJavaToolchainIdeInfo().getTargetVersion()).isNotEmpty();
-
- TargetIdeInfo a = targetIdeInfos.get("//com/google/example:a");
- assertThat(a.getDependenciesList())
- .containsAllOf("//com/google/example:b", toolChainInfo.getLabel());
- }
-
- @Test
- public void testJavaToolchainForAndroid() throws Exception {
- scratch.file(
- "com/google/example/BUILD",
- "android_library(",
- " name = 'a',",
- " srcs = ['A.java'],",
- ")");
-
- Map<String, TargetIdeInfo> targetIdeInfos = buildIdeInfo("//com/google/example:a");
- assertThat(targetIdeInfos).hasSize(2);
-
- List<TargetIdeInfo> javaToolChainInfos = findJavaToolchain(targetIdeInfos);
- assertThat(javaToolChainInfos).hasSize(1);
- }
-
- @Test
- public void testAndroidLibrary() throws Exception {
- scratch.file(
- "com/google/example/BUILD",
- "android_library(",
- " name = 'l1',",
- " manifest = 'AndroidManifest.xml',",
- " custom_package = 'com.google.example',",
- " resource_files = ['r1/values/a.xml'],",
- ")",
- "android_library(",
- " name = 'l',",
- " srcs = ['Main.java'],",
- " deps = [':l1'],",
- " manifest = 'AndroidManifest.xml',",
- " custom_package = 'com.google.example',",
- " resource_files = ['res/drawable/a.png', 'res/drawable/b.png'],",
- ")");
- Map<String, TargetIdeInfo> targetIdeInfos = buildIdeInfo("//com/google/example:l");
- TargetIdeInfo target = getTargetIdeInfoAndVerifyLabel("//com/google/example:l", targetIdeInfos);
- assertThat(target.getKindString()).isEqualTo("android_library");
- assertThat(relativePathsForJavaSourcesOf(target))
- .containsExactly("com/google/example/Main.java");
- assertThat(transform(target.getJavaIdeInfo().getJarsList(), LIBRARY_ARTIFACT_TO_STRING))
- .containsExactly(
- jarString("com/google/example", "libl.jar", "libl-hjar.jar", "libl-src.jar"),
- jarString("com/google/example", "l_resources.jar", null, "l_resources-src.jar"));
- assertThat(transform(target.getAndroidIdeInfo().getResourcesList(), ARTIFACT_TO_RELATIVE_PATH))
- .containsExactly("com/google/example/res");
- assertThat(target.getAndroidIdeInfo().getManifest().getRelativePath())
- .isEqualTo("com/google/example/AndroidManifest.xml");
- assertThat(target.getAndroidIdeInfo().getJavaPackage()).isEqualTo("com.google.example");
- assertThat(LIBRARY_ARTIFACT_TO_STRING.apply(target.getAndroidIdeInfo().getResourceJar()))
- .isEqualTo(jarString("com/google/example", "l_resources.jar", null, "l_resources-src.jar"));
-
- assertThat(target.getDependenciesList()).contains("//com/google/example:l1");
- assertThat(getIdeResolveFiles())
- .containsExactly(
- "com/google/example/libl.jar",
- "com/google/example/libl-hjar.jar",
- "com/google/example/libl-src.jar",
- "com/google/example/l_resources.jar",
- "com/google/example/l_resources-src.jar",
- "com/google/example/libl1.jar",
- "com/google/example/libl1-src.jar",
- "com/google/example/l1_resources.jar",
- "com/google/example/l1_resources-src.jar");
- assertThat(target.getJavaIdeInfo().getJdeps().getRelativePath())
- .isEqualTo("com/google/example/libl.jdeps");
- }
-
- @Test
- public void testAndroidBinary() throws Exception {
- scratch.file(
- "com/google/example/BUILD",
- "android_library(",
- " name = 'l1',",
- " manifest = 'AndroidManifest.xml',",
- " custom_package = 'com.google.example',",
- " resource_files = ['r1/values/a.xml'],",
- ")",
- "android_binary(",
- " name = 'b',",
- " srcs = ['Main.java'],",
- " deps = [':l1'],",
- " manifest = 'AndroidManifest.xml',",
- " custom_package = 'com.google.example',",
- " resource_files = ['res/drawable/a.png', 'res/drawable/b.png'],",
- ")");
- Map<String, TargetIdeInfo> targetIdeInfos = buildIdeInfo("//com/google/example:b");
- TargetIdeInfo target = getTargetIdeInfoAndVerifyLabel("//com/google/example:b", targetIdeInfos);
-
- assertThat(target.getKindString()).isEqualTo("android_binary");
- assertThat(relativePathsForJavaSourcesOf(target))
- .containsExactly("com/google/example/Main.java");
- assertThat(transform(target.getJavaIdeInfo().getJarsList(), LIBRARY_ARTIFACT_TO_STRING))
- .containsExactly(
- jarString("com/google/example", "libb.jar", "libb-hjar.jar", "libb-src.jar"),
- jarString("com/google/example", "b_resources.jar", null, "b_resources-src.jar"));
-
- assertThat(transform(target.getAndroidIdeInfo().getResourcesList(), ARTIFACT_TO_RELATIVE_PATH))
- .containsExactly("com/google/example/res");
- assertThat(target.getAndroidIdeInfo().getManifest().getRelativePath())
- .isEqualTo("com/google/example/AndroidManifest.xml");
- assertThat(target.getAndroidIdeInfo().getJavaPackage()).isEqualTo("com.google.example");
- assertThat(target.getAndroidIdeInfo().getApk().getRelativePath())
- .isEqualTo("com/google/example/b.apk");
-
- assertThat(target.getDependenciesList()).contains("//com/google/example:l1");
-
- assertThat(getIdeResolveFiles())
- .containsExactly(
- "com/google/example/libb.jar",
- "com/google/example/libb-hjar.jar",
- "com/google/example/libb-src.jar",
- "com/google/example/b_resources.jar",
- "com/google/example/b_resources-src.jar",
- "com/google/example/libl1.jar",
- "com/google/example/libl1-src.jar",
- "com/google/example/l1_resources.jar",
- "com/google/example/l1_resources-src.jar");
- assertThat(target.getJavaIdeInfo().getJdeps().getRelativePath())
- .isEqualTo("com/google/example/libb.jdeps");
- }
-
- @Test
- public void testAndroidInferredPackage() throws Exception {
- scratch.file(
- "java/com/google/example/BUILD",
- "android_library(",
- " name = 'l',",
- " manifest = 'AndroidManifest.xml',",
- ")",
- "android_binary(",
- " name = 'b',",
- " srcs = ['Main.java'],",
- " deps = [':l'],",
- " manifest = 'AndroidManifest.xml',",
- ")");
- Map<String, TargetIdeInfo> targetIdeInfos = buildIdeInfo("//java/com/google/example:b");
- TargetIdeInfo lTarget =
- getTargetIdeInfoAndVerifyLabel("//java/com/google/example:l", targetIdeInfos);
- TargetIdeInfo bTarget =
- getTargetIdeInfoAndVerifyLabel("//java/com/google/example:b", targetIdeInfos);
-
- assertThat(bTarget.getAndroidIdeInfo().getJavaPackage()).isEqualTo("com.google.example");
- assertThat(lTarget.getAndroidIdeInfo().getJavaPackage()).isEqualTo("com.google.example");
- }
-
- @Test
- public void testAndroidLibraryWithoutAidlHasNoIdlJars() throws Exception {
- scratch.file(
- "java/com/google/example/BUILD",
- "android_library(",
- " name = 'no_idl',",
- " srcs = ['Test.java'],",
- ")");
- String noIdlTarget = "//java/com/google/example:no_idl";
- Map<String, TargetIdeInfo> targetIdeInfos = buildIdeInfo(noIdlTarget);
- TargetIdeInfo noIdlTargetIdeInfo = getTargetIdeInfoAndVerifyLabel(noIdlTarget, targetIdeInfos);
-
- assertThat(noIdlTargetIdeInfo.getAndroidIdeInfo().getHasIdlSources()).isFalse();
- }
-
- @Test
- public void testAndroidLibraryWithAidlHasIdlJars() throws Exception {
- scratch.file(
- "java/com/google/example/BUILD",
- "android_library(",
- " name = 'has_idl',",
- " idl_srcs = ['a.aidl'],",
- ")");
- String idlTarget = "//java/com/google/example:has_idl";
- Map<String, TargetIdeInfo> targetIdeInfos = buildIdeInfo(idlTarget);
- TargetIdeInfo idlTargetIdeInfo = getTargetIdeInfoAndVerifyLabel(idlTarget, targetIdeInfos);
-
- assertThat(idlTargetIdeInfo.getAndroidIdeInfo().getHasIdlSources()).isTrue();
- assertThat(LIBRARY_ARTIFACT_TO_STRING.apply(idlTargetIdeInfo.getAndroidIdeInfo().getIdlJar()))
- .isEqualTo(
- jarString(
- "java/com/google/example", "libhas_idl-idl.jar", null, "libhas_idl-idl.srcjar"));
- assertThat(relativePathsForJavaSourcesOf(idlTargetIdeInfo)).isEmpty();
- assertThat(getIdeResolveFiles())
- .containsExactly(
- "java/com/google/example/libhas_idl.jar",
- "java/com/google/example/libhas_idl-hjar.jar",
- "java/com/google/example/libhas_idl-src.jar",
- "java/com/google/example/libhas_idl-idl.jar",
- "java/com/google/example/libhas_idl-idl.srcjar");
- }
-
- @Test
- public void testAndroidLibraryWithAidlWithoutImportRoot() throws Exception {
- scratch.file(
- "java/com/google/example/BUILD",
- "android_library(",
- " name = 'no_idl_import_root',",
- " idl_srcs = ['a.aidl'],",
- ")");
- String idlTarget = "//java/com/google/example:no_idl_import_root";
- Map<String, TargetIdeInfo> targetIdeInfos = buildIdeInfo(idlTarget);
- TargetIdeInfo idlTargetIdeInfo = getTargetIdeInfoAndVerifyLabel(idlTarget, targetIdeInfos);
- assertThat(idlTargetIdeInfo.getAndroidIdeInfo().getIdlImportRoot()).isEmpty();
- }
-
- @Test
- public void testAndroidLibraryWithAidlWithImportRoot() throws Exception {
- scratch.file(
- "java/com/google/example/BUILD",
- "android_library(",
- " name = 'has_idl_import_root',",
- " idl_import_root = 'idl',",
- " idl_srcs = ['idl/com/google/example/a.aidl'],",
- ")");
- String idlTarget = "//java/com/google/example:has_idl_import_root";
- Map<String, TargetIdeInfo> targetIdeInfos = buildIdeInfo(idlTarget);
- TargetIdeInfo idlTargetIdeInfo = getTargetIdeInfoAndVerifyLabel(idlTarget, targetIdeInfos);
- assertThat(idlTargetIdeInfo.getAndroidIdeInfo().getIdlImportRoot()).isEqualTo("idl");
- }
-
- @Test
- public void testAndroidLibraryGeneratedManifestIsAddedToOutputGroup() throws Exception {
- scratch.file(
- "com/google/example/BUILD",
- "android_library(",
- " name = 'lib',",
- " manifest = ':manifest',",
- " custom_package = 'com.google.example',",
- ")",
- "genrule(",
- " name = 'manifest',",
- " outs = ['AndroidManifest.xml'],",
- " cmd = '',",
- ")");
- buildIdeInfo("//com/google/example:lib");
- assertThat(getIdeResolveFiles())
- .containsExactly(
- "com/google/example/liblib.jar",
- "com/google/example/liblib-src.jar",
- "com/google/example/lib_resources.jar",
- "com/google/example/lib_resources-src.jar",
- "com/google/example/AndroidManifest.xml");
- }
-
- @Test
- public void testJavaLibraryWithoutGeneratedSourcesHasNoGenJars() throws Exception {
- scratch.file(
- "java/com/google/example/BUILD",
- "java_library(",
- " name = 'no_plugin',",
- " srcs = ['Test.java'],",
- ")");
- Map<String, TargetIdeInfo> targetIdeInfos = buildIdeInfo("//java/com/google/example:no_plugin");
- TargetIdeInfo targetIdeInfo =
- getTargetIdeInfoAndVerifyLabel("//java/com/google/example:no_plugin", targetIdeInfos);
-
- assertThat(targetIdeInfo.getJavaIdeInfo().getGeneratedJarsList()).isEmpty();
- }
-
- @Test
- public void testJavaLibraryWithGeneratedSourcesHasGenJars() throws Exception {
- scratch.file(
- "java/com/google/example/BUILD",
- "java_library(",
- " name = 'test',",
- " srcs = ['Test.java'],",
- " plugins = [':plugin']",
- ")",
- "java_plugin(",
- " name = 'plugin',",
- " processor_class = 'com.google.example.Plugin',",
- " deps = ['plugin_lib'],",
- ")",
- "java_library(",
- " name = 'plugin_lib',",
- " srcs = ['Plugin.java'],",
- ")");
- Map<String, TargetIdeInfo> targetIdeInfos = buildIdeInfo("//java/com/google/example:test");
- TargetIdeInfo targetIdeInfo =
- getTargetIdeInfoAndVerifyLabel("//java/com/google/example:test", targetIdeInfos);
-
- assertThat(
- transform(
- targetIdeInfo.getJavaIdeInfo().getGeneratedJarsList(), LIBRARY_ARTIFACT_TO_STRING))
- .containsExactly(
- jarString("java/com/google/example", "libtest-gen.jar", null, "libtest-gensrc.jar"));
- assertThat(getIdeResolveFiles())
- .containsExactly(
- "java/com/google/example/libtest.jar",
- "java/com/google/example/libtest-hjar.jar",
- "java/com/google/example/libtest-src.jar",
- "java/com/google/example/libtest-gen.jar",
- "java/com/google/example/libtest-gensrc.jar");
- }
-
- @Test
- public void testTags() throws Exception {
- scratch.file(
- "com/google/example/BUILD",
- "java_library(",
- " name = 'lib',",
- " srcs = ['Test.java'],",
- " tags = ['d', 'b', 'c', 'a'],",
- ")");
- Map<String, TargetIdeInfo> targetIdeInfos = buildIdeInfo("//com/google/example:lib");
- TargetIdeInfo targetIdeInfo =
- getTargetIdeInfoAndVerifyLabel("//com/google/example:lib", targetIdeInfos);
- assertThat(targetIdeInfo.getTagsList()).containsExactly("a", "b", "c", "d");
- }
-
- @Test
- public void testAndroidLibraryWithoutSourcesExportsDependencies() throws Exception {
- scratch.file(
- "java/com/google/example/BUILD",
- "android_library(",
- " name = 'lib',",
- " srcs = ['Test.java']",
- ")",
- "android_library(",
- " name = 'forward',",
- " deps = [':lib'],",
- ")",
- "android_library(",
- " name = 'super',",
- " deps = [':forward'],",
- ")");
- Map<String, TargetIdeInfo> targetIdeInfos = buildIdeInfo("//java/com/google/example:super");
- TargetIdeInfo target =
- getTargetIdeInfoAndVerifyLabel("//java/com/google/example:super", targetIdeInfos);
-
- assertThat(target.getDependenciesList())
- .containsAllOf("//java/com/google/example:forward", "//java/com/google/example:lib");
- }
-
- @Test
- public void testAndroidLibraryExportsDoNotOverReport() throws Exception {
- scratch.file(
- "com/google/example/BUILD",
- "android_library(",
- " name = 'lib',",
- " deps = [':middle'],",
- ")",
- "android_library(",
- " name = 'middle',",
- " srcs = ['Middle.java'],",
- " deps = [':exported'],",
- ")",
- "android_library(",
- " name = 'exported',",
- " srcs = ['Exported.java'],",
- ")");
- Map<String, TargetIdeInfo> targetIdeInfos = buildIdeInfo("//com/google/example:lib");
- TargetIdeInfo target =
- getTargetIdeInfoAndVerifyLabel("//com/google/example:lib", targetIdeInfos);
- TargetIdeInfo javaToolchain = Iterables.getOnlyElement(findJavaToolchain(targetIdeInfos));
- assertThat(target.getDependenciesList())
- .containsExactly(javaToolchain.getLabel(), "//com/google/example:middle");
- }
-
- @Test
- public void testSourceFilesAreCorrectlyMarkedAsSourceOrGenerated() throws Exception {
- scratch.file(
- "com/google/example/BUILD",
- "genrule(",
- " name = 'gen',",
- " outs = ['gen.java'],",
- " cmd = '',",
- ")",
- "java_library(",
- " name = 'lib',",
- " srcs = ['Test.java', ':gen'],",
- ")");
- Map<String, TargetIdeInfo> targetIdeInfos = buildIdeInfo("//com/google/example:lib");
- TargetIdeInfo targetIdeInfo =
- getTargetIdeInfoAndVerifyLabel("//com/google/example:lib", targetIdeInfos);
- // todo(dslomov): Skylark aspect implementation does not yet return a correct root path.
- assertThat(targetIdeInfo.getJavaIdeInfo().getSourcesList())
- .containsExactly(
- ArtifactLocation.newBuilder()
- .setRootExecutionPathFragment(
- targetConfig.getGenfilesDirectory(RepositoryName.MAIN).getExecPathString())
- .setRelativePath("com/google/example/gen.java")
- .setIsSource(false)
- .build(),
- ArtifactLocation.newBuilder()
- .setRelativePath("com/google/example/Test.java")
- .setIsSource(true)
- .build());
- }
-
- @Test
- public void testAspectIsPropagatedAcrossRuntimeDeps() throws Exception {
- scratch.file(
- "com/google/example/BUILD",
- "java_library(",
- " name = 'foobar',",
- " srcs = ['FooBar.java'],",
- ")",
- "java_library(",
- " name = 'lib',",
- " srcs = ['Lib.java'],",
- " runtime_deps = [':foobar'],",
- ")");
-
- Map<String, TargetIdeInfo> targetIdeInfos = buildIdeInfo("//com/google/example:lib");
- // Fails if aspect was not propagated
- getTargetIdeInfoAndVerifyLabel("//com/google/example:foobar", targetIdeInfos);
-
- getTargetIdeInfoAndVerifyLabel("//com/google/example:foobar", targetIdeInfos);
- }
-
- @Test
- public void testRuntimeDepsAddedToProto() throws Exception {
- scratch.file(
- "com/google/example/BUILD",
- "java_library(",
- " name = 'foobar',",
- " srcs = ['FooBar.java'],",
- ")",
- "java_library(",
- " name = 'foobar2',",
- " srcs = ['FooBar2.java'],",
- ")",
- "java_library(",
- " name = 'lib',",
- " srcs = ['Lib.java'],",
- " deps = [':lib2'],",
- " runtime_deps = [':foobar'],",
- ")",
- "java_library(",
- " name = 'lib2',",
- " srcs = ['Lib2.java'],",
- " runtime_deps = [':foobar2'],",
- ")");
-
- Map<String, TargetIdeInfo> targetIdeInfos = buildIdeInfo("//com/google/example:lib");
- // Fails if aspect was not propagated
- TargetIdeInfo lib = getTargetIdeInfoAndVerifyLabel("//com/google/example:lib", targetIdeInfos);
- TargetIdeInfo lib2 =
- getTargetIdeInfoAndVerifyLabel("//com/google/example:lib2", targetIdeInfos);
-
- assertThat(lib.getRuntimeDepsList()).containsExactly("//com/google/example:foobar");
- assertThat(lib2.getRuntimeDepsList()).containsExactly("//com/google/example:foobar2");
- }
-
- @Test
- public void testAndroidLibraryGeneratesResourceClass() throws Exception {
- scratch.file(
- "java/com/google/example/BUILD",
- "android_library(",
- " name = 'resource_files',",
- " resource_files = ['res/drawable/a.png'],",
- " manifest = 'AndroidManifest.xml',",
- ")",
- "android_library(",
- " name = 'manifest',",
- " manifest = 'AndroidManifest.xml',",
- ")",
- "android_library(",
- " name = 'neither',",
- " srcs = ['FooBar.java'],",
- " deps = [':resource_files', ':manifest']",
- ")");
-
- Map<String, TargetIdeInfo> targetIdeInfos = buildIdeInfo("//java/com/google/example:neither");
- TargetIdeInfo neither =
- getTargetIdeInfoAndVerifyLabel("//java/com/google/example:neither", targetIdeInfos);
- TargetIdeInfo resourceFiles =
- getTargetIdeInfoAndVerifyLabel("//java/com/google/example:resource_files", targetIdeInfos);
- TargetIdeInfo manifest =
- getTargetIdeInfoAndVerifyLabel("//java/com/google/example:manifest", targetIdeInfos);
-
- assertThat(neither.getAndroidIdeInfo().getGenerateResourceClass()).isFalse();
- assertThat(resourceFiles.getAndroidIdeInfo().getGenerateResourceClass()).isTrue();
- assertThat(manifest.getAndroidIdeInfo().getGenerateResourceClass()).isTrue();
- }
-
- @Test
- public void testJavaPlugin() throws Exception {
- scratch.file(
- "java/com/google/example/BUILD",
- "java_plugin(",
- " name = 'plugin',",
- " srcs = ['Plugin.java'],",
- " processor_class = 'com.google.example.Plugin',",
- ")");
- Map<String, TargetIdeInfo> targetIdeInfos = buildIdeInfo("//java/com/google/example:plugin");
- TargetIdeInfo plugin =
- getTargetIdeInfoAndVerifyLabel("//java/com/google/example:plugin", targetIdeInfos);
-
- assertThat(plugin.getKindString()).isEqualTo("java_plugin");
- assertThat(transform(plugin.getJavaIdeInfo().getJarsList(), LIBRARY_ARTIFACT_TO_STRING))
- .containsExactly(
- jarString(
- "java/com/google/example",
- "libplugin.jar",
- "libplugin-hjar.jar",
- "libplugin-src.jar"));
- }
-
- @Test
- public void testSimpleCCLibraryForCCToolchainExistence() throws Exception {
- scratch.file(
- "com/google/example/BUILD",
- "cc_library(",
- " name = 'simple',",
- " srcs = ['simple/simple.cc'],",
- " hdrs = ['simple/simple.h'],",
- ")");
- Map<String, TargetIdeInfo> targetIdeInfos = buildIdeInfo("//com/google/example:simple");
- assertThat(targetIdeInfos).hasSize(2);
- TargetIdeInfo target =
- getTargetIdeInfoAndVerifyLabel("//com/google/example:simple", targetIdeInfos);
- Entry<String, TargetIdeInfo> toolchainEntry =
- getCcToolchainRuleAndVerifyThereIsOnlyOne(targetIdeInfos);
- TargetIdeInfo toolchainInfo = toolchainEntry.getValue();
- ArtifactLocation location = target.getBuildFileArtifactLocation();
- assertThat(Paths.get(location.getRelativePath()).toString())
- .isEqualTo(Paths.get("com/google/example/BUILD").toString());
-
- assertThat(target.hasCIdeInfo()).isTrue();
- assertThat(target.getDependenciesList()).hasSize(1);
- assertThat(toolchainInfo.hasCToolchainIdeInfo()).isTrue();
- }
-
- @Test
- public void testSimpleCCLibrary() throws Exception {
- scratch.file(
- "com/google/example/BUILD",
- "cc_library(",
- " name = 'simple',",
- " srcs = ['simple/simple.cc'],",
- " hdrs = ['simple/simple.h'],",
- ")");
- Map<String, TargetIdeInfo> targetIdeInfos = buildIdeInfo("//com/google/example:simple");
- assertThat(targetIdeInfos).hasSize(2);
- TargetIdeInfo targetIdeInfo =
- getTargetIdeInfoAndVerifyLabel("//com/google/example:simple", targetIdeInfos);
- ArtifactLocation location = targetIdeInfo.getBuildFileArtifactLocation();
- assertThat(Paths.get(location.getRelativePath()).toString())
- .isEqualTo(Paths.get("com/google/example/BUILD").toString());
-
- assertThat(targetIdeInfo.getKindString()).isEqualTo("cc_library");
- assertThat(targetIdeInfo.getDependenciesCount()).isEqualTo(1);
-
- assertThat(relativePathsForCSourcesOf(targetIdeInfo))
- .containsExactly("com/google/example/simple/simple.cc");
-
- assertThat(targetIdeInfo.hasCIdeInfo()).isTrue();
- assertThat(targetIdeInfo.hasJavaIdeInfo()).isFalse();
- assertThat(targetIdeInfo.hasAndroidIdeInfo()).isFalse();
- CIdeInfo cTargetIdeInfo = targetIdeInfo.getCIdeInfo();
-
- assertThat(cTargetIdeInfo.getTargetCoptList()).isEmpty();
- assertThat(cTargetIdeInfo.getTargetDefineList()).isEmpty();
- assertThat(cTargetIdeInfo.getTargetIncludeList()).isEmpty();
-
- ProtocolStringList transQuoteIncludeDirList =
- cTargetIdeInfo.getTransitiveQuoteIncludeDirectoryList();
- assertThat(transQuoteIncludeDirList).contains(".");
-
- assertThat(targetIdeInfo.getJavaIdeInfo().getJarsList()).isEmpty();
-
- assertThat(getIdeResolveFiles()).containsExactly("com/google/example/simple/simple.h");
- }
-
- @Test
- public void testSimpleCCLibraryWithIncludes() throws Exception {
- scratch.file(
- "com/google/example/BUILD",
- "cc_library(",
- " name = 'simple',",
- " srcs = ['simple/simple.cc'],",
- " hdrs = ['simple/simple.h'],",
- " includes = ['foo/bar'],",
- ")");
- Map<String, TargetIdeInfo> targetIdeInfos = buildIdeInfo("//com/google/example:simple");
- assertThat(targetIdeInfos).hasSize(2);
- TargetIdeInfo targetIdeInfo =
- getTargetIdeInfoAndVerifyLabel("//com/google/example:simple", targetIdeInfos);
-
- assertThat(targetIdeInfo.hasCIdeInfo()).isTrue();
- CIdeInfo cTargetIdeInfo = targetIdeInfo.getCIdeInfo();
-
- assertThat(cTargetIdeInfo.getTargetIncludeList()).containsExactly("foo/bar");
-
- // Make sure our understanding of where this attributes show up in other providers is correct.
- Entry<String, TargetIdeInfo> toolchainEntry =
- getCcToolchainRuleAndVerifyThereIsOnlyOne(targetIdeInfos);
- TargetIdeInfo toolchainInfo = toolchainEntry.getValue();
- assertThat(toolchainInfo.hasCToolchainIdeInfo()).isTrue();
- CToolchainIdeInfo cToolchainIdeInfo = toolchainInfo.getCToolchainIdeInfo();
- ProtocolStringList builtInIncludeDirectoryList =
- cToolchainIdeInfo.getBuiltInIncludeDirectoryList();
- assertThat(builtInIncludeDirectoryList).doesNotContain("foo/bar");
- assertThat(builtInIncludeDirectoryList).doesNotContain("com/google/example/foo/bar");
-
- ProtocolStringList transIncludeDirList = cTargetIdeInfo.getTransitiveIncludeDirectoryList();
- assertThat(transIncludeDirList).doesNotContain("foo/bar");
- assertThat(transIncludeDirList).doesNotContain("com/google/example/foo/bar");
-
- ProtocolStringList transQuoteIncludeDirList =
- cTargetIdeInfo.getTransitiveQuoteIncludeDirectoryList();
- assertThat(transQuoteIncludeDirList).doesNotContain("foo/bar");
- assertThat(transQuoteIncludeDirList).doesNotContain("com/google/example/foo/bar");
-
- ProtocolStringList transSysIncludeDirList =
- cTargetIdeInfo.getTransitiveSystemIncludeDirectoryList();
- assertThat(transSysIncludeDirList).doesNotContain("foo/bar");
- assertThat(transSysIncludeDirList).contains("com/google/example/foo/bar");
- }
-
- @Test
- public void testSimpleCCLibraryWithCompilerFlags() throws Exception {
- scratch.file(
- "com/google/example/BUILD",
- "cc_library(",
- " name = 'simple',",
- " srcs = ['simple/simple.cc'],",
- " hdrs = ['simple/simple.h'],",
- " copts = ['-DGOPT', '-Ifoo/baz/'],",
- ")");
- Map<String, TargetIdeInfo> targetIdeInfos = buildIdeInfo("//com/google/example:simple");
- assertThat(targetIdeInfos).hasSize(2);
- TargetIdeInfo targetIdeInfo =
- getTargetIdeInfoAndVerifyLabel("//com/google/example:simple", targetIdeInfos);
-
- assertThat(targetIdeInfo.hasCIdeInfo()).isTrue();
- CIdeInfo cTargetIdeInfo = targetIdeInfo.getCIdeInfo();
-
- assertThat(cTargetIdeInfo.getTargetCoptList()).containsExactly("-DGOPT", "-Ifoo/baz/");
-
- // Make sure our understanding of where this attributes show up in other providers is correct.
- Entry<String, TargetIdeInfo> toolchainEntry =
- getCcToolchainRuleAndVerifyThereIsOnlyOne(targetIdeInfos);
- TargetIdeInfo toolchainInfo = toolchainEntry.getValue();
- assertThat(toolchainInfo.hasCToolchainIdeInfo()).isTrue();
- CToolchainIdeInfo cToolchainIdeInfo = toolchainInfo.getCToolchainIdeInfo();
- ProtocolStringList baseCompilerOptionList = cToolchainIdeInfo.getBaseCompilerOptionList();
- assertThat(baseCompilerOptionList).doesNotContain("-DGOPT");
- assertThat(baseCompilerOptionList).doesNotContain("-Ifoo/baz/");
-
- ProtocolStringList cOptionList = cToolchainIdeInfo.getCOptionList();
- assertThat(cOptionList).doesNotContain("-DGOPT");
- assertThat(cOptionList).doesNotContain("-Ifoo/baz/");
-
- ProtocolStringList cppOptionList = cToolchainIdeInfo.getCppOptionList();
- assertThat(cppOptionList).doesNotContain("-DGOPT");
- assertThat(cppOptionList).doesNotContain("-Ifoo/baz/");
- }
-
- @Test
- public void testSimpleCCLibraryWithDefines() throws Exception {
- scratch.file(
- "com/google/example/BUILD",
- "cc_library(",
- " name = 'simple',",
- " srcs = ['simple/simple.cc'],",
- " hdrs = ['simple/simple.h'],",
- " defines = ['VERSION2'],",
- ")");
- Map<String, TargetIdeInfo> targetIdeInfos = buildIdeInfo("//com/google/example:simple");
- assertThat(targetIdeInfos).hasSize(2);
- TargetIdeInfo targetIdeInfo =
- getTargetIdeInfoAndVerifyLabel("//com/google/example:simple", targetIdeInfos);
-
- assertThat(targetIdeInfo.hasCIdeInfo()).isTrue();
- CIdeInfo cTargetIdeInfo = targetIdeInfo.getCIdeInfo();
-
- assertThat(cTargetIdeInfo.getTargetDefineList()).containsExactly("VERSION2");
-
- // Make sure our understanding of where this attributes show up in other providers is correct.
- ProtocolStringList transDefineList = cTargetIdeInfo.getTransitiveDefineList();
- assertThat(transDefineList).contains("VERSION2");
- }
-
- @Test
- public void testSimpleCCBinary() throws Exception {
- scratch.file(
- "com/google/example/BUILD",
- "cc_binary(",
- " name = 'simple',",
- " srcs = ['simple/simple.cc'],",
- ")");
- Map<String, TargetIdeInfo> targetIdeInfos = buildIdeInfo("//com/google/example:simple");
- assertThat(targetIdeInfos).hasSize(2);
- TargetIdeInfo targetIdeInfo =
- getTargetIdeInfoAndVerifyLabel("//com/google/example:simple", targetIdeInfos);
- ArtifactLocation location = targetIdeInfo.getBuildFileArtifactLocation();
- assertThat(Paths.get(location.getRelativePath()).toString())
- .isEqualTo(Paths.get("com/google/example/BUILD").toString());
- assertThat(targetIdeInfo.getKindString()).isEqualTo("cc_binary");
- assertThat(targetIdeInfo.getDependenciesCount()).isEqualTo(1);
-
- assertThat(relativePathsForCSourcesOf(targetIdeInfo))
- .containsExactly("com/google/example/simple/simple.cc");
-
- assertThat(targetIdeInfo.hasCIdeInfo()).isTrue();
- assertThat(targetIdeInfo.hasJavaIdeInfo()).isFalse();
- assertThat(targetIdeInfo.hasAndroidIdeInfo()).isFalse();
- CIdeInfo cTargetIdeInfo = targetIdeInfo.getCIdeInfo();
-
- assertThat(cTargetIdeInfo.getTargetCoptList()).isEmpty();
- assertThat(cTargetIdeInfo.getTargetDefineList()).isEmpty();
- assertThat(cTargetIdeInfo.getTargetIncludeList()).isEmpty();
-
- assertThat(targetIdeInfo.getJavaIdeInfo().getJarsList()).isEmpty();
-
- assertThat(getIdeResolveFiles()).isEmpty();
- }
-
- @Test
- public void testSimpleCCTest() throws Exception {
- scratch.file(
- "com/google/example/BUILD",
- "cc_test(",
- " name = 'simple',",
- " srcs = ['simple/simple.cc'],",
- ")");
- Map<String, TargetIdeInfo> targetIdeInfos = buildIdeInfo("//com/google/example:simple");
- assertThat(targetIdeInfos).hasSize(2);
- TargetIdeInfo targetIdeInfo =
- getTargetIdeInfoAndVerifyLabel("//com/google/example:simple", targetIdeInfos);
- ArtifactLocation location = targetIdeInfo.getBuildFileArtifactLocation();
- assertThat(Paths.get(location.getRelativePath()).toString())
- .isEqualTo(Paths.get("com/google/example/BUILD").toString());
- assertThat(targetIdeInfo.getKindString()).isEqualTo("cc_test");
- assertThat(targetIdeInfo.getDependenciesCount()).isEqualTo(1);
-
- assertThat(relativePathsForCSourcesOf(targetIdeInfo))
- .containsExactly("com/google/example/simple/simple.cc");
-
- assertThat(targetIdeInfo.hasCIdeInfo()).isTrue();
- assertThat(targetIdeInfo.hasJavaIdeInfo()).isFalse();
- assertThat(targetIdeInfo.hasAndroidIdeInfo()).isFalse();
- CIdeInfo cTargetIdeInfo = targetIdeInfo.getCIdeInfo();
-
- assertThat(cTargetIdeInfo.getTargetCoptList()).isEmpty();
- assertThat(cTargetIdeInfo.getTargetDefineList()).isEmpty();
- assertThat(cTargetIdeInfo.getTargetIncludeList()).isEmpty();
-
- assertThat(targetIdeInfo.getJavaIdeInfo().getJarsList()).isEmpty();
-
- assertThat(getIdeResolveFiles()).isEmpty();
- }
-
- @Test
- public void testSimpleCCLibraryWithDeps() throws Exception {
- // Specify '-fPIC' so that compilation output filenames are consistent for mac and linux.
- scratch.file(
- "com/google/example/BUILD",
- "cc_library(",
- " name = 'lib',",
- " srcs = ['lib/lib.cc'],",
- " hdrs = ['lib/lib.h'],",
- ")",
- "cc_library(",
- " name = 'simple',",
- " srcs = ['simple/simple.cc'],",
- " hdrs = ['simple/simple.h'],",
- " deps = [':lib'],",
- " nocopts = '-fPIC',",
- ")");
- Map<String, TargetIdeInfo> targetIdeInfos = buildIdeInfo("//com/google/example:simple");
- assertThat(targetIdeInfos).hasSize(3);
- TargetIdeInfo targetIdeInfo =
- getTargetIdeInfoAndVerifyLabel("//com/google/example:simple", targetIdeInfos);
-
- assertThat(targetIdeInfo.getDependenciesList()).contains("//com/google/example:lib");
- assertThat(targetIdeInfo.getDependenciesList()).hasSize(2);
-
- assertThat(getIdeCompileFiles())
- .containsExactly("com/google/example/_objs/simple/com/google/example/simple/simple.o");
- }
-
- @Test
- public void testSimpleAndroidBinaryThatDependsOnCCLibrary() throws Exception {
- scratch.file(
- "com/google/example/BUILD",
- "android_library(",
- " name = 'androidlib',",
- " srcs = ['Lib.java'],",
- " deps = ['simple'],",
- ")",
- "cc_library(",
- " name = 'simple',",
- " srcs = ['simple/simple.cc'],",
- " hdrs = ['simple/simple.h'],",
- ")");
- Map<String, TargetIdeInfo> targetIdeInfos = buildIdeInfo("//com/google/example:androidlib");
- TargetIdeInfo targetIdeInfo =
- getTargetIdeInfoAndVerifyLabel("//com/google/example:androidlib", targetIdeInfos);
-
- assertThat(targetIdeInfo.getDependenciesList()).contains("//com/google/example:simple");
- }
-
- @Test
- public void testTransitiveCCLibraryWithIncludes() throws Exception {
- scratch.file(
- "com/google/example/BUILD",
- "cc_library(",
- " name = 'lib2',",
- " srcs = ['lib2/lib2.cc'],",
- " hdrs = ['lib2/lib2.h'],",
- " includes = ['baz/lib'],",
- ")",
- "cc_library(",
- " name = 'lib1',",
- " srcs = ['lib1/lib1.cc'],",
- " hdrs = ['lib1/lib1.h'],",
- " includes = ['foo/bar'],",
- " deps = [':lib2'],",
- ")");
- Map<String, TargetIdeInfo> targetIdeInfos = buildIdeInfo("//com/google/example:lib1");
- assertThat(targetIdeInfos).hasSize(3);
- TargetIdeInfo lib1 =
- getTargetIdeInfoAndVerifyLabel("//com/google/example:lib1", targetIdeInfos);
-
- assertThat(lib1.hasCIdeInfo()).isTrue();
- CIdeInfo cTargetIdeInfo = lib1.getCIdeInfo();
-
- assertThat(cTargetIdeInfo.getTargetIncludeList()).containsExactly("foo/bar");
-
- // Make sure our understanding of where this attributes show up in other providers is correct.
- Entry<String, TargetIdeInfo> toolchainEntry =
- getCcToolchainRuleAndVerifyThereIsOnlyOne(targetIdeInfos);
- TargetIdeInfo toolchainInfo = toolchainEntry.getValue();
- assertThat(toolchainInfo.hasCToolchainIdeInfo()).isTrue();
- CToolchainIdeInfo cToolchainIdeInfo = toolchainInfo.getCToolchainIdeInfo();
- ProtocolStringList builtInIncludeDirectoryList =
- cToolchainIdeInfo.getBuiltInIncludeDirectoryList();
- assertThat(builtInIncludeDirectoryList).doesNotContain("foo/bar");
- assertThat(builtInIncludeDirectoryList).doesNotContain("baz/lib");
- assertThat(builtInIncludeDirectoryList).doesNotContain("com/google/example/foo/bar");
- assertThat(builtInIncludeDirectoryList).doesNotContain("com/google/example/baz/lib");
-
- ProtocolStringList transIncludeDirList = cTargetIdeInfo.getTransitiveIncludeDirectoryList();
- assertThat(transIncludeDirList).doesNotContain("foo/bar");
- assertThat(transIncludeDirList).doesNotContain("baz/lib");
- assertThat(transIncludeDirList).doesNotContain("com/google/example/foo/bar");
- assertThat(transIncludeDirList).doesNotContain("com/google/example/baz/lib");
-
- ProtocolStringList transQuoteIncludeDirList =
- cTargetIdeInfo.getTransitiveQuoteIncludeDirectoryList();
- assertThat(transQuoteIncludeDirList).doesNotContain("foo/bar");
- assertThat(transQuoteIncludeDirList).doesNotContain("baz/lib");
- assertThat(transQuoteIncludeDirList).doesNotContain("com/google/example/foo/bar");
- assertThat(transQuoteIncludeDirList).doesNotContain("com/google/example/baz/lib");
-
- ProtocolStringList transSysIncludeDirList =
- cTargetIdeInfo.getTransitiveSystemIncludeDirectoryList();
- assertThat(transSysIncludeDirList).doesNotContain("foo/bar");
- assertThat(transSysIncludeDirList).doesNotContain("baz/lib");
- assertThat(transSysIncludeDirList).contains("com/google/example/foo/bar");
- assertThat(transSysIncludeDirList).contains("com/google/example/baz/lib");
- }
-
- @Test
- public void testTransitiveCLibraryWithCompilerFlags() throws Exception {
- scratch.file(
- "com/google/example/BUILD",
- "cc_library(",
- " name = 'lib2',",
- " srcs = ['lib2/lib2.cc'],",
- " hdrs = ['lib2/lib2.h'],",
- " copts = ['-v23', '-DDEV'],",
- ")",
- "cc_library(",
- " name = 'lib1',",
- " srcs = ['lib1/lib1.cc'],",
- " hdrs = ['lib1/lib1.h'],",
- " copts = ['-DGOPT', '-Ifoo/baz/'],",
- " deps = [':lib2'],",
- ")");
- Map<String, TargetIdeInfo> targetIdeInfos = buildIdeInfo("//com/google/example:lib1");
- assertThat(targetIdeInfos).hasSize(3);
- TargetIdeInfo lib1 =
- getTargetIdeInfoAndVerifyLabel("//com/google/example:lib1", targetIdeInfos);
-
- assertThat(lib1.hasCIdeInfo()).isTrue();
- CIdeInfo cTargetIdeInfo = lib1.getCIdeInfo();
-
- assertThat(cTargetIdeInfo.getTargetCoptList()).containsExactly("-DGOPT", "-Ifoo/baz/");
-
- // Make sure our understanding of where this attributes show up in other providers is correct.
- Entry<String, TargetIdeInfo> toolchainEntry =
- getCcToolchainRuleAndVerifyThereIsOnlyOne(targetIdeInfos);
- TargetIdeInfo toolchainInfo = toolchainEntry.getValue();
- assertThat(toolchainInfo.hasCToolchainIdeInfo()).isTrue();
- CToolchainIdeInfo cToolchainIdeInfo = toolchainInfo.getCToolchainIdeInfo();
- ProtocolStringList baseCompilerOptionList = cToolchainIdeInfo.getBaseCompilerOptionList();
- assertThat(baseCompilerOptionList).doesNotContain("-DGOPT");
- assertThat(baseCompilerOptionList).doesNotContain("-Ifoo/baz/");
- assertThat(baseCompilerOptionList).doesNotContain("-v23");
- assertThat(baseCompilerOptionList).doesNotContain("-DDEV");
-
- ProtocolStringList cOptionList = cToolchainIdeInfo.getCOptionList();
- assertThat(cOptionList).doesNotContain("-DGOPT");
- assertThat(cOptionList).doesNotContain("-Ifoo/baz/");
- assertThat(cOptionList).doesNotContain("-v23");
- assertThat(cOptionList).doesNotContain("-DDEV");
-
- ProtocolStringList cppOptionList = cToolchainIdeInfo.getCppOptionList();
- assertThat(cppOptionList).doesNotContain("-DGOPT");
- assertThat(cppOptionList).doesNotContain("-Ifoo/baz/");
- assertThat(cppOptionList).doesNotContain("-v23");
- assertThat(cppOptionList).doesNotContain("-DDEV");
- }
-
- @Test
- public void testTransitiveCCLibraryWithDefines() throws Exception {
- scratch.file(
- "com/google/example/BUILD",
- "cc_library(",
- " name = 'lib2',",
- " srcs = ['lib2/lib2.cc'],",
- " hdrs = ['lib2/lib2.h'],",
- " defines = ['COMPLEX_IMPL'],",
- ")",
- "cc_library(",
- " name = 'lib1',",
- " srcs = ['lib1/lib1.cc'],",
- " hdrs = ['lib1/lib1.h'],",
- " defines = ['VERSION2'],",
- " deps = [':lib2'],",
- ")");
- Map<String, TargetIdeInfo> targetIdeInfos = buildIdeInfo("//com/google/example:lib1");
- assertThat(targetIdeInfos).hasSize(3);
- TargetIdeInfo lib1 =
- getTargetIdeInfoAndVerifyLabel("//com/google/example:lib1", targetIdeInfos);
-
- assertThat(lib1.hasCIdeInfo()).isTrue();
- CIdeInfo cIdeInfo = lib1.getCIdeInfo();
-
- assertThat(cIdeInfo.getTargetDefineList()).containsExactly("VERSION2");
-
- // Make sure our understanding of where this attributes show up in other providers is correct.
- ProtocolStringList transDefineList = cIdeInfo.getTransitiveDefineList();
- assertThat(transDefineList).contains("VERSION2");
- assertThat(transDefineList).contains("COMPLEX_IMPL");
- }
-
- @Test
- public void testMacroDoesntAffectRuleClass() throws Exception {
- scratch.file(
- "java/com/google/example/build_defs.bzl",
- "def my_macro(name):",
- " native.android_binary(",
- " name = name,",
- " srcs = ['simple/Simple.java'],",
- " manifest = 'AndroidManifest.xml',",
- ")");
- scratch.file(
- "java/com/google/example/BUILD",
- "load('//java/com/google/example:build_defs.bzl', 'my_macro')",
- "my_macro(",
- " name = 'simple',",
- ")");
- Map<String, TargetIdeInfo> targetIdeInfos = buildIdeInfo("//java/com/google/example:simple");
- TargetIdeInfo targetIdeInfo =
- getTargetIdeInfoAndVerifyLabel("//java/com/google/example:simple", targetIdeInfos);
- assertThat(targetIdeInfo.getKindString()).isEqualTo("android_binary");
- }
-
- @Test
- public void testAndroidBinaryIsSerialized() throws Exception {
- TargetIdeInfo.Builder builder = TargetIdeInfo.newBuilder();
- builder.setKindString("android_binary");
- ByteString byteString = builder.build().toByteString();
- TargetIdeInfo result = TargetIdeInfo.parseFrom(byteString);
- assertThat(result.getKindString()).isEqualTo("android_binary");
- }
-
- @Test
- public void testCcToolchainInfoIsOnlyPresentForToolchainRules() throws Exception {
- scratch.file(
- "com/google/example/BUILD",
- "cc_library(",
- " name = 'simple',",
- " srcs = ['simple/simple.cc'],",
- " hdrs = ['simple/simple.h'],",
- ")");
- Map<String, TargetIdeInfo> targetIdeInfos = buildIdeInfo("//com/google/example:simple");
- assertThat(targetIdeInfos).hasSize(2);
- TargetIdeInfo targetIdeInfo =
- getTargetIdeInfoAndVerifyLabel("//com/google/example:simple", targetIdeInfos);
- Entry<String, TargetIdeInfo> toolchainEntry =
- getCcToolchainRuleAndVerifyThereIsOnlyOne(targetIdeInfos);
- TargetIdeInfo toolchainInfo = toolchainEntry.getValue();
- ArtifactLocation location = targetIdeInfo.getBuildFileArtifactLocation();
- assertThat(Paths.get(location.getRelativePath()).toString())
- .isEqualTo(Paths.get("com/google/example/BUILD").toString());
-
- assertThat(targetIdeInfo.hasCToolchainIdeInfo()).isFalse();
- assertThat(toolchainInfo.hasCToolchainIdeInfo()).isTrue();
- }
-
- @Test
- public void testJavaLibraryDoesNotHaveCInfo() throws Exception {
- scratch.file(
- "com/google/example/BUILD",
- "java_library(",
- " name = 'simple',",
- " srcs = ['simple/Simple.java']",
- ")");
- Map<String, TargetIdeInfo> targetIdeInfos = buildIdeInfo("//com/google/example:simple");
- TargetIdeInfo targetIdeInfo =
- getTargetIdeInfoAndVerifyLabel("//com/google/example:simple", targetIdeInfos);
- assertThat(targetIdeInfo.hasCIdeInfo()).isFalse();
- }
-
- @Test
- public void testSimplePyBinary() throws Exception {
- scratch.file(
- "com/google/example/BUILD",
- "py_binary(",
- " name = 'simple',",
- " srcs = ['simple/simple.py'],",
- ")");
- Map<String, TargetIdeInfo> targetIdeInfos = buildIdeInfo("//com/google/example:simple");
- assertThat(targetIdeInfos).hasSize(2);
- TargetIdeInfo targetIdeInfo =
- getTargetIdeInfoAndVerifyLabel("//com/google/example:simple", targetIdeInfos);
- ArtifactLocation location = targetIdeInfo.getBuildFileArtifactLocation();
- assertThat(Paths.get(location.getRelativePath()).toString())
- .isEqualTo(Paths.get("com/google/example/BUILD").toString());
- assertThat(targetIdeInfo.getKindString()).isEqualTo("py_binary");
- assertThat(targetIdeInfo.getDependenciesCount()).isEqualTo(1);
-
- assertThat(relativePathsForPySourcesOf(targetIdeInfo))
- .containsExactly("com/google/example/simple/simple.py");
-
- assertThat(targetIdeInfo.hasPyIdeInfo()).isTrue();
- assertThat(targetIdeInfo.hasJavaIdeInfo()).isFalse();
- assertThat(targetIdeInfo.hasCIdeInfo()).isFalse();
- assertThat(targetIdeInfo.hasAndroidIdeInfo()).isFalse();
-
- assertThat(getIdeResolveFiles()).containsExactly("com/google/example/simple/simple.py");
- }
-
- @Test
- public void testSimplePyLibrary() throws Exception {
- scratch.file(
- "com/google/example/BUILD",
- "py_library(",
- " name = 'simple',",
- " srcs = ['simple/simple.py'],",
- ")");
- Map<String, TargetIdeInfo> targetIdeInfos = buildIdeInfo("//com/google/example:simple");
- assertThat(targetIdeInfos).hasSize(1);
- TargetIdeInfo targetIdeInfo =
- getTargetIdeInfoAndVerifyLabel("//com/google/example:simple", targetIdeInfos);
- ArtifactLocation location = targetIdeInfo.getBuildFileArtifactLocation();
- assertThat(Paths.get(location.getRelativePath()).toString())
- .isEqualTo(Paths.get("com/google/example/BUILD").toString());
- assertThat(targetIdeInfo.getKindString()).isEqualTo("py_library");
- assertThat(targetIdeInfo.getDependenciesCount()).isEqualTo(0);
-
- assertThat(relativePathsForPySourcesOf(targetIdeInfo))
- .containsExactly("com/google/example/simple/simple.py");
-
- assertThat(targetIdeInfo.hasPyIdeInfo()).isTrue();
- assertThat(targetIdeInfo.hasJavaIdeInfo()).isFalse();
- assertThat(targetIdeInfo.hasCIdeInfo()).isFalse();
- assertThat(targetIdeInfo.hasAndroidIdeInfo()).isFalse();
-
- assertThat(getIdeResolveFiles()).containsExactly("com/google/example/simple/simple.py");
- }
-
- @Test
- public void testSimplePyTest() throws Exception {
- scratch.file(
- "com/google/example/BUILD",
- "py_test(",
- " name = 'simple',",
- " srcs = ['simple/simple.py'],",
- ")");
- Map<String, TargetIdeInfo> targetIdeInfos = buildIdeInfo("//com/google/example:simple");
- assertThat(targetIdeInfos).hasSize(2);
- TargetIdeInfo targetIdeInfo =
- getTargetIdeInfoAndVerifyLabel("//com/google/example:simple", targetIdeInfos);
- ArtifactLocation location = targetIdeInfo.getBuildFileArtifactLocation();
- assertThat(Paths.get(location.getRelativePath()).toString())
- .isEqualTo(Paths.get("com/google/example/BUILD").toString());
- assertThat(targetIdeInfo.getKindString()).isEqualTo("py_test");
- assertThat(targetIdeInfo.getDependenciesCount()).isEqualTo(1);
-
- assertThat(relativePathsForPySourcesOf(targetIdeInfo))
- .containsExactly("com/google/example/simple/simple.py");
-
- assertThat(targetIdeInfo.hasPyIdeInfo()).isTrue();
- assertThat(targetIdeInfo.hasJavaIdeInfo()).isFalse();
- assertThat(targetIdeInfo.hasCIdeInfo()).isFalse();
- assertThat(targetIdeInfo.hasAndroidIdeInfo()).isFalse();
-
- assertThat(getIdeResolveFiles()).containsExactly("com/google/example/simple/simple.py");
- }
-
- @Test
- public void testPyTestWithDeps() throws Exception {
- scratch.file(
- "com/google/example/BUILD",
- "py_library(",
- " name = 'lib',",
- " srcs = ['lib.py'],",
- ")",
- "py_test(",
- " name = 'test',",
- " srcs = ['test.py'],",
- " deps = [':lib'],",
- ")");
- Map<String, TargetIdeInfo> targetIdeInfos = buildIdeInfo("//com/google/example:test");
- assertThat(targetIdeInfos).hasSize(3);
- TargetIdeInfo targetIdeInfo =
- getTargetIdeInfoAndVerifyLabel("//com/google/example:test", targetIdeInfos);
- ArtifactLocation location = targetIdeInfo.getBuildFileArtifactLocation();
- assertThat(Paths.get(location.getRelativePath()).toString())
- .isEqualTo(Paths.get("com/google/example/BUILD").toString());
- assertThat(targetIdeInfo.getKindString()).isEqualTo("py_test");
-
- assertThat(targetIdeInfo.getDependenciesList()).contains("//com/google/example:lib");
- assertThat(targetIdeInfo.getDependenciesCount()).isEqualTo(2);
-
- assertThat(relativePathsForPySourcesOf(targetIdeInfo))
- .containsExactly("com/google/example/test.py");
-
- assertThat(targetIdeInfo.hasPyIdeInfo()).isTrue();
- assertThat(targetIdeInfo.hasJavaIdeInfo()).isFalse();
- assertThat(targetIdeInfo.hasCIdeInfo()).isFalse();
- assertThat(targetIdeInfo.hasAndroidIdeInfo()).isFalse();
-
- assertThat(getIdeResolveFiles())
- .containsExactly("com/google/example/test.py", "com/google/example/lib.py");
- }
-
- @Test
- public void testAlias() throws Exception {
- scratch.file(
- "com/google/example/BUILD",
- "java_library(",
- " name = 'test',",
- " srcs = ['Test.java'],",
- " deps = [':alias']",
- ")",
- "alias(",
- " name = 'alias',",
- " actual = ':alias2',",
- ")",
- "alias(",
- " name = 'alias2',",
- " actual = ':real',",
- ")",
- "java_library(",
- " name = 'real',",
- " srcs = ['Real.java'],",
- ")");
- Map<String, TargetIdeInfo> targetIdeInfos = buildIdeInfo("//com/google/example:test");
- TargetIdeInfo testInfo =
- getTargetIdeInfoAndVerifyLabel("//com/google/example:test", targetIdeInfos);
- assertThat(testInfo.getDependenciesList()).contains("//com/google/example:real");
- assertThat(getTargetIdeInfoAndVerifyLabel("//com/google/example:real", targetIdeInfos))
- .isNotNull();
- }
-
- @Test
- public void testDataModeDepsAttributeDoesNotCrashAspect() throws Exception {
- scratch.file(
- "com/google/example/foo.bzl",
- "def impl(ctx):",
- " return struct()",
- "",
- "foo = rule(",
- " implementation=impl,",
- " attrs={'deps': attr.label_list(cfg='data')},",
- ")");
- scratch.file(
- "com/google/example/BUILD",
- "load('//com/google/example:foo.bzl', 'foo')",
- "foo(",
- " name='foo',",
- ")");
- buildIdeInfo("//com/google/example:foo");
- }
-
- @Test
- public void testExternalRootCorrectlyIdentified() throws Exception {
- ArtifactLocation location =
- AndroidStudioInfoAspect.makeArtifactLocation(
- Root.asSourceRoot(outputBase, false), new PathFragment("external/foo/bar.jar"), true);
- assertThat(location.getIsExternal()).isTrue();
- }
-
- @Test
- public void testNonExternalRootCorrectlyIdentified() throws Exception {
- ArtifactLocation location =
- AndroidStudioInfoAspect.makeArtifactLocation(
- Root.asSourceRoot(rootDirectory, true), new PathFragment("foo/bar.jar"), false);
- assertThat(location.getIsExternal()).isFalse();
- }
-
- @Test
- public void testExternalTarget() throws Exception {
- scratch.file(
- "/r/BUILD", "java_import(", " name = 'junit',", " jars = ['junit.jar'],", ")");
- scratch.file("/r/junit.jar");
-
- // AnalysisMock adds required toolchains, etc. to WORKSPACE, so retain the previous contents.
- String oldContents = scratch.readFile("WORKSPACE");
- scratch.overwriteFile("WORKSPACE", oldContents + "\nlocal_repository(name='r', path='/r')");
- invalidatePackages();
-
- scratch.file(
- "com/google/example/BUILD",
- "java_library(",
- " name = 'junit',",
- " exports = ['@r//:junit'],",
- ")");
-
- Map<String, TargetIdeInfo> targetIdeInfos = buildIdeInfo("//com/google/example:junit");
- assertThat(
- getTargetIdeInfoAndVerifyLabel("//com/google/example:junit", targetIdeInfos)
- .getBuildFileArtifactLocation()
- .getIsExternal())
- .isFalse();
-
- TargetIdeInfo targetInfo = getTargetIdeInfoAndVerifyLabel("@r//:junit", targetIdeInfos);
- assertThat(targetInfo.getBuildFileArtifactLocation().getIsExternal()).isTrue();
- assertThat(targetInfo.getBuildFileArtifactLocation().getRelativePath()).startsWith("external");
-
- JavaIdeInfo javaInfo = targetInfo.getJavaIdeInfo();
- assertThat(javaInfo.getJarsList()).hasSize(1);
- ArtifactLocation jar = javaInfo.getJars(0).getJar();
- assertThat(jar.getIsSource()).isTrue();
- assertThat(jar.getIsExternal()).isTrue();
- assertThat(jar.getRelativePath()).isEqualTo("external/r/junit.jar");
- }
-}
diff --git a/src/test/java/com/google/devtools/build/lib/ideinfo/AndroidStudioInfoAspectTestBase.java b/src/test/java/com/google/devtools/build/lib/ideinfo/AndroidStudioInfoAspectTestBase.java
deleted file mode 100644
index 97e76f0..0000000
--- a/src/test/java/com/google/devtools/build/lib/ideinfo/AndroidStudioInfoAspectTestBase.java
+++ /dev/null
@@ -1,231 +0,0 @@
-// Copyright 2014 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 static com.google.common.collect.Iterables.transform;
-import static com.google.common.truth.Truth.assertThat;
-import static com.google.common.truth.Truth.assertWithMessage;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-
-import com.google.common.base.Function;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Lists;
-import com.google.common.eventbus.EventBus;
-import com.google.devtools.build.lib.actions.Action;
-import com.google.devtools.build.lib.actions.Artifact;
-import com.google.devtools.build.lib.analysis.BuildView.AnalysisResult;
-import com.google.devtools.build.lib.analysis.ConfiguredAspect;
-import com.google.devtools.build.lib.analysis.OutputGroupProvider;
-import com.google.devtools.build.lib.analysis.actions.BinaryFileWriteAction;
-import com.google.devtools.build.lib.analysis.actions.SpawnAction;
-import com.google.devtools.build.lib.analysis.util.BuildViewTestCase;
-import com.google.devtools.build.lib.collect.nestedset.NestedSet;
-import com.google.devtools.build.lib.skyframe.AspectValue;
-import com.google.devtools.intellij.ideinfo.IntellijIdeInfo.ArtifactLocation;
-import com.google.devtools.intellij.ideinfo.IntellijIdeInfo.LibraryArtifact;
-import com.google.devtools.intellij.ideinfo.IntellijIdeInfo.TargetIdeInfo;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import javax.annotation.Nullable;
-
-/**
- * Provides utils for AndroidStudioInfoAspectTest.
- */
-abstract class AndroidStudioInfoAspectTestBase extends BuildViewTestCase {
-
- protected static final Function<ArtifactLocation, String> ARTIFACT_TO_RELATIVE_PATH =
- new Function<ArtifactLocation, String>() {
- @Nullable
- @Override
- public String apply(ArtifactLocation artifactLocation) {
- return artifactLocation.getRelativePath();
- }
- };
- protected static final Function<LibraryArtifact, String> LIBRARY_ARTIFACT_TO_STRING =
- new Function<LibraryArtifact, String>() {
- @Override
- public String apply(LibraryArtifact libraryArtifact) {
- StringBuilder stringBuilder = new StringBuilder();
- if (libraryArtifact.hasJar()) {
- stringBuilder.append("<jar:");
- stringBuilder.append(artifactLocationPath(libraryArtifact.getJar()));
- stringBuilder.append(">");
- }
- if (libraryArtifact.hasInterfaceJar()) {
- stringBuilder.append("<ijar:");
- stringBuilder.append(artifactLocationPath(libraryArtifact.getInterfaceJar()));
- stringBuilder.append(">");
- }
- if (libraryArtifact.hasSourceJar()) {
- stringBuilder.append("<source:");
- stringBuilder.append(artifactLocationPath(libraryArtifact.getSourceJar()));
- stringBuilder.append(">");
- }
-
- return stringBuilder.toString();
- }
-
- private String artifactLocationPath(ArtifactLocation artifact) {
- String relativePath = artifact.getRelativePath();
- return artifact.getIsExternal() ? relativePath + "[external]" : relativePath;
- }
- };
-
- protected ConfiguredAspect configuredAspect;
-
- /**
- * Constructs a string that matches OutputJar#toString for comparison testing.
- */
- protected static String jarString(String base, String jar, String iJar, String sourceJar) {
- StringBuilder sb = new StringBuilder();
- if (jar != null) {
- sb.append("<jar:" + base + "/" + jar + ">");
- }
- if (iJar != null) {
- sb.append("<ijar:" + base + "/" + iJar + ">");
- }
- if (sourceJar != null) {
- sb.append("<source:" + base + "/" + sourceJar + ">");
- }
- return sb.toString();
- }
-
- protected static Iterable<String> relativePathsForJavaSourcesOf(TargetIdeInfo ruleIdeInfo) {
- return relativePathsForSources(ruleIdeInfo.getJavaIdeInfo().getSourcesList());
- }
-
- protected static Iterable<String> relativePathsForCSourcesOf(TargetIdeInfo ruleIdeInfo) {
- return relativePathsForSources(ruleIdeInfo.getCIdeInfo().getSourceList());
- }
-
- protected static Iterable<String> relativePathsForPySourcesOf(TargetIdeInfo ruleIdeInfo) {
- return relativePathsForSources(ruleIdeInfo.getPyIdeInfo().getSourcesList());
- }
-
- private static Iterable<String> relativePathsForSources(List<ArtifactLocation> sourcesList) {
- return transform(sourcesList, ARTIFACT_TO_RELATIVE_PATH);
- }
-
- protected TargetIdeInfo getTargetIdeInfoAndVerifyLabel(
- String target, Map<String, TargetIdeInfo> ruleIdeInfos) {
- TargetIdeInfo ruleIdeInfo = ruleIdeInfos.get(target);
- assertThat(ruleIdeInfo).named(target).isNotNull();
- assertThat(ruleIdeInfo.getLabel()).isEqualTo(target);
- return ruleIdeInfo;
- }
-
- protected Entry<String, TargetIdeInfo> getCcToolchainRuleAndVerifyThereIsOnlyOne(
- Map<String, TargetIdeInfo> ruleIdeInfos) {
- Entry<String, TargetIdeInfo> toolchainInfo = null;
- for (Entry<String, TargetIdeInfo> entry : ruleIdeInfos.entrySet()) {
- if (entry.getValue().getKindString().equals("cc_toolchain")) {
- // Make sure we only have 1.
- assertThat(toolchainInfo).isNull();
- assertThat(entry.getValue().hasCToolchainIdeInfo()).isTrue();
- toolchainInfo = entry;
- }
- }
- assertThat(toolchainInfo).isNotNull();
- return toolchainInfo;
- }
-
- private void buildTarget(String target) throws Exception {
- AnalysisResult analysisResult =
- update(
- ImmutableList.of(target),
- ImmutableList.of(AndroidStudioInfoAspect.NAME),
- false,
- LOADING_PHASE_THREADS,
- true,
- new EventBus());
- Collection<AspectValue> aspects = analysisResult.getAspects();
- assertThat(aspects.size()).isEqualTo(1);
- AspectValue value = aspects.iterator().next();
- this.configuredAspect = value.getConfiguredAspect();
- assertThat(configuredAspect.getName()).isEqualTo(AndroidStudioInfoAspect.NAME);
- }
-
- /**
- * Returns a map of (label as string) -> TargetIdeInfo for each rule in the transitive closure of
- * the passed target.
- */
- protected Map<String, TargetIdeInfo> buildIdeInfo(String target) throws Exception {
- buildTarget(target);
- AndroidStudioInfoFilesProvider provider =
- configuredAspect.getProvider(AndroidStudioInfoFilesProvider.class);
- Iterable<Artifact> artifacts = provider.getIdeInfoFiles();
- Map<String, TargetIdeInfo> ruleIdeInfos = new HashMap<>();
- for (Artifact artifact : artifacts) {
- Action generatingAction = getGeneratingAction(artifact);
- if (generatingAction instanceof BinaryFileWriteAction) {
- BinaryFileWriteAction writeAction = (BinaryFileWriteAction) generatingAction;
- TargetIdeInfo ruleIdeInfo = TargetIdeInfo.parseFrom(writeAction.getSource().openStream());
- ruleIdeInfos.put(ruleIdeInfo.getLabel(), ruleIdeInfo);
- } else {
- verifyPackageManifestSpawnAction(generatingAction);
- }
- }
- return ruleIdeInfos;
- }
-
- protected final void verifyPackageManifestSpawnAction(Action genAction) {
- assertEquals(genAction.getMnemonic(), "JavaPackageManifest");
- SpawnAction action = (SpawnAction) genAction;
- assertFalse(action.isShellCommand());
- }
-
- protected List<String> getOutputGroupResult(String outputGroup) {
- OutputGroupProvider outputGroupProvider =
- this.configuredAspect.getProvider(OutputGroupProvider.class);
- assert outputGroupProvider != null;
- NestedSet<Artifact> artifacts = outputGroupProvider.getOutputGroup(outputGroup);
-
- for (Artifact artifact : artifacts) {
- if (artifact.isSourceArtifact()) {
- continue;
- }
- assertWithMessage("Artifact %s has no generating action", artifact)
- .that(getGeneratingAction(artifact))
- .isNotNull();
- }
-
- List<String> artifactRelativePaths = Lists.newArrayList();
- for (Artifact artifact : artifacts) {
- artifactRelativePaths.add(artifact.getRootRelativePathString());
- }
- return artifactRelativePaths;
- }
-
- protected List<String> getIdeResolveFiles() {
- return getOutputGroupResult(AndroidStudioInfoAspect.IDE_RESOLVE);
- }
-
- protected List<String> getIdeCompileFiles() {
- return getOutputGroupResult(AndroidStudioInfoAspect.IDE_COMPILE);
- }
-
- protected static List<TargetIdeInfo> findJavaToolchain(Map<String, TargetIdeInfo> ruleIdeInfos) {
- List<TargetIdeInfo> result = Lists.newArrayList();
- for (TargetIdeInfo ruleIdeInfo : ruleIdeInfos.values()) {
- if (ruleIdeInfo.getKindString().equals("java_toolchain")) {
- result.add(ruleIdeInfo);
- }
- }
- return result;
- }
-}
diff --git a/src/test/shell/integration/BUILD b/src/test/shell/integration/BUILD
index a2f7fe9..8cfbff7 100644
--- a/src/test/shell/integration/BUILD
+++ b/src/test/shell/integration/BUILD
@@ -156,24 +156,6 @@
)
sh_test(
- name = "ide_info_generation_native",
- size = "large",
- srcs = ["ide_info_generation.sh"],
- args = [
- "AndroidStudioInfoAspect",
- "ide-info",
- "aswb-build",
- "ide-info-text",
- "aswb-build.txt",
- "ide-resolve",
- ],
- data = [
- ":test-deps",
- "//src/tools/android/java/com/google/devtools/build/android/ideinfo:PackageParser",
- ],
-)
-
-sh_test(
name = "ide_info_generation_skylark",
size = "large",
srcs = ["ide_info_generation.sh"],