# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under both the MIT license found in the
# LICENSE-MIT file in the root directory of this source tree and the Apache
# License, Version 2.0 found in the LICENSE-APACHE file in the root directory
# of this source tree.
load("@prelude//rust:outputs.bzl", "RustcExtraOutputsInfo")
def _check_targets_impl(ctx: bxl.Context) -> list[bxl.EnsuredArtifact]:
uquery_owners = ctx.uquery().owner(ctx.cli_args.file)
target_universe = ctx.target_universe(uquery_owners)
owners = ctx.cquery().owner(ctx.cli_args.file, target_universe.target_set())
nodes = ctx.cquery().kind("^(rust_binary|rust_library|rust_test)$", owners)
if len(nodes) == 0:
return []
analysis = ctx.analysis(nodes).values()
artifacts = []
for a in analysis:
o = a.providers()[RustcExtraOutputsInfo]
if ctx.cli_args.use_clippy:
artifacts.append(o.clippy_incr.diag_json)
else:
artifacts.append(o.metadata_incr.diag_json)
art_output = ctx.output.ensure_multiple(artifacts)
return [
artifact.abs_path()
for artifact in art_output
]
def _run(ctx: bxl.Context) -> None:
diagnostic_paths = _check_targets_impl(ctx)
out = {
"diagnostic_paths": diagnostic_paths,
"project_root": ctx.root(),
}
ctx.output.print_json(out)
check = bxl_main(
impl = _run,
cli_args = {
"file": cli_args.string(),
"use-clippy": cli_args.bool(),
},
)