Files
Jing Chen 7cc17225e6 Remove references to math/rand package's Read function.
The helper function is deprecated. The package gvisor.dev/gvisor/pkg/rand
depends on crypto/rand which performs worse thatn math/rand, the changes
are fine since they are not at any gVisor's hot path.

The ultimate goal is to migrate math/rand to math/rand/v2.
2024-10-16 18:17:15 +00:00

96 lines
2.5 KiB
Python

load("//tools:defs.bzl", "go_binary", "go_library", "go_test")
package(
default_applicable_licenses = ["//:license"],
licenses = ["notice"],
)
alias(
name = "mockgen",
actual = "@com_github_golang_mock//mockgen:mockgen",
)
MOCK_SRC_PACKAGE = "gvisor.dev/gvisor/pkg/p9"
# mockgen_reflect is a source file that contains mock generation code that
# imports the p9 package and generates a specification via reflection. The
# usual generation path must be split into two distinct parts because the full
# source tree is not available to all build targets. Only declared dependencies
# are available (and even then, not the Go source files).
genrule(
name = "mockgen_reflect",
testonly = 1,
outs = ["mockgen_reflect.go"],
cmd = (
"$(location :mockgen) " +
"-package p9test " +
"-prog_only " + MOCK_SRC_PACKAGE + " " +
"Attacher,File > $@"
),
tools = [":mockgen"],
)
# mockgen_exec is the binary that includes the above reflection generator.
# Running this binary will emit an encoded version of the p9 Attacher and File
# structures. This is consumed by the mocks genrule, below.
go_binary(
name = "mockgen_exec",
testonly = 1,
srcs = ["mockgen_reflect.go"],
deps = [
"//pkg/p9",
"@com_github_golang_mock//mockgen/model:go_default_library",
],
)
# mocks consumes the encoded output above, and generates the full source for a
# set of mocks. These are included directly in the p9test library.
genrule(
name = "mocks",
testonly = 1,
outs = ["mocks.go"],
cmd = (
"$(location :mockgen) " +
"-package p9test " +
"-exec_only $(location :mockgen_exec) " + MOCK_SRC_PACKAGE + " File > $@"
),
tools = [
":mockgen",
":mockgen_exec",
],
)
go_library(
name = "p9test",
srcs = [
"mocks.go",
"p9test.go",
],
visibility = ["//:sandbox"],
deps = [
"//pkg/atomicbitops",
"//pkg/fd",
"//pkg/log",
"//pkg/p9",
"//pkg/sync",
"//pkg/unet",
"@com_github_golang_mock//gomock:go_default_library",
"@org_golang_x_sys//unix:go_default_library",
],
)
go_test(
name = "client_test",
size = "medium",
srcs = ["client_test.go"],
library = ":p9test",
deps = [
"//pkg/fd",
"//pkg/p9",
"//pkg/rand",
"//pkg/sync",
"@com_github_golang_mock//gomock:go_default_library",
"@org_golang_x_sys//unix:go_default_library",
],
)