Skip to content
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

feat(bzlmod): allow patches in archive_overrides #1665

Merged
merged 1 commit into from
Nov 21, 2023
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
11 changes: 11 additions & 0 deletions internal/bzlmod/go_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ def _process_archive_override(archive_override_tag):
urls = archive_override_tag.urls,
sha256 = archive_override_tag.sha256,
strip_prefix = archive_override_tag.strip_prefix,
patches = archive_override_tag.patches,
patch_strip = archive_override_tag.patch_strip,
)

def _extension_metadata(module_ctx, *, root_module_direct_deps, root_module_direct_dev_deps):
Expand Down Expand Up @@ -393,6 +395,8 @@ def _go_deps_impl(module_ctx):
"urls": archive_override.urls,
"strip_prefix": archive_override.strip_prefix,
"sha256": archive_override.sha256,
"patches": _get_patches(path, archive_overrides),
"patch_args": _get_patch_args(path, archive_overrides),
})
else:
go_repository_args.update({
Expand Down Expand Up @@ -510,6 +514,13 @@ _archive_override_tag = tag_class(
SHA-256 sum of the downloaded archive. When set, Bazel will verify the archive
against this sum before extracting it.""",
),
"patches": attr.label_list(
doc = "A list of patches to apply to the repository *after* gazelle runs.",
),
"patch_strip": attr.int(
default = 0,
doc = "The number of leading path segments to be stripped from the file name in the patches.",
),
},
doc = "Override the default source location on a given Go module in this extension.",
)
Expand Down
4 changes: 4 additions & 0 deletions tests/bcr/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ go_deps.archive_override(
urls = [
"https://github.com/bazelbuild/buildtools/archive/ae8e3206e815d086269eb208b01f300639a4b194.tar.gz",
],
patch_strip = 1,
patches = [
"//patches:buildtools.patch",
],
strip_prefix = "buildtools-ae8e3206e815d086269eb208b01f300639a4b194",
path = "github.com/bazelbuild/buildtools",
sha256 = "05d7c3d2bd3cc0b02d15672fefa0d6be48c7aebe459c1c99dced7ac5e598508f",
Expand Down
24 changes: 16 additions & 8 deletions tests/bcr/MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions tests/bcr/patches/buildtools.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/labels/labels.go b/labels/labels.go
index 7564621..aba07c0 100644
--- a/labels/labels.go
+++ b/labels/labels.go
@@ -23,6 +23,8 @@ import (
"strings"
)

+const Patched = "hello"
+
// Label represents a Bazel target label.
type Label struct {
Repository string // Repository of the target, can be empty if the target belongs to the current repository
4 changes: 4 additions & 0 deletions tests/bcr/pkg/pkg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,7 @@ func TestArchiveOverrideUsed(t *testing.T) {
label := labels.Parse("@com_github_bazelbuild_buildtools//labels:labels")
require.NotEmpty(t, label)
}

func TestArchiveOverrideWithPatch(t *testing.T) {
require.Equal(t, labels.Patched, "hello")
}