Skip to main content

export_file

name

def name(
*,
name: str,
default_target_platform: None | str = ...,
target_compatible_with: list[str] = ...,
compatible_with: list[str] = ...,
exec_compatible_with: list[str] = ...,
visibility: list[str] = ...,
within_view: list[str] = ...,
metadata: OpaqueMetadata = ...,
tests: list[str] = ...,
modifiers: OpaqueMetadata = ...,
_apple_platforms: dict[str, str] = ...,
contacts: list[str] = ...,
default_host_platform: None | str = ...,
labels: list[str] = ...,
licenses: list[str] = ...,
mode: None | str = ...,
out: None | str = ...,
src: None | str = ...,
) -> None

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

Parameters

  • name: name of the target
  • default_target_platform: specifies the default target platform, used when no platforms are specified on the command line
  • target_compatible_with: a list of constraints that are required to be satisfied for this target to be compatible with a configuration
  • compatible_with: a list of constraints that are required to be satisfied for this target to be compatible with a configuration
  • exec_compatible_with: a list of constraints that are required to be satisfied for this target to be compatible with an execution platform
  • visibility: a list of visibility patterns restricting what targets can depend on this one
  • within_view: a list of visibility patterns restricting what this target can depend on
  • metadata: a key-value map of metadata associated with this target
  • tests: a list of targets that provide tests for this one
  • modifiers: an array of modifiers associated with this target
  • mode: 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.
  • out: The name which the file will be called if another rule depends on it instead of the name it already has.
  • src: The path to the file that should be exported.

Details

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