Skip to content

deps: Get repositories.bzl in sync with go.mod #4316

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions go/private/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,13 @@ def go_rules_dependencies(force = False):
wrapper(
http_archive,
name = "org_golang_x_sys",
# v0.20.0, latest as of 2024-05-20
# v0.30.0, from 2025-01-31
urls = [
"https://mirror.bazel.build/github.com/golang/sys/archive/refs/tags/v0.20.0.zip",
"https://github.com/golang/sys/archive/refs/tags/v0.20.0.zip",
"https://mirror.bazel.build/github.com/golang/sys/archive/refs/tags/v0.30.0.zip",
"https://github.com/golang/sys/archive/refs/tags/v0.30.0.zip",
],
sha256 = "e9ad578952169036fb5023b0f53c0315d5f73146fc33d70255fa6d6edd859f84",
strip_prefix = "sys-0.20.0",
sha256 = "4acf3387a5ab61b6e2af0463491d0c6cea7a8db5f855ad4f77819f1bce93f749",
strip_prefix = "sys-0.30.0",
patches = [
# releaser:patch-cmd gazelle -repo_root . -go_prefix golang.org/x/sys -go_naming_convention import_alias
Label("//third_party:org_golang_x_sys-gazelle.patch"),
Expand Down Expand Up @@ -179,13 +179,13 @@ def go_rules_dependencies(force = False):
wrapper(
http_archive,
name = "org_golang_google_protobuf",
sha256 = "39a8bbfadaa3e71f9d7741d67ee60d69db40422dc531708a777259e594d923e3",
# v1.33.0, latest as of 2024-04-19
sha256 = "87fc5518c998c350c44a0feab93b236cc10b2d184d4a8b8129b8991d4d5ca584",
# v1.36.3, from 2025-01-15
urls = [
"https://mirror.bazel.build/github.com/protocolbuffers/protobuf-go/archive/refs/tags/v1.33.0.zip",
"https://github.com/protocolbuffers/protobuf-go/archive/refs/tags/v1.33.0.zip",
"https://mirror.bazel.build/github.com/protocolbuffers/protobuf-go/archive/refs/tags/v1.36.3.zip",
"https://github.com/protocolbuffers/protobuf-go/archive/refs/tags/v1.36.3.zip",
],
strip_prefix = "protobuf-go-1.33.0",
strip_prefix = "protobuf-go-1.36.3",
patches = [
# releaser:patch-cmd gazelle -repo_root . -go_prefix google.golang.org/protobuf -go_naming_convention import_alias -proto disable_global
Label("//third_party:org_golang_google_protobuf-gazelle.patch"),
Expand Down Expand Up @@ -263,13 +263,13 @@ def go_rules_dependencies(force = False):
wrapper(
http_archive,
name = "org_golang_google_genproto",
# main, as of 2024-05-20
# from 2025-01-15
urls = [
"https://mirror.bazel.build/github.com/googleapis/go-genproto/archive/dc85e6b867a5ebdfeaa293ddb423f00255ec921e.zip",
"https://github.com/googleapis/go-genproto/archive/dc85e6b867a5ebdfeaa293ddb423f00255ec921e.zip",
"https://mirror.bazel.build/github.com/googleapis/go-genproto/archive/1a7da9e5054f0b2e0ac1394d0a8538a3b74f6983.zip",
"https://github.com/googleapis/go-genproto/archive/1a7da9e5054f0b2e0ac1394d0a8538a3b74f6983.zip",
],
sha256 = "ef3c82a1e6951a7931107d00ad4fe034366903290feae82bb1a19211c86d9d2f",
strip_prefix = "go-genproto-dc85e6b867a5ebdfeaa293ddb423f00255ec921e",
sha256 = "e0123b04bc8265fb288f565c4fd867af1e846a3d20306988c6d83c05736f2e5b",
strip_prefix = "go-genproto-1a7da9e5054f0b2e0ac1394d0a8538a3b74f6983",
patches = [
# releaser:patch-cmd gazelle -repo_root . -go_prefix google.golang.org/genproto -go_naming_convention import_alias -proto disable_global
Label("//third_party:org_golang_google_genproto-gazelle.patch"),
Expand All @@ -291,18 +291,18 @@ def go_rules_dependencies(force = False):
_maybe(
http_archive,
name = "com_github_golang_mock",
# v1.6.0, latest as of 2024-05-20
# v1.7.0-rc.1, from 2022-05-12
urls = [
"https://mirror.bazel.build/github.com/golang/mock/archive/refs/tags/v1.6.0.zip",
"https://github.com/golang/mock/archive/refs/tags/v1.6.0.zip",
"https://mirror.bazel.build/github.com/golang/mock/archive/refs/tags/v1.7.0-rc.1.zip",
"https://github.com/golang/mock/archive/refs/tags/v1.7.0-rc.1.zip",
],
patches = [
# releaser:patch-cmd gazelle -repo_root . -go_prefix github.com/golang/mock -go_naming_convention import_alias
Label("//third_party:com_github_golang_mock-gazelle.patch"),
],
patch_args = ["-p1"],
sha256 = "604d9ab25b07d60c1b8ba6d3ea2e66873138edeed2e561c5358de804ea421a0e",
strip_prefix = "mock-1.6.0",
sha256 = "5359c78b0c1649cf7beb3b48ff8b1d1aaf0243b22ea4789aba94805280075d8e",
strip_prefix = "mock-1.7.0-rc.1",
)

# This may be overridden by go_register_toolchains, but it's not mandatory
Expand Down
97 changes: 74 additions & 23 deletions go/tools/releaser/upgradedep.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ var upgradeDepCmd = command{

upgrade-dep upgrades one or more rules_go dependencies in WORKSPACE or
go/private/repositories.bzl. Dependency names (matching the name attributes)
can be specified with positional arguments. "all" may be specified to upgrade
all upgradeable dependencies.
can be specified with positional arguments. They may have a suffix of the form
'@version' to request update to a specific version.
"all" may be specified to upgrade all upgradeable dependencies.

For each dependency, upgrade-dep finds the highest version available in the
upstream repository. If no version is available, upgrade-dep uses the commit
Expand Down Expand Up @@ -80,6 +81,18 @@ func init() {
upgradeDepCmd.run = runUpgradeDep
}

// parseDepArg parses a dependency argument like [email protected]
// into the dependency name and version.
// If there is no @, the arg will be returned unchanged and the version
// will be an empty string.
func parseDepArg(arg string) (string, string) {
i := strings.Index(arg, "@")
if i < 0 {
return arg, ""
}
return arg[:i], arg[i+1:]
}

func runUpgradeDep(ctx context.Context, stderr io.Writer, args []string) error {
// Parse arguments.
flags := flag.NewFlagSet("releaser upgrade-dep", flag.ContinueOnError)
Expand Down Expand Up @@ -210,19 +223,20 @@ func runUpgradeDep(ctx context.Context, stderr io.Writer, args []string) error {
continue
}
eg.Go(func() error {
return upgradeDepDecl(egctx, gh, workDir, name, depIndex[name], uploadToMirror)
return upgradeDepDecl(egctx, gh, workDir, name, "", depIndex[name], uploadToMirror)
})
}
} else {
for _, arg := range flags.Args() {
if depIndex[arg] == nil {
dep, _ := parseDepArg(arg)
if depIndex[dep] == nil {
return fmt.Errorf("could not find dependency %s", arg)
}
}
for _, arg := range flags.Args() {
arg := arg
arg, ver := parseDepArg(arg)
eg.Go(func() error {
return upgradeDepDecl(egctx, gh, workDir, arg, depIndex[arg], uploadToMirror)
return upgradeDepDecl(egctx, gh, workDir, arg, ver, depIndex[arg], uploadToMirror)
})
}
}
Expand All @@ -240,7 +254,7 @@ func runUpgradeDep(ctx context.Context, stderr io.Writer, args []string) error {
}

// upgradeDepDecl upgrades a specific dependency.
func upgradeDepDecl(ctx context.Context, gh *githubClient, workDir, name string, call *bzl.CallExpr, uploadToMirror bool) (err error) {
func upgradeDepDecl(ctx context.Context, gh *githubClient, workDir, name, version string, call *bzl.CallExpr, uploadToMirror bool) (err error) {
defer func() {
if err != nil {
err = fmt.Errorf("upgrading %s: %w", name, err)
Expand Down Expand Up @@ -321,7 +335,8 @@ func upgradeDepDecl(ctx context.Context, gh *githubClient, workDir, name string,
if name != semver.Canonical(name) {
continue
}
if semver.Prerelease(name) != "" {
// Only use pre-release tags if specifically requested.
if semver.Prerelease(name) != "" && (version == "" || semver.Prerelease(version) == "") {
continue
}
tags[w] = tags[r]
Expand All @@ -333,6 +348,11 @@ func upgradeDepDecl(ctx context.Context, gh *githubClient, workDir, name string,
var highestVname string
for _, tag := range tags {
name := vname(*tag.Name)
if version != "" && name == version {
highestTag = tag
highestVname = name
break
}
if highestTag == nil || semver.Compare(name, highestVname) > 0 {
highestTag = tag
highestVname = name
Expand All @@ -342,6 +362,11 @@ func upgradeDepDecl(ctx context.Context, gh *githubClient, workDir, name string,
var ghURL, stripPrefix, urlComment string
date := time.Now().Format("2006-01-02")
if highestTag != nil {
// Check that this is the tag that was requested.
if version != "" && highestVname != version {
err = fmt.Errorf("version %s not found, latest is %s", version, *highestTag.Name)
return err
}
// If the tag is part of a release, check whether there is a release
// artifact we should use.
release, _, err := gh.Repositories.GetReleaseByTag(ctx, orgName, repoName, *highestTag.Name)
Expand Down Expand Up @@ -369,23 +394,49 @@ func upgradeDepDecl(ctx context.Context, gh *githubClient, workDir, name string,
stripPrefix += "/" + relPath
}
}
urlComment = fmt.Sprintf("%s, latest as of %s", *highestTag.Name, date)
} else {
repo, _, err := gh.Repositories.Get(ctx, orgName, repoName)
if err != nil {
return err
}
defaultBranchName := "main"
if repo.DefaultBranch != nil {
defaultBranchName = *repo.DefaultBranch

if version != "" {
// This tag is not necessarily latest as of today, so get the commit
// so we can report the actual date.
commit, _, _ := gh.Repositories.GetCommit(ctx, orgName, repoName, *highestTag.Commit.SHA)
if commit := commit.GetCommit(); commit != nil {
if d := commit.Committer.GetDate(); !d.IsZero() {
date = d.Format("2006-01-02")
} else if d := commit.Author.GetDate(); !d.IsZero() {
date = d.Format("2006-01-02")
}
}
urlComment = fmt.Sprintf("%s, from %s", *highestTag.Name, date)
} else {
urlComment = fmt.Sprintf("%s, latest as of %s", *highestTag.Name, date)
}
branch, _, err := gh.Repositories.GetBranch(ctx, orgName, repoName, defaultBranchName)
if err != nil {
return err
} else {
var commit *github.RepositoryCommit
if version != "" {
commit, _, err = gh.Repositories.GetCommit(ctx, orgName, repoName, version)
if err != nil {
return err
}
date = commit.GetCommit().Committer.GetDate().Format("2006-01-02")
urlComment = fmt.Sprintf("from %s", date)
} else {
repo, _, err := gh.Repositories.Get(ctx, orgName, repoName)
if err != nil {
return err
}
defaultBranchName := "main"
if repo.DefaultBranch != nil {
defaultBranchName = *repo.DefaultBranch
}
branch, _, err := gh.Repositories.GetBranch(ctx, orgName, repoName, defaultBranchName)
if err != nil {
return err
}
commit = branch.Commit
urlComment = fmt.Sprintf("%s, as of %s", defaultBranchName, date)
}
ghURL = fmt.Sprintf("https://github.com/%s/%s/archive/%s.zip", orgName, repoName, *branch.Commit.SHA)
stripPrefix = repoName + "-" + *branch.Commit.SHA
urlComment = fmt.Sprintf("%s, as of %s", defaultBranchName, date)
ghURL = fmt.Sprintf("https://github.com/%s/%s/archive/%s.zip", orgName, repoName, *commit.SHA)
stripPrefix = repoName + "-" + *commit.SHA
}
ghURLWithoutScheme := ghURL[len("https://"):]
mirrorURL := "https://mirror.bazel.build/" + ghURLWithoutScheme
Expand Down
77 changes: 70 additions & 7 deletions third_party/com_github_golang_mock-gazelle.patch
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
diff -urN a/gomock/BUILD.bazel b/gomock/BUILD.bazel
--- a/gomock/BUILD.bazel 1970-01-01 00:00:00.000000000 +0000
+++ b/gomock/BUILD.bazel 2000-01-01 00:00:00.000000000 -0000
@@ -0,0 +1,35 @@
@@ -0,0 +1,34 @@
+load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
+
+go_library(
Expand All @@ -10,6 +10,7 @@ diff -urN a/gomock/BUILD.bazel b/gomock/BUILD.bazel
+ "call.go",
+ "callset.go",
+ "controller.go",
+ "doc.go",
+ "matchers.go",
+ ],
+ importpath = "github.com/golang/mock/gomock",
Expand All @@ -27,8 +28,6 @@ diff -urN a/gomock/BUILD.bazel b/gomock/BUILD.bazel
+ srcs = [
+ "call_test.go",
+ "callset_test.go",
+ "controller_113_test.go",
+ "controller_114_test.go",
+ "controller_test.go",
+ "example_test.go",
+ "matchers_test.go",
Expand Down Expand Up @@ -59,17 +58,18 @@ diff -urN a/gomock/internal/mock_gomock/BUILD.bazel b/gomock/internal/mock_gomoc
diff -urN a/mockgen/BUILD.bazel b/mockgen/BUILD.bazel
--- a/mockgen/BUILD.bazel 1970-01-01 00:00:00.000000000 +0000
+++ b/mockgen/BUILD.bazel 2000-01-01 00:00:00.000000000 -0000
@@ -0,0 +1,35 @@
@@ -0,0 +1,36 @@
+load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library", "go_test")
+
+go_library(
+ name = "mockgen_lib",
+ srcs = [
+ "generic_go118.go",
+ "generic_notgo118.go",
+ "mockgen.go",
+ "parse.go",
+ "reflect.go",
+ "version.1.11.go",
+ "version.1.12.go",
+ "version.go",
+ ],
+ importpath = "github.com/golang/mock/mockgen",
+ visibility = ["//visibility:private"],
Expand Down Expand Up @@ -355,17 +355,80 @@ diff -urN a/mockgen/internal/tests/generated_identifier_conflict/BUILD.bazel b/m
+ embed = [":generated_identifier_conflict"],
+ deps = ["//gomock"],
+)
diff -urN a/mockgen/internal/tests/generics/BUILD.bazel b/mockgen/internal/tests/generics/BUILD.bazel
--- a/mockgen/internal/tests/generics/BUILD.bazel 1970-01-01 00:00:00.000000000 +0000
+++ b/mockgen/internal/tests/generics/BUILD.bazel 2000-01-01 00:00:00.000000000 -0000
@@ -0,0 +1,21 @@
+load("@io_bazel_rules_go//go:def.bzl", "go_library")
+
+go_library(
+ name = "generics",
+ srcs = [
+ "external.go",
+ "generics.go",
+ ],
+ importpath = "github.com/golang/mock/mockgen/internal/tests/generics",
+ visibility = ["//mockgen:__subpackages__"],
+ deps = [
+ "//mockgen/internal/tests/generics/other",
+ "@org_golang_x_exp//constraints:go_default_library",
+ ],
+)
+
+alias(
+ name = "go_default_library",
+ actual = ":generics",
+ visibility = ["//mockgen:__subpackages__"],
+)
diff -urN a/mockgen/internal/tests/generics/other/BUILD.bazel b/mockgen/internal/tests/generics/other/BUILD.bazel
--- a/mockgen/internal/tests/generics/other/BUILD.bazel 1970-01-01 00:00:00.000000000 +0000
+++ b/mockgen/internal/tests/generics/other/BUILD.bazel 2000-01-01 00:00:00.000000000 -0000
@@ -0,0 +1,14 @@
+load("@io_bazel_rules_go//go:def.bzl", "go_library")
+
+go_library(
+ name = "other",
+ srcs = ["other.go"],
+ importpath = "github.com/golang/mock/mockgen/internal/tests/generics/other",
+ visibility = ["//mockgen:__subpackages__"],
+)
+
+alias(
+ name = "go_default_library",
+ actual = ":other",
+ visibility = ["//mockgen:__subpackages__"],
+)
diff -urN a/mockgen/internal/tests/generics/source/BUILD.bazel b/mockgen/internal/tests/generics/source/BUILD.bazel
--- a/mockgen/internal/tests/generics/source/BUILD.bazel 1970-01-01 00:00:00.000000000 +0000
+++ b/mockgen/internal/tests/generics/source/BUILD.bazel 2000-01-01 00:00:00.000000000 -0000
@@ -0,0 +1,15 @@
+load("@io_bazel_rules_go//go:def.bzl", "go_test")
+
+go_test(
+ name = "source_test",
+ srcs = [
+ "mock_external_test.go",
+ "mock_generics_test.go",
+ ],
+ deps = [
+ "//gomock",
+ "//mockgen/internal/tests/generics",
+ "//mockgen/internal/tests/generics/other",
+ "@org_golang_x_exp//constraints:go_default_library",
+ ],
+)
diff -urN a/mockgen/internal/tests/import_embedded_interface/BUILD.bazel b/mockgen/internal/tests/import_embedded_interface/BUILD.bazel
--- a/mockgen/internal/tests/import_embedded_interface/BUILD.bazel 1970-01-01 00:00:00.000000000 +0000
+++ b/mockgen/internal/tests/import_embedded_interface/BUILD.bazel 2000-01-01 00:00:00.000000000 -0000
@@ -0,0 +1,35 @@
@@ -0,0 +1,36 @@
+load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
+
+go_library(
+ name = "import_embedded_interface",
+ srcs = [
+ "bugreport.go",
+ "bugreport_mock.go",
+ "foo.go",
+ "net.go",
+ "net_mock.go",
+ ],
Expand Down
Loading