Skip to content

Commit 8251e45

Browse files
authored
deps: Get repositories.bzl in sync with go.mod (#4316)
Bump the versions of dependencies in repositories.bzl to match what's in go.mod. Specifically bumps: - golang.org/x/sys - google.golang.org/protobuf - google.golang.org/grpc/cmd/protoc-gen-go-grpc - google.golang.org/genproto - github.com/golang/mock Additionally add features to the `releaser` tool for updating to a specific version, rather than latest, so we can avoid further modifications to `go.mod`. Fixes #4262
1 parent 3d7141d commit 8251e45

6 files changed

+1350
-302
lines changed

go/private/repositories.bzl

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,13 @@ def go_rules_dependencies(force = False):
125125
wrapper(
126126
http_archive,
127127
name = "org_golang_x_sys",
128-
# v0.20.0, latest as of 2024-05-20
128+
# v0.30.0, from 2025-01-31
129129
urls = [
130-
"https://mirror.bazel.build/github.com/golang/sys/archive/refs/tags/v0.20.0.zip",
131-
"https://github.com/golang/sys/archive/refs/tags/v0.20.0.zip",
130+
"https://mirror.bazel.build/github.com/golang/sys/archive/refs/tags/v0.30.0.zip",
131+
"https://github.com/golang/sys/archive/refs/tags/v0.30.0.zip",
132132
],
133-
sha256 = "e9ad578952169036fb5023b0f53c0315d5f73146fc33d70255fa6d6edd859f84",
134-
strip_prefix = "sys-0.20.0",
133+
sha256 = "4acf3387a5ab61b6e2af0463491d0c6cea7a8db5f855ad4f77819f1bce93f749",
134+
strip_prefix = "sys-0.30.0",
135135
patches = [
136136
# releaser:patch-cmd gazelle -repo_root . -go_prefix golang.org/x/sys -go_naming_convention import_alias
137137
Label("//third_party:org_golang_x_sys-gazelle.patch"),
@@ -179,13 +179,13 @@ def go_rules_dependencies(force = False):
179179
wrapper(
180180
http_archive,
181181
name = "org_golang_google_protobuf",
182-
sha256 = "39a8bbfadaa3e71f9d7741d67ee60d69db40422dc531708a777259e594d923e3",
183-
# v1.33.0, latest as of 2024-04-19
182+
sha256 = "87fc5518c998c350c44a0feab93b236cc10b2d184d4a8b8129b8991d4d5ca584",
183+
# v1.36.3, from 2025-01-15
184184
urls = [
185-
"https://mirror.bazel.build/github.com/protocolbuffers/protobuf-go/archive/refs/tags/v1.33.0.zip",
186-
"https://github.com/protocolbuffers/protobuf-go/archive/refs/tags/v1.33.0.zip",
185+
"https://mirror.bazel.build/github.com/protocolbuffers/protobuf-go/archive/refs/tags/v1.36.3.zip",
186+
"https://github.com/protocolbuffers/protobuf-go/archive/refs/tags/v1.36.3.zip",
187187
],
188-
strip_prefix = "protobuf-go-1.33.0",
188+
strip_prefix = "protobuf-go-1.36.3",
189189
patches = [
190190
# releaser:patch-cmd gazelle -repo_root . -go_prefix google.golang.org/protobuf -go_naming_convention import_alias -proto disable_global
191191
Label("//third_party:org_golang_google_protobuf-gazelle.patch"),
@@ -263,13 +263,13 @@ def go_rules_dependencies(force = False):
263263
wrapper(
264264
http_archive,
265265
name = "org_golang_google_genproto",
266-
# main, as of 2024-05-20
266+
# from 2025-01-15
267267
urls = [
268-
"https://mirror.bazel.build/github.com/googleapis/go-genproto/archive/dc85e6b867a5ebdfeaa293ddb423f00255ec921e.zip",
269-
"https://github.com/googleapis/go-genproto/archive/dc85e6b867a5ebdfeaa293ddb423f00255ec921e.zip",
268+
"https://mirror.bazel.build/github.com/googleapis/go-genproto/archive/1a7da9e5054f0b2e0ac1394d0a8538a3b74f6983.zip",
269+
"https://github.com/googleapis/go-genproto/archive/1a7da9e5054f0b2e0ac1394d0a8538a3b74f6983.zip",
270270
],
271-
sha256 = "ef3c82a1e6951a7931107d00ad4fe034366903290feae82bb1a19211c86d9d2f",
272-
strip_prefix = "go-genproto-dc85e6b867a5ebdfeaa293ddb423f00255ec921e",
271+
sha256 = "e0123b04bc8265fb288f565c4fd867af1e846a3d20306988c6d83c05736f2e5b",
272+
strip_prefix = "go-genproto-1a7da9e5054f0b2e0ac1394d0a8538a3b74f6983",
273273
patches = [
274274
# releaser:patch-cmd gazelle -repo_root . -go_prefix google.golang.org/genproto -go_naming_convention import_alias -proto disable_global
275275
Label("//third_party:org_golang_google_genproto-gazelle.patch"),
@@ -291,18 +291,18 @@ def go_rules_dependencies(force = False):
291291
_maybe(
292292
http_archive,
293293
name = "com_github_golang_mock",
294-
# v1.6.0, latest as of 2024-05-20
294+
# v1.7.0-rc.1, from 2022-05-12
295295
urls = [
296-
"https://mirror.bazel.build/github.com/golang/mock/archive/refs/tags/v1.6.0.zip",
297-
"https://github.com/golang/mock/archive/refs/tags/v1.6.0.zip",
296+
"https://mirror.bazel.build/github.com/golang/mock/archive/refs/tags/v1.7.0-rc.1.zip",
297+
"https://github.com/golang/mock/archive/refs/tags/v1.7.0-rc.1.zip",
298298
],
299299
patches = [
300300
# releaser:patch-cmd gazelle -repo_root . -go_prefix github.com/golang/mock -go_naming_convention import_alias
301301
Label("//third_party:com_github_golang_mock-gazelle.patch"),
302302
],
303303
patch_args = ["-p1"],
304-
sha256 = "604d9ab25b07d60c1b8ba6d3ea2e66873138edeed2e561c5358de804ea421a0e",
305-
strip_prefix = "mock-1.6.0",
304+
sha256 = "5359c78b0c1649cf7beb3b48ff8b1d1aaf0243b22ea4789aba94805280075d8e",
305+
strip_prefix = "mock-1.7.0-rc.1",
306306
)
307307

308308
# This may be overridden by go_register_toolchains, but it's not mandatory

go/tools/releaser/upgradedep.go

Lines changed: 74 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ var upgradeDepCmd = command{
4545
4646
upgrade-dep upgrades one or more rules_go dependencies in WORKSPACE or
4747
go/private/repositories.bzl. Dependency names (matching the name attributes)
48-
can be specified with positional arguments. "all" may be specified to upgrade
49-
all upgradeable dependencies.
48+
can be specified with positional arguments. They may have a suffix of the form
49+
'@version' to request update to a specific version.
50+
"all" may be specified to upgrade all upgradeable dependencies.
5051
5152
For each dependency, upgrade-dep finds the highest version available in the
5253
upstream repository. If no version is available, upgrade-dep uses the commit
@@ -80,6 +81,18 @@ func init() {
8081
upgradeDepCmd.run = runUpgradeDep
8182
}
8283

84+
// parseDepArg parses a dependency argument like [email protected]
85+
// into the dependency name and version.
86+
// If there is no @, the arg will be returned unchanged and the version
87+
// will be an empty string.
88+
func parseDepArg(arg string) (string, string) {
89+
i := strings.Index(arg, "@")
90+
if i < 0 {
91+
return arg, ""
92+
}
93+
return arg[:i], arg[i+1:]
94+
}
95+
8396
func runUpgradeDep(ctx context.Context, stderr io.Writer, args []string) error {
8497
// Parse arguments.
8598
flags := flag.NewFlagSet("releaser upgrade-dep", flag.ContinueOnError)
@@ -210,19 +223,20 @@ func runUpgradeDep(ctx context.Context, stderr io.Writer, args []string) error {
210223
continue
211224
}
212225
eg.Go(func() error {
213-
return upgradeDepDecl(egctx, gh, workDir, name, depIndex[name], uploadToMirror)
226+
return upgradeDepDecl(egctx, gh, workDir, name, "", depIndex[name], uploadToMirror)
214227
})
215228
}
216229
} else {
217230
for _, arg := range flags.Args() {
218-
if depIndex[arg] == nil {
231+
dep, _ := parseDepArg(arg)
232+
if depIndex[dep] == nil {
219233
return fmt.Errorf("could not find dependency %s", arg)
220234
}
221235
}
222236
for _, arg := range flags.Args() {
223-
arg := arg
237+
arg, ver := parseDepArg(arg)
224238
eg.Go(func() error {
225-
return upgradeDepDecl(egctx, gh, workDir, arg, depIndex[arg], uploadToMirror)
239+
return upgradeDepDecl(egctx, gh, workDir, arg, ver, depIndex[arg], uploadToMirror)
226240
})
227241
}
228242
}
@@ -240,7 +254,7 @@ func runUpgradeDep(ctx context.Context, stderr io.Writer, args []string) error {
240254
}
241255

242256
// upgradeDepDecl upgrades a specific dependency.
243-
func upgradeDepDecl(ctx context.Context, gh *githubClient, workDir, name string, call *bzl.CallExpr, uploadToMirror bool) (err error) {
257+
func upgradeDepDecl(ctx context.Context, gh *githubClient, workDir, name, version string, call *bzl.CallExpr, uploadToMirror bool) (err error) {
244258
defer func() {
245259
if err != nil {
246260
err = fmt.Errorf("upgrading %s: %w", name, err)
@@ -321,7 +335,8 @@ func upgradeDepDecl(ctx context.Context, gh *githubClient, workDir, name string,
321335
if name != semver.Canonical(name) {
322336
continue
323337
}
324-
if semver.Prerelease(name) != "" {
338+
// Only use pre-release tags if specifically requested.
339+
if semver.Prerelease(name) != "" && (version == "" || semver.Prerelease(version) == "") {
325340
continue
326341
}
327342
tags[w] = tags[r]
@@ -333,6 +348,11 @@ func upgradeDepDecl(ctx context.Context, gh *githubClient, workDir, name string,
333348
var highestVname string
334349
for _, tag := range tags {
335350
name := vname(*tag.Name)
351+
if version != "" && name == version {
352+
highestTag = tag
353+
highestVname = name
354+
break
355+
}
336356
if highestTag == nil || semver.Compare(name, highestVname) > 0 {
337357
highestTag = tag
338358
highestVname = name
@@ -342,6 +362,11 @@ func upgradeDepDecl(ctx context.Context, gh *githubClient, workDir, name string,
342362
var ghURL, stripPrefix, urlComment string
343363
date := time.Now().Format("2006-01-02")
344364
if highestTag != nil {
365+
// Check that this is the tag that was requested.
366+
if version != "" && highestVname != version {
367+
err = fmt.Errorf("version %s not found, latest is %s", version, *highestTag.Name)
368+
return err
369+
}
345370
// If the tag is part of a release, check whether there is a release
346371
// artifact we should use.
347372
release, _, err := gh.Repositories.GetReleaseByTag(ctx, orgName, repoName, *highestTag.Name)
@@ -369,23 +394,49 @@ func upgradeDepDecl(ctx context.Context, gh *githubClient, workDir, name string,
369394
stripPrefix += "/" + relPath
370395
}
371396
}
372-
urlComment = fmt.Sprintf("%s, latest as of %s", *highestTag.Name, date)
373-
} else {
374-
repo, _, err := gh.Repositories.Get(ctx, orgName, repoName)
375-
if err != nil {
376-
return err
377-
}
378-
defaultBranchName := "main"
379-
if repo.DefaultBranch != nil {
380-
defaultBranchName = *repo.DefaultBranch
397+
398+
if version != "" {
399+
// This tag is not necessarily latest as of today, so get the commit
400+
// so we can report the actual date.
401+
commit, _, _ := gh.Repositories.GetCommit(ctx, orgName, repoName, *highestTag.Commit.SHA)
402+
if commit := commit.GetCommit(); commit != nil {
403+
if d := commit.Committer.GetDate(); !d.IsZero() {
404+
date = d.Format("2006-01-02")
405+
} else if d := commit.Author.GetDate(); !d.IsZero() {
406+
date = d.Format("2006-01-02")
407+
}
408+
}
409+
urlComment = fmt.Sprintf("%s, from %s", *highestTag.Name, date)
410+
} else {
411+
urlComment = fmt.Sprintf("%s, latest as of %s", *highestTag.Name, date)
381412
}
382-
branch, _, err := gh.Repositories.GetBranch(ctx, orgName, repoName, defaultBranchName)
383-
if err != nil {
384-
return err
413+
} else {
414+
var commit *github.RepositoryCommit
415+
if version != "" {
416+
commit, _, err = gh.Repositories.GetCommit(ctx, orgName, repoName, version)
417+
if err != nil {
418+
return err
419+
}
420+
date = commit.GetCommit().Committer.GetDate().Format("2006-01-02")
421+
urlComment = fmt.Sprintf("from %s", date)
422+
} else {
423+
repo, _, err := gh.Repositories.Get(ctx, orgName, repoName)
424+
if err != nil {
425+
return err
426+
}
427+
defaultBranchName := "main"
428+
if repo.DefaultBranch != nil {
429+
defaultBranchName = *repo.DefaultBranch
430+
}
431+
branch, _, err := gh.Repositories.GetBranch(ctx, orgName, repoName, defaultBranchName)
432+
if err != nil {
433+
return err
434+
}
435+
commit = branch.Commit
436+
urlComment = fmt.Sprintf("%s, as of %s", defaultBranchName, date)
385437
}
386-
ghURL = fmt.Sprintf("https://github.com/%s/%s/archive/%s.zip", orgName, repoName, *branch.Commit.SHA)
387-
stripPrefix = repoName + "-" + *branch.Commit.SHA
388-
urlComment = fmt.Sprintf("%s, as of %s", defaultBranchName, date)
438+
ghURL = fmt.Sprintf("https://github.com/%s/%s/archive/%s.zip", orgName, repoName, *commit.SHA)
439+
stripPrefix = repoName + "-" + *commit.SHA
389440
}
390441
ghURLWithoutScheme := ghURL[len("https://"):]
391442
mirrorURL := "https://mirror.bazel.build/" + ghURLWithoutScheme

third_party/com_github_golang_mock-gazelle.patch

Lines changed: 70 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
diff -urN a/gomock/BUILD.bazel b/gomock/BUILD.bazel
22
--- a/gomock/BUILD.bazel 1970-01-01 00:00:00.000000000 +0000
33
+++ b/gomock/BUILD.bazel 2000-01-01 00:00:00.000000000 -0000
4-
@@ -0,0 +1,35 @@
4+
@@ -0,0 +1,34 @@
55
+load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
66
+
77
+go_library(
@@ -10,6 +10,7 @@ diff -urN a/gomock/BUILD.bazel b/gomock/BUILD.bazel
1010
+ "call.go",
1111
+ "callset.go",
1212
+ "controller.go",
13+
+ "doc.go",
1314
+ "matchers.go",
1415
+ ],
1516
+ importpath = "github.com/golang/mock/gomock",
@@ -27,8 +28,6 @@ diff -urN a/gomock/BUILD.bazel b/gomock/BUILD.bazel
2728
+ srcs = [
2829
+ "call_test.go",
2930
+ "callset_test.go",
30-
+ "controller_113_test.go",
31-
+ "controller_114_test.go",
3231
+ "controller_test.go",
3332
+ "example_test.go",
3433
+ "matchers_test.go",
@@ -59,17 +58,18 @@ diff -urN a/gomock/internal/mock_gomock/BUILD.bazel b/gomock/internal/mock_gomoc
5958
diff -urN a/mockgen/BUILD.bazel b/mockgen/BUILD.bazel
6059
--- a/mockgen/BUILD.bazel 1970-01-01 00:00:00.000000000 +0000
6160
+++ b/mockgen/BUILD.bazel 2000-01-01 00:00:00.000000000 -0000
62-
@@ -0,0 +1,35 @@
61+
@@ -0,0 +1,36 @@
6362
+load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library", "go_test")
6463
+
6564
+go_library(
6665
+ name = "mockgen_lib",
6766
+ srcs = [
67+
+ "generic_go118.go",
68+
+ "generic_notgo118.go",
6869
+ "mockgen.go",
6970
+ "parse.go",
7071
+ "reflect.go",
71-
+ "version.1.11.go",
72-
+ "version.1.12.go",
72+
+ "version.go",
7373
+ ],
7474
+ importpath = "github.com/golang/mock/mockgen",
7575
+ visibility = ["//visibility:private"],
@@ -355,17 +355,80 @@ diff -urN a/mockgen/internal/tests/generated_identifier_conflict/BUILD.bazel b/m
355355
+ embed = [":generated_identifier_conflict"],
356356
+ deps = ["//gomock"],
357357
+)
358+
diff -urN a/mockgen/internal/tests/generics/BUILD.bazel b/mockgen/internal/tests/generics/BUILD.bazel
359+
--- a/mockgen/internal/tests/generics/BUILD.bazel 1970-01-01 00:00:00.000000000 +0000
360+
+++ b/mockgen/internal/tests/generics/BUILD.bazel 2000-01-01 00:00:00.000000000 -0000
361+
@@ -0,0 +1,21 @@
362+
+load("@io_bazel_rules_go//go:def.bzl", "go_library")
363+
+
364+
+go_library(
365+
+ name = "generics",
366+
+ srcs = [
367+
+ "external.go",
368+
+ "generics.go",
369+
+ ],
370+
+ importpath = "github.com/golang/mock/mockgen/internal/tests/generics",
371+
+ visibility = ["//mockgen:__subpackages__"],
372+
+ deps = [
373+
+ "//mockgen/internal/tests/generics/other",
374+
+ "@org_golang_x_exp//constraints:go_default_library",
375+
+ ],
376+
+)
377+
+
378+
+alias(
379+
+ name = "go_default_library",
380+
+ actual = ":generics",
381+
+ visibility = ["//mockgen:__subpackages__"],
382+
+)
383+
diff -urN a/mockgen/internal/tests/generics/other/BUILD.bazel b/mockgen/internal/tests/generics/other/BUILD.bazel
384+
--- a/mockgen/internal/tests/generics/other/BUILD.bazel 1970-01-01 00:00:00.000000000 +0000
385+
+++ b/mockgen/internal/tests/generics/other/BUILD.bazel 2000-01-01 00:00:00.000000000 -0000
386+
@@ -0,0 +1,14 @@
387+
+load("@io_bazel_rules_go//go:def.bzl", "go_library")
388+
+
389+
+go_library(
390+
+ name = "other",
391+
+ srcs = ["other.go"],
392+
+ importpath = "github.com/golang/mock/mockgen/internal/tests/generics/other",
393+
+ visibility = ["//mockgen:__subpackages__"],
394+
+)
395+
+
396+
+alias(
397+
+ name = "go_default_library",
398+
+ actual = ":other",
399+
+ visibility = ["//mockgen:__subpackages__"],
400+
+)
401+
diff -urN a/mockgen/internal/tests/generics/source/BUILD.bazel b/mockgen/internal/tests/generics/source/BUILD.bazel
402+
--- a/mockgen/internal/tests/generics/source/BUILD.bazel 1970-01-01 00:00:00.000000000 +0000
403+
+++ b/mockgen/internal/tests/generics/source/BUILD.bazel 2000-01-01 00:00:00.000000000 -0000
404+
@@ -0,0 +1,15 @@
405+
+load("@io_bazel_rules_go//go:def.bzl", "go_test")
406+
+
407+
+go_test(
408+
+ name = "source_test",
409+
+ srcs = [
410+
+ "mock_external_test.go",
411+
+ "mock_generics_test.go",
412+
+ ],
413+
+ deps = [
414+
+ "//gomock",
415+
+ "//mockgen/internal/tests/generics",
416+
+ "//mockgen/internal/tests/generics/other",
417+
+ "@org_golang_x_exp//constraints:go_default_library",
418+
+ ],
419+
+)
358420
diff -urN a/mockgen/internal/tests/import_embedded_interface/BUILD.bazel b/mockgen/internal/tests/import_embedded_interface/BUILD.bazel
359421
--- a/mockgen/internal/tests/import_embedded_interface/BUILD.bazel 1970-01-01 00:00:00.000000000 +0000
360422
+++ b/mockgen/internal/tests/import_embedded_interface/BUILD.bazel 2000-01-01 00:00:00.000000000 -0000
361-
@@ -0,0 +1,35 @@
423+
@@ -0,0 +1,36 @@
362424
+load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
363425
+
364426
+go_library(
365427
+ name = "import_embedded_interface",
366428
+ srcs = [
367429
+ "bugreport.go",
368430
+ "bugreport_mock.go",
431+
+ "foo.go",
369432
+ "net.go",
370433
+ "net_mock.go",
371434
+ ],

0 commit comments

Comments
 (0)