Skip to content

Commit

Permalink
Unconditionally enable --keep_going
Browse files Browse the repository at this point in the history
  • Loading branch information
fmeum committed Nov 6, 2024
1 parent a2e0597 commit fb6b76c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
import com.google.devtools.build.lib.runtime.BlazeCommandResult;
import com.google.devtools.build.lib.runtime.Command;
import com.google.devtools.build.lib.runtime.CommandEnvironment;
import com.google.devtools.build.lib.runtime.KeepGoingOption;
import com.google.devtools.build.lib.runtime.LoadingPhaseThreadsOption;
import com.google.devtools.build.lib.server.FailureDetails;
import com.google.devtools.build.lib.server.FailureDetails.FailureDetail;
Expand Down Expand Up @@ -103,7 +102,6 @@
options = {
ModOptions.class,
PackageOptions.class,
KeepGoingOption.class,
LoadingPhaseThreadsOption.class
},
help = "resource:mod.txt",
Expand Down Expand Up @@ -193,7 +191,6 @@ private BlazeCommandResult execInternal(CommandEnvironment env, OptionsParsingRe
EvaluationContext.newBuilder()
.setParallelism(threadsOption.threads)
.setEventHandler(env.getReporter())
.setKeepGoing(options.getOptions(KeepGoingOption.class).keepGoing)
.build();

try {
Expand All @@ -208,7 +205,7 @@ private BlazeCommandResult execInternal(CommandEnvironment env, OptionsParsingRe
keys.add(BazelDepGraphValue.KEY, BazelModuleInspectorValue.KEY);
}
EvaluationResult<SkyValue> evaluationResult =
skyframeExecutor.getEvaluator().evaluate(keys.build(), evaluationContext);
skyframeExecutor.prepareAndGet(keys.build(), evaluationContext);

if (evaluationResult.hasError()) {
Exception e = evaluationResult.getError().getException();
Expand Down Expand Up @@ -546,7 +543,10 @@ private BlazeCommandResult execInternal(CommandEnvironment env, OptionsParsingRe
} else {
return reportAndCreateFailureResult(
env,
"Not all extensions have been processed due to errors",
String.format(
"Results may be incomplete as %d extension%s failed.",
moduleInspector.getErrors().size(),
moduleInspector.getErrors().size() == 1 ? "" : "s"),
Code.ERROR_DURING_GRAPH_INSPECTION);
}
}
Expand Down Expand Up @@ -599,7 +599,9 @@ private BlazeCommandResult runTidy(CommandEnvironment env, BazelModTidyValue mod
} else {
return reportAndCreateFailureResult(
env,
"Not all extensions have been processed due to errors",
String.format(
"Failed to process %d extension%s due to errors.",
modTidyValue.errors().size(), modTidyValue.errors().size() == 1 ? "" : "s"),
Code.ERROR_DURING_GRAPH_INSPECTION);
}
}
Expand Down Expand Up @@ -654,9 +656,13 @@ private static ImmutableSortedSet<ModuleExtensionId> extensionArgListToIds(
private static BlazeCommandResult reportAndCreateFailureResult(
CommandEnvironment env, String message, Code detailedCode) {
String fullMessage =
String.format(
"%s%s Type '%s help mod' for syntax and help.",
message, message.endsWith(".") ? "" : ".", env.getRuntime().getProductName());
switch (detailedCode) {
case MISSING_ARGUMENTS, TOO_MANY_ARGUMENTS, INVALID_ARGUMENTS ->
String.format(
"%s%s Type '%s help mod' for syntax and help.",
message, message.endsWith(".") ? "" : ".", env.getRuntime().getProductName());
default -> message;
};
env.getReporter().handle(Event.error(fullMessage));
return createFailureResult(fullMessage, detailedCode);
}
Expand Down
22 changes: 2 additions & 20 deletions src/test/py/bazel/bzlmod/mod_command_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,25 +249,10 @@ def testGraphWithFailingExtensions(self):

exit_code, stdout, stderr = self.RunBazel(
['mod', 'graph', '--extension_info=all'],
rstrip=True, allow_failure=True,
)
self.AssertNotExitCode(exit_code, 0, stderr)
self.assertIn('\t\tfail("ext failed")', stderr)
self.assertIn('Error in fail: ext failed', stderr)
self.assertEmpty(stdout)

def testGraphWithFailingExtensionsKeepGoing(self):
# Force ext2 to fail.
with open(self.Path('MODULE.bazel'), 'a+') as f:
f.write("ext2.dep(name = 'repo2')\n")
f.write("ext2.dep(name = 'fail')\n")

exit_code, stdout, stderr = self.RunBazel(
['mod', 'graph', '--extension_info=all', '--keep_going'],
rstrip=True, allow_failure=True
)
self.AssertNotExitCode(exit_code, 0, stderr)
self.assertIn('Not all extensions have been processed due to errors', '\n'.join(stderr))
self.assertIn('ERROR: Results may be incomplete as 1 extension failed.', stderr)
self.assertIn('\t\tfail("ext failed")', stderr)
self.assertIn('Error in fail: ext failed', stderr)
self.assertListEqual(
Expand Down Expand Up @@ -1061,7 +1046,6 @@ def testModTidyKeepGoing(self):
'mod',
'deps',
'--lockfile_mode=update',
'--keep_going',
], allow_failure=True)
self.AssertNotExitCode(exit_code, 0, stderr)
stderr = '\n'.join(stderr)
Expand All @@ -1084,12 +1068,11 @@ def testModTidyKeepGoing(self):
'mod',
'tidy',
'--lockfile_mode=update',
'--keep_going',
], allow_failure=True)
self.AssertNotExitCode(exit_code, 0, stderr)
self.assertEqual([], stdout)
self.assertIn('ERROR: Failed to process 1 extension due to errors.', stderr)
stderr = '\n'.join(stderr)
self.assertIn('Not all extensions have been processed due to errors', stderr)
# The passing extension should not be reevaluated by the command.
self.assertNotIn('ext1 is being evaluated', stderr)
self.assertIn('ext2 is being evaluated', stderr)
Expand Down Expand Up @@ -1118,7 +1101,6 @@ def testModTidyKeepGoing(self):
'mod',
'deps',
'--lockfile_mode=error',
'--keep_going',
], allow_failure=True)
self.AssertNotExitCode(exit_code, 0, stderr)
# The exit code if the build fails due to a lockfile that is not up-to-date.
Expand Down

0 comments on commit fb6b76c

Please sign in to comment.