buck targets
List information about the build targets in the current project.
buck targets <build target> | <build target pattern> ...
The buck targets command must take at least one parameter: a build target or build target pattern or a combination of these.
The following prints all build targets in the project (sorted alphabetically) to standard out:
buck targets //...
You can pass a list of targets to buck targets, and Buck prints information only for those targets. For example, the following command line prints the target main from the BUCK file in the root of the Buck project and all the targets from the BUCK file in the subdirectory myclass.
buck targets //:main //myclass:
The buck targets command is commonly used with the --show-output option to obtain the output paths for the build artifacts for Buck targets.
buck targets --show-output //java/com/myproject:binary > //java/com/myproject:binary buck-out/gen/java/com/myproject/binary.apk
Parameters
--typeThe types of target by which to filter. For example:
buck targets //java/com/myproject/... --type java_test java_binary
Note that the
--typeparameter comes after the specified targets.This parameter can be handy in programmatic tasks, such as running all of the Java tests under
//java/com/myproject:buck targets //java/com/myproject/... --type java_test | xargs buck test
--referenced-fileFilters targets by the list of rules that include the specified file in their transitive closure.
For example, to run all tests that could be affected by a particular file, you could use:
buck targets //java/com/myproject/... --type java_test \ --referenced-file java/com/example/Foo.java | xargs buck test
--jsonPrint a JSON representation of each target.
In addition, the JSON includes a list of
direct_dependenciesfor each target, which may include additional dependencies for targets whose descriptions implementImplicitDepsInferringDescription. The fully qualified names of targets are given.For example, when resolving a genrule, the direct dependencies includes both the build targets in
depsas well as any build targets in a script associated with the genrule.--output-attributesSpecify the attributes used in the JSON representation.
If you omit this option, Buck shows all attributes.
--print0Delimit targets using the ASCII NUL character if
--jsonis not specified. This facilitates use withxargs:buck targets --print0 | xargs -0 buck build
--resolve-aliasPrint the fully-qualified build target for the specified alias[es]. This command also accepts build targets. For more information, see
[alias]in the.buckconfigdocumentation.--show-outputPrint the relative paths to the output for each target after the target name. Note that some rules—such as
genrule—generate sources instead of build artifacts.--show-rulekeyPrint the rule keys, for the specified targets.
For example, if you have a rule named
maindefined in the build file in your current directory, the following command prints its rule key.buck targets --show-rulekey ':main'
Note that the rule key for a target is different from the target hash for that target. (See
show-target-hashbelow.) Further, the inputs for the computation of the rule key are not a superset of the inputs for the target hash. For example, the value of the visibility argument is not an input for the rule key but is an input for the target hash.--show-transitive-rulekeysWhen specified in conjunction with
--show-rulekey, prints the rule keys for the specified targets and their transitive closure.For example, if you have a rule named
maindefined in the build file in your current directory, the following command prints the rule key for that rule and the rule keys for all of the rules that are in its transitive closure.buck targets --show-rulekey --show-transitive-rulekeys ':main'
--show-target-hashPrint each rule's target hash after the rule's name. Target hashes can be used to detect which targets are affected when source files in BUCK files change: if a target is affected, its target hash will be different after the change from what it was before.
A target hash is created by finding all the transitive dependencies of the given target and hashing all their attributes and the files they reference. For more details about how the referenced files are hashed see the
--target-hash-file-modeflag. The format of the data that is hashed is undocumented and can change between Buck versions.--target-hash-file-modeModify how target hashes are computed.
Can be set to either
PATHS_AND_CONTENTSorPATHS_ONLY.If set to
PATHS_AND_CONTENTS(the default), the contents of all files referenced from the targets will be used to compute the target hash.If set to
PATHS_ONLY, only files' paths contribute to the hash.PATHS_ONLYwill generally be faster because it does not need to read all of the referenced files, but it will not detect file changes automatically. See--target-hash-modified-pathsfor another way to handle changes to referenced files without losing the performance benefits.--target-hash-modified-pathsModify how target hashes are computed.
If a target or its dependencies reference a file from the specified set of paths, the target's hash will be different than if this option had been omitted. Otherwise, the target's hash will be the same as if this option was omitted.
This option can be used to detect changes in referenced files if the list of modified files is available from an external source, such as a source control system.
This option is effective only when
--target-hash-file-modeis set toPATHS_ONLY. Otherwise, the actual contents of the files are used to detect modifications and this option is ignored.