aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rwxr-xr-xsrc/test/shell/bazel/bazel_go_example_test.sh46
-rw-r--r--tools/build_rules/go/def.bzl2
2 files changed, 48 insertions, 0 deletions
diff --git a/src/test/shell/bazel/bazel_go_example_test.sh b/src/test/shell/bazel/bazel_go_example_test.sh
index 8183414f82..fb5fa1062d 100755
--- a/src/test/shell/bazel/bazel_go_example_test.sh
+++ b/src/test/shell/bazel/bazel_go_example_test.sh
@@ -151,7 +151,53 @@ EOF
test -x ./bazel-bin/ex/runfiles_test || fail "binary not found"
(./bazel-bin/ex/runfiles_test > out) || fail "binary does not execute"
grep "Runfile: 12345" out || fail "binary output suspect"
+}
+
+function test_runfiles_lib() {
+ mkdir -p ex/
+ cat <<EOF > ex/m.go
+package main
+import (
+ "fmt"
+ "io/ioutil"
+ "log"
+
+ "prefix/ex"
+)
+func main() {
+ rfcontent, err := ioutil.ReadFile(ex.RunfilePath())
+ if err != nil {
+ log.Fatalf("Runfiles test binary: Error reading from runfile: %v", err)
+ }
+
+ fmt.Printf("Runfile: %s\n", rfcontent)
+}
+
+EOF
+ cat <<EOF > ex/l.go
+package ex
+func RunfilePath() string { return "ex/runfile" }
+EOF
+
+ cat <<EOF > ex/runfile
+12345
+EOF
+
+ cat <<EOF > ex/BUILD
+load("/tools/build_rules/go/def", "go_library", "go_binary")
+go_library(name = "go_default_library",
+ data = [ "runfile" ],
+ srcs = [ "l.go"])
+go_binary(name = "m",
+ srcs = [ "m.go" ],
+ deps = [ ":go_default_library" ])
+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 "Runfile: 12345" out || fail "binary output suspect"
}
run_suite "go_examples"
diff --git a/tools/build_rules/go/def.bzl b/tools/build_rules/go/def.bzl
index f63da7b942..4c304f5b49 100644
--- a/tools/build_rules/go/def.bzl
+++ b/tools/build_rules/go/def.bzl
@@ -210,10 +210,12 @@ def go_library_impl(ctx):
for dep in ctx.attr.deps:
transitive_libs += dep.transitive_go_library_object
+ runfiles = ctx.runfiles(collect_data = True)
return struct(
label = ctx.label,
files = set([out_lib]),
direct_deps = deps,
+ runfiles = runfiles,
go_sources = sources,
go_library_object = out_lib,
transitive_go_library_object = transitive_libs)