gvisor.dev/gvisor@v0.0.0-20240520182842-f9d4d51c7e0f/tools/show_paths.bzl (about)

     1  """Formatter to extract the output files from a target."""
     2  
     3  def format(target):
     4      provider_map = providers(target)
     5      if not provider_map:
     6          return ""
     7      outputs = dict()
     8  
     9      # Try to resolve in order.
    10      files_to_run = provider_map.get("FilesToRunProvider", None)
    11      default_info = provider_map.get("DefaultInfo", None)
    12      output_group_info = provider_map.get("OutputGroupInfo", None)
    13      if files_to_run and files_to_run.executable:
    14          outputs[files_to_run.executable.path] = True
    15      elif default_info:
    16          for x in default_info.files:
    17              outputs[x.path] = True
    18      elif output_group_info:
    19          for entry in dir(output_group_info):
    20              # Filter out all built-ins and anything that is not a depset.
    21              if entry.startswith("_") or not hasattr(getattr(output_group_info, entry), "to_list"):
    22                  continue
    23              for x in getattr(output_group_info, entry).to_list():
    24                  outputs[x.path] = True
    25  
    26      # Return all found files.
    27      return "\n".join(outputs.keys())