Skip to content

Commit

Permalink
Clean up usage of TransitionFactories with AndroidSplitTransition.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 588085701
Change-Id: Ie30e03a167bcb82243086171972f0d4033c667ca
  • Loading branch information
katre authored and copybara-github committed Dec 5, 2023
1 parent c572286 commit dd9c500
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ && containsNonNoneKey(arguments, ALLOW_SINGLE_FILE_ARG)) {
} else if (trans instanceof ExecutionTransitionFactory) {
builder.cfg((ExecutionTransitionFactory) trans);
} else if (trans instanceof SplitTransition) {
// TODO(jcater): remove TransitionFactories usage.
builder.cfg(TransitionFactories.of((SplitTransition) trans));
} else if (trans instanceof TransitionFactory) {
@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import com.google.devtools.build.lib.analysis.RuleDefinition;
import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment;
import com.google.devtools.build.lib.analysis.config.ExecutionTransitionFactory;
import com.google.devtools.build.lib.analysis.config.TransitionFactories;
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.events.EventHandler;
import com.google.devtools.build.lib.packages.Attribute;
Expand Down Expand Up @@ -213,11 +212,7 @@ public static LabelLateBoundDefault<?> getAndroidSdkLabel(Label androidSdk) {
androidSdk,
(rule, attributes, configuration) -> configuration.getSdk());
}

@SerializationConstant
public static final AndroidSplitTransition ANDROID_SPLIT_TRANSITION =
new AndroidSplitTransition();


@SerializationConstant
static final LabelLateBoundDefault<AndroidConfiguration> LEGACY_MAIN_DEX_LIST_GENERATOR =
LabelLateBoundDefault.fromTargetConfiguration(
Expand Down Expand Up @@ -517,7 +512,7 @@ public RuleClass build(RuleClass.Builder builder, final RuleDefinitionEnvironmen
.override(
builder
.copy("deps")
.cfg(TransitionFactories.of(ANDROID_SPLIT_TRANSITION))
.cfg(AndroidSplitTransition.FACTORY)
.allowedRuleClasses(ALLOWED_DEPENDENCIES)
.allowedFileTypes()
.mandatoryProviders(CONTAINS_CC_INFO_PARAMS)
Expand Down Expand Up @@ -818,7 +813,7 @@ is exceeded. Assumes multidex classes are loaded through application code (i.e.
// We need the C++ toolchain for every sub-configuration to get the correct linker.
.add(
attr("$cc_toolchain_split", LABEL)
.cfg(TransitionFactories.of(ANDROID_SPLIT_TRANSITION))
.cfg(AndroidSplitTransition.FACTORY)
.value(env.getToolsLabel("//tools/cpp:current_cc_toolchain")))
/* <!-- #BLAZE_RULE(android_binary).ATTRIBUTE(manifest_values) -->
A dictionary of values to be overridden in the manifest.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,48 @@
import com.google.devtools.build.lib.analysis.config.BuildOptionsView;
import com.google.devtools.build.lib.analysis.config.CoreOptions;
import com.google.devtools.build.lib.analysis.config.FragmentOptions;
import com.google.devtools.build.lib.analysis.config.transitions.ConfigurationTransition;
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.events.EventHandler;
import com.google.devtools.build.lib.packages.AttributeTransitionData;
import com.google.devtools.build.lib.rules.android.AndroidConfiguration.ConfigurationDistinguisher;
import com.google.devtools.build.lib.rules.cpp.CppOptions;
import com.google.devtools.build.lib.starlarkbuildapi.android.AndroidSplitTransitionApi;
import java.util.List;
import net.starlark.java.eval.Printer;

/** Android Split configuration transition for properly handling native dependencies */
final class AndroidSplitTransition implements SplitTransition, AndroidSplitTransitionApi {
public final class AndroidSplitTransition implements SplitTransition, AndroidSplitTransitionApi {

public static final AndroidSplitTransition INSTANCE = new AndroidSplitTransition();

public static final TransitionFactory<AttributeTransitionData> FACTORY = new Factory();

/** A {@link TransitionFactory} instance that returns the {@link AndroidSplitTransition}. */
static final class Factory implements TransitionFactory<AttributeTransitionData> {

@Override
public ConfigurationTransition create(AttributeTransitionData unused) {
return INSTANCE;
}

@Override
public TransitionType transitionType() {
return TransitionType.ATTRIBUTE;
}

@Override
public boolean isTool() {
return false;
}

@Override
public boolean isSplit() {
return true;
}
}

@Override
public ImmutableSet<Class<? extends FragmentOptions>> requiresOptionFragments() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public String getSourceDirectoryRelativePathFromResource(Artifact resource) {

@Override
public AndroidSplitTransitionApi getAndroidSplitTransition() {
return AndroidRuleClasses.ANDROID_SPLIT_TRANSITION;
return AndroidSplitTransition.INSTANCE;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ java_library(
"//src/main/java/com/google/devtools/build/lib/analysis:config/fragment_options",
"//src/main/java/com/google/devtools/build/lib/analysis:config/invalid_configuration_exception",
"//src/main/java/com/google/devtools/build/lib/analysis:config/toolchain_type_requirement",
"//src/main/java/com/google/devtools/build/lib/analysis:config/transition_factories",
"//src/main/java/com/google/devtools/build/lib/analysis:config/transitions/configuration_transition",
"//src/main/java/com/google/devtools/build/lib/analysis:config/transitions/patch_transition",
"//src/main/java/com/google/devtools/build/lib/analysis:config/transitions/split_transition",
"//src/main/java/com/google/devtools/build/lib/analysis:config/transitions/starlark_exposed_rule_transition_factory",
Expand Down

0 comments on commit dd9c500

Please sign in to comment.