Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't mask error in cquery transitions output formatter #23210

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ public CqueryTransitionResolver(
* @see ResolvedTransition for more details.
* @param configuredTarget the configured target whose dependencies are being looked up.
*/
public ImmutableSet<ResolvedTransition> dependencies(CqueryNode configuredTarget)
throws EvaluateException, InterruptedException {
ImmutableSet<ResolvedTransition> dependencies(CqueryNode configuredTarget)
throws EvaluateException, InterruptedException, IncompatibleTargetException {
if (!(configuredTarget instanceof RuleConfiguredTarget)) {
return ImmutableSet.of();
}
Expand Down Expand Up @@ -161,7 +161,7 @@ public ImmutableSet<ResolvedTransition> dependencies(CqueryNode configuredTarget
eventHandler)) {
throw new EvaluateException("DependencyResolver.evaluate did not complete");
}
} catch (ReportedException | UnreportedException | IncompatibleTargetException e) {
} catch (ReportedException | UnreportedException e) {
throw new EvaluateException(e.getMessage());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
import com.google.devtools.build.lib.analysis.config.BuildOptions;
import com.google.devtools.build.lib.analysis.config.OptionsDiff;
import com.google.devtools.build.lib.analysis.config.StarlarkTransitionCache;
import com.google.devtools.build.lib.analysis.config.transitions.ConfigurationTransition;
import com.google.devtools.build.lib.analysis.config.transitions.TransitionFactory;
import com.google.devtools.build.lib.analysis.constraints.IncompatibleTargetChecker;
import com.google.devtools.build.lib.analysis.producers.BuildConfigurationKeyCache;
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.events.Event;
Expand Down Expand Up @@ -113,8 +115,18 @@ public void processOutput(Iterable<CqueryNode> partialResult) throws Interrupted
buildConfigurationKeyCache)
.dependencies(keyedConfiguredTarget);
} catch (EvaluateException e) {
// This is an abuse of InterruptedException.
throw new InterruptedException(e.getMessage());
eventHandler.handle(
Event.error(
String.format(
"Failed to evaluate %s: %s", keyedConfiguredTarget.getOriginalLabel(), e)));
return;
} catch (IncompatibleTargetChecker.IncompatibleTargetException e) {
eventHandler.handle(
Event.warn(
String.format(
"Skipping dependencies of incompatible target %s",
keyedConfiguredTarget.getOriginalLabel())));
return;
}
for (ResolvedTransition dep : dependencies) {
addResult(
Expand Down
32 changes: 32 additions & 0 deletions src/test/shell/integration/configured_query_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,38 @@ function test_transitions_full() {
assert_contains "host_dep#//$pkg:host#(exec + (TestTrimmingTransition + ConfigFeatureFlagTaggedTrimmingTransition))" output
}

function test_transitions_incompatible_target() {
local -r pkg=$FUNCNAME

mkdir -p $pkg
cat > $pkg/BUILD <<EOF
constraint_setting(name = "incompatible_setting")
constraint_value(
name = "incompatible",
constraint_setting = ":incompatible_setting",
)
genrule(
name = "gr",
srcs = [":input"],
cmd = "touch $@",
outs = ["out"],
target_compatible_with = [":incompatible"],
)
genrule(
name = "input",
cmd = "echo hi > $@",
outs = ["in"],
)
EOF

bazel cquery "deps(//$pkg:gr)" --transitions=lite \
> output 2>"$TEST_log" || fail "Excepted success"

assert_contains "//$pkg:gr" output
assert_not_contains "//$pkg:input" output
expect_log "WARNING: Skipping dependencies of incompatible target //$pkg:gr"
}

function write_test_targets() {
mkdir -p $pkg
cat > $pkg/rule.bzl <<'EOF'
Expand Down
Loading