Skip to content

Commit

Permalink
Make go_test() with embedsrcs work (#2936)
Browse files Browse the repository at this point in the history
Even though there already is testing coverage for go_test() with
embedsrcs using generated files and such, I can't seem to get one of the
most trivial cases to work. The file to be embedded doesn't get placed
in the sandbox during GoCompilePkg.

This change addresses this by explicitly copying the embedsrcs from the
internal source to the external, which seems to make things work
properly.
  • Loading branch information
EdSchouten authored Sep 23, 2021
1 parent 63dfd99 commit 9f77676
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions go/private/rules/test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def _go_test_impl(ctx):
)
external_source = go.library_to_source(go, struct(
srcs = [struct(files = go_srcs)],
embedsrcs = [struct(files = internal_source.embedsrcs)],
deps = internal_archive.direct + [internal_archive],
x_defs = ctx.attr.x_defs,
), external_library, ctx.coverage_instrumented())
Expand Down
6 changes: 6 additions & 0 deletions tests/core/go_library/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,9 @@ go_bazel_test(
size = "medium",
srcs = ["embedsrcs_error_test.go"],
)

go_test(
name = "embedsrcs_simple_test",
srcs = ["embedsrcs_simple_test.go"],
embedsrcs = ["embedsrcs_static/no"],
)
6 changes: 6 additions & 0 deletions tests/core/go_library/embedsrcs_simple_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package embedsrcs_simple_test

import _ "embed"

//go:embed embedsrcs_static/no
var no []byte

0 comments on commit 9f77676

Please sign in to comment.