Skip to content

Commit

Permalink
Attempt 1 at fixing bazelbuild#12553
Browse files Browse the repository at this point in the history
  • Loading branch information
philsc committed Nov 25, 2020
1 parent d0efd7b commit 46a2cd5
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import com.google.devtools.build.lib.analysis.config.transitions.ConfigurationTransition;
import com.google.devtools.build.lib.analysis.config.transitions.NoTransition;
import com.google.devtools.build.lib.analysis.constraints.ConstraintSemantics;
import com.google.devtools.build.lib.analysis.constraints.RuleContextConstraintSemantics;
import com.google.devtools.build.lib.analysis.platform.ConstraintValueInfo;
import com.google.devtools.build.lib.analysis.platform.PlatformInfo;
import com.google.devtools.build.lib.analysis.stringtemplate.TemplateContext;
Expand Down Expand Up @@ -2292,6 +2293,13 @@ private boolean checkRuleDependencyMandatoryProviders(
return true;
}

if (RuleContextConstraintSemantics.prerequisiteIsIncompatible(prerequisite.getConfiguredTarget())) {
// If the prerequisite doesn't satisfy the required providers and it is incompatible (i.e.
// has an incompatible provider set), we pretend that the required providers are satisfied.
return true;
}

new Error().printStackTrace();
unfulfilledRequirements.add(
String.format(
"'%s' does not have mandatory providers: %s",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,15 @@ private static void addSelectValuesToSet(BuildType.Selector<?> select, final Set
}
}

public static boolean prerequisiteIsIncompatible(ConfiguredTarget prerequisite) {
if (prerequisite instanceof OutputFileConfiguredTarget) {
// For generated files, we want to query the generating rule for providers. genrule() for
// example doesn't attach providers like IncompatiblePlatformProvider to its outputs.
prerequisite = ((OutputFileConfiguredTarget) prerequisite).getGeneratingRule();
}
return prerequisite.getProvider(IncompatiblePlatformProvider.class) != null;
}

/**
* Creates an incompatible {@link ConfiguredTarget} if the corresponding rule is incompatible.
*
Expand Down Expand Up @@ -873,22 +882,18 @@ public static ConfiguredTarget incompatibleConfiguredTarget(
}

// This is incompatible if one of the dependencies is as well.
ImmutableList.Builder<ConfiguredTarget> incompatibleDependenciesBuilder =
ImmutableList.builder();
for (ConfiguredTargetAndData infoCollection : prerequisiteMap.values()) {
ConfiguredTarget dependency = infoCollection.getConfiguredTarget();
if (dependency instanceof OutputFileConfiguredTarget) {
// For generated files, we want to query the generating rule for providers. genrule() for
// example doesn't attach providers like IncompatiblePlatformProvider to its outputs.
dependency = ((OutputFileConfiguredTarget) dependency).getGeneratingRule();
}
if (dependency.getProvider(IncompatiblePlatformProvider.class) != null) {
incompatibleDependenciesBuilder.add(dependency);
}
}

ImmutableList<ConfiguredTarget> incompatibleDependencies =
incompatibleDependenciesBuilder.build();
stream(prerequisiteMap.values()).map(value -> value.getConfiguredTarget()).filter(dep -> prerequisiteIsIncompatible(dep)).collect(toImmutableList());
//ImmutableList.Builder<ConfiguredTarget> incompatibleDependenciesBuilder =
// ImmutableList.builder();
//for (ConfiguredTargetAndData infoCollection : prerequisiteMap.values()) {
// if (prerequisiteIsIncompatible(infoCollection.getConfiguredTarget())) {
// incompatibleDependenciesBuilder.add(dependency);
// }
//}

//ImmutableList<ConfiguredTarget> incompatibleDependencies =
// incompatibleDependenciesBuilder.build();
if (!incompatibleDependencies.isEmpty()) {
return createIncompatibleConfiguredTarget(ruleContext, incompatibleDependencies, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ private static String reportOnIncompatibility(ConfiguredTarget target) {
while (target != null) {
message += "\n " + target.getLabel();
provider = target.getProvider(IncompatiblePlatformProvider.class);
if (provider == null) {
System.out.println(message);
}
ImmutableList<ConfiguredTarget> targetList = provider.targetsResponsibleForIncompatibility();
if (targetList == null) {
target = null;
Expand Down
43 changes: 43 additions & 0 deletions src/test/shell/integration/target_compatible_with_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,49 @@ EOF
expect_log 'FAILED: Build did NOT complete successfully'
}
function test_aaaaa() {
cat > target_skipping/rules.bzl <<EOF
DummyProvider = provider()
def _dummy_rule_impl(ctx):
return [DummyProvider()]
dummy_rule = rule(
implementation = _dummy_rule_impl,
attrs = {
"deps": attr.label_list(providers=[DummyProvider]),
},
)
EOF
cat >> target_skipping/BUILD <<EOF
load("//target_skipping:rules.bzl", "dummy_rule")
dummy_rule(
name = "dummy1",
target_compatible_with = [
"//target_skipping:foo1",
],
)
dummy_rule(
name = "dummy2",
deps = [
":dummy1",
],
)
EOF
cd target_skipping || fail "couldn't cd into workspace"
pwd >&2
bazel build \
--show_result=10 \
--host_platform=@//target_skipping:foo3_platform \
--platforms=@//target_skipping:foo3_platform \
//target_skipping/... &> "${TEST_log}" || fail "Bazel failed unexpectedly."
}
# Validates the same thing as test_non_top_level_skipping, but with a cc_test
# and adding one more level of dependencies.
function test_cc_test() {
Expand Down

0 comments on commit 46a2cd5

Please sign in to comment.