kythe.io@v0.0.68-0.20240422202219-7225dbc01741/tools/build_rules/verifier_test/jvm_verifier_test.bzl (about)

     1  # Copyright 2019 The Kythe Authors. All rights reserved.
     2  #
     3  # Licensed under the Apache License, Version 2.0 (the "License");
     4  # you may not use this file except in compliance with the License.
     5  # You may obtain a copy of the License at
     6  #
     7  #   http://www.apache.org/licenses/LICENSE-2.0
     8  #
     9  # Unless required by applicable law or agreed to in writing, software
    10  # distributed under the License is distributed on an "AS IS" BASIS,
    11  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  # See the License for the specific language governing permissions and
    13  # limitations under the License.
    14  
    15  load("@rules_java//java:defs.bzl", "JavaInfo")
    16  load(
    17      ":verifier_test.bzl",
    18      "KytheVerifierSources",
    19      "extract",
    20      "index_compilation",
    21      "verifier_test",
    22  )
    23  
    24  def _invoke(rulefn, name, **kwargs):
    25      """Invoke rulefn with name and kwargs, returning the label of the rule."""
    26      rulefn(name = name, **kwargs)
    27      return "//{}:{}".format(native.package_name(), name)
    28  
    29  def _jvm_extract_kzip_impl(ctx):
    30      jars = []
    31      for dep in ctx.attr.deps:
    32          jars.append(dep[JavaInfo].full_compile_jars)
    33      jars = depset(transitive = jars)
    34  
    35      extract(
    36          srcs = jars,
    37          ctx = ctx,
    38          extractor = ctx.executable.extractor,
    39          kzip = ctx.outputs.kzip,
    40          mnemonic = "JvmExtractKZip",
    41          opts = ctx.attr.opts,
    42          vnames_config = ctx.file.vnames_config,
    43      )
    44      return [KytheVerifierSources(files = depset())]
    45  
    46  jvm_extract_kzip = rule(
    47      attrs = {
    48          "extractor": attr.label(
    49              default = Label("//kythe/java/com/google/devtools/kythe/extractors/jvm:jar_extractor"),
    50              executable = True,
    51              cfg = "exec",
    52          ),
    53          "opts": attr.string_list(),
    54          "vnames_config": attr.label(
    55              default = Label("//external:vnames_config"),
    56              allow_single_file = True,
    57          ),
    58          "deps": attr.label_list(
    59              providers = [JavaInfo],
    60          ),
    61      },
    62      outputs = {"kzip": "%{name}.kzip"},
    63      implementation = _jvm_extract_kzip_impl,
    64  )
    65  
    66  def jvm_verifier_test(
    67          name,
    68          srcs,
    69          deps = [],
    70          size = "small",
    71          tags = [],
    72          indexer_opts = [],
    73          verifier_opts = ["--ignore_dups"],
    74          visibility = None):
    75      """Extract, analyze, and verify a JVM compilation.
    76  
    77      Args:
    78        srcs: Source files containing verifier goals for the JVM compilation
    79        deps: List of java/jvm verifier_test targets to be used as compilation dependencies
    80        indexer_opts: List of options passed to the indexer tool
    81        verifier_opts: List of options passed to the verifier tool
    82      """
    83      kzip = _invoke(
    84          jvm_extract_kzip,
    85          name = name + "_kzip",
    86          testonly = True,
    87          tags = tags,
    88          visibility = visibility,
    89          # This is a hack to depend on the .jar producer.
    90          deps = [d + "_kzip" for d in deps],
    91      )
    92      indexer = "//kythe/java/com/google/devtools/kythe/analyzers/jvm:class_file_indexer"
    93      entries = _invoke(
    94          index_compilation,
    95          name = name + "_entries",
    96          testonly = True,
    97          indexer = indexer,
    98          target_indexer = indexer,
    99          opts = indexer_opts,
   100          tags = tags + ["manual"],
   101          visibility = visibility,
   102          deps = [kzip],
   103      )
   104      return _invoke(
   105          verifier_test,
   106          name = name,
   107          size = size,
   108          srcs = [entries] + srcs,
   109          opts = verifier_opts,
   110          tags = tags,
   111          visibility = visibility,
   112          deps = [entries],
   113      )