aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Klaus Aehlig <aehlig@google.com>2018-02-27 07:22:07 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2018-02-27 07:23:36 -0800
commit6e0933886d3c6b7f68075da4bdb08500ce2b6f86 (patch)
tree9f154446d7b4ea3335b50ec5963a7639d7fa98c4
parentdb80298391bd953b1a1f8e9bb83c2d4c2f3747b4 (diff)
Make repository_chache non-experimental and enable by default
Make the --experimental_repository_cache option no longer experimental and enable the cache by default. The default location is in the a separate directory under the install base (under .cache/bazel user's home directory); this means it is shared between workspaces und not between different versions of bazel. We plan to also share it between different bazel versions in the future. Fixes #4676. RELNOTES: repository_cache is no longer experimental and enabled by default. Change-Id: I8499c2d1811e0fe8d830796e07cd6f8bc75e48ba PiperOrigin-RevId: 187172766
-rw-r--r--src/main/java/com/google/devtools/build/lib/bazel/BazelRepositoryModule.java24
-rw-r--r--src/main/java/com/google/devtools/build/lib/bazel/repository/RepositoryOptions.java3
-rwxr-xr-xsrc/test/shell/bazel/external_integration_test.sh73
3 files changed, 94 insertions, 6 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/BazelRepositoryModule.java b/src/main/java/com/google/devtools/build/lib/bazel/BazelRepositoryModule.java
index 4d2c0328bd..8a18f3c59f 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/BazelRepositoryModule.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/BazelRepositoryModule.java
@@ -51,6 +51,7 @@ import com.google.devtools.build.lib.bazel.rules.workspace.MavenServerRule;
import com.google.devtools.build.lib.bazel.rules.workspace.NewGitRepositoryRule;
import com.google.devtools.build.lib.bazel.rules.workspace.NewHttpArchiveRule;
import com.google.devtools.build.lib.cmdline.RepositoryName;
+import com.google.devtools.build.lib.events.Event;
import com.google.devtools.build.lib.pkgcache.PackageCacheOptions;
import com.google.devtools.build.lib.rules.repository.LocalRepositoryFunction;
import com.google.devtools.build.lib.rules.repository.LocalRepositoryRule;
@@ -73,12 +74,14 @@ import com.google.devtools.build.lib.skyframe.SkyFunctions;
import com.google.devtools.build.lib.skyframe.SkyValueDirtinessChecker;
import com.google.devtools.build.lib.util.io.TimestampGranularityMonitor;
import com.google.devtools.build.lib.vfs.FileSystem;
+import com.google.devtools.build.lib.vfs.FileSystemUtils;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.PathFragment;
import com.google.devtools.build.skyframe.SkyKey;
import com.google.devtools.build.skyframe.SkyValue;
import com.google.devtools.common.options.OptionsBase;
import com.google.devtools.common.options.OptionsProvider;
+import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;
import java.util.Map.Entry;
@@ -91,6 +94,9 @@ import javax.annotation.Nullable;
*/
public class BazelRepositoryModule extends BlazeModule {
+ // Default location (relative to output user root) of the repository cache.
+ public static final String DEFAULT_CACHE_LOCATION = "cache/repos/v1";
+
// A map of repository handlers that can be looked up by rule class name.
private final ImmutableMap<String, RepositoryFunction> repositoryHandlers;
private final AtomicBoolean isFetch = new AtomicBoolean(false);
@@ -210,7 +216,23 @@ public class BazelRepositoryModule extends BlazeModule {
}
repositoryCache.setRepositoryCachePath(repositoryCachePath);
} else {
- repositoryCache.setRepositoryCachePath(null);
+ Path repositoryCachePath =
+ env.getDirectories()
+ .getServerDirectories()
+ .getOutputUserRoot()
+ .getRelative(DEFAULT_CACHE_LOCATION);
+ try {
+ FileSystemUtils.createDirectoryAndParents(repositoryCachePath);
+ repositoryCache.setRepositoryCachePath(repositoryCachePath);
+ } catch (IOException e) {
+ env.getReporter()
+ .handle(
+ Event.warn(
+ "Failed to set up cache at "
+ + repositoryCachePath.toString()
+ + ": "
+ + e.getMessage()));
+ }
}
if (repoOptions.experimentalDistdir != null) {
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/repository/RepositoryOptions.java b/src/main/java/com/google/devtools/build/lib/bazel/repository/RepositoryOptions.java
index 61e50105f6..56c1e554c1 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/repository/RepositoryOptions.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/repository/RepositoryOptions.java
@@ -34,7 +34,8 @@ import java.util.List;
public class RepositoryOptions extends OptionsBase {
@Option(
- name = "experimental_repository_cache",
+ name = "repository_cache",
+ oldName = "experimental_repository_cache",
defaultValue = "null",
documentationCategory = OptionDocumentationCategory.BAZEL_CLIENT_OPTIONS,
effectTags = {OptionEffectTag.BAZEL_INTERNAL_CONFIGURATION},
diff --git a/src/test/shell/bazel/external_integration_test.sh b/src/test/shell/bazel/external_integration_test.sh
index 9356fd8e75..e948e14754 100755
--- a/src/test/shell/bazel/external_integration_test.sh
+++ b/src/test/shell/bazel/external_integration_test.sh
@@ -1105,7 +1105,7 @@ EOF
}
function test_repository_cache_relative_path() {
- # Verify that --experimental_repository_cache works for query and caches soly
+ # Verify that --repository_cache works for query and caches soly
# based on the predicted hash, for a repository-cache location given as path
# relative to the WORKSPACE
WRKDIR=$(mktemp -d "${TEST_TMPDIR}/testXXXXXX")
@@ -1144,7 +1144,7 @@ http_archive(
)
EOF
# Use the external repository once to make sure it is cached.
- bazel build --experimental_repository_cache="../cache" '@ext//:bar' \
+ bazel build --repository_cache="../cache" '@ext//:bar' \
|| fail "expected sucess"
# Now "go offline" and clean local resources.
@@ -1154,7 +1154,7 @@ EOF
# The value should still be available from the repository cache
bazel query 'deps("@ext//:bar")' \
- --experimental_repository_cache="../cache" > "${TEST_log}" \
+ --repository_cache="../cache" > "${TEST_log}" \
|| fail "Expected success"
expect_log '@ext//:foo'
@@ -1172,11 +1172,76 @@ http_archive(
)
EOF
bazel query 'deps("@ext//:bar")' \
- --experimental_repository_cache="../cache" > "${TEST_log}" \
+ --repository_cache="../cache" > "${TEST_log}" \
|| fail "Expected success"
expect_log '@ext//:foo'
}
+test_default_cache()
+{
+ # Verify that the default cache works for query and caches soly
+ # based on the predicted hash, for a repository-cache location given as path
+ # relative to the WORKSPACE
+ WRKDIR=$(mktemp -d "${TEST_TMPDIR}/testXXXXXX")
+ cd "${WRKDIR}"
+ mkdir ext
+ cat > ext/BUILD <<'EOF'
+genrule(
+ name="foo",
+ outs=["foo.txt"],
+ cmd="echo Hello World > $@",
+)
+genrule(
+ name="bar",
+ outs=["bar.txt"],
+ srcs=[":foo"],
+ cmd="cp $< $@",
+)
+EOF
+ zip ext.zip ext/*
+ rm -rf ext
+ sha256=$(sha256sum ext.zip | head -c 64)
+
+ rm -rf main
+ mkdir main
+ cd main
+ cat > WORKSPACE <<EOF
+load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
+http_archive(
+ name="ext",
+ strip_prefix="ext",
+ urls=["file://${WRKDIR}/ext.zip"],
+ sha256="${sha256}",
+)
+EOF
+ # Use the external repository once to make sure it is cached.
+ bazel build '@ext//:bar' || fail "expected sucess"
+
+ # Now "go offline" and clean local resources.
+ rm -f "${WRKDIR}/ext.zip"
+ bazel clean --expunge
+
+ # The value should still be available from the repository cache
+ bazel query 'deps("@ext//:bar")' > "${TEST_log}" || fail "Expected success"
+ expect_log '@ext//:foo'
+
+ # Clean again.
+ bazel clean --expunge
+ # Even with a different source URL, the cache sould be consulted.
+
+ cat > WORKSPACE <<EOF
+load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
+http_archive(
+ name="ext",
+ strip_prefix="ext",
+ urls=["http://doesnotexist.example.com/invalidpath/othername.zip"],
+ sha256="${sha256}",
+)
+EOF
+ bazel query 'deps("@ext//:bar")' > "${TEST_log}" || fail "Expected success"
+ expect_log '@ext//:foo'
+}
+
function test_repository_cache() {
# Verify that --experimental_repository_cache works for query and caches soly
# based on the predicted hash.