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
    bazelbuild/bazel#5883

    RELNOTES: None.
    PiperOrigin-RevId: 228216650
  • Loading branch information
Luca Di Grazia committed Sep 4, 2022
1 parent e5a7286 commit 49ea692
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,7 @@

/** A module that contains Skylark utilities for C++ support. */
public class CcModule
implements CcModuleApi<
CcToolchainProvider,
FeatureConfiguration,
CcCompilationContext,
CcLinkingContext,
LibraryToLinkWrapper,
CcToolchainVariables> {
implements CcModuleApi<CcToolchainProvider, FeatureConfiguration, CcToolchainVariables> {

private enum RegisterActions {
ALWAYS,
Expand Down Expand Up @@ -332,7 +326,7 @@ protected Iterable<String> userFlagsToIterable(CppConfiguration cppConfiguration
* @throws InterruptedException
*/
@Override
public LibraryToLinkWrapper createLibraryLinkerInput(
public Object createLibraryLinkerInput(
Object actionsObject,
Object featureConfigurationObject,
Object ccToolchainProviderObject,
Expand Down Expand Up @@ -478,7 +472,7 @@ private static SkylarkNestedSet toNestedSetOfStrings(Object obj, String fieldNam
}

@Override
public CcLinkingContext createCcLinkingInfo(
public Object createCcLinkingInfo(
Object librariesToLinkObject,
Object userLinkFlagsObject,
Location location,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@
public interface CcModuleApi<
CcToolchainProviderT extends CcToolchainProviderApi,
FeatureConfigurationT extends FeatureConfigurationApi,
CompilationContextT extends CcCompilationContextApi,
LinkingContextT extends CcLinkingContextApi,
LibraryToLinkWrapperT extends LibraryToLinkWrapperApi,
CcToolchainVariablesT extends CcToolchainVariablesApi> {

@SkylarkCallable(
Expand Down Expand Up @@ -546,7 +543,7 @@ CcToolchainVariablesT getLinkBuildVariables(
named = true,
defaultValue = "False"),
})
LibraryToLinkWrapperT createLibraryLinkerInput(
Object createLibraryLinkerInput(
Object actions,
Object featureConfiguration,
Object ccToolchainProvider,
Expand Down Expand Up @@ -582,7 +579,7 @@ LibraryToLinkWrapperT createLibraryLinkerInput(
defaultValue = "None",
type = SkylarkList.class)
})
LinkingContextT createCcLinkingInfo(
Object createCcLinkingInfo(
Object librariesToLinkObject,
Object userLinkFlagsObject,
Location location,
Expand Down Expand Up @@ -651,7 +648,7 @@ LinkingContextT createCcLinkingInfo(
defaultValue = "unbound",
type = Object.class)
})
CompilationContextT createCcCompilationContext(
CcCompilationContextApi createCcCompilationContext(
Object headers, Object systemIncludes, Object includes, Object quoteIncludes, Object defines)
throws EvalException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,12 @@
import com.google.devtools.build.lib.skylarkbuildapi.cpp.CcCompilationContextApi;
import com.google.devtools.build.lib.skylarkbuildapi.cpp.CcCompilationOutputsApi;
import com.google.devtools.build.lib.skylarkbuildapi.cpp.CcInfoApi;
import com.google.devtools.build.lib.skylarkbuildapi.cpp.CcLinkingContextApi;
import com.google.devtools.build.lib.skylarkbuildapi.cpp.CcLinkingInfoApi;
import com.google.devtools.build.lib.skylarkbuildapi.cpp.CcModuleApi;
import com.google.devtools.build.lib.skylarkbuildapi.cpp.CcToolchainProviderApi;
import com.google.devtools.build.lib.skylarkbuildapi.cpp.CcToolchainVariablesApi;
import com.google.devtools.build.lib.skylarkbuildapi.cpp.CompilationInfoApi;
import com.google.devtools.build.lib.skylarkbuildapi.cpp.FeatureConfigurationApi;
import com.google.devtools.build.lib.skylarkbuildapi.cpp.LibraryToLinkWrapperApi;
import com.google.devtools.build.lib.skylarkbuildapi.cpp.LinkingInfoApi;
import com.google.devtools.build.lib.syntax.Environment;
import com.google.devtools.build.lib.syntax.EvalException;
Expand All @@ -47,8 +45,6 @@ public class FakeCcModule
CcCompilationOutputsApi,
LinkingInfoApi,
CcLinkingInfoApi,
CcLinkingContextApi,
LibraryToLinkWrapperApi,
CcToolchainVariablesApi> {

@Override
Expand Down Expand Up @@ -116,7 +112,7 @@ public CcToolchainVariablesApi getVariables() {
}

@Override
public LibraryToLinkWrapperApi createLibraryLinkerInput(
public Object createLibraryLinkerInput(
Object actions,
Object featureConfiguration,
Object ccToolchainProvider,
Expand All @@ -131,7 +127,7 @@ public LibraryToLinkWrapperApi createLibraryLinkerInput(
}

@Override
public CcLinkingContextApi createCcLinkingInfo(
public Object createCcLinkingInfo(
Object librariesToLinkObject,
Object userLinkFlagsObject,
Location location,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4379,9 +4379,7 @@ public void testCcToolchainInfoToProto() throws Exception {
" not_features=['b', 'c']),",
" with_feature_set(features=['b'])],",
" execution_requirements = ['a', 'b', 'c'])],",
" implies = ['compiler_input_flags', 'compiler_output_flags'],",
" flag_sets = [flag_set(flag_groups = [flag_group(flags = ['a'])]",
" )])],",
" implies = ['compiler_input_flags', 'compiler_output_flags'])],",
" artifact_name_patterns = [artifact_name_pattern(",
" category_name = 'static_library',",
" prefix = 'prefix',",
Expand Down Expand Up @@ -4493,20 +4491,7 @@ public void testCcToolchainInfoToProto() throws Exception {
assertThat(tool.getExecutionRequirementList()).containsExactly("a", "b", "c");
assertThat(tool.getWithFeature(0).getFeatureList()).containsExactly("a");
assertThat(tool.getWithFeature(0).getNotFeatureList()).containsExactly("b", "c");
// When we create an ActionConfig from a proto we put the action name as the only element of its
// FlagSet.action lists. So when we convert back to proto, we need to remove it.
assertThat(
ccToolchainConfigInfo.getActionConfigs().stream()
.filter(config -> config.getName().equals("action_two"))
.findFirst()
.get()
.getFlagSets()
.get(0)
.getActions())
.containsExactly("action_two");
CToolchain.FlagSet actionConfigFlagSet =
Iterables.getOnlyElement(actionConfig.getFlagSetList());
assertThat(actionConfigFlagSet.getActionCount()).isEqualTo(0);

assertThat(Iterables.getOnlyElement(toolchain.getArtifactNamePatternList()))
.isEqualTo(
CToolchain.ArtifactNamePattern.newBuilder()
Expand Down

0 comments on commit 49ea692

Please sign in to comment.