Simplify `TestTrimmingTransitionFactory`.
Instead of copying the set of referenced options and removing non-test options, simply iterate over the set and check whether each referenced option is a test option.
@@ -26,8 +26,6 @@ import com.google.devtools.build.lib.events.EventHandler;
import com.google.devtools.build.lib.packages.Rule;
import com.google.devtools.build.lib.packages.RuleClass;
import com.google.devtools.common.options.Options;
-import java.util.LinkedHashSet;
-import java.util.Set;
/**
* Trimming transition factory which removes the test config fragment when entering a non-test rule.
@@ -71,11 +69,10 @@ public final class TestTrimmingTransitionFactory implements TransitionFactory<Ru
originalOptions,
// The transition uses no non-BuildOptions arguments
0,
- () -> {
- return originalOptions.underlying().toBuilder()
+ () ->
+ originalOptions.underlying().toBuilder()
.removeFragmentOptions(TestOptions.class)
- .build();
- });
+ .build());
}
}
@@ -89,13 +86,12 @@ public final class TestTrimmingTransitionFactory implements TransitionFactory<Ru
return NoTransition.INSTANCE;
}
- Set<String> referencedTestOptions =
- new LinkedHashSet<>(ruleClass.getOptionReferenceFunction().apply(rule));
- referencedTestOptions.retainAll(TEST_OPTIONS);
- if (!referencedTestOptions.isEmpty()) {
+ for (String referencedOptions : ruleClass.getOptionReferenceFunction().apply(rule)) {
+ if (TEST_OPTIONS.contains(referencedOptions)) {
// Test-option-referencing config_setting; no need to trim here.
return NoTransition.INSTANCE;
}
+ }
// Non-test rule. Trim it!
return TestTrimmingTransition.INSTANCE;
