Skip to content

Latest commit

 

History

History
172 lines (149 loc) · 5.35 KB

rules-general.md

File metadata and controls

172 lines (149 loc) · 5.35 KB

General Apple build rules

apple_bundle_version

apple_bundle_version(name, build_label_pattern, build_version, capture_groups,
short_version_string)

Produces a target that contains versioning information for an Apple bundle.

This rule allows version numbers to be hard-coded into the BUILD file or extracted from the build label passed into Bazel using the --embed_label command line flag.

Targets created by this rule do not generate outputs themselves, but instead should be used in the version attribute of an Apple application or extension bundle target to set the version keys in that bundle's Info.plist file.

Examples

# A version scheme that uses hard-coded versions checked into your
# BUILD files.
apple_bundle_version(
    name = "simple",
    build_version = "1.0.134",
    short_version_string = "1.0",
)

ios_application(
    name = "foo_app",
    ...,
    version = ":simple",
)

# A version scheme that parses version information out of the build
# label. For example, the following command
#
#    bazel build //myapp:myapp --embed_label=MyApp_1.2_build_345
#
# would yield the Info.plist values:
#
#    CFBundleVersion = "1.2.345"
#    CFBundleShortVersionString = "1.2"
#
apple_bundle_version(
    name = "build_label_version",
    build_label_pattern = "MyApp_{version}_build_{build}",
    build_version = "{version}.{build}",
    capture_group = {
        "version": "\d+\.\d+",
        "build": "\d+",
    },
    short_version_string = "{version}",
)

ios_application(
    name = "bar_app",
    ...,
    version = ":build_label_version",
)
Attributes
name

Name, required

A unique name for the target.

build_label_pattern

String; optional

A pattern that should contain placeholders inside curly braces (e.g., "foo_{version}_bar") that is used to parse the build label passed into Bazel using the --embed_label command line flag. Each of the placeholders is expected to match one of the keys in the capture_groups attribute.

build_version

String; required

A string that will be used as the value for the CFBundleVersion key in a depending bundle's Info.plist. If this string contains placeholders, then they will be replaced by strings captured out of build_label_pattern.

capture_groups

Dictionary of strings to strings; optional

A dictionary where each key is the name of a placeholder found in build_label_pattern and the corresponding value is the regular expression that should match that placeholder. If this attribute is provided, then build_label_pattern must also be provided.

short_version_string

String; optional

A string that will be used as the value for the CFBundleShortVersionString key in a depending bundle's Info.plist. If this string contains placeholders, then they will be replaced by strings captured out of build_label_pattern. This attribute is optional; if it is omitted, then the value of build_version will be used for this key as well.

apple_genrule

Variation of genrule that provides an Apple-specific environment and make variables. This rule will only run on macOS.

This rule takes the same attributes as Bazel's native genrule; please refer to its documentation for a full description of those attributes.

Example of use:

load("@build_bazel_rules_apple//apple:apple_genrule.bzl", "apple_genrule")

apple_genrule(
    name = "world",
    outs = ["hi"],
    cmd = "touch $(@)",
)

This rule also does location expansion, much like the native genrule. For example, $(location hi) may be used to refer to the output in the above example.

The set of make variables that are supported for this rule:

  • $OUTS: The outs list. If you have only one output file, you can also use $@.
  • $SRCS: The srcs list (or more precisely, the path names of the files corresponding to labels in the srcs list). If you have only one source file, you can also use $<.
  • $<: srcs, if it's a single file.
  • $@: outs, if it's a single file.

The following environment variables are added to the rule action:

  • $DEVELOPER_DIR: The base developer directory as defined on Apple architectures, most commonly used in invoking Apple tools such as xcrun.