Skip to main content

export_file

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

Function Signature

def export_file(
*,
name: str,
default_target_platform: None | str = None,
target_compatible_with: list[str] = [],
compatible_with: list[str] = [],
exec_compatible_with: list[str] = [],
visibility: list[str] = [],
within_view: list[str] = ["PUBLIC"],
metadata: OpaqueMetadata = {},
tests: list[str] = [],
modifiers: OpaqueMetadata = [],
_apple_platforms: dict[str, str] = {},
constraint_overrides: list[None | str] = [],
contacts: list[str] = [],
default_host_platform: None | str = None,
executable_bit_override: None | bool = None,
labels: list[str] = [],
licenses: list[str] = [],
mode: None | str = None,
out: None | str = None,
platform_override: None | str = None,
src: None | str = None,
uses_experimental_content_based_path_hashing: bool = False,
) -> None

Parameters

  • name: (required)

    name of the target

  • default_target_platform: (defaults to: None)

    specifies the default target platform, used when no platforms are specified on the command line

  • target_compatible_with: (defaults to: [])

    a list of constraints that are required to be satisfied for this target to be compatible with a configuration

  • compatible_with: (defaults to: [])

    a list of constraints that are required to be satisfied for this target to be compatible with a configuration

  • exec_compatible_with: (defaults to: [])

    a list of constraints that are required to be satisfied for this target to be compatible with an execution platform

  • visibility: (defaults to: [])

    a list of visibility patterns restricting what targets can depend on this one

  • within_view: (defaults to: ["PUBLIC"])

    a list of visibility patterns restricting what this target can depend on

  • metadata: (defaults to: {})

    a key-value map of metadata associated with this target

  • tests: (defaults to: [])

    a list of targets that provide tests for this one

  • modifiers: (defaults to: [])

    an array of modifiers associated with this target

  • executable_bit_override: (defaults to: None)

    Override the executable bit of the file. If not set, the executable bit is preserved.

  • mode: (defaults to: None)

    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: (defaults to: None)

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

  • src: (defaults to: None)

    The path to the file that should be exported.

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