Buck: export_file()

export_file()

This is liable to change in the future.

An export_file() takes a single file or folder and exposes it so other rules can use it. This is especially useful to work around package boundary violations where you want to use a file that is owned by a different build file.

Arguments

  • name (required) #

    A descriptive name for the rule. If this is the only parameter to the export_file() code, this must 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.

  • visibility (defaults to []) #

    List of build target patterns that identify the build rules that can include this rule in its deps.

  • 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',
)