diff --git a/MODULE.bazel.lock b/MODULE.bazel.lock index 0ff47ee68..82ff4a2c8 100644 --- a/MODULE.bazel.lock +++ b/MODULE.bazel.lock @@ -177,7 +177,7 @@ "//bazel:generated.bzl%generated": { "general": { "bzlTransitiveDigest": "nMR2FBcoRPImVocN9DNOnm2NQWyTbJPu7SHJgAXsLFw=", - "usagesDigest": "8mdYbdjeyWhYUhUViUkt2T2IwtnrN+PHXdKUhqo0aqk=", + "usagesDigest": "RW2+z2kwE9p84qnYz0CxsJ3kl5x4i1Ps7ey0bnGHhEA=", "recordedFileInputs": {}, "recordedDirentsInputs": {}, "envVariables": {}, diff --git a/README.md b/README.md index c430e8cd3..c24c3a490 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,8 @@ use_repo(use_extension("@periphery//bazel:generated.bzl", "generated"), "periphe bazel run @periphery -- scan --bazel ``` +This command queries your project to identify all top-level targets, generates an implementation of the [scan](https://github.com/peripheryapp/periphery/blob/master/bazel/rules.bzl) rule, and then invokes Bazel. You can filter the top-level targets with the `-—bazel-filter ` option, where `` will be passed as the first argument to Bazel’s [filter](https://bazel.build/query/language#filter) operator. The generated query can be seen in the console with the `-—verbose` option. + ## How To Use ### The `scan` Command diff --git a/bazel/internal/scan/scan.bzl b/bazel/internal/scan/scan.bzl index 17dbb9988..fcd0e1489 100644 --- a/bazel/internal/scan/scan.bzl +++ b/bazel/internal/scan/scan.bzl @@ -26,7 +26,7 @@ def _force_indexstore_impl(settings, _attr): ], } -_force_indexstore = transition( +force_indexstore = transition( implementation = _force_indexstore_impl, inputs = [ "//command_line_option:features", @@ -138,7 +138,8 @@ def _scan_inputs_aspect_impl(target, ctx): ), ] -def _scan_impl(ctx): +# buildifier: disable=function-docstring +def scan_impl(ctx): swift_srcs_set = sets.make() indexstores_set = sets.make() plists_set = sets.make() @@ -203,30 +204,3 @@ scan_inputs_aspect = aspect( _scan_inputs_aspect_impl, attr_aspects = ["deps", "swift_target"], ) - -scan = rule( - doc = "Scans the top-level deps and their transitive deps for unused code.", - attrs = { - "deps": attr.label_list( - cfg = _force_indexstore, - mandatory = True, - aspects = [scan_inputs_aspect], - doc = "Top-level project targets to scan.", - ), - "config": attr.string(doc = "Path to the periphery.yml configuration file."), - "periphery": attr.label( - doc = "The periphery executable target.", - default = "@periphery//:periphery", - ), - "_template": attr.label( - allow_single_file = True, - default = "@periphery//bazel/internal/scan:scan_template.sh", - ), - }, - outputs = { - "project_config": "project_config.json", - "scan": "scan.sh", - }, - implementation = _scan_impl, - executable = True, -) diff --git a/bazel/rules.bzl b/bazel/rules.bzl index 1a4efde11..4fbaa763b 100644 --- a/bazel/rules.bzl +++ b/bazel/rules.bzl @@ -2,9 +2,31 @@ Periphery public rules. """ -load( - "//bazel/internal/scan:scan.bzl", - _scan = "scan", -) +load("//bazel/internal/scan:scan.bzl", "force_indexstore", "scan_impl", "scan_inputs_aspect") -scan = _scan +scan = rule( + doc = "Scans the top-level deps and their transitive deps for unused code.", + attrs = { + "deps": attr.label_list( + cfg = force_indexstore, + mandatory = True, + aspects = [scan_inputs_aspect], + doc = "Top-level project targets to scan.", + ), + "config": attr.string(doc = "Path to the periphery.yml configuration file."), + "periphery": attr.label( + doc = "The periphery executable target.", + default = "@periphery//:periphery", + ), + "_template": attr.label( + allow_single_file = True, + default = "@periphery//bazel/internal/scan:scan_template.sh", + ), + }, + outputs = { + "project_config": "project_config.json", + "scan": "scan.sh", + }, + implementation = scan_impl, + executable = True, +)