Skip to content

Commit

Permalink
Add cc_common.action_is_enabled
Browse files Browse the repository at this point in the history
This will help users who want to use CROSSTOOL with other than C++ rules, plus
it will enable users to make rules forward compatible for incompatible CROSSTOOL
changes.

Progress towards
#5883

RELNOTES: None.
PiperOrigin-RevId: 228216650
  • Loading branch information
hlopko authored and Copybara-Service committed Jan 7, 2019
1 parent 0d493ba commit 3af93c9
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ public boolean isEnabled(FeatureConfiguration featureConfiguration, String featu
return featureConfiguration.isEnabled(featureName);
}

@Override
public boolean actionIsEnabled(FeatureConfiguration featureConfiguration, String actionName) {
return featureConfiguration.actionIsConfigured(actionName);
}

@Override
public SkylarkList<String> getCommandLine(
FeatureConfiguration featureConfiguration,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,24 @@ FeatureConfigurationT configureFeatures(
})
boolean isEnabled(FeatureConfigurationT featureConfiguration, String featureName);

@SkylarkCallable(
name = "action_is_enabled",
doc = "Returns True if given action_config is enabled in the feature configuration.",
parameters = {
@Param(
name = "feature_configuration",
doc = "Feature configuration to be queried.",
positional = false,
named = true,
type = FeatureConfigurationApi.class),
@Param(
name = "action_name",
doc = "Name of the action_config.",
named = true,
positional = false),
})
boolean actionIsEnabled(FeatureConfigurationT featureConfiguration, String actionName);

@SkylarkCallable(
name = "get_memory_inefficient_command_line",
doc =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ public boolean isEnabled(FeatureConfigurationApi featureConfiguration, String fe
return false;
}

@Override
public boolean actionIsEnabled(FeatureConfigurationApi featureConfiguration, String actionName) {
return false;
}

@Override
public SkylarkList<String> getCommandLine(FeatureConfigurationApi featureConfiguration,
String actionName, CcToolchainVariablesApi variables) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,43 @@ public void testGetEnvironment() throws Exception {
CppActionNames.CPP_COMPILE, CcToolchainVariables.EMPTY));
}

@Test
public void testActionIsEnabled() throws Exception {
scratch.file(
"a/BUILD",
"load(':rule.bzl', 'crule')",
"cc_toolchain_alias(name='alias')",
"crule(name='r')");

scratch.file(
"a/rule.bzl",
"def _impl(ctx):",
" toolchain = ctx.attr._cc_toolchain[cc_common.CcToolchainInfo]",
" feature_configuration = cc_common.configure_features(cc_toolchain = toolchain)",
" return struct(",
" enabled_action = cc_common.action_is_enabled(",
" feature_configuration = feature_configuration,",
" action_name = 'c-compile'),",
" disabled_action = cc_common.action_is_enabled(",
" feature_configuration = feature_configuration,",
" action_name = 'wololoo'))",
"crule = rule(",
" _impl,",
" attrs = { ",
" '_cc_toolchain': attr.label(default=Label('//a:alias'))",
" },",
" fragments = ['cpp'],",
");");

ConfiguredTarget r = getConfiguredTarget("//a:r");
@SuppressWarnings("unchecked")
boolean enabledActionIsEnabled = (boolean) r.get("enabled_action");
@SuppressWarnings("unchecked")
boolean disabledActionIsDisabled = (boolean) r.get("disabled_action");
assertThat(enabledActionIsEnabled).isTrue();
assertThat(disabledActionIsDisabled).isFalse();
}

@Test
public void testIsEnabled() throws Exception {
scratch.file(
Expand Down

0 comments on commit 3af93c9

Please sign in to comment.