Skip to content

Commit

Permalink
Allow empty go_prefix.
Browse files Browse the repository at this point in the history
Fixes #676.

--
Change-Id: I7474d3e3071c99452b6e1835d6f70671f34b1fd9
Reviewed-on: https://bazel-review.googlesource.com/#/c/2693
MOS_MIGRATED_REVID=112564791
  • Loading branch information
hanwen authored and lberki committed Jan 20, 2016
1 parent c4af828 commit 17e419e
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
49 changes: 49 additions & 0 deletions src/test/shell/bazel/bazel_go_example_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,53 @@ EOF
grep "Runfile: 12345" out || fail "binary output suspect"
}


function test_empty_prefix() {
setup_go

cat <<EOF > BUILD
load("/tools/build_rules/go/def", "go_prefix")
go_prefix("")
EOF

rm -rf ex
mkdir -p ex/
cat <<EOF > ex/m.go
package main
import (
"fmt"
"library"
)
func main() {
fmt.Println(library.F())
}
EOF
cat <<EOF > ex/BUILD
load("/tools/build_rules/go/def", "go_library", "go_binary")
go_binary(name = "m",
srcs = [ "m.go" ],
deps = [ "//library:go_default_library" ])
EOF

mkdir -p library

cat <<EOF > library/BUILD
package(default_visibility=["//visibility:public"])
load("/tools/build_rules/go/def", "go_library", "go_binary")
go_library(name = "go_default_library",
srcs = [ "l.go"])
EOF

cat <<EOF > library/l.go
package library
func F() int { return 42 }
EOF

assert_build //ex:m
test -x ./bazel-bin/ex/m || fail "binary not found"
(./bazel-bin/ex/m > out) || fail "binary does not execute"
grep "42" out || fail "binary output suspect"
}

run_suite "go_examples"
4 changes: 3 additions & 1 deletion tools/build_rules/go/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ They currently do not support (in order of importance):
go_repositories()
```

* Add a `BUILD` file to the top of your workspace, containing
* Add a `BUILD` file to the top of your workspace, declaring the name of your
workspace using `go_prefix`. It is strongly recommended that the prefix is not
empty.

```python
load("/tools/build_rules/go/def", "go_prefix")
Expand Down
2 changes: 1 addition & 1 deletion tools/build_rules/go/def.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def _go_prefix_impl(ctx):
def _go_prefix(ctx):
"""slash terminated go-prefix"""
prefix = ctx.attr.go_prefix.go_prefix
if not prefix.endswith("/"):
if prefix != "" and not prefix.endswith("/"):
prefix = prefix + "/"
return prefix

Expand Down

0 comments on commit 17e419e

Please sign in to comment.