github.com/SagerNet/gvisor@v0.0.0-20210707092255-7731c139d75c/pkg/p9/p9test/BUILD (about)

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