aboutsummaryrefslogtreecommitdiff
path: root/tests/core/go_library
diff options
context:
space:
mode:
Diffstat (limited to 'tests/core/go_library')
-rw-r--r--tests/core/go_library/BUILD.bazel168
-rw-r--r--tests/core/go_library/README.rst57
-rw-r--r--tests/core/go_library/def.bzl22
-rw-r--r--tests/core/go_library/embedsrcs_error_test.go138
-rw-r--r--tests/core/go_library/embedsrcs_gen_test.go.in20
-rw-r--r--tests/core/go_library/embedsrcs_simple_test.go6
-rw-r--r--tests/core/go_library/embedsrcs_static/contains_hidden/.hidden0
-rw-r--r--tests/core/go_library/embedsrcs_static/contains_hidden/.hidden_dir/.env0
-rw-r--r--tests/core/go_library/embedsrcs_static/contains_hidden/.hidden_dir/visible_file0
-rw-r--r--tests/core/go_library/embedsrcs_static/contains_hidden/_hidden_dir/.bashrc0
-rw-r--r--tests/core/go_library/embedsrcs_static/contains_hidden/_hidden_dir/_hidden_file0
-rw-r--r--tests/core/go_library/embedsrcs_static/contains_hidden/_hidden_dir/visible_file0
-rw-r--r--tests/core/go_library/embedsrcs_static/contains_hidden/visible/.bzr/file-under-version-control0
-rw-r--r--tests/core/go_library/embedsrcs_static/contains_hidden/visible/visible_file0
-rw-r--r--tests/core/go_library/embedsrcs_static/dir/_no0
-rw-r--r--tests/core/go_library/embedsrcs_static/dir/f0
-rw-r--r--tests/core/go_library/embedsrcs_static/file0
-rw-r--r--tests/core/go_library/embedsrcs_static/glob/_hidden0
-rw-r--r--tests/core/go_library/embedsrcs_static/glob/f0
-rw-r--r--tests/core/go_library/embedsrcs_static/no0
-rw-r--r--tests/core/go_library/embedsrcs_test.go199
-rw-r--r--tests/core/go_library/empty_bar.go3
-rw-r--r--tests/core/go_library/empty_baz.s1
-rw-r--r--tests/core/go_library/empty_foo.go3
-rw-r--r--tests/core/go_library/empty_main.go3
-rw-r--r--tests/core/go_library/gen_embedsrcs_files.go51
-rw-r--r--tests/core/go_library/import_alias_a_v2.go17
-rw-r--r--tests/core/go_library/import_alias_b.go17
-rw-r--r--tests/core/go_library/import_alias_test.go33
-rw-r--r--tests/core/go_library/inc.go1
-rw-r--r--tests/core/go_library/inc_asmhdr.s1
-rw-r--r--tests/core/go_library/inc_bar.s1
-rw-r--r--tests/core/go_library/inc_foo.s0
-rw-r--r--tests/core/go_library/no_srcs_test.go78
-rw-r--r--tests/core/go_library/package_height.go6
-rw-r--r--tests/core/go_library/package_height_dep_deep.go7
-rw-r--r--tests/core/go_library/package_height_dep_shallow.go3
-rw-r--r--tests/core/go_library/package_height_embeddee.go7
-rw-r--r--tests/core/go_library/package_height_embedder.go3
39 files changed, 845 insertions, 0 deletions
diff --git a/tests/core/go_library/BUILD.bazel b/tests/core/go_library/BUILD.bazel
new file mode 100644
index 00000000..25293cbe
--- /dev/null
+++ b/tests/core/go_library/BUILD.bazel
@@ -0,0 +1,168 @@
+load("//go:def.bzl", "go_binary", "go_library", "go_test")
+load("//go/tools/bazel_testing:def.bzl", "go_bazel_test")
+load(":def.bzl", "embedsrcs_files")
+
+go_library(
+ name = "empty",
+ srcs = [
+ # foo and bar have different package names
+ "empty_foo.go",
+ "empty_bar.go",
+ "empty_baz.s",
+ ],
+ importpath = "empty",
+)
+
+go_library(
+ name = "asm_include",
+ srcs = [
+ "inc.go",
+ "inc_bar.s",
+ "inc_foo.s",
+ ],
+ importpath = "asm_include",
+)
+
+go_library(
+ name = "asm_header",
+ srcs = [
+ "inc.go",
+ "inc_asmhdr.s",
+ ],
+ importpath = "asm_header",
+)
+
+go_library(
+ name = "package_height",
+ srcs = ["package_height.go"],
+ importpath = "package_height",
+ deps = [
+ ":package_height_dep_deep",
+ ":package_height_embedder",
+ ],
+)
+
+go_library(
+ name = "package_height_embedder",
+ srcs = ["package_height_embedder.go"],
+ embed = [":package_height_embeddee"],
+ importpath = "package_height/embed",
+ deps = [":package_height_dep_deep"],
+)
+
+go_library(
+ name = "package_height_embeddee",
+ srcs = ["package_height_embeddee.go"],
+ importpath = "package_height/embed",
+ deps = [":package_height_dep_shallow"],
+)
+
+go_library(
+ name = "package_height_dep_deep",
+ srcs = ["package_height_dep_deep.go"],
+ importpath = "package_height/dep",
+)
+
+go_library(
+ name = "package_height_dep_shallow",
+ srcs = ["package_height_dep_shallow.go"],
+ importpath = "package_height/dep",
+)
+
+go_test(
+ name = "import_alias_test",
+ srcs = ["import_alias_test.go"],
+ deps = [
+ ":import_alias_a_v2",
+ ":import_alias_b",
+ ":import_alias_b_v2",
+ ],
+)
+
+go_library(
+ name = "import_alias_a_v2",
+ srcs = ["import_alias_a_v2.go"],
+ importpath = "import_alias/a/v2",
+ importpath_aliases = ["import_alias/a"],
+)
+
+go_library(
+ name = "import_alias_b",
+ srcs = ["import_alias_b.go"],
+ importpath = "import_alias/b",
+)
+
+go_library(
+ name = "import_alias_b_v2",
+ importpath = "import_alias/b/v2",
+ importpath_aliases = ["import_alias/b"],
+)
+
+go_test(
+ name = "embedsrcs_test",
+ srcs = [
+ "embedsrcs_gen_test.go",
+ "embedsrcs_test.go",
+ ],
+ embedsrcs = [
+ ":embedsrcs_transitioned",
+ ":embedsrcs_dynamic",
+ "embedsrcs_test.go",
+ ] + glob(["embedsrcs_static/**"]),
+)
+
+genrule(
+ name = "embedsrcs_gen",
+ srcs = ["embedsrcs_gen_test.go.in"],
+ outs = ["embedsrcs_gen_test.go"],
+ cmd = "cp $< $@",
+)
+
+embedsrcs_files(
+ name = "embedsrcs_dynamic",
+ files = [
+ "dir/_no",
+ "dir/f",
+ "empty/",
+ "file",
+ "glob/_hidden",
+ "glob/f",
+ "no",
+ ],
+)
+
+go_binary(
+ name = "embedsrcs_transitioned",
+ srcs = ["empty_main.go"],
+ out = "embedsrcs_transitioned",
+ # Causes a transition on the incoming dependency edge.
+ race = "on",
+)
+
+go_binary(
+ name = "gen_embedsrcs_files",
+ srcs = ["gen_embedsrcs_files.go"],
+)
+
+go_bazel_test(
+ name = "embedsrcs_error_test",
+ size = "medium",
+ srcs = ["embedsrcs_error_test.go"],
+)
+
+go_test(
+ name = "embedsrcs_simple_test",
+ srcs = ["embedsrcs_simple_test.go"],
+ embedsrcs = ["embedsrcs_static/no"],
+)
+
+go_bazel_test(
+ name = "no_srcs_test",
+ size = "medium",
+ srcs = ["no_srcs_test.go"],
+)
+
+go_library(
+ name = "no_srcs_lib",
+ importpath = "github.com/bazelbuild/rules_go/tests/core/no_srcs_lib",
+)
diff --git a/tests/core/go_library/README.rst b/tests/core/go_library/README.rst
new file mode 100644
index 00000000..4410902f
--- /dev/null
+++ b/tests/core/go_library/README.rst
@@ -0,0 +1,57 @@
+Basic go_library functionality
+==============================
+
+.. _go_library: /docs/go/core/rules.md#_go_library
+.. _#1262: https://github.com/bazelbuild/rules_go/issues/1262
+.. _#1520: https://github.com/bazelbuild/rules_go/issues/1520
+.. _#1772: https://github.com/bazelbuild/rules_go/issues/1772
+.. _#2058: https://github.com/bazelbuild/rules_go/issues/2058
+.. _#3558: https://github.com/bazelbuild/rules_go/issues/3558
+
+empty
+-----
+
+Checks that a `go_library`_ will compile and link even if all the sources
+(including assembly sources) are filtered out by build constraints.
+
+asm_include
+-----------
+
+Checks that assembly files in a `go_library`_ may include other assembly
+files in the same library. Verifies `#1520`_.
+
+asm_header
+----------
+
+Checks that assembly files in a `go_library`_ may include ``"go_asm.h"``,
+generated by the compiler. Verifies `#1262`_.
+
+package_height
+--------------
+
+Checks that when a library embeds another library, the embedder's dependencies
+may override the embeddee's dependencies. Verifies `#1772`_.
+
+import_alias_test
+-----------------
+
+Checks that a library may import another library using one of the strings
+listed in ``importpath_aliases``. This is the basic mechanism for minimal
+module compatibility. Verifies `#2058`_.
+
+embedsrcs_test
+--------------
+
+Checks that `go_library`_ can match ``//go:embed`` directives to files listed
+in the ``embedsrcs`` attribute and can pass those files to the compiler.
+
+embedsrcs_error_test
+--------------------
+
+Verifies common errors with ``//go:embed`` directives are correctly reported.
+
+no_srcs_test
+------------
+
+Verifies that `go_library`_ targets without Go source files build concurrently,
+even unsandboxed, and reproducibly. Verifies `#3558`_. \ No newline at end of file
diff --git a/tests/core/go_library/def.bzl b/tests/core/go_library/def.bzl
new file mode 100644
index 00000000..613ea84d
--- /dev/null
+++ b/tests/core/go_library/def.bzl
@@ -0,0 +1,22 @@
+def _embedsrcs_files_impl(ctx):
+ name = ctx.attr.name
+ dir = ctx.actions.declare_directory(name)
+ args = [dir.path] + ctx.attr.files
+ ctx.actions.run(
+ outputs = [dir],
+ executable = ctx.executable._gen,
+ arguments = args,
+ )
+ return [DefaultInfo(files = depset([dir]))]
+
+embedsrcs_files = rule(
+ implementation = _embedsrcs_files_impl,
+ attrs = {
+ "files": attr.string_list(),
+ "_gen": attr.label(
+ default = ":gen_embedsrcs_files",
+ executable = True,
+ cfg = "exec",
+ ),
+ },
+)
diff --git a/tests/core/go_library/embedsrcs_error_test.go b/tests/core/go_library/embedsrcs_error_test.go
new file mode 100644
index 00000000..73629ddf
--- /dev/null
+++ b/tests/core/go_library/embedsrcs_error_test.go
@@ -0,0 +1,138 @@
+// Copyright 2021 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package embedsrcs_errors
+
+import (
+ "strings"
+ "testing"
+
+ "github.com/bazelbuild/rules_go/go/tools/bazel_testing"
+)
+
+func TestMain(m *testing.M) {
+ bazel_testing.TestMain(m, bazel_testing.Args{
+ Main: `
+-- BUILD.bazel --
+load("@io_bazel_rules_go//go:def.bzl", "go_library")
+
+go_library(
+ name = "invalid",
+ srcs = ["invalid.go"],
+ importpath = "invalid",
+)
+
+go_library(
+ name = "none",
+ srcs = ["none.go"],
+ importpath = "none",
+)
+
+go_library(
+ name = "multi_dir",
+ srcs = [
+ "a.go",
+ "b/b.go",
+ ],
+ embedsrcs = [
+ "a.txt",
+ "b/b.txt",
+ ],
+ importpath = "multi_dir",
+)
+
+go_library(
+ name = "embeds_vcs_dir",
+ srcs = ["c/c.go"],
+ embedsrcs = ["c/.bzr/c.txt"],
+ importpath = "embeds_vcs_dir",
+)
+-- invalid.go --
+package invalid
+
+import _ "embed"
+
+//go:embed ..
+var x string
+-- none.go --
+package none
+
+import _ "embed"
+
+//go:embed none
+var x string
+-- a.go --
+package a
+
+import _ "embed"
+
+//go:embed a.txt
+var x string
+-- a.txt --
+-- b/b.go --
+package a
+
+import _ "embed"
+
+//go:embed b.txt
+var y string
+-- b/b.txt --
+-- c/c.go --
+package a
+
+import _ "embed"
+
+//go:embed .bzr
+var z string
+-- c/.bzr/c.txt --
+`,
+ })
+}
+
+func Test(t *testing.T) {
+ for _, test := range []struct {
+ desc, target, want string
+ }{
+ {
+ desc: "invalid",
+ target: "//:invalid",
+ want: "invalid pattern syntax",
+ },
+ {
+ desc: "none",
+ target: "//:none",
+ want: "could not embed none: no matching files found",
+ },
+ {
+ desc: "multi_dir",
+ target: "//:multi_dir",
+ want: "source files with //go:embed should be in same directory",
+ },
+ {
+ desc: "embeds_vcs_dir",
+ target: "//:embeds_vcs_dir",
+ want: "could not embed .bzr: cannot embed directory .bzr: invalid name .bzr",
+ },
+ } {
+ t.Run(test.desc, func(t *testing.T) {
+ err := bazel_testing.RunBazel("build", test.target)
+ if err == nil {
+ t.Fatalf("expected error matching %q", test.want)
+ }
+ if errMsg := err.Error(); !strings.Contains(errMsg, test.want) {
+ t.Fatalf("expected error matching %q; got %v", test.want, errMsg)
+ }
+ })
+ }
+}
diff --git a/tests/core/go_library/embedsrcs_gen_test.go.in b/tests/core/go_library/embedsrcs_gen_test.go.in
new file mode 100644
index 00000000..a845b48e
--- /dev/null
+++ b/tests/core/go_library/embedsrcs_gen_test.go.in
@@ -0,0 +1,20 @@
+// Copyright 2021 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package embedsrcs
+
+import "embed"
+
+//go:embed embedsrcs_test.go
+var gen embed.FS
diff --git a/tests/core/go_library/embedsrcs_simple_test.go b/tests/core/go_library/embedsrcs_simple_test.go
new file mode 100644
index 00000000..32b3fdee
--- /dev/null
+++ b/tests/core/go_library/embedsrcs_simple_test.go
@@ -0,0 +1,6 @@
+package embedsrcs_simple_test
+
+import _ "embed"
+
+//go:embed embedsrcs_static/no
+var no []byte
diff --git a/tests/core/go_library/embedsrcs_static/contains_hidden/.hidden b/tests/core/go_library/embedsrcs_static/contains_hidden/.hidden
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/tests/core/go_library/embedsrcs_static/contains_hidden/.hidden
diff --git a/tests/core/go_library/embedsrcs_static/contains_hidden/.hidden_dir/.env b/tests/core/go_library/embedsrcs_static/contains_hidden/.hidden_dir/.env
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/tests/core/go_library/embedsrcs_static/contains_hidden/.hidden_dir/.env
diff --git a/tests/core/go_library/embedsrcs_static/contains_hidden/.hidden_dir/visible_file b/tests/core/go_library/embedsrcs_static/contains_hidden/.hidden_dir/visible_file
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/tests/core/go_library/embedsrcs_static/contains_hidden/.hidden_dir/visible_file
diff --git a/tests/core/go_library/embedsrcs_static/contains_hidden/_hidden_dir/.bashrc b/tests/core/go_library/embedsrcs_static/contains_hidden/_hidden_dir/.bashrc
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/tests/core/go_library/embedsrcs_static/contains_hidden/_hidden_dir/.bashrc
diff --git a/tests/core/go_library/embedsrcs_static/contains_hidden/_hidden_dir/_hidden_file b/tests/core/go_library/embedsrcs_static/contains_hidden/_hidden_dir/_hidden_file
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/tests/core/go_library/embedsrcs_static/contains_hidden/_hidden_dir/_hidden_file
diff --git a/tests/core/go_library/embedsrcs_static/contains_hidden/_hidden_dir/visible_file b/tests/core/go_library/embedsrcs_static/contains_hidden/_hidden_dir/visible_file
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/tests/core/go_library/embedsrcs_static/contains_hidden/_hidden_dir/visible_file
diff --git a/tests/core/go_library/embedsrcs_static/contains_hidden/visible/.bzr/file-under-version-control b/tests/core/go_library/embedsrcs_static/contains_hidden/visible/.bzr/file-under-version-control
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/tests/core/go_library/embedsrcs_static/contains_hidden/visible/.bzr/file-under-version-control
diff --git a/tests/core/go_library/embedsrcs_static/contains_hidden/visible/visible_file b/tests/core/go_library/embedsrcs_static/contains_hidden/visible/visible_file
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/tests/core/go_library/embedsrcs_static/contains_hidden/visible/visible_file
diff --git a/tests/core/go_library/embedsrcs_static/dir/_no b/tests/core/go_library/embedsrcs_static/dir/_no
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/tests/core/go_library/embedsrcs_static/dir/_no
diff --git a/tests/core/go_library/embedsrcs_static/dir/f b/tests/core/go_library/embedsrcs_static/dir/f
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/tests/core/go_library/embedsrcs_static/dir/f
diff --git a/tests/core/go_library/embedsrcs_static/file b/tests/core/go_library/embedsrcs_static/file
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/tests/core/go_library/embedsrcs_static/file
diff --git a/tests/core/go_library/embedsrcs_static/glob/_hidden b/tests/core/go_library/embedsrcs_static/glob/_hidden
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/tests/core/go_library/embedsrcs_static/glob/_hidden
diff --git a/tests/core/go_library/embedsrcs_static/glob/f b/tests/core/go_library/embedsrcs_static/glob/f
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/tests/core/go_library/embedsrcs_static/glob/f
diff --git a/tests/core/go_library/embedsrcs_static/no b/tests/core/go_library/embedsrcs_static/no
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/tests/core/go_library/embedsrcs_static/no
diff --git a/tests/core/go_library/embedsrcs_test.go b/tests/core/go_library/embedsrcs_test.go
new file mode 100644
index 00000000..0a4506e6
--- /dev/null
+++ b/tests/core/go_library/embedsrcs_test.go
@@ -0,0 +1,199 @@
+// Copyright 2021 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package embedsrcs
+
+import (
+ "bytes"
+ "embed"
+ "io/fs"
+ "strings"
+ "testing"
+)
+
+//go:embed embedsrcs_test.go
+var self embed.FS
+
+//go:embed embedsrcs_static/file embedsrcs_static/dir embedsrcs_static/glob/*
+var static embed.FS
+
+//go:embed embedsrcs_dynamic/file embedsrcs_dynamic/dir embedsrcs_dynamic/glob/*
+var dynamic embed.FS
+
+//go:embed embedsrcs_transitioned
+var transitioned embed.FS
+
+//go:embed *
+var star embed.FS
+
+//go:embed all:embedsrcs_static/contains_hidden
+var all embed.FS
+
+//go:embed embedsrcs_static/contains_hidden
+var allButHidden embed.FS
+
+func TestFiles(t *testing.T) {
+ for _, test := range []struct {
+ desc string
+ fsys fs.FS
+ want []string
+ }{
+ {
+ desc: "self",
+ fsys: self,
+ want: []string{
+ ".",
+ "embedsrcs_test.go",
+ },
+ },
+ {
+ desc: "gen",
+ fsys: gen,
+ want: []string{
+ ".",
+ "embedsrcs_test.go",
+ },
+ },
+ {
+ desc: "static",
+ fsys: static,
+ want: []string{
+ ".",
+ "embedsrcs_static",
+ "embedsrcs_static/dir",
+ "embedsrcs_static/dir/f",
+ "embedsrcs_static/file",
+ "embedsrcs_static/glob",
+ "embedsrcs_static/glob/_hidden",
+ "embedsrcs_static/glob/f",
+ },
+ },
+ {
+ desc: "dynamic",
+ fsys: dynamic,
+ want: []string{
+ ".",
+ "embedsrcs_dynamic",
+ "embedsrcs_dynamic/dir",
+ "embedsrcs_dynamic/dir/f",
+ "embedsrcs_dynamic/file",
+ "embedsrcs_dynamic/glob",
+ "embedsrcs_dynamic/glob/_hidden",
+ "embedsrcs_dynamic/glob/f",
+ },
+ },
+ {
+ desc: "transitioned",
+ fsys: transitioned,
+ want: []string{
+ ".",
+ "embedsrcs_transitioned",
+ },
+ },
+ {
+ desc: "star",
+ fsys: star,
+ want: []string{
+ ".",
+ "embedsrcs_dynamic",
+ "embedsrcs_dynamic/dir",
+ "embedsrcs_dynamic/dir/f",
+ "embedsrcs_dynamic/empty",
+ "embedsrcs_dynamic/file",
+ "embedsrcs_dynamic/glob",
+ "embedsrcs_dynamic/glob/f",
+ "embedsrcs_dynamic/no",
+ "embedsrcs_static",
+ "embedsrcs_static/contains_hidden",
+ "embedsrcs_static/contains_hidden/visible",
+ "embedsrcs_static/contains_hidden/visible/visible_file",
+ "embedsrcs_static/dir",
+ "embedsrcs_static/dir/f",
+ "embedsrcs_static/file",
+ "embedsrcs_static/glob",
+ "embedsrcs_static/glob/f",
+ "embedsrcs_static/no",
+ "embedsrcs_test.go",
+ "embedsrcs_transitioned",
+ },
+ },
+ {
+ desc: "all",
+ fsys: all,
+ want: []string{
+ ".",
+ "embedsrcs_static",
+ "embedsrcs_static/contains_hidden",
+ "embedsrcs_static/contains_hidden/.hidden",
+ "embedsrcs_static/contains_hidden/.hidden_dir",
+ "embedsrcs_static/contains_hidden/.hidden_dir/.env",
+ "embedsrcs_static/contains_hidden/.hidden_dir/visible_file",
+ "embedsrcs_static/contains_hidden/_hidden_dir",
+ "embedsrcs_static/contains_hidden/_hidden_dir/.bashrc",
+ "embedsrcs_static/contains_hidden/_hidden_dir/_hidden_file",
+ "embedsrcs_static/contains_hidden/_hidden_dir/visible_file",
+ "embedsrcs_static/contains_hidden/visible",
+ "embedsrcs_static/contains_hidden/visible/visible_file",
+ },
+ },
+ {
+ desc: "allButHidden",
+ fsys: allButHidden,
+ want: []string{
+ ".",
+ "embedsrcs_static",
+ "embedsrcs_static/contains_hidden",
+ "embedsrcs_static/contains_hidden/visible",
+ "embedsrcs_static/contains_hidden/visible/visible_file",
+ },
+ },
+ } {
+ t.Run(test.desc, func(t *testing.T) {
+ got, err := listFiles(test.fsys)
+ if err != nil {
+ t.Fatal(err)
+ }
+ gotStr := strings.Join(got, "\n")
+ wantStr := strings.Join(test.want, "\n")
+ if gotStr != wantStr {
+ t.Errorf("got:\n%s\nwant:\n%s", gotStr, wantStr)
+ }
+ })
+ }
+}
+
+func listFiles(fsys fs.FS) ([]string, error) {
+ var files []string
+ err := fs.WalkDir(fsys, ".", func(path string, _ fs.DirEntry, err error) error {
+ if err != nil {
+ return err
+ }
+ files = append(files, path)
+ return nil
+ })
+ if err != nil {
+ return nil, err
+ }
+ return files, nil
+}
+
+func TestContent(t *testing.T) {
+ data, err := fs.ReadFile(self, "embedsrcs_test.go")
+ if err != nil {
+ t.Fatal(err)
+ }
+ if !bytes.Contains(data, []byte("package embedsrcs")) {
+ t.Error("embedded content did not contain package declaration")
+ }
+}
diff --git a/tests/core/go_library/empty_bar.go b/tests/core/go_library/empty_bar.go
new file mode 100644
index 00000000..d73206c4
--- /dev/null
+++ b/tests/core/go_library/empty_bar.go
@@ -0,0 +1,3 @@
+// +build ignore
+
+package bar
diff --git a/tests/core/go_library/empty_baz.s b/tests/core/go_library/empty_baz.s
new file mode 100644
index 00000000..15934b3b
--- /dev/null
+++ b/tests/core/go_library/empty_baz.s
@@ -0,0 +1 @@
+// +build ignore
diff --git a/tests/core/go_library/empty_foo.go b/tests/core/go_library/empty_foo.go
new file mode 100644
index 00000000..ce414ed6
--- /dev/null
+++ b/tests/core/go_library/empty_foo.go
@@ -0,0 +1,3 @@
+// +build ignore
+
+package foo
diff --git a/tests/core/go_library/empty_main.go b/tests/core/go_library/empty_main.go
new file mode 100644
index 00000000..38dd16da
--- /dev/null
+++ b/tests/core/go_library/empty_main.go
@@ -0,0 +1,3 @@
+package main
+
+func main() {}
diff --git a/tests/core/go_library/gen_embedsrcs_files.go b/tests/core/go_library/gen_embedsrcs_files.go
new file mode 100644
index 00000000..68ff2fef
--- /dev/null
+++ b/tests/core/go_library/gen_embedsrcs_files.go
@@ -0,0 +1,51 @@
+// Copyright 2021 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package main
+
+import (
+ "fmt"
+ "io/ioutil"
+ "os"
+ "path/filepath"
+ "strings"
+)
+
+func main() {
+ dir := os.Args[1]
+ files := os.Args[2:]
+ if err := run(dir, files); err != nil {
+ fmt.Fprintf(os.Stderr, "%v\n", err)
+ os.Exit(1)
+ }
+}
+
+func run(dir string, files []string) error {
+ for _, file := range files {
+ path := filepath.Join(dir, file)
+ if strings.HasSuffix(path, "/") {
+ if err := os.MkdirAll(path, 0777); err != nil {
+ return err
+ }
+ } else {
+ if err := os.MkdirAll(filepath.Dir(path), 0777); err != nil {
+ return err
+ }
+ if err := ioutil.WriteFile(path, nil, 0666); err != nil {
+ return err
+ }
+ }
+ }
+ return nil
+}
diff --git a/tests/core/go_library/import_alias_a_v2.go b/tests/core/go_library/import_alias_a_v2.go
new file mode 100644
index 00000000..66326f94
--- /dev/null
+++ b/tests/core/go_library/import_alias_a_v2.go
@@ -0,0 +1,17 @@
+// Copyright 2019 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package a
+
+const A = "import_alias/a/v2"
diff --git a/tests/core/go_library/import_alias_b.go b/tests/core/go_library/import_alias_b.go
new file mode 100644
index 00000000..1fa79977
--- /dev/null
+++ b/tests/core/go_library/import_alias_b.go
@@ -0,0 +1,17 @@
+// Copyright 2019 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package b
+
+const B = "import_alias/b"
diff --git a/tests/core/go_library/import_alias_test.go b/tests/core/go_library/import_alias_test.go
new file mode 100644
index 00000000..aabec973
--- /dev/null
+++ b/tests/core/go_library/import_alias_test.go
@@ -0,0 +1,33 @@
+// Copyright 2019 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package import_alias
+
+import (
+ "import_alias/a"
+ "import_alias/b"
+ "testing"
+)
+
+func TestA(t *testing.T) {
+ if a.A != "import_alias/a/v2" {
+ t.Errorf("got %q; want %q", a.A, "import_alias/a/v2")
+ }
+}
+
+func TestB(t *testing.T) {
+ if b.B != "import_alias/b" {
+ t.Errorf("got %q; want %q", b.B, "import_alias/b")
+ }
+}
diff --git a/tests/core/go_library/inc.go b/tests/core/go_library/inc.go
new file mode 100644
index 00000000..bb5e9272
--- /dev/null
+++ b/tests/core/go_library/inc.go
@@ -0,0 +1 @@
+package inc
diff --git a/tests/core/go_library/inc_asmhdr.s b/tests/core/go_library/inc_asmhdr.s
new file mode 100644
index 00000000..230bbe2f
--- /dev/null
+++ b/tests/core/go_library/inc_asmhdr.s
@@ -0,0 +1 @@
+#include "go_asm.h"
diff --git a/tests/core/go_library/inc_bar.s b/tests/core/go_library/inc_bar.s
new file mode 100644
index 00000000..47eaec6b
--- /dev/null
+++ b/tests/core/go_library/inc_bar.s
@@ -0,0 +1 @@
+#include "inc_foo.s"
diff --git a/tests/core/go_library/inc_foo.s b/tests/core/go_library/inc_foo.s
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/tests/core/go_library/inc_foo.s
diff --git a/tests/core/go_library/no_srcs_test.go b/tests/core/go_library/no_srcs_test.go
new file mode 100644
index 00000000..8e6bebc0
--- /dev/null
+++ b/tests/core/go_library/no_srcs_test.go
@@ -0,0 +1,78 @@
+// Copyright 2021 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package no_srcs
+
+import (
+ "bytes"
+ "os"
+ "strings"
+ "testing"
+
+ "github.com/bazelbuild/rules_go/go/tools/bazel_testing"
+)
+
+func TestMain(m *testing.M) {
+ bazel_testing.TestMain(m, bazel_testing.Args{
+ Main: `
+-- BUILD.bazel --
+load("@io_bazel_rules_go//go:def.bzl", "go_library")
+
+[
+ go_library(
+ name = "lib_" + str(i),
+ srcs = [],
+ importpath = "example.com/some/path",
+ )
+ for i in range(1000)
+]
+`,
+ })
+}
+
+func Test(t *testing.T) {
+ commonArgs := []string{
+ "--spawn_strategy=local",
+ "--compilation_mode=dbg",
+ }
+
+ if err := bazel_testing.RunBazel(append([]string{"build", "//..."}, commonArgs...)...); err != nil {
+ t.Fatal(err)
+ }
+
+ out, err := bazel_testing.BazelOutput(append([]string{"cquery", "--output=files", "//..."}, commonArgs...)...)
+ if err != nil {
+ t.Fatal(err)
+ }
+ archives := strings.Split(strings.TrimSpace(string(out)), "\n")
+
+ if len(archives) != 1000 {
+ t.Fatalf("expected 1000 archives, got %d", len(archives))
+ }
+
+ referenceContent, err := os.ReadFile(archives[0])
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ for _, archive := range archives {
+ content, err := os.ReadFile(archive)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if !bytes.Equal(content, referenceContent) {
+ t.Fatalf("expected all archives to be identical, got:\n\n%s\n\n%s\n", string(content), string(referenceContent))
+ }
+ }
+}
diff --git a/tests/core/go_library/package_height.go b/tests/core/go_library/package_height.go
new file mode 100644
index 00000000..cafb5faf
--- /dev/null
+++ b/tests/core/go_library/package_height.go
@@ -0,0 +1,6 @@
+package height
+
+import "package_height/embed"
+import "package_height/dep"
+
+var X = embed.T{F: dep.T{}}
diff --git a/tests/core/go_library/package_height_dep_deep.go b/tests/core/go_library/package_height_dep_deep.go
new file mode 100644
index 00000000..139a805d
--- /dev/null
+++ b/tests/core/go_library/package_height_dep_deep.go
@@ -0,0 +1,7 @@
+package dep
+
+import "os"
+
+type T struct {
+ F *os.File
+}
diff --git a/tests/core/go_library/package_height_dep_shallow.go b/tests/core/go_library/package_height_dep_shallow.go
new file mode 100644
index 00000000..1902c035
--- /dev/null
+++ b/tests/core/go_library/package_height_dep_shallow.go
@@ -0,0 +1,3 @@
+package dep
+
+type T struct{}
diff --git a/tests/core/go_library/package_height_embeddee.go b/tests/core/go_library/package_height_embeddee.go
new file mode 100644
index 00000000..0c36a32a
--- /dev/null
+++ b/tests/core/go_library/package_height_embeddee.go
@@ -0,0 +1,7 @@
+package embed
+
+import "package_height/dep"
+
+type T struct {
+ F dep.T
+}
diff --git a/tests/core/go_library/package_height_embedder.go b/tests/core/go_library/package_height_embedder.go
new file mode 100644
index 00000000..81a00369
--- /dev/null
+++ b/tests/core/go_library/package_height_embedder.go
@@ -0,0 +1,3 @@
+package embed
+
+var X = T{}