Buck: export_file()
Support Ukraine. Help Provide Humanitarian Aid to Ukraine.

export_file()

This is liable to change in the future.

Warning: this build rule is deprecated for folders. Use filegroup instead. It is still supported for individual files.

An export_file() takes a single file or folder and exposes it so other rules can use it.

Arguments

  • name (required) #

    The short name for this build target. If this is the only parameter, this must also be the path to the file.

  • src (defaults to None) #

    The path to the file that should be exported.

  • out (defaults to None) #

    The name which the file will be called if another rule depends on it instead of the name it already has.

  • mode (defaults to copy) #

    How files are referenced internally in buck. If set to 'copy', then a full copy will be made into the new location in buck-out. If set to 'reference', the original file will be used by internal build rules in-place. However, this mode does not work across repositories or if the 'out' property is set. For read-only operations, 'reference' can be more performant.

  • visibility (defaults to []) #

    List of build target patterns that identify the build rules that can include this rule as a dependency, for example, by listing it in their deps or exported_deps attributes. For more information, see visibility.

  • licenses (defaults to []) #

    Set of license files for this library. To get the list of license files for a given build rule and all of its dependencies, you can use buck query.

  • labels (defaults to []) #

    Set of arbitrary strings which allow you to annotate a build rule with tags that can be searched for over an entire dependency tree using buck query attrfilter().

Examples

The best way to see how the export_file() rule works is with some examples. The common case is:

export_file(
  name = 'example.html',
)

# This is equivalent to

export_file(
  name = 'example.html',
  src = 'example.html',
  out = 'example.html',
)

It is sometimes useful to refer to the file not by its path, but by a more logical name:

export_file(
  name = 'example',
  src = 'example.html',
)

# This is equivalent to

export_file(
  name = 'example',
  src = 'example.html',
  out = 'example.html',
)

Finally, there are occasions where you want to export a file more than once but want to copy it to a different name for each output:

export_file(
  name = 'runner',
  src = 'RemoteRunner.html',
)

export_file(
  name = 'runner_hta',
  src = 'RemoteRunner.html',
  out = 'RemoteRunner.hta',
)

Using the export_file() rule is also simple:

export_file(
  name = 'example',
  src = 'example.html',
)

genrule(
  name = 'demo',
  out = 'result.html'
  cmd = 'cp $(location :example) $OUT',
)