Remove GraphNodeAspect

-1 native aspect

PiperOrigin-RevId: 544044482
Change-Id: I3be0bc6fba70e5e46e2c31e46a9b10a13f2f8a5b
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/CcRules.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/CcRules.java
index 021c560..f7b562e 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/CcRules.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/CcRules.java
@@ -43,7 +43,6 @@
 import com.google.devtools.build.lib.rules.cpp.DebugPackageProvider;
 import com.google.devtools.build.lib.rules.cpp.FdoPrefetchHintsRule;
 import com.google.devtools.build.lib.rules.cpp.FdoProfileRule;
-import com.google.devtools.build.lib.rules.cpp.GraphNodeAspect;
 import com.google.devtools.build.lib.rules.cpp.PropellerOptimizeRule;
 import com.google.devtools.build.lib.rules.platform.PlatformRules;
 import com.google.devtools.build.lib.starlarkbuildapi.cpp.CcBootstrap;
@@ -63,7 +62,6 @@
 
   @Override
   public void init(ConfiguredRuleClassProvider.Builder builder) {
-    GraphNodeAspect graphNodeAspect = new GraphNodeAspect();
     BazelCcModule bazelCcModule = new BazelCcModule();
     // TODO(gnish): This is only required for cc_toolchain_suite rule,
     // because it does not have AppleConfiguration fragment.
@@ -76,7 +74,6 @@
     builder.addBzlToplevel("cc_proto_aspect", Starlark.NONE);
     builder.addBuildInfoFactory(new CppBuildInfo());
 
-    builder.addNativeAspectClass(graphNodeAspect);
     builder.addRuleDefinition(new CcToolchainRule());
     builder.addRuleDefinition(new CcToolchainSuiteRule());
     builder.addRuleDefinition(new CcToolchainAliasRule());
@@ -87,7 +84,7 @@
     builder.addRuleDefinition(new BazelCppRuleClasses.CcDeclRule());
     builder.addRuleDefinition(new BazelCppRuleClasses.CcBaseRule());
     builder.addRuleDefinition(new BazelCppRuleClasses.CcRule());
-    builder.addRuleDefinition(new BazelCppRuleClasses.CcBinaryBaseRule(graphNodeAspect));
+    builder.addRuleDefinition(new BazelCppRuleClasses.CcBinaryBaseRule());
     builder.addRuleDefinition(new BazelCcBinaryRule());
     builder.addRuleDefinition(new CcSharedLibraryRule());
     builder.addRuleDefinition(new BazelCcTestRule());
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BUILD b/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BUILD
index cdfa344..b46e763 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BUILD
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BUILD
@@ -35,7 +35,6 @@
         "//src/main/java/com/google/devtools/build/lib/starlarkbuildapi/cpp",
         "//src/main/java/com/google/devtools/build/lib/util:filetype",
         "//src/main/java/com/google/devtools/build/lib/util:os",
-        "//src/main/java/net/starlark/java/eval",
         "//third_party:guava",
         "//third_party:jsr305",
     ],
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCppRuleClasses.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCppRuleClasses.java
index 71f9612..b638612 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCppRuleClasses.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCppRuleClasses.java
@@ -57,7 +57,6 @@
 import com.google.devtools.build.lib.rules.cpp.CppFileTypes;
 import com.google.devtools.build.lib.rules.cpp.CppRuleClasses;
 import com.google.devtools.build.lib.rules.cpp.CppRuleClasses.CcIncludeScanningRule;
-import com.google.devtools.build.lib.rules.cpp.GraphNodeAspect;
 import com.google.devtools.build.lib.util.FileTypeSet;
 import javax.annotation.Nullable;
 
@@ -485,12 +484,6 @@
 
   /** Helper rule class. */
   public static final class CcBinaryBaseRule implements RuleDefinition {
-    private final GraphNodeAspect graphNodeAspect;
-
-    public CcBinaryBaseRule(GraphNodeAspect graphNodeAspect) {
-      this.graphNodeAspect = graphNodeAspect;
-    }
-
     @Override
     public RuleClass build(RuleClass.Builder builder, RuleDefinitionEnvironment env) {
       return builder
@@ -511,8 +504,7 @@
                   .allowedRuleClasses(DEPS_ALLOWED_RULES)
                   .allowedFileTypes(CppFileTypes.LINKER_SCRIPT)
                   .skipAnalysisTimeFileTypeCheck()
-                  .mandatoryProviders(StarlarkProviderIdentifier.forKey(CcInfo.PROVIDER.getKey()))
-                  .aspect(graphNodeAspect, GraphNodeAspect.ASPECT_PARAMETERS))
+                  .mandatoryProviders(StarlarkProviderIdentifier.forKey(CcInfo.PROVIDER.getKey())))
           .add(
               attr("dynamic_deps", LABEL_LIST)
                   .allowedFileTypes(FileTypeSet.NO_FILE)
@@ -541,8 +533,7 @@
               attr("malloc", LABEL)
                   .value(env.getToolsLabel("//tools/cpp:malloc"))
                   .allowedFileTypes()
-                  .allowedRuleClasses("cc_library")
-                  .aspect(graphNodeAspect, GraphNodeAspect.ASPECT_PARAMETERS))
+                  .allowedRuleClasses("cc_library"))
           .add(attr(":default_malloc", LABEL).value(CppRuleClasses.DEFAULT_MALLOC))
           /*<!-- #BLAZE_RULE($cc_binary_base).ATTRIBUTE(stamp) -->
           Whether to encode build information into the binary. Possible values:
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/GraphNodeAspect.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/GraphNodeAspect.java
deleted file mode 100644
index 68d42d9..0000000
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/GraphNodeAspect.java
+++ /dev/null
@@ -1,81 +0,0 @@
-// Copyright 2019 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.cpp;
-
-
-import com.google.common.base.Function;
-import com.google.common.collect.ImmutableList;
-import com.google.devtools.build.lib.actions.MutableActionGraph.ActionConflictException;
-import com.google.devtools.build.lib.analysis.AnalysisUtils;
-import com.google.devtools.build.lib.analysis.ConfiguredAspect;
-import com.google.devtools.build.lib.analysis.ConfiguredAspectFactory;
-import com.google.devtools.build.lib.analysis.ConfiguredTarget;
-import com.google.devtools.build.lib.analysis.RuleContext;
-import com.google.devtools.build.lib.cmdline.Label;
-import com.google.devtools.build.lib.cmdline.RepositoryName;
-import com.google.devtools.build.lib.packages.AspectDefinition;
-import com.google.devtools.build.lib.packages.AspectParameters;
-import com.google.devtools.build.lib.packages.NativeAspectClass;
-import com.google.devtools.build.lib.packages.Rule;
-import javax.annotation.Nullable;
-
-/**
- * Aspect for constructing a tree of labels that is used to prune static libraries that are already
- * linked dynamically into a cc_binary. TODO(b/145508948): Try to remove this class in the future.
- */
-public final class GraphNodeAspect extends NativeAspectClass implements ConfiguredAspectFactory {
-  // When the dynamic_deps attribute is not set, we return null. We would only want the graph to be
-  // analyzed with the aspect in the cases that we have set dynamic_deps. Otherwise it would be a
-  // waste of memory in the cases where we don't need the aspect. If we return null, the aspect is
-  // not used analyze anything.
-  // See
-  // https://github.com/bazelbuild/bazel/blob/df52777aac8cbfc7719af9f0dbb23335e59c42df/src/main/java/com/google/devtools/build/lib/packages/Attribute.java#L114
-  public static final Function<Rule, AspectParameters> ASPECT_PARAMETERS =
-      new Function<Rule, AspectParameters>() {
-        @Nullable
-        @Override
-        public AspectParameters apply(Rule rule) {
-          return rule.isAttributeValueExplicitlySpecified("dynamic_deps")
-              ? AspectParameters.EMPTY
-              : null;
-        }
-      };
-
-  @Override
-  public AspectDefinition getDefinition(AspectParameters aspectParameters) {
-    return new AspectDefinition.Builder(this)
-        .propagateAlongAllAttributes()
-        .requireStarlarkProviders(CcInfo.PROVIDER.id())
-        .build();
-  }
-
-  @Override
-  public ConfiguredAspect create(
-      Label targetLabel,
-      ConfiguredTarget ct,
-      RuleContext ruleContext,
-      AspectParameters params,
-      RepositoryName toolsRepository)
-      throws ActionConflictException, InterruptedException {
-    ImmutableList.Builder<GraphNodeInfo> children = ImmutableList.builder();
-    if (ruleContext.attributes().has("deps")) {
-      children.addAll(
-          AnalysisUtils.getProviders(ruleContext.getPrerequisites("deps"), GraphNodeInfo.class));
-    }
-    return new ConfiguredAspect.Builder(ruleContext)
-        .addProvider(
-            GraphNodeInfo.class, new GraphNodeInfo(ruleContext.getLabel(), children.build()))
-        .build();
-  }
-}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/GraphNodeInfo.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/GraphNodeInfo.java
deleted file mode 100644
index 9c663ed..0000000
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/GraphNodeInfo.java
+++ /dev/null
@@ -1,40 +0,0 @@
-// Copyright 2019 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.cpp;
-
-import com.google.common.collect.ImmutableList;
-import com.google.devtools.build.lib.analysis.TransitiveInfoProvider;
-import com.google.devtools.build.lib.cmdline.Label;
-import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
-import java.util.List;
-
-/** Provider used to propagate information for {@link GraphNodeAspect}. */
-@Immutable
-public final class GraphNodeInfo implements TransitiveInfoProvider {
-  private final Label label;
-  private final ImmutableList<GraphNodeInfo> children;
-
-  public GraphNodeInfo(Label label, List<GraphNodeInfo> children) {
-    this.label = label;
-    this.children = children == null ? null : ImmutableList.copyOf(children);
-  }
-
-  public Label getLabel() {
-    return label;
-  }
-
-  public List<GraphNodeInfo> getChildren() {
-    return children;
-  }
-}