gvisor.dev/gvisor@v0.0.0-20240520182842-f9d4d51c7e0f/pkg/p9/p9test/BUILD (about) 1 load("//tools:defs.bzl", "go_binary", "go_library", "go_test") 2 3 package( 4 default_applicable_licenses = ["//:license"], 5 licenses = ["notice"], 6 ) 7 8 alias( 9 name = "mockgen", 10 actual = "@com_github_golang_mock//mockgen:mockgen", 11 ) 12 13 MOCK_SRC_PACKAGE = "gvisor.dev/gvisor/pkg/p9" 14 15 # mockgen_reflect is a source file that contains mock generation code that 16 # imports the p9 package and generates a specification via reflection. The 17 # usual generation path must be split into two distinct parts because the full 18 # source tree is not available to all build targets. Only declared dependencies 19 # are available (and even then, not the Go source files). 20 genrule( 21 name = "mockgen_reflect", 22 testonly = 1, 23 outs = ["mockgen_reflect.go"], 24 cmd = ( 25 "$(location :mockgen) " + 26 "-package p9test " + 27 "-prog_only " + MOCK_SRC_PACKAGE + " " + 28 "Attacher,File > $@" 29 ), 30 tools = [":mockgen"], 31 ) 32 33 # mockgen_exec is the binary that includes the above reflection generator. 34 # Running this binary will emit an encoded version of the p9 Attacher and File 35 # structures. This is consumed by the mocks genrule, below. 36 go_binary( 37 name = "mockgen_exec", 38 testonly = 1, 39 srcs = ["mockgen_reflect.go"], 40 deps = [ 41 "//pkg/p9", 42 "@com_github_golang_mock//mockgen/model:go_default_library", 43 ], 44 ) 45 46 # mocks consumes the encoded output above, and generates the full source for a 47 # set of mocks. These are included directly in the p9test library. 48 genrule( 49 name = "mocks", 50 testonly = 1, 51 outs = ["mocks.go"], 52 cmd = ( 53 "$(location :mockgen) " + 54 "-package p9test " + 55 "-exec_only $(location :mockgen_exec) " + MOCK_SRC_PACKAGE + " File > $@" 56 ), 57 tools = [ 58 ":mockgen", 59 ":mockgen_exec", 60 ], 61 ) 62 63 go_library( 64 name = "p9test", 65 srcs = [ 66 "mocks.go", 67 "p9test.go", 68 ], 69 visibility = ["//:sandbox"], 70 deps = [ 71 "//pkg/atomicbitops", 72 "//pkg/fd", 73 "//pkg/log", 74 "//pkg/p9", 75 "//pkg/sync", 76 "//pkg/unet", 77 "@com_github_golang_mock//gomock:go_default_library", 78 "@org_golang_x_sys//unix:go_default_library", 79 ], 80 ) 81 82 go_test( 83 name = "client_test", 84 size = "medium", 85 srcs = ["client_test.go"], 86 library = ":p9test", 87 deps = [ 88 "//pkg/fd", 89 "//pkg/p9", 90 "//pkg/sync", 91 "@com_github_golang_mock//gomock:go_default_library", 92 "@org_golang_x_sys//unix:go_default_library", 93 ], 94 )