Skip to content

Commit

Permalink
C++: Fixes bug in C++ API with external repo aspects
Browse files Browse the repository at this point in the history
    Reported in: bazelbuild/bazel#8254

    Added test testApiWithAspectsOnTargetsInExternalRepos()

    RELNOTES:none
    PiperOrigin-RevId: 247412486
  • Loading branch information
Luca Di Grazia committed Sep 4, 2022
1 parent 44dcdc5 commit 1de3bab
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,6 @@ public String getToolForAction(
return featureConfiguration.getFeatureConfiguration().getToolPathForAction(actionName);
}

@Override
public SkylarkList<String> getExecutionRequirements(
FeatureConfigurationForStarlark featureConfiguration, String actionName) {
return SkylarkList.createImmutable(
featureConfiguration.getFeatureConfiguration().getToolRequirementsForAction(actionName));
}

@Override
public boolean isEnabled(
FeatureConfigurationForStarlark featureConfiguration, String featureName) {
Expand Down Expand Up @@ -653,7 +646,6 @@ public CcToolchainConfigInfo ccToolchainConfigInfoFromSkylark(

ImmutableList.Builder<Feature> featureBuilder = ImmutableList.builder();
for (Object feature : features) {
checkRightSkylarkInfoProvider(feature, "features", "FeatureInfo");
featureBuilder.add(featureFromSkylark((SkylarkInfo) feature));
}
ImmutableList<Feature> featureList = featureBuilder.build();
Expand All @@ -669,7 +661,6 @@ public CcToolchainConfigInfo ccToolchainConfigInfoFromSkylark(

ImmutableList.Builder<ActionConfig> actionConfigBuilder = ImmutableList.builder();
for (Object actionConfig : actionConfigs) {
checkRightSkylarkInfoProvider(actionConfig, "action_configs", "ActionConfigInfo");
actionConfigBuilder.add(actionConfigFromSkylark((SkylarkInfo) actionConfig));
}
ImmutableList<ActionConfig> actionConfigList = actionConfigBuilder.build();
Expand All @@ -680,8 +671,6 @@ public CcToolchainConfigInfo ccToolchainConfigInfoFromSkylark(

ImmutableList.Builder<ArtifactNamePattern> artifactNamePatternBuilder = ImmutableList.builder();
for (Object artifactNamePattern : artifactNamePatterns) {
checkRightSkylarkInfoProvider(
artifactNamePattern, "artifact_name_patterns", "ArtifactNamePatternInfo");
artifactNamePatternBuilder.add(
artifactNamePatternFromSkylark((SkylarkInfo) artifactNamePattern));
}
Expand All @@ -701,7 +690,6 @@ public CcToolchainConfigInfo ccToolchainConfigInfoFromSkylark(
// Pairs (toolName, toolPath)
ImmutableList.Builder<Pair<String, String>> toolPathPairs = ImmutableList.builder();
for (Object toolPath : toolPaths) {
checkRightSkylarkInfoProvider(toolPath, "tool_paths", "ToolPathInfo");
Pair<String, String> toolPathPair = toolPathFromSkylark((SkylarkInfo) toolPath);
toolPathPairs.add(toolPathPair);
cToolchain.addToolPath(
Expand Down Expand Up @@ -808,7 +796,6 @@ public CcToolchainConfigInfo ccToolchainConfigInfoFromSkylark(

ImmutableList.Builder<Pair<String, String>> makeVariablePairs = ImmutableList.builder();
for (Object makeVariable : makeVariables) {
checkRightSkylarkInfoProvider(makeVariable, "make_variables", "MakeVariableInfo");
Pair<String, String> makeVariablePair = makeVariableFromSkylark((SkylarkInfo) makeVariable);
makeVariablePairs.add(makeVariablePair);
cToolchain.addMakeVariable(
Expand Down Expand Up @@ -856,20 +843,6 @@ public CcToolchainConfigInfo ccToolchainConfigInfoFromSkylark(
cToolchain.build().toString());
}

private static void checkRightSkylarkInfoProvider(
Object o, String parameterName, String expectedProvider) throws EvalException {
if (!(o instanceof SkylarkInfo)) {
throw new EvalException(
Location.BUILTIN,
String.format(
"'%s' parameter of cc_common.create_cc_toolchain_config_info() contains an element"
+ " of type '%s' instead of a '%s' provider. Use the methods provided in"
+ " https://source.bazel.build/bazel/+/master:tools/cpp/cc_toolchain_config_lib.bzl"
+ " for obtaining the right providers.",
parameterName, EvalUtils.getDataTypeName(o), expectedProvider));
}
}

/** Checks whether the {@link SkylarkInfo} is of the required type. */
private static void checkRightProviderType(SkylarkInfo provider, String type)
throws EvalException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,7 @@ public void testGetToolForAction() throws Exception {
"load('//myinfo:myinfo.bzl', 'MyInfo')",
"def _impl(ctx):",
" toolchain = ctx.attr._cc_toolchain[cc_common.CcToolchainInfo]",
" feature_configuration = cc_common.configure_features(",
" ctx = ctx,",
" cc_toolchain = toolchain,",
" )",
" feature_configuration = cc_common.configure_features(cc_toolchain = toolchain)",
" return [MyInfo(",
" action_tool_path = cc_common.get_tool_for_action(",
" feature_configuration = feature_configuration,",
Expand Down Expand Up @@ -251,7 +248,6 @@ public void testFeatureConfigurationWithAdditionalEnabledFeature() throws Except
"def _impl(ctx):",
" toolchain = ctx.attr._cc_toolchain[cc_common.CcToolchainInfo]",
" feature_configuration = cc_common.configure_features(",
" ctx = ctx,",
" cc_toolchain = toolchain,",
" requested_features = ['foo_feature'])",
" return [MyInfo(",
Expand Down Expand Up @@ -291,7 +287,6 @@ public void testFeatureConfigurationWithAdditionalUnsupportedFeature() throws Ex
"def _impl(ctx):",
" toolchain = ctx.attr._cc_toolchain[cc_common.CcToolchainInfo]",
" feature_configuration = cc_common.configure_features(",
" ctx = ctx,",
" cc_toolchain = toolchain,",
" unsupported_features = ['foo_feature'])",
" return [MyInfo(",
Expand Down Expand Up @@ -325,10 +320,7 @@ public void testGetCommandLine() throws Exception {
"load('//myinfo:myinfo.bzl', 'MyInfo')",
"def _impl(ctx):",
" toolchain = ctx.attr._cc_toolchain[cc_common.CcToolchainInfo]",
" feature_configuration = cc_common.configure_features(",
" ctx = ctx,",
" cc_toolchain = toolchain,",
" )",
" feature_configuration = cc_common.configure_features(cc_toolchain = toolchain)",
" return [MyInfo(",
" command_line = cc_common.get_memory_inefficient_command_line(",
" feature_configuration = feature_configuration,",
Expand Down Expand Up @@ -374,10 +366,7 @@ public void testGetEnvironment() throws Exception {
"load('//myinfo:myinfo.bzl', 'MyInfo')",
"def _impl(ctx):",
" toolchain = ctx.attr._cc_toolchain[cc_common.CcToolchainInfo]",
" feature_configuration = cc_common.configure_features(",
" ctx = ctx,",
" cc_toolchain = toolchain,",
" )",
" feature_configuration = cc_common.configure_features(cc_toolchain = toolchain)",
" return [MyInfo(",
" environment_variables = cc_common.get_environment_variables(",
" feature_configuration = feature_configuration,",
Expand Down Expand Up @@ -424,10 +413,7 @@ public void testActionIsEnabled() throws Exception {
"load('//myinfo:myinfo.bzl', 'MyInfo')",
"def _impl(ctx):",
" toolchain = ctx.attr._cc_toolchain[cc_common.CcToolchainInfo]",
" feature_configuration = cc_common.configure_features(",
" ctx = ctx,",
" cc_toolchain = toolchain,",
" )",
" feature_configuration = cc_common.configure_features(cc_toolchain = toolchain)",
" return [MyInfo(",
" enabled_action = cc_common.action_is_enabled(",
" feature_configuration = feature_configuration,",
Expand Down Expand Up @@ -465,10 +451,7 @@ public void testIsEnabled() throws Exception {
"load('//myinfo:myinfo.bzl', 'MyInfo')",
"def _impl(ctx):",
" toolchain = ctx.attr._cc_toolchain[cc_common.CcToolchainInfo]",
" feature_configuration = cc_common.configure_features(",
" ctx = ctx,",
" cc_toolchain = toolchain,",
" )",
" feature_configuration = cc_common.configure_features(cc_toolchain = toolchain)",
" return [MyInfo(",
" enabled_feature = cc_common.is_enabled(",
" feature_configuration = feature_configuration,",
Expand Down Expand Up @@ -556,10 +539,7 @@ public void testActionNames() throws Exception {
" 'STRIP_ACTION_NAME')",
"def _impl(ctx):",
" toolchain = ctx.attr._cc_toolchain[cc_common.CcToolchainInfo]",
" feature_configuration = cc_common.configure_features(",
" ctx = ctx,",
" cc_toolchain = toolchain,",
" )",
" feature_configuration = cc_common.configure_features(cc_toolchain = toolchain)",
" return [MyInfo(",
" c_compile_action_name=C_COMPILE_ACTION_NAME,",
" cpp_compile_action_name=CPP_COMPILE_ACTION_NAME,",
Expand Down Expand Up @@ -957,10 +937,7 @@ private SkylarkList<String> commandLineForVariables(
"load('//myinfo:myinfo.bzl', 'MyInfo')",
"def _impl(ctx):",
" toolchain = ctx.attr._cc_toolchain[cc_common.CcToolchainInfo]",
" feature_configuration = cc_common.configure_features(",
" ctx = ctx,",
" cc_toolchain = toolchain,",
" )",
" feature_configuration = cc_common.configure_features(cc_toolchain = toolchain)",
" variables = " + Joiner.on("\n").join(variables),
" return [MyInfo(",
" command_line = cc_common.get_memory_inefficient_command_line(",
Expand Down Expand Up @@ -1340,10 +1317,7 @@ private void setUpCcLinkingContextTest() throws Exception {
" alwayslink=alwayslink)",
"def _impl(ctx):",
" toolchain = ctx.attr._cc_toolchain[cc_common.CcToolchainInfo]",
" feature_configuration = cc_common.configure_features(",
" ctx = ctx,",
" cc_toolchain = toolchain,",
" )",
" feature_configuration = cc_common.configure_features(cc_toolchain = toolchain)",
" library_to_link = _create(ctx, feature_configuration, ctx.file.static_library, ",
" ctx.file.pic_static_library, ctx.file.dynamic_library, ctx.file.interface_library,",
" ctx.attr.alwayslink)",
Expand Down Expand Up @@ -5303,7 +5277,6 @@ private static void createFiles(
"def _cc_aspect_impl(target, ctx):",
" toolchain = ctx.attr._cc_toolchain[cc_common.CcToolchainInfo]",
" feature_configuration = cc_common.configure_features(",
" ctx = ctx,",
" cc_toolchain = toolchain,",
" requested_features = ctx.features,",
" unsupported_features = ctx.disabled_features,",
Expand Down Expand Up @@ -5342,7 +5315,6 @@ private static void createFiles(
" dep_linking_contexts.append(dep[CcInfo].linking_context)",
" toolchain = ctx.attr._cc_toolchain[cc_common.CcToolchainInfo]",
" feature_configuration = cc_common.configure_features(",
" ctx = ctx,",
" cc_toolchain=toolchain,",
" requested_features = ctx.features,",
" unsupported_features = ctx.disabled_features)",
Expand Down Expand Up @@ -5539,10 +5511,7 @@ private static void setupTestTransitiveLink(Scratch scratch, String... additiona
"load('//myinfo:myinfo.bzl', 'MyInfo')",
"def _cc_bin_impl(ctx):",
" toolchain = ctx.attr._cc_toolchain[cc_common.CcToolchainInfo]",
" feature_configuration = cc_common.configure_features(",
" ctx = ctx,",
" cc_toolchain = toolchain,",
" )",
" feature_configuration = cc_common.configure_features(cc_toolchain = toolchain)",
" dep_linking_contexts = []",
" for dep in ctx.attr.deps:",
" dep_linking_contexts.append(dep[CcInfo].linking_context)",
Expand Down

0 comments on commit 1de3bab

Please sign in to comment.