Buck: buck targets

buck targets

Lists the build targets available in the current project.

The following will print all build targets in the project (sorted alphabetically) to standard out:

buck targets
This command can be handy in programmatic tasks, such as running all of the Java tests under //java/com/myproject:
buck targets --type java_test | \
  grep '//java/com/myproject' | \
  xargs buck test

A list of rules can also be passed into buck targets and Buck will only print out target information for those rules. For example:

buck targets --show-output //java/com/myproject:binary
> //java/com/myproject:binary buck-out/gen/java/com/myproject/binary.apk


  • --type The types of target to filter by. For example:

    buck targets --type java_test java_binary
  • --referenced-file Filters targets by the list of rules that include referenced-file in their transitive closure.

    For example, if a developer wanted to run all tests that could be affected by particular file, they would run:

    buck targets --type java_test \
      --referenced-file java/com/example/Foo.java |
      xargs buck test
  • --json Print JSON representation of each target.

    In addition, the JSON includes the list of 'direct_dependencies' for each target, which may include additional dependencies for targets whose descriptions implement ImplicitDepsInferringDescription. The fully qualified names of targets are given.

    For example, when resolving a genrule, the direct dependencies includes both the build targets in 'deps' as well as any build targets in a script associated with the genrule.

  • --output-attributes Specify attributes used in JSON representation.

    Omitting this option results in showing all attributes.

  • --print0 Delimit targets using the ASCII NUL character (when --json is not specified). This facilitates use with xargs:

    buck targets --print0 | xargs -0 buck build
  • --resolve-alias Print the fully-qualified build target for the specified alias[es]. This command also accepts build targets. See .buckconfig for more information.
  • --show-output Prints the relative path to the output for each rule after the rule name.
  • --show-target-hash Prints each rule's target hash after the rule name. A target hash is created by finding all of the transitive dependencies of the given target and hashing all of their attributes and files they reference. For more details about how the referenced files are hashed see the --target-hash-file-mode flag. The format of the data that is hashed is undocumented and can change between Buck versions. Target hashes can be used to detect which targets are affected when source files of BUCK files change: if a target is affected, its target hash will be different after the change from what it was before.
  • --target-hash-file-mode Modifies how target hashes are computed. Can be either PATHS_AND_CONTENTS or PATHS_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_ONLY will 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-paths for another way to handle changes to referenced files without losing the performance benefits.
  • --target-hash-modified-paths Modifies how target hashes are computed. This option is only effective when --target-hash-file-mode is set to PATHS_ONLY, otherwise the actual contents of the files are used to detect modifications and this option is ignored. If a target or its dependencies reference a file from this set, the target's hash will be different than if this option was 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, for example a source control system.