Convert uses of RuleTransitionFactory to TransitionFactory.

Part of #7814.

Closes #7922.

PiperOrigin-RevId: 241744479
diff --git a/src/main/java/com/google/devtools/build/lib/packages/AttributeTransitionData.java b/src/main/java/com/google/devtools/build/lib/packages/AttributeTransitionData.java
index a43c760..de6199e 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/AttributeTransitionData.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/AttributeTransitionData.java
@@ -18,7 +18,7 @@
 
 /**
  * Helper class which contains data used by a {@link TransitionFactory} to create a transition for
- * rules and attributes.
+ * attributes.
  */
 // This class is in lib.packages in order to access AttributeMap, which is not available to
 // the lib.analysis.config.transitions package.
diff --git a/src/main/java/com/google/devtools/build/lib/packages/RuleClass.java b/src/main/java/com/google/devtools/build/lib/packages/RuleClass.java
index b46bce6..328a840 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/RuleClass.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/RuleClass.java
@@ -35,6 +35,7 @@
 import com.google.devtools.build.lib.analysis.config.transitions.ConfigurationTransition;
 import com.google.devtools.build.lib.analysis.config.transitions.PatchTransition;
 import com.google.devtools.build.lib.analysis.config.transitions.SplitTransition;
+import com.google.devtools.build.lib.analysis.config.transitions.TransitionFactory;
 import com.google.devtools.build.lib.cmdline.Label;
 import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
 import com.google.devtools.build.lib.cmdline.PackageIdentifier;
@@ -624,23 +625,6 @@
       }
     }
 
-    /** A RuleTransitionFactory which always returns the same transition. */
-    @AutoCodec.VisibleForSerialization
-    @AutoCodec
-    static final class FixedTransitionFactory implements RuleTransitionFactory {
-      private final PatchTransition transition;
-
-      @AutoCodec.VisibleForSerialization
-      FixedTransitionFactory(PatchTransition transition) {
-        this.transition = transition;
-      }
-
-      @Override
-      public PatchTransition buildTransitionFor(Rule rule) {
-        return transition;
-      }
-    }
-
     /**
      * Name of default attribute implicitly added to all Skylark RuleClasses that are {@code
      * build_setting}s.
@@ -679,7 +663,7 @@
     private boolean hasStarlarkRuleTransition = false;
     private boolean ignorePackageLicenses = false;
     private ImplicitOutputsFunction implicitOutputsFunction = ImplicitOutputsFunction.NONE;
-    private RuleTransitionFactory transitionFactory;
+    private TransitionFactory<Rule> transitionFactory;
     private ConfiguredTargetFactory<?, ?, ?> configuredTargetFactory = null;
     private PredicateWithMessage<Rule> validityPredicate =
         PredicatesWithMessage.<Rule>alwaysTrue();
@@ -1049,15 +1033,14 @@
      * Applies the given transition to all incoming edges for this rule class.
      *
      * <p>This cannot be a {@link SplitTransition} because that requires coordination with the
-     * rule's parent: use {@link
-     * Attribute.Builder#cfg(com.google.devtools.build.lib.analysis.config.transitions.TransitionFactory)}
-     * on the parent to declare splits.
+     * rule's parent: use {@link Attribute.Builder#cfg(TransitionFactory)} on the parent to declare
+     * splits.
      *
      * <p>If you need the transition to depend on the rule it's being applied to, use {@link
-     * #cfg(RuleTransitionFactory)}.
+     * #cfg(TransitionFactory)}.
      */
     public Builder cfg(PatchTransition transition) {
-      return cfg(new FixedTransitionFactory(transition));
+      return cfg((TransitionFactory<Rule>) (unused) -> (transition));
     }
 
     /**
@@ -1066,12 +1049,13 @@
      * <p>Unlike {@link #cfg(PatchTransition)}, the factory can examine the rule when deciding what
      * transition to use.
      */
-    public Builder cfg(RuleTransitionFactory transitionFactory) {
+    public Builder cfg(TransitionFactory<Rule> transitionFactory) {
       Preconditions.checkState(type != RuleClassType.ABSTRACT,
           "Setting not inherited property (cfg) of abstract rule class '%s'", name);
       Preconditions.checkState(this.transitionFactory == null,
           "Property cfg has already been set");
       Preconditions.checkNotNull(transitionFactory);
+      Preconditions.checkArgument(!transitionFactory.isSplit());
       this.transitionFactory = transitionFactory;
       return this;
     }
@@ -1491,7 +1475,7 @@
    * A factory which will produce a configuration transition that should be applied on any edge of
    * the configured target graph that leads into a target of this rule class.
    */
-  private final RuleTransitionFactory transitionFactory;
+  private final TransitionFactory<Rule> transitionFactory;
 
   /** The factory that creates configured targets from this rule. */
   private final ConfiguredTargetFactory<?, ?, ?> configuredTargetFactory;
@@ -1597,7 +1581,7 @@
       boolean hasFunctionTransitionWhitelist,
       boolean ignorePackageLicenses,
       ImplicitOutputsFunction implicitOutputsFunction,
-      RuleTransitionFactory transitionFactory,
+      TransitionFactory<Rule> transitionFactory,
       ConfiguredTargetFactory<?, ?, ?> configuredTargetFactory,
       PredicateWithMessage<Rule> validityPredicate,
       Predicate<String> preferredDependencyPredicate,
@@ -1704,7 +1688,7 @@
     return implicitOutputsFunction;
   }
 
-  public RuleTransitionFactory getTransitionFactory() {
+  public TransitionFactory<Rule> getTransitionFactory() {
     return transitionFactory;
   }
 
diff --git a/src/main/java/com/google/devtools/build/lib/packages/RuleTransitionFactory.java b/src/main/java/com/google/devtools/build/lib/packages/RuleTransitionFactory.java
deleted file mode 100644
index 7fe079c..0000000
--- a/src/main/java/com/google/devtools/build/lib/packages/RuleTransitionFactory.java
+++ /dev/null
@@ -1,39 +0,0 @@
-// Copyright 2017 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.packages;
-
-import com.google.devtools.build.lib.analysis.config.transitions.PatchTransition;
-
-/**
- * Customizable transition which accepts the rule it will be executing on.
- */
-public interface RuleTransitionFactory {
-  /**
-   * Generates a transition to be used when entering the given rule.
-   *
-   * <p>This cannot be a {@link
-   * com.google.devtools.build.lib.analysis.config.transitions.SplitTransition} because splits are
-   * conceptually a property of the <i>parent<i> rule. In other words, it makes sense for a parent
-   * to say "build my deps in configurations A and B". But it doesn't make sense for a dep to say
-   * "build myself in configurations A and B" if its parent doesn't know how to intelligently handle
-   * the results.
-   *
-   * <p>If this class determines that no transition should be performed, it should return {@code
-   * NoTransition.INSTANCE}.
-   */
-  // TODO(bazel-team): Refactor to only take an AttributeMap. Currently the entire Rule is consumed
-  // by StarlarkRuleTransitionProvider and TestTrimmingTransitionFactory.
-  PatchTransition buildTransitionFor(Rule rule);
-}