Remove JavaNativeLibrayInfo provider.

PiperOrigin-RevId: 372545965
diff --git a/src/main/java/com/google/devtools/build/lib/packages/semantics/BuildLanguageOptions.java b/src/main/java/com/google/devtools/build/lib/packages/semantics/BuildLanguageOptions.java
index 56b371e..fd7f696 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/semantics/BuildLanguageOptions.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/semantics/BuildLanguageOptions.java
@@ -147,14 +147,6 @@
   public boolean experimentalEnableAndroidMigrationApis;
 
   @Option(
-      name = "experimental_enable_javanativelibraryinfo",
-      defaultValue = "true",
-      documentationCategory = OptionDocumentationCategory.STARLARK_SEMANTICS,
-      effectTags = OptionEffectTag.BUILD_FILE_SEMANTICS,
-      help = "If set to false, disables the APIs for JavaNativeLibraryInfo.")
-  public boolean experimentalEnableJavaNativeLibraryInfo;
-
-  @Option(
       name = "experimental_google_legacy_api",
       defaultValue = "false",
       documentationCategory = OptionDocumentationCategory.STARLARK_SEMANTICS,
@@ -643,8 +635,6 @@
             .set(EXPERIMENTAL_BUILTINS_INJECTION_OVERRIDE, experimentalBuiltinsInjectionOverride)
             .setBool(
                 EXPERIMENTAL_ENABLE_ANDROID_MIGRATION_APIS, experimentalEnableAndroidMigrationApis)
-            .setBool(
-                EXPERIMENTAL_ENABLE_JAVANATIVELIBRARYINFO, experimentalEnableJavaNativeLibraryInfo)
             .setBool(EXPERIMENTAL_GOOGLE_LEGACY_API, experimentalGoogleLegacyApi)
             .setBool(EXPERIMENTAL_NINJA_ACTIONS, experimentalNinjaActions)
             .setBool(EXPERIMENTAL_PLATFORMS_API, experimentalPlatformsApi)
@@ -712,8 +702,6 @@
       "-experimental_disable_external_package";
   public static final String EXPERIMENTAL_ENABLE_ANDROID_MIGRATION_APIS =
       "-experimental_enable_android_migration_apis";
-  public static final String EXPERIMENTAL_ENABLE_JAVANATIVELIBRARYINFO =
-      "+experimental_enable_javanativelibraryinfo";
   public static final String EXPERIMENTAL_EXEC_GROUPS = "-experimental_exec_groups";
   public static final String EXPERIMENTAL_GOOGLE_LEGACY_API = "-experimental_google_legacy_api";
   public static final String EXPERIMENTAL_NINJA_ACTIONS = "-experimental_ninja_actions";
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/BUILD b/src/main/java/com/google/devtools/build/lib/rules/java/BUILD
index 504ef0c..3399a06 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/java/BUILD
+++ b/src/main/java/com/google/devtools/build/lib/rules/java/BUILD
@@ -138,7 +138,6 @@
         "JavaInfo.java",
         "JavaInfoBuildHelper.java",
         "JavaLibraryHelper.java",
-        "JavaNativeLibraryInfo.java",
         "JavaOptions.java",
         "JavaPackageConfigurationProvider.java",
         "JavaPluginInfo.java",
@@ -153,7 +152,6 @@
         "JavaToolchainTool.java",
         "JavaUtil.java",
         "MessageBundleInfo.java",
-        "NativeLibraryNestedSetBuilder.java",
         "OneVersionCheckActionBuilder.java",
         "ResourceJarActionBuilder.java",
         "SingleJarActionBuilder.java",
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaBinary.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaBinary.java
index a77b2e6..3e2fbb9 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaBinary.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaBinary.java
@@ -690,8 +690,6 @@
     NestedSet<LibraryToLink> linkerInputs =
         NestedSetBuilder.fromNestedSets(
                 Streams.concat(
-                        AnalysisUtils.getProviders(deps, JavaNativeLibraryInfo.PROVIDER).stream()
-                            .map(JavaNativeLibraryInfo::getTransitiveJavaNativeLibraries),
                         JavaInfo.getProvidersFromListOfTargets(JavaCcInfoProvider.class, deps)
                             .stream()
                             .map(JavaCcInfoProvider::getCcInfo)
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaCommon.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaCommon.java
index cc3ed40..208f7cb 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaCommon.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaCommon.java
@@ -46,7 +46,6 @@
 import com.google.devtools.build.lib.packages.Type;
 import com.google.devtools.build.lib.rules.cpp.CcInfo;
 import com.google.devtools.build.lib.rules.cpp.CcNativeLibraryInfo;
-import com.google.devtools.build.lib.rules.cpp.LibraryToLink;
 import com.google.devtools.build.lib.rules.java.JavaCompilationArgsProvider.ClasspathType;
 import com.google.devtools.build.lib.rules.java.JavaPluginInfo.JavaPluginData;
 import com.google.devtools.build.lib.util.FileTypeSet;
@@ -309,21 +308,6 @@
   }
 
   /**
-   * Returns transitive Java native libraries.
-   *
-   * @see JavaNativeLibraryInfo
-   */
-  protected NestedSet<LibraryToLink> collectTransitiveJavaNativeLibraries() {
-    NativeLibraryNestedSetBuilder builder = new NativeLibraryNestedSetBuilder();
-    builder.addJavaTargets(targetsTreatedAsDeps(ClasspathType.BOTH));
-
-    if (ruleContext.getRule().isAttrDefined("data", BuildType.LABEL_LIST)) {
-      builder.addJavaTargets(ruleContext.getPrerequisites("data"));
-    }
-    return builder.build();
-  }
-
-  /**
    * Collects transitive source jars for the current rule.
    *
    * @param targetSrcJars The source jar artifacts corresponding to the output of the current rule.
@@ -724,11 +708,6 @@
         CcNativeLibraryInfo.merge(
             Streams.concat(
                     Stream.of(mergedCcInfo.getCcNativeLibraryInfo()),
-                    AnalysisUtils.getProviders(
-                            Iterables.concat(deps, data), JavaNativeLibraryInfo.PROVIDER)
-                        .stream()
-                        .map(JavaNativeLibraryInfo::getTransitiveJavaNativeLibraries)
-                        .map(CcNativeLibraryInfo::new),
                     JavaInfo.getProvidersFromListOfTargets(JavaCcInfoProvider.class, data).stream()
                         .map(JavaCcInfoProvider::getCcInfo)
                         .map(CcInfo::getCcNativeLibraryInfo),
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaImport.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaImport.java
index cf9429e..cfbb405 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaImport.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaImport.java
@@ -31,7 +31,6 @@
 import com.google.devtools.build.lib.collect.nestedset.NestedSet;
 import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
 import com.google.devtools.build.lib.collect.nestedset.Order;
-import com.google.devtools.build.lib.rules.cpp.LibraryToLink;
 import com.google.devtools.build.lib.rules.java.JavaRuleOutputJarsProvider.JavaOutput;
 import java.util.LinkedHashSet;
 import java.util.Set;
@@ -79,8 +78,6 @@
     JavaCompilationArtifacts javaArtifacts = collectJavaArtifacts(jars, interfaceJars);
     common.setJavaCompilationArtifacts(javaArtifacts);
 
-    NestedSet<LibraryToLink> transitiveJavaNativeLibraries =
-        common.collectTransitiveJavaNativeLibraries();
     boolean neverLink = JavaCommon.isNeverLink(ruleContext);
     JavaCompilationArgsProvider javaCompilationArgs =
         common.collectJavaCompilationArgs(neverLink, false);
@@ -149,7 +146,6 @@
         .setFilesToBuild(filesToBuild)
         .addNativeDeclaredProvider(javaInfo)
         .add(RunfilesProvider.class, RunfilesProvider.simple(runfiles))
-        .addNativeDeclaredProvider(new JavaNativeLibraryInfo(transitiveJavaNativeLibraries))
         .addNativeDeclaredProvider(new ProguardSpecProvider(proguardSpecs))
         .addOutputGroup(JavaSemantics.SOURCE_JARS_OUTPUT_GROUP, transitiveJavaSourceJars)
         .addOutputGroup(
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaLibrary.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaLibrary.java
index 8d42bf41..26e70cd 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaLibrary.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaLibrary.java
@@ -26,7 +26,6 @@
 import com.google.devtools.build.lib.collect.nestedset.NestedSet;
 import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
 import com.google.devtools.build.lib.collect.nestedset.Order;
-import com.google.devtools.build.lib.rules.cpp.LibraryToLink;
 import com.google.devtools.build.lib.rules.java.JavaCompilationArgsProvider.ClasspathType;
 import com.google.devtools.build.lib.rules.java.JavaRuleOutputJarsProvider.JavaOutput;
 import com.google.devtools.build.lib.rules.java.proto.GeneratedExtensionRegistryProvider;
@@ -150,8 +149,6 @@
 
     JavaCompilationArgsProvider javaCompilationArgs =
         common.collectJavaCompilationArgs(neverLink, /* srcLessDepsExport= */ false);
-    NestedSet<LibraryToLink> transitiveJavaNativeLibraries =
-        common.collectTransitiveJavaNativeLibraries();
 
     RuleConfiguredTargetBuilder builder = new RuleConfiguredTargetBuilder(ruleContext);
 
@@ -199,7 +196,6 @@
             RunfilesProvider.simple(
                 JavaCommon.getRunfiles(ruleContext, semantics, javaArtifacts, neverLink)))
         .setFilesToBuild(filesToBuild)
-        .addNativeDeclaredProvider(new JavaNativeLibraryInfo(transitiveJavaNativeLibraries))
         .addNativeDeclaredProvider(new ProguardSpecProvider(proguardSpecs))
         .addNativeDeclaredProvider(javaInfo)
         .addOutputGroup(JavaSemantics.SOURCE_JARS_OUTPUT_GROUP, transitiveSourceJars)
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaNativeLibraryInfo.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaNativeLibraryInfo.java
deleted file mode 100644
index c8dd570..0000000
--- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaNativeLibraryInfo.java
+++ /dev/null
@@ -1,96 +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.rules.java;
-
-import com.google.devtools.build.lib.actions.Artifact;
-import com.google.devtools.build.lib.collect.nestedset.Depset;
-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;
-import com.google.devtools.build.lib.packages.BuiltinProvider;
-import com.google.devtools.build.lib.packages.NativeInfo;
-import com.google.devtools.build.lib.rules.cpp.LibraryToLink;
-import com.google.devtools.build.lib.rules.cpp.LtoBackendArtifacts;
-import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
-import com.google.devtools.build.lib.starlarkbuildapi.java.JavaNativeLibraryInfoApi;
-import net.starlark.java.eval.EvalException;
-
-/**
- * A target that provides native libraries in the transitive closure of its deps that are needed for
- * executing Java code.
- */
-@Immutable
-@AutoCodec
-public final class JavaNativeLibraryInfo extends NativeInfo
-    implements JavaNativeLibraryInfoApi<Artifact, LtoBackendArtifacts, LibraryToLink> {
-
-  public static final Provider PROVIDER = new Provider();
-
-  private final NestedSet<LibraryToLink> transitiveJavaNativeLibraries;
-
-  public JavaNativeLibraryInfo(NestedSet<LibraryToLink> transitiveJavaNativeLibraries) {
-    this.transitiveJavaNativeLibraries = transitiveJavaNativeLibraries;
-  }
-
-  @Override
-  public Provider getProvider() {
-    return PROVIDER;
-  }
-
-  /**
-   * Collects native libraries in the transitive closure of its deps that are needed for executing
-   * Java code.
-   */
-  NestedSet<LibraryToLink> getTransitiveJavaNativeLibraries() {
-    return transitiveJavaNativeLibraries;
-  }
-
-  @Override
-  public Depset /*<LibraryToLink>*/ getTransitiveJavaNativeLibrariesForStarlark() {
-    return Depset.of(LibraryToLink.TYPE, transitiveJavaNativeLibraries);
-  }
-
-  public static JavaNativeLibraryInfo merge(Iterable<JavaNativeLibraryInfo> deps) {
-    NestedSetBuilder<LibraryToLink> transitiveSourceJars = NestedSetBuilder.stableOrder();
-
-    for (JavaNativeLibraryInfo wrapper : deps) {
-      transitiveSourceJars.addTransitive(wrapper.getTransitiveJavaNativeLibraries());
-    }
-    return new JavaNativeLibraryInfo(transitiveSourceJars.build());
-  }
-
-  /** Provider class for {@link JavaNativeLibraryInfo} objects. */
-  public static class Provider extends BuiltinProvider<JavaNativeLibraryInfo>
-      implements JavaNativeLibraryInfoApi.Provider<Artifact, LtoBackendArtifacts, LibraryToLink> {
-
-    private Provider() {
-      super(NAME, JavaNativeLibraryInfo.class);
-    }
-
-    public String getName() {
-      return NAME;
-    }
-
-    @Override
-    public JavaNativeLibraryInfo create(Depset transitiveLibraries)
-        throws EvalException {
-      return new JavaNativeLibraryInfo(
-          NestedSetBuilder.<LibraryToLink>stableOrder()
-              .addTransitive(
-                  Depset.cast(transitiveLibraries, LibraryToLink.class, "transitive_libraries"))
-              .build());
-    }
-  }
-}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/NativeLibraryNestedSetBuilder.java b/src/main/java/com/google/devtools/build/lib/rules/java/NativeLibraryNestedSetBuilder.java
deleted file mode 100644
index a18da6b..0000000
--- a/src/main/java/com/google/devtools/build/lib/rules/java/NativeLibraryNestedSetBuilder.java
+++ /dev/null
@@ -1,81 +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.rules.java;
-
-import com.google.devtools.build.lib.analysis.TransitiveInfoCollection;
-import com.google.devtools.build.lib.collect.nestedset.NestedSet;
-import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
-import com.google.devtools.build.lib.rules.cpp.CcInfo;
-import com.google.devtools.build.lib.rules.cpp.LibraryToLink;
-
-/** A builder that helps construct nested sets of native libraries. */
-public final class NativeLibraryNestedSetBuilder {
-
-  private final NestedSetBuilder<LibraryToLink> builder = NestedSetBuilder.linkOrder();
-
-  /** Build a nested set of native libraries. */
-  public NestedSet<LibraryToLink> build() {
-    return builder.build();
-  }
-
-  /** Include specified artifacts as native libraries in the nested set. */
-  public NativeLibraryNestedSetBuilder addAll(Iterable<LibraryToLink> deps) {
-    builder.addAll(deps);
-    return this;
-  }
-
-  /** Include native libraries of specified dependencies into the nested set. */
-  public NativeLibraryNestedSetBuilder addJavaTargets(
-      Iterable<? extends TransitiveInfoCollection> deps) {
-    for (TransitiveInfoCollection dep : deps) {
-      addJavaTarget(dep);
-    }
-    return this;
-  }
-
-  /** Include native Java libraries of a specified target into the nested set. */
-  public NativeLibraryNestedSetBuilder addJavaTarget(TransitiveInfoCollection dep) {
-    JavaNativeLibraryInfo javaProvider = dep.get(JavaNativeLibraryInfo.PROVIDER);
-    if (javaProvider != null) {
-      builder.addTransitive(javaProvider.getTransitiveJavaNativeLibraries());
-      return this;
-    }
-
-    CcInfo ccProvider = dep.get(CcInfo.PROVIDER);
-    if (ccProvider != null && ccProvider.getCcNativeLibraryInfo() != null) {
-      builder.addTransitive(ccProvider.getCcNativeLibraryInfo().getTransitiveCcNativeLibraries());
-      return this;
-    }
-
-    return this;
-  }
-
-  /** Include native C/C++ libraries of specified dependencies into the nested set. */
-  public NativeLibraryNestedSetBuilder addCcTargets(
-      Iterable<? extends TransitiveInfoCollection> deps) {
-    for (TransitiveInfoCollection dep : deps) {
-      addCcTarget(dep);
-    }
-    return this;
-  }
-
-  /** Include native Java libraries of a specified target into the nested set. */
-  private void addCcTarget(TransitiveInfoCollection dep) {
-    CcInfo ccProvider = dep.get(CcInfo.PROVIDER);
-    if (ccProvider != null && ccProvider.getCcNativeLibraryInfo() != null) {
-      builder.addTransitive(ccProvider.getCcNativeLibraryInfo().getTransitiveCcNativeLibraries());
-    }
-  }
-}
diff --git a/src/main/java/com/google/devtools/build/lib/starlarkbuildapi/java/JavaNativeLibraryInfoApi.java b/src/main/java/com/google/devtools/build/lib/starlarkbuildapi/java/JavaNativeLibraryInfoApi.java
deleted file mode 100644
index da609e7..0000000
--- a/src/main/java/com/google/devtools/build/lib/starlarkbuildapi/java/JavaNativeLibraryInfoApi.java
+++ /dev/null
@@ -1,89 +0,0 @@
-// Copyright 2020 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.starlarkbuildapi.java;
-
-import com.google.devtools.build.docgen.annot.DocCategory;
-import com.google.devtools.build.docgen.annot.StarlarkConstructor;
-import com.google.devtools.build.lib.collect.nestedset.Depset;
-import com.google.devtools.build.lib.packages.semantics.BuildLanguageOptions;
-import com.google.devtools.build.lib.starlarkbuildapi.FileApi;
-import com.google.devtools.build.lib.starlarkbuildapi.core.ProviderApi;
-import com.google.devtools.build.lib.starlarkbuildapi.core.StructApi;
-import com.google.devtools.build.lib.starlarkbuildapi.cpp.LibraryToLinkApi;
-import com.google.devtools.build.lib.starlarkbuildapi.cpp.LtoBackendArtifactsApi;
-import net.starlark.java.annot.Param;
-import net.starlark.java.annot.ParamType;
-import net.starlark.java.annot.StarlarkBuiltin;
-import net.starlark.java.annot.StarlarkMethod;
-import net.starlark.java.eval.EvalException;
-
-/** A target that provides C++ {@link LibraryToLinkApi}s to be linked into Java targets. */
-@StarlarkBuiltin(
-    name = "JavaNativeLibraryInfo",
-    doc =
-        "Do not use this module. It is intended for migration purposes only. If you depend on it, "
-            + "you will be broken when it is removed."
-            + "Information about the C++ libraries to be linked into Java targets.",
-    documented = true,
-    category = DocCategory.PROVIDER)
-public interface JavaNativeLibraryInfoApi<
-        FileT extends FileApi,
-        LtoBackendArtifactsT extends LtoBackendArtifactsApi<FileT>,
-        LibraryToLinkT extends LibraryToLinkApi<FileT, LtoBackendArtifactsT>>
-    extends StructApi {
-  /** Name of this info object. */
-  String NAME = "JavaNativeLibraryInfo";
-
-  /** Returns the cc linking info */
-  @StarlarkMethod(
-      name = "transitive_libraries",
-      structField = true,
-      doc = "Returns the set of transitive LibraryToLink objects.",
-      documented = true,
-      enableOnlyWithFlag = BuildLanguageOptions.EXPERIMENTAL_ENABLE_JAVANATIVELIBRARYINFO)
-  Depset /*<LibraryToLinkT>*/ getTransitiveJavaNativeLibrariesForStarlark();
-
-  /** The provider implementing this can construct the JavaNativeLibraryInfo provider. */
-  @StarlarkBuiltin(
-      name = "Provider",
-      doc =
-          "Do not use this module. It is intended for migration purposes only. If you depend on "
-              + "it, you will be broken when it is removed.",
-      documented = false)
-  interface Provider<
-          FileT extends FileApi,
-          LtoBackendArtifactsT extends LtoBackendArtifactsApi<FileT>,
-          LibraryToLinkT extends LibraryToLinkApi<FileT, LtoBackendArtifactsT>>
-      extends ProviderApi {
-
-    @StarlarkMethod(
-        name = NAME,
-        doc = "The <code>JavaNativeLibraryInfo</code> constructor.",
-        documented = true,
-        enableOnlyWithFlag = BuildLanguageOptions.EXPERIMENTAL_ENABLE_JAVANATIVELIBRARYINFO,
-        parameters = {
-          @Param(
-              name = "transitive_libraries",
-              doc = "The transitive set of LibraryToLink providers.",
-              positional = true,
-              named = false,
-              allowedTypes = {@ParamType(type = Depset.class, generic1 = LibraryToLinkApi.class)}),
-        },
-        selfCall = true)
-    @StarlarkConstructor
-    JavaNativeLibraryInfoApi<FileT, LtoBackendArtifactsT, LibraryToLinkT> create(
-        Depset transitiveLibraries) throws EvalException;
-  }
-}