Skip to content

Commit 683208d

Browse files
authored
Update overlay repository and rules_go (#139)
* In overlay repository rules, resolve labels before downloading the repo. This is a backport of bazel-contrib/rules_go#1349. * Update io_bazel_rules_go to tip of master. * Fix //internal/wspace:go_default_test, which was broken on macOS.
1 parent 39e8257 commit 683208d

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

WORKSPACE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ workspace(name = "bazel_gazelle")
33
git_repository(
44
name = "io_bazel_rules_go",
55
remote = "https://github.com/bazelbuild/rules_go",
6-
commit = "d36234e86678457e769ab62e597f90eef025bf8d",
6+
commit = "3e6e9bbf8f9ed35f5956fba80dde9283e121a66c",
77
)
88

99
load("@io_bazel_rules_go//go:def.bzl", "go_rules_dependencies", "go_register_toolchains")

internal/overlay_repository.bzl

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313
# limitations under the License.
1414

1515
def _http_archive_impl(ctx):
16+
overlay = _resolve_overlay(ctx, ctx.attr.overlay)
1617
ctx.download_and_extract(
1718
url = ctx.attr.urls,
1819
sha256 = ctx.attr.sha256,
1920
type = ctx.attr.type,
2021
stripPrefix = ctx.attr.strip_prefix,
2122
)
22-
23-
_apply_overlay(ctx, ctx.attr.overlay)
23+
_apply_overlay(ctx, overlay)
2424

2525
http_archive = repository_rule(
2626
implementation = _http_archive_impl,
@@ -43,12 +43,14 @@ def _git_repository_impl(ctx):
4343
if ctx.attr.commit and ctx.attr.tag:
4444
fail("'commit' and 'tag' may not both be specified")
4545

46+
overlay = _resolve_overlay(ctx, ctx.attr.overlay)
47+
4648
# TODO(jayconrod): sanitize inputs passed to git.
4749
revision = ctx.attr.commit if ctx.attr.commit else ctx.attr.tag
4850
_check_execute(ctx, ["git", "clone", "-n", ctx.attr.remote, "."], "failed to clone %s" % ctx.attr.remote)
4951
_check_execute(ctx, ["git", "checkout", revision], "failed to checkout revision %s in remote %s" % (revision, ctx.attr.remote))
5052

51-
_apply_overlay(ctx, ctx.attr.overlay)
53+
_apply_overlay(ctx, overlay)
5254

5355
git_repository = repository_rule(
5456
implementation = _git_repository_impl,
@@ -60,11 +62,23 @@ git_repository = repository_rule(
6062
},
6163
)
6264

65+
def _resolve_overlay(ctx, overlay):
66+
"""Resolve overlay labels to paths.
67+
68+
This should be done before downloading the repository, since it may
69+
trigger restarts.
70+
"""
71+
return [(ctx.path(src_label), dst_rel) for src_label, dst_rel in overlay.items()]
72+
6373
def _apply_overlay(ctx, overlay):
74+
"""Copies overlay files into the repository.
75+
76+
This should be done after downloading the repository, since it may replace
77+
downloaded files.
78+
"""
6479
# TODO(jayconrod): sanitize destination paths.
65-
for src_label, dst_rel in overlay.items():
66-
src_path = ctx.path(src_label)
67-
_check_execute(ctx, ["cp", src_path, dst_rel], "failed to copy file from %s" % src_label)
80+
for src_path, dst_rel in overlay:
81+
_check_execute(ctx, ["cp", src_path, dst_rel], "failed to copy file from %s" % src_path)
6882

6983
def _check_execute(ctx, arguments, message):
7084
res = ctx.execute(arguments)

internal/wspace/finder_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ func TestFind(t *testing.T) {
2929
t.Fatal(err)
3030
}
3131
defer os.RemoveAll(tmp)
32+
tmp, err = filepath.EvalSymlinks(tmp) // on macOS, TEST_TEMPDIR is a symlink
33+
if err != nil {
34+
t.Fatal(err)
35+
}
3236
if parent, err := Find(tmp); err == nil {
3337
t.Skipf("WORKSPACE visible in parent %q of tmp %q", parent, tmp)
3438
}

0 commit comments

Comments
 (0)