apple_test
An apple_test() rule contains Objective-C/C++ code which can be built and used to test code contained in other rules. The tests can be executed by running buck test.
Function Signature
def apple_test(
*,
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] = {},
_apple_toolchain: str = "gh_facebook_buck2_shims_meta//:apple-default",
_apple_tools: str = "prelude//apple/tools:apple-tools",
_apple_xctoolchain: str = "gh_facebook_buck2_shims_meta//:apple-xctoolchain",
_apple_xctoolchain_bundle_id: str = "gh_facebook_buck2_shims_meta//:apple-xctoolchain-bundle-id",
_bundling_cache_buster: None | str = None,
_bundling_log_file_enabled: bool = False,
_bundling_log_file_level: None | str = None,
_code_signing_configuration: None | str = None,
_codesign_command_override: None | str = None,
_codesign_identities_command_override: None | str = None,
_codesign_type: None | str = None,
_compile_resources_locally_override: None | bool = None,
_embed_provisioning_profile_when_adhoc_code_signing: None | bool = None,
_enable_library_evolution: bool = select({"prelude//features/apple:swift_library_evolution_enabled": True, "DEFAULT": False}),
_fast_adhoc_signing_enabled_default: bool = select({"prelude//features/apple:fast_adhoc_signing_disabled": False, "prelude//features/apple:fast_adhoc_signing_enabled": True, "DEFAULT": True}),
_fast_provisioning_profile_parsing_enabled: bool = False,
_incremental_bundling_enabled: bool = False,
_info_plist_identify_build_system_default: bool = False,
_inject_test_env: str = "prelude//test/tools:inject_test_env",
_ipad_simulator: str | (str, str) = gh_facebook_buck2_shims_meta//xplat/buck2/platform/apple:ipad_simulator,
_iphone_booted_simulator: str | (str, str) = gh_facebook_buck2_shims_meta//xplat/buck2/platform/apple:iphone_booted_simulator,
_iphone_unbooted_simulator: str | (str, str) = gh_facebook_buck2_shims_meta//xplat/buck2/platform/apple:iphone_unbooted_simulator,
_profile_bundling_enabled: bool = False,
_provisioning_profiles: str = "gh_facebook_buck2_shims_meta//xplat/buck2/platform/apple:provisioning_profiles",
_resource_bundle: None | str = None,
_skip_adhoc_resigning_scrubbed_frameworks_default: bool = select({"prelude//features/apple/constraints:skip_adhoc_resigning_scrubbed_frameworks_disabled": False, "prelude//features/apple/constraints:skip_adhoc_resigning_scrubbed_frameworks_enabled": True, "DEFAULT": False}),
_skip_adhoc_resigning_scrubbed_frameworks_override: None | bool = None,
_skip_swift_incremental_outputs: bool = False,
_strict_provisioning_profile_search_default: bool = select({"prelude//features/apple:strict_provisioning_profile_search_enabled": True, "DEFAULT": True}),
_swift_enable_testing: bool = True,
_test_toolchain: str = "gh_facebook_buck2_shims_meta//:test",
_use_entitlements_when_adhoc_code_signing: None | bool = None,
_watch_simulator: str | (str, str) = gh_facebook_buck2_shims_meta//xplat/buck2/platform/apple:watch_simulator,
allow_cache_upload: None | bool = None,
asset_catalogs_compilation_options: dict[str, typing.Any] = {},
attrs_validators: None | list[str] = None,
binary: None | str = None,
bridging_header: None | str = None,
can_be_asset: None | bool = None,
code_signing_configuration: None | str = None,
codesign_flags: list[str] = [],
codesign_identity: None | str = None,
codesign_type: None | str = None,
compiler_flags: list[str] = [],
constraint_overrides: list[None | str] = [],
contacts: list[str] = [],
cxx_runtime_type: None | str = None,
default_host_platform: None | str = None,
default_platform: None | str = None,
defaults: dict[str, str] = {},
deps: list[str] = [],
destination_specifier: dict[str, str] = {},
devirt_enabled: bool = False,
diagnostics: dict[str, str] = {},
embed_provisioning_profile_when_adhoc_code_signing: bool = False,
embed_xctest_frameworks_in_test_host_app: None | bool = None,
enable_cxx_interop: bool = False,
enable_library_evolution: None | bool = None,
enforce_minimum_os_plist_key: bool = False,
entitlements_file: None | str = None,
env: None | dict[str, str] = None,
executable_name: None | str = None,
exported_header_style: str = "local",
exported_headers: list[str] | dict[str, str] = [],
exported_lang_preprocessor_flags: dict[str, list[str]] = {},
exported_linker_flags: list[str] = [],
exported_post_linker_flags: list[str] = [],
exported_preprocessor_flags: list[str] = [],
extension: str,
extra_xcode_files: list[str] = [],
extra_xcode_sources: list[str] = [],
fast_adhoc_signing_enabled: None | bool = None,
fat_lto: bool = False,
focused_list_target: None | str = None,
force_static: None | bool = None,
frameworks: list[str] = [],
header_namespace: None | str = None,
header_path_prefix: None | str = None,
headers: list[str] | dict[str, str] = [],
headers_as_raw_headers_mode: None | str = None,
include_directories: list[str] = [],
incremental_bundling_enabled: None | bool = None,
info_plist: str,
info_plist_identify_build_system: None | bool = None,
info_plist_substitutions: dict[str, str] = {},
is_ui_test: bool = False,
labels: list[str] = [],
lang_compiler_flags: dict[str, list[str]] = {},
lang_preprocessor_flags: dict[str, list[str]] = {},
libraries: list[str] = [],
licenses: list[str] = [],
link_execution_preference: None | str = None,
link_group: None | str = None,
link_group_map: None | str | list[(str, list[(None | str | list[None | str], str, None | str | list[str], None | str)], None | dict[str, typing.Any])] = None,
link_ordering: None | str = None,
link_style: str = "static",
link_whole: None | bool = None,
linker_extra_outputs: list[str] = [],
linker_flags: list[str] = [],
minimum_os_version: None | str = None,
modular: bool = False,
module_name: None | str = None,
module_requires_cxx: bool = False,
platform_override: None | str = None,
post_linker_flags: list[str] = [],
precompiled_header: None | str = None,
preferred_linkage: str = "shared",
prefix_header: None | str = None,
preprocessor_flags: list[str] = [],
provisioning_profile_filter: None | str = None,
public_include_directories: list[str] = [],
public_system_include_directories: list[str] = [],
raw_headers: list[str] = [],
reexport_all_header_dependencies: None | bool = None,
resource_group: None | str = None,
resource_group_map: None | str = None,
run_test_separately: bool = False,
runner: None | str = None,
sanitizer_runtime_enabled: None | bool = None,
sdk_modules: list[str] = [],
serialize_debugging_options: None | bool = None,
skip_adhoc_resigning_scrubbed_frameworks: None | bool = None,
skip_copying_swift_stdlib: None | bool = None,
snapshot_reference_images_path: None | str = None,
soname: None | str = None,
specs: None | str = None,
srcs: list[str | (str, list[str])] = [],
static_library_basename: None | str = None,
strict_provisioning_profile_search: None | bool = None,
stripped: bool = False,
supported_platforms_regex: None | str = None,
supports_merged_linking: None | bool = None,
swift_compilation_mode: str = "wmo",
swift_compiler_flags: list[str] = [],
swift_incremental_file_hashing: bool = False,
swift_incremental_logging: bool = False,
swift_interface_compilation_enabled: bool = False,
swift_macro_deps: list[str] = [],
swift_module_skip_function_bodies: bool = True,
swift_package_name: None | str = None,
swift_version: None | str = None,
target_sdk_version: None | str = None,
test_device_type: str = "default",
test_host_app: None | str | (str, str) = None,
test_re_capabilities: None | dict[str, str] = None,
test_re_use_case: None | str = None,
test_rule_timeout_ms: None | int = None,
thin_lto: bool = False,
try_skip_code_signing: None | bool = None,
ui_test_target_app: None | str = None,
use_entitlements_when_adhoc_code_signing: bool = False,
use_submodules: bool = True,
uses_cxx_explicit_modules: bool = False,
uses_explicit_modules: bool = False,
uses_modules: bool = False,
validation_deps: list[str] = [],
versioned_macos_bundle: bool = select({"prelude//features/apple/constraints:versioned_macos_bundle_false": False, "prelude//features/apple/constraints:versioned_macos_bundle_true": True, "DEFAULT": False}),
xcode_product_type: None | str = None,
xcode_scheme_settings: None | str = None,
) -> 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
-
allow_cache_upload: (defaults to:None)Whether to allow uploading the output of this rule to be uploaded to cache when the action is executed locally if the configuration allows (i.e. there is a cache configured and the client has permission to write to it).
-
asset_catalogs_compilation_options: (defaults to:{})A dict holding parameters for asset catalogs compiler (actool). Its options include:
notices(defaults toTrue)warnings(defaults toTrue)errors(defaults toTrue)compress_pngs(defaults toTrue)optimization(defaults to'space')output_format(defaults to'human-readable-text')extra_flags(defaults to[])
-
compiler_flags: (defaults to:[])Flags to use when compiling any of the above sources (which require compilation).
-
contacts: (defaults to:[])A list of organizational contacts for this rule. These could be individuals who you would contact in the event of a failure or other issue with the rule.
contacts = [ 'Joe Sixpack', 'Erika Mustermann' ] -
embed_xctest_frameworks_in_test_host_app: (defaults to:None)Controls whether a marker constraint is added to the
test_host_app. -
exported_header_style: (defaults to:"local")How dependents should include exported headers from this rule. Can be either
local(e.g.-I) orsystem(e.g.-isystem). -
extra_xcode_files: (defaults to:[])When the project is generated, this is the list of files that will added to the project. Those files won't be added to the build phase "Compile Sources".
-
extra_xcode_sources: (defaults to:[])When the project is generated, this is the list of files that will added to the build phase "Compile Sources" of the given target.
-
frameworks: (defaults to:[])A list of system frameworks that the code in this target uses. Each entry should be a path starting with
$SDKROOTor$PLATFORM_DIRto denote that the rest of the path is relative to the root of the SDK used for the build or to the platform toolchain directory. -
header_namespace: (defaults to:None)A path prefix when including headers of this target. Defaults to the path from the root of the repository to the directory where this target is defined. Can contain forward slashes (
/), but cannot start with one. Seeheadersfor more information. -
header_path_prefix: (defaults to:None)A path prefix when including headers of this target. For example, headers from a library defined using
apple_library(
name = "Library",
headers = glob(["**/*.h"]),
header_path_prefix = "Lib",
)can be imported using following mapping
Library/SubDir/Header1.h -> Lib/Header1.h
Library/Header2.h -> Lib/Header2.hDefaults to the short name of the target. Can contain forward slashes (
/), but cannot start with one. Seeheadersfor more information. -
headers: (defaults to:[])The set of header files that are made available for inclusion to the source files in this target. These should be specified as either a list of header files or a dictionary of header names to header files. The header names can contain forward slashes (
/). If a list of header files is specified, the headers can be imported with#import "$HEADER_PATH_PREFIX/$HEADER_NAME"or#import "$HEADER_NAME", where$HEADER_PATH_PREFIXis the value of the target'sheader_path_prefixattribute, and$HEADER_NAMEis the filename of the header file. If a dictionary is specified, each header can be imported with#import "$HEADER_NAME", where$HEADER_NAMEis the key corresponding to this file. In this case, theheader_path_prefixattribute is ignored. In either case, quotes in the import statements can be replaced with angle brackets. -
include_directories: (defaults to:[])A list of include directories (with
raw_headers) to be added to the compile command for compiling this target (via-I). An include directory is relative to the current package. -
info_plist: (required)A path to an
Info.plistfile that will be placed in the bundle. The specified file will be processed by substituting variable names with their values (seeinfo_plist_substitutionsfor more information). -
info_plist_substitutions: (defaults to:{})A dictionary that assigns variable names to their values. It is used for variable substitution when processing the file specified in
info_plist. For example if this argument is set to{'VAR': 'MyValue'}, then each occurrence of$(VAR)or${VAR}in the file will be replaced byMyValue. -
labels: (defaults to:[])A list of labels to be applied to these tests. These labels are arbitrary text strings and have no meaning within buck itself. They can, however, have meaning for you as a test author (e.g.,
smokeorfast). A label can be used to filter or include a specific test rule when executingbuck test -
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
-
link_execution_preference: (defaults to:None)The execution preference for linking. Options are:
- any : No preference is set, and the link action will be performed based on buck2's executor configuration.
- full_hybrid : The link action will execute both locally and remotely, regardless of buck2's executor configuration (if the executor is capable of hybrid execution). The use_limited_hybrid setting of the hybrid executor is ignored.
- local : The link action will execute locally if compatible on current host platform.
- local_only : The link action will execute locally, and error if the current platform is not compatible.
- remote : The link action will execute remotely if a compatible remote platform exists, otherwise locally.
The default is None, expressing that no preference has been set on the target itself.
-
linker_flags: (defaults to:[])Flags to add to the linker command line whenever the output from this rule is used in a link operation, such as linked into an executable or a shared library.
-
preprocessor_flags: (defaults to:[])Flags to use when preprocessing any of the above sources (which require preprocessing).
-
public_include_directories: (defaults to:[])A list of include directories (with
raw_headers) to be added to the compile command for compiling this target and every target that depends on it (via-I). An include directory is relative to the current package. -
public_system_include_directories: (defaults to:[])A list of include directories (with
raw_headers) to be added to the compile command for compiling this target and every target that depends on it (via-isystemif the compiler supports it of via-Iotherwise). An include directory is relative to the current package. -
soname: (defaults to:None)Sets the soname ("shared object name") of any shared library produced from this rule. The default value is based on the full rule name. The macro
$(ext)will be replaced with a platform-appropriate extension. An argument can be provided, which is a library version. For examplesoname = 'libfoo.$(ext 2.3)'will belibfoo.2.3.dylibon Mac andlibfoo.so.2.3on Linux. -
srcs: (defaults to:[])The set of C, C++, Objective-C, Objective-C++, or assembly source files to be preprocessed, compiled, and assembled by this rule. We determine which stages to run on each input source based on its file extension. See the GCC documentation for more detail on how file extensions are interpreted. Each element can be either a string specifying a source file (e.g.
'') or a tuple of a string specifying a source file and a list of compilation flags (e.g.('', ['-Wall', '-Werror'])). In the latter case the specified flags will be used in addition to the rule's other flags when preprocessing and compiling that file (if applicable). -
supported_platforms_regex: (defaults to:None)If present, an un-anchored regex (in java.util.regex.Pattern syntax) that matches all platforms that this library supports. It will not be built for other platforms.
-
target_sdk_version: (defaults to:None)The minimum OS version that the library target should support, overriding the minimum set in
.buckconfig. When set, Buck will automatically add flags to both Objective-C and Swift compilation that will allow the use of the new APIs without guarding code inside availability checks. -
test_host_app: (defaults to:None)A build target identifying an
apple_bundle()rule that builds an application bundle. Output of the specified rule will be used as a test host of this test. This impliesrun_test_separately. Since symbols that are defined in the test host application and its dependencies will not be linked into the test binary, to make those symbols accessible to the test target they need to be specified as a dependency of this target and['-undefined', 'dynamic_lookup']needs to be added to this target'slinker_flags(this will suppress undefined reference errors during compilation, but if the symbols do not exist, it might result in runtime crashes). -
test_re_capabilities: (defaults to:None)An optional dictionary with the RE capabilities for the test execution. Overrides a default selection mechanism.
-
test_re_use_case: (defaults to:None)An optional name of the RE use case for the test execution. Overrides a default selection mechanism.
-
xcode_scheme_settings: (defaults to:None)Optional settings to set on schemes when this target is represented in Xcode.
Examples
apple_test(
name = 'MyTest',
info_plist = 'MyTest-Info.plist',
preprocessor_flags = ['-fobjc-arc'],
srcs = [
'MyTest.m',
],
deps = [
':MyLibrary',
],
frameworks = [
'$SDKROOT/System/Library/Frameworks/Foundation.framework',
'$SDKROOT/System/Library/Frameworks/UIKit.framework',
'$PLATFORM_DIR/Developer/Library/Frameworks/XCTest.framework',
],
)