Skip to content

Commit

Permalink
Don't register import deps checker actions if --experimental_import_…
Browse files Browse the repository at this point in the history
…deps_checker is off

    Fixes #8340

    Closes #8341.

    PiperOrigin-RevId: 248883983
  • Loading branch information
Luca Di Grazia committed Sep 4, 2022
1 parent 21e16ae commit 41f80ec
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@
import com.google.devtools.build.lib.rules.java.JavaRuntimeInfo;
import com.google.devtools.build.lib.rules.java.JavaSemantics;
import com.google.devtools.build.lib.rules.java.JavaSkylarkApiProvider;
import com.google.devtools.build.lib.rules.java.JavaSourceInfoProvider;
import com.google.devtools.build.lib.rules.java.JavaSourceJarsProvider;
import com.google.devtools.build.lib.rules.java.JavaToolchainProvider;
import com.google.devtools.build.lib.vfs.PathFragment;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -194,36 +192,12 @@ public ConfiguredTarget create(RuleContext ruleContext)
/* isNeverLink = */ JavaCommon.isNeverLink(ruleContext),
/* srcLessDepsExport = */ false);

// Wire up the source jar for the current target and transitive source jars from dependencies.
ImmutableList<Artifact> srcJars = ImmutableList.of();
Artifact srcJar = ruleContext.getPrerequisiteArtifact("srcjar", Mode.TARGET);
NestedSetBuilder<Artifact> transitiveJavaSourceJarBuilder = NestedSetBuilder.stableOrder();
if (srcJar != null) {
srcJars = ImmutableList.of(srcJar);
transitiveJavaSourceJarBuilder.add(srcJar);
}
for (JavaSourceJarsProvider other :
JavaInfo.getProvidersFromListOfTargets(
JavaSourceJarsProvider.class, ruleContext.getPrerequisites("exports", Mode.TARGET))) {
transitiveJavaSourceJarBuilder.addTransitive(other.getTransitiveSourceJars());
}
NestedSet<Artifact> transitiveJavaSourceJars = transitiveJavaSourceJarBuilder.build();
JavaSourceJarsProvider javaSourceJarsProvider =
JavaSourceJarsProvider.create(transitiveJavaSourceJars, srcJars);
JavaSourceInfoProvider javaSourceInfoProvider =
new JavaSourceInfoProvider.Builder()
.setJarFiles(ImmutableList.of(mergedJar))
.setSourceJarsForJarFiles(srcJars)
.build();

JavaInfo.Builder javaInfoBuilder =
JavaInfo.Builder.create()
.setRuntimeJars(ImmutableList.of(mergedJar))
.setJavaConstraints(ImmutableList.of("android"))
.setNeverlink(JavaCommon.isNeverLink(ruleContext))
.addProvider(JavaCompilationArgsProvider.class, javaCompilationArgsProvider)
.addProvider(JavaSourceJarsProvider.class, javaSourceJarsProvider)
.addProvider(JavaSourceInfoProvider.class, javaSourceInfoProvider)
.addProvider(JavaRuleOutputJarsProvider.class, jarProviderBuilder.build());

common.addTransitiveInfoProviders(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
import com.google.devtools.build.lib.rules.java.JavaInfo;
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.JavaSourceJarsProvider;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -76,27 +74,17 @@ public void setup() throws Exception {
")");
scratch.file(
"a/BUILD",
"java_import(",
" name = 'foo_src',",
" jars = ['foo-src.jar'],",
")",
"aar_import(",
" name = 'foo',",
" aar = 'foo.aar',",
" srcjar = ':foo_src',",
")",
"aar_import(",
" name = 'baz',",
" aar = 'baz.aar',",
")",
"java_import(",
" name = 'bar_src',",
" jars = ['bar-src.jar'],",
")",
"aar_import(",
" name = 'bar',",
" aar = 'bar.aar',",
" srcjar = ':bar_src',",
" deps = [':baz'],",
" exports = [':foo', '//java:baz'],",
")",
Expand Down Expand Up @@ -196,43 +184,6 @@ public void testResourcesProvided() throws Exception {
assertThat(assetsTreeArtifact.getExecPathString()).endsWith("_aar/unzipped/assets/foo");
}

@Test
public void testSourceJarsProvided() throws Exception {
ConfiguredTarget aarImportTarget = getConfiguredTarget("//a:foo");

Iterable<Artifact> srcJars =
JavaInfo.getProvider(JavaSourceJarsProvider.class, aarImportTarget).getSourceJars();
assertThat(srcJars).hasSize(1);
Artifact srcJar = Iterables.getOnlyElement(srcJars);
assertThat(srcJar.getExecPathString()).endsWith("foo-src.jar");

Iterable<Artifact> srcInfoJars =
JavaInfo.getProvider(JavaSourceInfoProvider.class, aarImportTarget)
.getSourceJarsForJarFiles();
assertThat(srcInfoJars).hasSize(1);
Artifact srcInfoJar = Iterables.getOnlyElement(srcInfoJars);
assertThat(srcInfoJar.getExecPathString()).endsWith("foo-src.jar");
}

@Test
public void testSourceJarsCollectedTransitively() throws Exception {
ConfiguredTarget aarImportTarget = getConfiguredTarget("//a:bar");

Iterable<Artifact> srcJars =
JavaInfo.getProvider(JavaSourceJarsProvider.class, aarImportTarget)
.getTransitiveSourceJars();
assertThat(srcJars).hasSize(2);
assertThat(ActionsTestUtil.baseArtifactNames(srcJars))
.containsExactly("foo-src.jar", "bar-src.jar");

Iterable<Artifact> srcInfoJars =
JavaInfo.getProvider(JavaSourceInfoProvider.class, aarImportTarget)
.getSourceJarsForJarFiles();
assertThat(srcInfoJars).hasSize(1);
Artifact srcInfoJar = Iterables.getOnlyElement(srcInfoJars);
assertThat(srcInfoJar.getExecPathString()).endsWith("bar-src.jar");
}

@Test
public void testResourcesExtractor() throws Exception {
ValidatedAndroidResources resourceContainer =
Expand Down

0 comments on commit 41f80ec

Please sign in to comment.