Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

go_path: support go:embed of generated files #3285

Merged
merged 2 commits into from
Nov 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion go/private/tools/path.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ def _go_path_impl(ctx):
for f in pkg.embedsrcs:
if src_dir == None:
fail("cannot relativize {}: src_dir is unset".format(f.path))
dst = pkg.dir + "/" + paths.relativize(f.path, src_dir)
embedpath = paths.relativize(f.path, f.root.path)
dst = pkg.dir + "/" + paths.relativize(embedpath, src_dir)
_add_manifest_entry(manifest_entries, manifest_entry_map, inputs, f, dst)
if ctx.attr.include_pkg:
for pkg in pkg_map.values():
Expand Down
10 changes: 10 additions & 0 deletions tests/core/go_path/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ test_suite(name = "go_path")
],
) for mode in ("archive", "copy", "link")]

go_path(
name = "transition_path",
testonly = True,
data = ["extra.txt"],
include_pkg = True,
mode = "copy",
deps = ["//tests/core/go_path/cmd/bin:pie"],
)

go_path(
name = "nodata_path",
testonly = True,
Expand Down Expand Up @@ -49,6 +58,7 @@ go_test(
":archive_path",
":copy_path",
":link_path",
":transition_path",
":nodata_path",
":notransitive_path",
],
Expand Down
11 changes: 11 additions & 0 deletions tests/core/go_path/cmd/bin/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ go_binary(
visibility = ["//visibility:public"],
)

go_binary(
name = "pie",
srcs = ["bin.go"],
importpath = "example.com/repo/cmd/bin",
visibility = ["//visibility:public"],
linkmode = "pie",
deps = [
"//tests/core/go_path/pkg/lib:go_default_library"
]
)

go_binary(
name = "cross",
srcs = ["bin.go"],
Expand Down
8 changes: 8 additions & 0 deletions tests/core/go_path/pkg/lib/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
load("@bazel_skylib//rules:copy_file.bzl", "copy_file")

go_library(
name = "go_default_library",
Expand All @@ -10,13 +11,20 @@ go_library(
],
embedsrcs = [
"embedded_src.txt",
"renamed_embedded_src.txt",
"template/index.html.tmpl",
],
importpath = "example.com/repo/pkg/lib",
visibility = ["//visibility:public"],
deps = [":transitive_lib"],
)

copy_file(
fmeum marked this conversation as resolved.
Show resolved Hide resolved
name = "rename_embedded_src.txt",
src = ":embedded_src.txt",
out = "renamed_embedded_src.txt",
)

go_test(
name = "go_default_test",
srcs = [
Expand Down
3 changes: 3 additions & 0 deletions tests/core/go_path/pkg/lib/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@ import (
//go:embed embedded_src.txt
var embeddedSource string

//go:embed renamed_embedded_src.txt
var renamedEmbeddedSource string

//go:embed template/index.html.tmpl
var indexTmpl string