Skip to content

Commit

Permalink
Merge two experimental_local_disk_cache options to one
Browse files Browse the repository at this point in the history
Fixes: bazelbuild#4870.

Test Plan:

  $ bazel test src/test/shell/bazel:local_action_cache_test
  • Loading branch information
davido committed Mar 22, 2018
1 parent e2df6e2 commit 9bdb69a
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public Iterable<? extends ActionContext> getActionContexts() {
String buildRequestId = env.getBuildRequestId().toString();
String commandId = env.getCommandId().toString();

if (remoteOptions.experimentalRemoteSpawnCache || remoteOptions.experimentalLocalDiskCache) {
if (remoteOptions.experimentalRemoteSpawnCache || remoteOptions.buildCache != null) {
RemoteSpawnCache spawnCache =
new RemoteSpawnCache(
env.getExecRoot(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,27 +190,18 @@ public final class RemoteOptions extends OptionsBase {
)
public boolean experimentalRemoteSpawnCache;

// TODO(davido): Find a better place for this and the next option.
// TODO(davido): Find a better place for this option.
@Option(
name = "experimental_local_disk_cache",
defaultValue = "false",
category = "remote",
documentationCategory = OptionDocumentationCategory.UNCATEGORIZED,
effectTags = {OptionEffectTag.UNKNOWN},
help = "Whether to use the experimental local disk cache."
)
public boolean experimentalLocalDiskCache;

@Option(
name = "experimental_local_disk_cache_path",
name = "build_cache",
defaultValue = "null",
category = "remote",
documentationCategory = OptionDocumentationCategory.UNCATEGORIZED,
effectTags = {OptionEffectTag.UNKNOWN},
converter = OptionsUtils.PathFragmentConverter.class,
help = "A file path to a local disk cache."
help = "A path to a directory where Bazel can read and write actions and action outputs. "
+ "If the directory does not exist, it will be created."
)
public PathFragment experimentalLocalDiskCachePath;
public PathFragment buildCache;

@Option(
name = "experimental_guard_against_concurrent_changes",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ public static SimpleBlobStore createRest(RemoteOptions options, Credentials cred
}
}

public static SimpleBlobStore createLocalDisk(RemoteOptions options, Path workingDirectory)
public static SimpleBlobStore createBuildCache(RemoteOptions options, Path workingDirectory)
throws IOException {
return new OnDiskBlobStore(
workingDirectory.getRelative(checkNotNull(options.experimentalLocalDiskCachePath)));
workingDirectory.getRelative(checkNotNull(options.buildCache)));
}

public static SimpleBlobStore create(
Expand All @@ -58,20 +58,20 @@ public static SimpleBlobStore create(
if (isRestUrlOptions(options)) {
return createRest(options, creds);
}
if (workingDirectory != null && isLocalDiskCache(options)) {
return createLocalDisk(options, workingDirectory);
if (workingDirectory != null && isBuildCache(options)) {
return createBuildCache(options, workingDirectory);
}
throw new IllegalArgumentException(
"Unrecognized concurrent map RemoteOptions: must specify "
+ "either Rest URL, or local cache options.");
}

public static boolean isRemoteCacheOptions(RemoteOptions options) {
return isRestUrlOptions(options) || isLocalDiskCache(options);
return isRestUrlOptions(options) || isBuildCache(options);
}

public static boolean isLocalDiskCache(RemoteOptions options) {
return options.experimentalLocalDiskCache;
public static boolean isBuildCache(RemoteOptions options) {
return options.buildCache != null;
}

private static boolean isRestUrlOptions(RemoteOptions options) {
Expand Down
4 changes: 2 additions & 2 deletions src/test/shell/bazel/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,9 @@ sh_test(
)

sh_test(
name = "local_action_cache_test",
name = "build_cache_test",
size = "small",
srcs = ["local_action_cache_test.sh"],
srcs = ["build_cache_test.sh"],
data = [":test-deps"],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function test_local_action_cache() {
local execution_file="${TEST_TMPDIR}/run.log"
local input_file="foo.in"
local output_file="bazel-genfiles/foo.txt"
local flags="--experimental_local_disk_cache_path=$cache --experimental_local_disk_cache"
local flags="--build_cache=$cache"

rm -rf $cache
mkdir $cache
Expand Down

0 comments on commit 9bdb69a

Please sign in to comment.