Skip to content

Commit

Permalink
Support multiple remote execution digest functions
Browse files Browse the repository at this point in the history
The following PR on the remote-apis side adds support for remote execution services to announce support for multiple digest functions:

bazelbuild/remote-apis#236

This makes migrating from one digest function to the other more graceful. This change extends Bazel's server capabilities checking code to take the new field in the execution capabilities into account.

Closes bazelbuild#16791.

PiperOrigin-RevId: 517084447
Change-Id: I72afce6c1fae9e624f9e7ed1936c744ae9c81280
  • Loading branch information
EdSchouten authored and fweikert committed May 25, 2023
1 parent 5313431 commit 65a33fd
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -201,17 +201,24 @@ public static ClientServerCompatibilityStatus checkClientServerCompatibility(
return result.build(); // No point checking other execution fields.
}

// Check execution digest function.
if (execCap.getDigestFunction() == DigestFunction.Value.UNKNOWN) {
// Server side error -- this is not supposed to happen.
result.addError("Remote server error: UNKNOWN execution digest function.");
}
if (execCap.getDigestFunction() != digestFunction) {
// Check execution digest function. The protocol only later added
// support for multiple digest functions for remote execution, so
// check both the singular and repeated field.
if (execCap.getDigestFunctionsList().isEmpty()
&& execCap.getDigestFunction() != DigestFunction.Value.UNKNOWN) {
if (execCap.getDigestFunction() != digestFunction) {
result.addError(
String.format(
"Cannot use hash function %s with remote execution. "
+ "Server supported function is %s",
digestFunction, execCap.getDigestFunction()));
}
} else if (!execCap.getDigestFunctionsList().contains(digestFunction)) {
result.addError(
String.format(
"Cannot use hash function %s with remote execution. "
+ "Server supported function is %s",
digestFunction, execCap.getDigestFunction()));
+ "Server supported functions are: %s",
digestFunction, execCap.getDigestFunctionsList()));
}

// Check execution priority is in the supported range.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,31 @@ public void testCheckClientServerCompatibility_executionCapsOnly() throws Except
assertThat(st.isOk()).isTrue();
}

@Test
public void testCheckClientServerCompatibility_executionCapsDigestFunctionsList()
throws Exception {
ServerCapabilities caps =
ServerCapabilities.newBuilder()
.setLowApiVersion(ApiVersion.current.toSemVer())
.setHighApiVersion(ApiVersion.current.toSemVer())
.setExecutionCapabilities(
ExecutionCapabilities.newBuilder()
.addDigestFunctions(DigestFunction.Value.MD5)
.addDigestFunctions(DigestFunction.Value.SHA256)
.setExecEnabled(true)
.build())
.build();
RemoteOptions remoteOptions = Options.getDefaults(RemoteOptions.class);
remoteOptions.remoteExecutor = "server:port";
RemoteServerCapabilities.ClientServerCompatibilityStatus st =
RemoteServerCapabilities.checkClientServerCompatibility(
caps,
remoteOptions,
DigestFunction.Value.SHA256,
ServerCapabilitiesRequirement.EXECUTION);
assertThat(st.isOk()).isTrue();
}

@Test
public void testCheckClientServerCompatibility_cacheCapsOnly() throws Exception {
ServerCapabilities caps =
Expand Down

0 comments on commit 65a33fd

Please sign in to comment.