Skip to content

Commit

Permalink
Update overlay repository and rules_go (#139)
Browse files Browse the repository at this point in the history
* In overlay repository rules, resolve labels before downloading the
  repo. This is a backport of bazelbuild/rules_go#1349.
* Update io_bazel_rules_go to tip of master.
* Fix //internal/wspace:go_default_test, which was broken on macOS.
  • Loading branch information
jayconrod authored Feb 24, 2018
1 parent 39e8257 commit 683208d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
2 changes: 1 addition & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ workspace(name = "bazel_gazelle")
git_repository(
name = "io_bazel_rules_go",
remote = "https://github.com/bazelbuild/rules_go",
commit = "d36234e86678457e769ab62e597f90eef025bf8d",
commit = "3e6e9bbf8f9ed35f5956fba80dde9283e121a66c",
)

load("@io_bazel_rules_go//go:def.bzl", "go_rules_dependencies", "go_register_toolchains")
Expand Down
26 changes: 20 additions & 6 deletions internal/overlay_repository.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
# limitations under the License.

def _http_archive_impl(ctx):
overlay = _resolve_overlay(ctx, ctx.attr.overlay)
ctx.download_and_extract(
url = ctx.attr.urls,
sha256 = ctx.attr.sha256,
type = ctx.attr.type,
stripPrefix = ctx.attr.strip_prefix,
)

_apply_overlay(ctx, ctx.attr.overlay)
_apply_overlay(ctx, overlay)

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

overlay = _resolve_overlay(ctx, ctx.attr.overlay)

# TODO(jayconrod): sanitize inputs passed to git.
revision = ctx.attr.commit if ctx.attr.commit else ctx.attr.tag
_check_execute(ctx, ["git", "clone", "-n", ctx.attr.remote, "."], "failed to clone %s" % ctx.attr.remote)
_check_execute(ctx, ["git", "checkout", revision], "failed to checkout revision %s in remote %s" % (revision, ctx.attr.remote))

_apply_overlay(ctx, ctx.attr.overlay)
_apply_overlay(ctx, overlay)

git_repository = repository_rule(
implementation = _git_repository_impl,
Expand All @@ -60,11 +62,23 @@ git_repository = repository_rule(
},
)

def _resolve_overlay(ctx, overlay):
"""Resolve overlay labels to paths.
This should be done before downloading the repository, since it may
trigger restarts.
"""
return [(ctx.path(src_label), dst_rel) for src_label, dst_rel in overlay.items()]

def _apply_overlay(ctx, overlay):
"""Copies overlay files into the repository.
This should be done after downloading the repository, since it may replace
downloaded files.
"""
# TODO(jayconrod): sanitize destination paths.
for src_label, dst_rel in overlay.items():
src_path = ctx.path(src_label)
_check_execute(ctx, ["cp", src_path, dst_rel], "failed to copy file from %s" % src_label)
for src_path, dst_rel in overlay:
_check_execute(ctx, ["cp", src_path, dst_rel], "failed to copy file from %s" % src_path)

def _check_execute(ctx, arguments, message):
res = ctx.execute(arguments)
Expand Down
4 changes: 4 additions & 0 deletions internal/wspace/finder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ func TestFind(t *testing.T) {
t.Fatal(err)
}
defer os.RemoveAll(tmp)
tmp, err = filepath.EvalSymlinks(tmp) // on macOS, TEST_TEMPDIR is a symlink
if err != nil {
t.Fatal(err)
}
if parent, err := Find(tmp); err == nil {
t.Skipf("WORKSPACE visible in parent %q of tmp %q", parent, tmp)
}
Expand Down

0 comments on commit 683208d

Please sign in to comment.