A build target is a string that is used to identify a build rule in your project.
Here is an example of a fully-qualified build target:
//java/com/facebook/share:uiA fully-qualified build target has three components:
//prefix indicates that this path is relative to the root of your project.
java/com/facebook/sharecomponent between the
//prefix and the colon (
:) indicates that the build file can be found in the
uiafter the colon (
:) indicates the name of the build rule within the build file in which it is defines. Build rule names must be unique within a build file.
:) and is followed by only the third component (or "short name") of the fully-qualified build target. For example, within
:uican be used to reference
# This is in java/com/facebook/share/BUCK. java_binary( name = 'ui_jar', deps = [ # This would be the same as using: #Build targets are frequently used as arguments to build rules and to the command-line interface for Buck.
'//java/com/facebook/share:ui'':ui', ], )
Command-line ProtipWhen specifying a build target on the command-line, it can be tedious to type:
buck build //java/com/facebook/share:shareFortunately, Buck is loose with its parsing of build targets on the command-line (but is always strict when parsing them in build files). Specifically, the leading
//is optional on the command line, so the above could be:
buck build java/com/facebook/share:shareAlso, if there is a forward slash before the colon, it is ignored, so this could also be written as:
buck build java/com/facebook/share/:shareThis looks odd until you realize that the red text can be produced by tab-completing the path to the directory, which dramatically reduces how much you need to type:
buck build java/com/facebook/share/:shareFinally, if the final path element matches the value specified after the colon, it can be omitted from the command line:
# This is treated as //java/com/facebook/share:share.Note that this is even easier to tab-complete! For this reason, the name of the build rule for the primary deliverable in a build file is often named the same thing as the parent directory so it can be built from the command-line with less typing.
buck build java/com/facebook/share/