Skip to content

Commit

Permalink
Don't mask error in cquery transitions output formatter
Browse files Browse the repository at this point in the history
All errors used to be wrapped in an `InterruptedException` instead of being reported with a message. Also show a warning when an incompatible target is skipped instead of failing the build.

Work towards #21010

Closes #23210.

PiperOrigin-RevId: 660116656
Change-Id: I22651110984e471a6b31dcc59a387f3f85ad49bc
  • Loading branch information
fmeum authored and copybara-github committed Aug 6, 2024
1 parent 7e689a5 commit 300c586
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 5 deletions.
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

0 comments on commit 300c586

Please sign in to comment.