use of com.google.devtools.build.lib.analysis.config.PatchTransition in project bazel by bazelbuild.
the class ConfiguredTargetFunction method getDynamicTransitionOptions.
/**
* Applies a dynamic configuration transition over a set of build options.
*
* @return the build options for the transitioned configuration. If trimResults is true,
* only options needed by the required fragments are included. Else the same options as the
* original input are included (with different possible values, of course).
*/
static List<BuildOptions> getDynamicTransitionOptions(BuildOptions fromOptions, Attribute.Transition transition, Iterable<Class<? extends BuildConfiguration.Fragment>> requiredFragments, RuleClassProvider ruleClassProvider, boolean trimResults) {
List<BuildOptions> result;
if (transition == Attribute.ConfigurationTransition.NONE) {
result = ImmutableList.<BuildOptions>of(fromOptions);
} else if (transition instanceof PatchTransition) {
// TODO(bazel-team): safety-check that this never mutates fromOptions.
result = ImmutableList.<BuildOptions>of(((PatchTransition) transition).apply(fromOptions));
} else if (transition instanceof Attribute.SplitTransition) {
// Attribute.java doesn't have the BuildOptions symbol.
@SuppressWarnings("unchecked") List<BuildOptions> toOptions = ((Attribute.SplitTransition<BuildOptions>) transition).split(fromOptions);
if (toOptions.isEmpty()) {
// When the split returns an empty list, it's signaling it doesn't apply to this instance.
// Check that it's safe to skip the transition and return the original options.
Verify.verify(transition.defaultsToSelf());
result = ImmutableList.<BuildOptions>of(fromOptions);
} else {
result = toOptions;
}
} else {
throw new IllegalStateException(String.format("unsupported dynamic transition type: %s", transition.getClass().getName()));
}
if (!trimResults) {
return result;
} else {
ImmutableList.Builder<BuildOptions> trimmedOptions = ImmutableList.builder();
for (BuildOptions toOptions : result) {
trimmedOptions.add(toOptions.trim(BuildConfiguration.getOptionsClasses(requiredFragments, ruleClassProvider)));
}
return trimmedOptions.build();
}
}
use of com.google.devtools.build.lib.analysis.config.PatchTransition in project bazel by bazelbuild.
the class ConfigurationsForTargetsWithDynamicConfigurationsTest method newPatchTransition.
/**
* Returns a custom {@link PatchTransition} with the given value added to
* {@link BuildConfiguration.Options#testFilter}.
*/
private static PatchTransition newPatchTransition(final String value) {
return new PatchTransition() {
@Override
public BuildOptions apply(BuildOptions options) {
BuildOptions toOptions = options.clone();
BuildConfiguration.Options baseOptions = toOptions.get(BuildConfiguration.Options.class);
baseOptions.testFilter = (nullToEmpty(baseOptions.testFilter)) + value;
return toOptions;
}
@Override
public boolean defaultsToSelf() {
return false;
}
};
}
Aggregations