Skip to content

Commit

Permalink
Add prefix_root option
Browse files Browse the repository at this point in the history
  • Loading branch information
Ainsley Escorce-Jones committed Feb 9, 2017
1 parent adfad77 commit 512545a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
13 changes: 12 additions & 1 deletion go/def.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ def _go_prefix(ctx):
prefix = prefix + "/"
return prefix

def _prefix_root(ctx):
"""slash terminated go-prefix"""
root = ctx.attr.go_prefix.prefix_root
if root != "" and not root.endswith("/"):
root = root + "/"
return root

# TODO(bazel-team): it would be nice if Bazel had this built-in.
def symlink_tree_commands(dest_dir, artifact_dict):
"""Symlink_tree_commands returns a list of commands to create the
Expand Down Expand Up @@ -165,8 +172,12 @@ def _go_importpath(ctx):
Go importpath of the library
"""
path = _go_prefix(ctx)[:-1]
prefix_root = _prefix_root(ctx)
if ctx.label.package:
path += "/" + ctx.label.package
label = ctx.label.package
if ctx.label.package.startswith(prefix_root):
label = label[len(prefix_root):]
path += "/" + label
if ctx.label.name != _DEFAULT_LIB:
path += "/" + ctx.label.name
if path.rfind(_VENDOR_PREFIX) != -1:
Expand Down
11 changes: 8 additions & 3 deletions go/private/go_prefix.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,23 @@

def _go_prefix_impl(ctx):
"""go_prefix_impl provides the go prefix to use as a transitive info provider."""
return struct(go_prefix = ctx.attr.prefix)
return struct(go_prefix = ctx.attr.prefix, prefix_root = ctx.attr.prefix_root)

_go_prefix_rule = rule(
_go_prefix_impl,
attrs = {
"prefix": attr.string(mandatory = True),
"prefix_root": attr.string(default = ""),
},
)

def go_prefix(prefix):
"""go_prefix sets the Go import name to be used for this workspace."""
def go_prefix(prefix, prefix_root=""):
"""
go_prefix sets the Go import name to be used for this workspace.
prefix_root (optional) - subdirectory within the workspace in which go code is located
"""
_go_prefix_rule(name = "go_prefix",
prefix = prefix,
prefix_root = prefix_root,
visibility = ["//visibility:public" ]
)

0 comments on commit 512545a

Please sign in to comment.