Add TransitionFactory interface, to be used later for creating
transitions.

Part of work on #7814.

Closes #7825.

PiperOrigin-RevId: 240196293
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/config/transitions/TransitionFactory.java b/src/main/java/com/google/devtools/build/lib/analysis/config/transitions/TransitionFactory.java
new file mode 100644
index 0000000..dc9fa88
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/analysis/config/transitions/TransitionFactory.java
@@ -0,0 +1,58 @@
+// 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.analysis.config.transitions;
+
+import com.google.devtools.build.lib.analysis.config.transitions.TransitionFactory.TransitionFactoryData;
+
+/**
+ * Factory interface for transitions that are created dynamically, instead of being created as
+ * singletons.
+ *
+ * <p>This class allows for cases where the general <i>type</i> of a transition is known, but the
+ * specifics of the transition itself cannot be determined until the target is configured. Examples
+ * of this are transitions that depend on other (non-configured) attributes from the same target, or
+ * transitions that depend on state determined during configuration, such as the execution platform
+ * or resolved toolchains.
+ *
+ * <p>Implementations must override {@link Object#equals} and {@link Object#hashCode} unless
+ * exclusively accessed as singletons.
+ *
+ * @param <T> the type of data object passed to the {@link #create} method, used to create the
+ *     actual {@link ConfigurationTransition} instance
+ */
+public interface TransitionFactory<T extends TransitionFactoryData> {
+
+  /** Interface for types of data that a {@link TransitionFactory} can use. */
+  interface TransitionFactoryData {}
+
+  /** Returns a new {@link ConfigurationTransition}, based on the given data. */
+  ConfigurationTransition create(T data);
+
+  // TODO(https://github.com/bazelbuild/bazel/issues/7814): Once everything uses TransitionFactory,
+  // remove these methods.
+  /** Returns {@code true} if the result of this {@link TransitionFactory} is a host transition. */
+  default boolean isHost() {
+    return false;
+  }
+
+  /** Returns {@code true} if the result of this {@link TransitionFactory} is a split transition. */
+  default boolean isSplit() {
+    return false;
+  }
+
+  /** Returns {@code true} if the result of this {@link TransitionFactory} is a final transition. */
+  default boolean isFinal() {
+    return false;
+  }
+}
diff --git a/src/main/java/com/google/devtools/build/lib/packages/RuleTransitionData.java b/src/main/java/com/google/devtools/build/lib/packages/RuleTransitionData.java
new file mode 100644
index 0000000..875c451
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/packages/RuleTransitionData.java
@@ -0,0 +1,37 @@
+// 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.packages;
+
+import com.google.auto.value.AutoValue;
+import com.google.devtools.build.lib.analysis.config.transitions.TransitionFactory;
+
+/**
+ * Helper class which contains data used by a {@link TransitionFactory} to create a transition for
+ * rules and attributes.
+ */
+// This class is in lib.packages in order to access AttributeMap, which is not available to
+// the lib.analysis.config.transitions package.
+@AutoValue
+public abstract class RuleTransitionData implements TransitionFactory.TransitionFactoryData {
+  /** Returns the {@link AttributeMap} which can be used to create a transition. */
+  public abstract AttributeMap attributes();
+
+  // TODO(https://github.com/bazelbuild/bazel/issues/7814): Add further data fields as needed by
+  // transition factory instances.
+
+  /** Returns a new {@link RuleTransitionData} instance. */
+  public static RuleTransitionData create(AttributeMap attributes) {
+    return new AutoValue_RuleTransitionData(attributes);
+  }
+}