Skip to content

Commit

Permalink
Revert "Use host module cache whithout build cache and verify it (baz…
Browse files Browse the repository at this point in the history
…elbuild#1755)"

This reverts commit bc05218.
  • Loading branch information
tyler-french committed Apr 10, 2024
1 parent 1e0d875 commit 64203de
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 34 deletions.
5 changes: 1 addition & 4 deletions cmd/fetch_repo/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ go_library(
],
importpath = "github.com/bazelbuild/bazel-gazelle/cmd/fetch_repo",
visibility = ["//visibility:private"],
deps = [
"@org_golang_x_mod//sumdb/dirhash",
"@org_golang_x_tools_go_vcs//:vcs",
],
deps = ["@org_golang_x_tools_go_vcs//:vcs"],
)

go_binary(
Expand Down
19 changes: 1 addition & 18 deletions cmd/fetch_repo/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ import (
"path/filepath"
"runtime"
"strings"

"golang.org/x/mod/sumdb/dirhash"
)

func fetchModule(dest, importpath, version, sum string) error {
Expand Down Expand Up @@ -116,22 +114,7 @@ func fetchModule(dest, importpath, version, sum string) error {
}

// Copy the module to the destination.
err = copyTree(dest, dl.Dir)
if err != nil {
return fmt.Errorf("failed copying repo: %w", err)
}

// Verify sum
repoSum, err := dirhash.HashDir(dest, importpath+"@"+version, dirhash.Hash1)
if err != nil {
return fmt.Errorf("failed computing sum: %w", err)
}

if repoSum != sum {
return fmt.Errorf("resulting module with sum %s; expected sum %s", repoSum, sum)
}

return nil
return copyTree(dest, dl.Dir)
}

func copyTree(destRoot, srcRoot string) error {
Expand Down
4 changes: 1 addition & 3 deletions internal/go_repository.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ When `go_repository` is in module mode, it saves downloaded modules in a shared,
internal cache within Bazel's cache. It may be cleared with `bazel clean --expunge`.
By setting the environment variable `GO_REPOSITORY_USE_HOST_CACHE=1`, you can
force `go_repository` to use the module cache on the host system in the location
returned by `go env GOPATH`. Alternatively, by setting the environment variable
`GO_REPOSITORY_USE_HOST_MODCACHE=1`, you can force `go_repository` to use only
the module cache on the host system in the location returned by `go env GOMODCACHE`.
returned by `go env GOPATH`.
**Example**
Expand Down
6 changes: 0 additions & 6 deletions internal/go_repository_cache.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@ def _go_repository_cache_impl(ctx):
go_path = str(ctx.path("."))
go_cache = str(ctx.path("gocache"))
go_mod_cache = ""
if ctx.os.environ.get("GO_REPOSITORY_USE_HOST_MODCACHE", "") == "1":
extension = executable_extension(ctx)
go_tool = go_root + "/bin/go" + extension
go_mod_cache = read_go_env(ctx, go_tool, "GOMODCACHE")
if not go_mod_cache:
fail("GOMODCACHE must be set when GO_REPOSITORY_USE_HOST_MODCACHE is enabled.")
if ctx.os.environ.get("GO_REPOSITORY_USE_HOST_CACHE", "") == "1":
extension = executable_extension(ctx)
go_tool = go_root + "/bin/go" + extension
Expand Down
4 changes: 1 addition & 3 deletions repository.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,7 @@ When `go_repository` is in module mode, it saves downloaded modules in a shared,
internal cache within Bazel's cache. It may be cleared with `bazel clean --expunge`.
By setting the environment variable `GO_REPOSITORY_USE_HOST_CACHE=1`, you can
force `go_repository` to use the module cache on the host system in the location
returned by `go env GOPATH`. Alternatively, by setting the environment variable
`GO_REPOSITORY_USE_HOST_MODCACHE=1`, you can force `go_repository` to use only
the module cache on the host system in the location returned by `go env GOMODCACHE`.
returned by `go env GOPATH`.

**Example**

Expand Down

0 comments on commit 64203de

Please sign in to comment.