aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/remote/RemoteModule.java
diff options
context:
space:
mode:
authorGravatar ulfjack <ulfjack@google.com>2017-06-13 09:53:06 +0200
committerGravatar Yun Peng <pcloudy@google.com>2017-06-13 12:27:18 +0200
commit019935dfbb61e61d08d1351b0365fb4e2d0df305 (patch)
treeff8240ef04bf03cfb412443918f7afc82e3af36d /src/main/java/com/google/devtools/build/lib/remote/RemoteModule.java
parent540aac6460c6d1671aa1e5cc8b78aa13ba5959ae (diff)
Fix bug in URI computation in RemoteModule
Also add tests for the CAS path converter. I've also changed the code to explicitly inject the RemoteOptions into the CasPathConverter - note that the class is now static, so it no longer has access to the fields in the RemoteModule class. This change will need to be cherry-picked into 0.5.2. PiperOrigin-RevId: 158816408
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/remote/RemoteModule.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/remote/RemoteModule.java21
1 files changed, 14 insertions, 7 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/remote/RemoteModule.java b/src/main/java/com/google/devtools/build/lib/remote/RemoteModule.java
index 9312cb2e55..fedfee1485 100644
--- a/src/main/java/com/google/devtools/build/lib/remote/RemoteModule.java
+++ b/src/main/java/com/google/devtools/build/lib/remote/RemoteModule.java
@@ -14,6 +14,7 @@
package com.google.devtools.build.lib.remote;
+import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableList;
import com.google.common.eventbus.Subscribe;
import com.google.devtools.build.lib.authandtls.AuthAndTLSOptions;
@@ -37,9 +38,15 @@ import java.io.IOException;
/** RemoteModule provides distributed cache and remote execution for Bazel. */
public final class RemoteModule extends BlazeModule {
- private final class CasPathConverter implements PathConverter {
- private CasPathConverter() {
- }
+ @VisibleForTesting
+ static final class CasPathConverter implements PathConverter {
+ // Not final; unfortunately, the Bazel startup process requires us to create this object before
+ // we have the options available, so we have to create it first, and then set the options
+ // afterwards. At the time of this writing, I believe that we aren't using the PathConverter
+ // before the options are available, so this should be safe.
+ // TODO(ulfjack): Change the Bazel startup process to make the options available when we create
+ // the PathConverter.
+ RemoteOptions options;
@Override
public String apply(Path path) {
@@ -57,7 +64,7 @@ public final class RemoteModule extends BlazeModule {
digest.getHash(),
digest.getSizeBytes())
: String.format(
- "//%s/projects/%s/blobs/%s/%d",
+ "//%s/%s/blobs/%s/%d",
server,
remoteInstanceName,
digest.getHash(),
@@ -69,13 +76,13 @@ public final class RemoteModule extends BlazeModule {
}
}
- private RemoteOptions options;
+ private final CasPathConverter converter = new CasPathConverter();
private CommandEnvironment env;
@Override
public void serverInit(OptionsProvider startupOptions, ServerBuilder builder)
throws AbruptExitException {
- builder.addPathToUriConverter(new CasPathConverter());
+ builder.addPathToUriConverter(converter);
}
@Override
@@ -86,7 +93,7 @@ public final class RemoteModule extends BlazeModule {
@Override
public void handleOptions(OptionsProvider optionsProvider) {
- this.options = optionsProvider.getOptions(RemoteOptions.class);
+ converter.options = optionsProvider.getOptions(RemoteOptions.class);
}
@Override