Skip to content

Commit

Permalink
Project import generated by Copybara.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 171789159
  • Loading branch information
A Googler authored and allevato committed Oct 11, 2017
1 parent 7ea0557 commit 2a7c5f5
Show file tree
Hide file tree
Showing 62 changed files with 2,064 additions and 379 deletions.
1 change: 1 addition & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ filegroup(
"WORKSPACE",
"//apple:for_bazel_tests",
"//apple/testing:for_bazel_tests",
"//common:for_bazel_tests",
"//tools:for_bazel_tests",
],
visibility = ["//:__subpackages__"],
Expand Down
10 changes: 6 additions & 4 deletions apple/apple_genrule.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,18 @@
load("@build_bazel_rules_apple//apple:utils.bzl",
"apple_action",
"DARWIN_EXECUTION_REQUIREMENTS",
"dirname")
"dirname",
"get_environment_supplier")

def _compute_make_variables(genfiles_dir,
label,
resolved_srcs,
files_to_build):
variables = {"SRCS": cmd_helper.join_paths(" ", resolved_srcs),
"OUTS": cmd_helper.join_paths(" ", files_to_build)}
if len(resolved_srcs) == 1:
if len(resolved_srcs.to_list()) == 1:
variables["<"] = list(resolved_srcs)[0].path
if len(files_to_build) == 1:
if len(files_to_build.to_list()) == 1:
variables["@"] = list(files_to_build)[0].path
variables["@D"] = dirname(variables["@"])
else:
Expand Down Expand Up @@ -65,7 +66,7 @@ def _apple_genrule_impl(ctx):
message = ctx.attr.message or "Executing apple_genrule"

env = ctx.configuration.default_shell_env
env += ctx.fragments.apple.apple_host_system_env()
env += get_environment_supplier(ctx).apple_host_system_env()

apple_action(ctx,
inputs=list(resolved_srcs) + resolved_inputs,
Expand All @@ -90,6 +91,7 @@ _apple_genrule_inner = rule(
"message": attr.string(),
"output_licenses": attr.license(),
"executable": attr.bool(default=False),
"_xcode_config": attr.label(default=Label("@bazel_tools//tools/osx:current_xcode_config")),
},
output_to_genfiles = True,
fragments=["apple"])
Expand Down
46 changes: 25 additions & 21 deletions apple/bundling/apple_bundling_aspect.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,26 @@

"""An aspect that collects information used during Apple bundling."""

load("@build_bazel_rules_apple//apple:providers.bzl",
"AppleBundlingSwiftInfo",
"AppleResourceInfo",
"AppleResourceSet",
"apple_resource_set_utils",
)
load("@build_bazel_rules_apple//apple:utils.bzl",
"basename",
"group_files_by_directory"
)
load("@build_bazel_rules_apple//apple/bundling:bundling_support.bzl",
"bundling_support")
load("@build_bazel_rules_apple//apple/bundling:provider_support.bzl",
"provider_support")
load(
"@build_bazel_rules_apple//apple:providers.bzl",
"AppleBundlingSwiftInfo",
"AppleResourceInfo",
"AppleResourceSet",
"apple_resource_set_utils",
)
load(
"@build_bazel_rules_apple//apple:utils.bzl",
"basename",
"group_files_by_directory",
)
load(
"@build_bazel_rules_apple//apple/bundling:bundling_support.bzl",
"bundling_support",
)
load(
"@build_bazel_rules_apple//common:providers.bzl",
"providers",
)


def _attr_files(ctx, name):
Expand Down Expand Up @@ -70,7 +76,7 @@ def _handle_native_library_dependency(target, ctx):
# transitive resources as a flat list based on their .bundle directory, we
# must prepend the current target's {name}.bundle to the path so that the
# files end up in the correct place.
for p in provider_support.matching_providers(bundles, AppleResourceInfo):
for p in providers.find_all(bundles, AppleResourceInfo):
resource_sets.extend([
apple_resource_set_utils.prefix_bundle_dir(rs, bundle_dir)
for rs in p.resource_sets
Expand All @@ -81,7 +87,7 @@ def _handle_native_library_dependency(target, ctx):

# The "bundles" attribute of an objc_library don't indicate a nesting
# relationship, so simply bring them over as-is.
for p in provider_support.matching_providers(bundles, AppleResourceInfo):
for p in providers.find_all(bundles, AppleResourceInfo):
resource_sets.extend(p.resource_sets)
else:
fail(("Internal consistency error: expected rule to be objc_library " +
Expand Down Expand Up @@ -192,8 +198,7 @@ def _transitive_apple_resource_info(target, ctx):
# If the rule has deps, propagate the transitive info from this target's
# dependencies.
deps = getattr(ctx.rule.attr, "deps", [])
resource_providers = provider_support.matching_providers(deps,
AppleResourceInfo)
resource_providers = providers.find_all(deps, AppleResourceInfo)
for p in resource_providers:
resource_sets.extend(p.resource_sets)

Expand Down Expand Up @@ -234,9 +239,8 @@ def _transitive_apple_bundling_swift_info(target, ctx):
# If the target itself doesn't use Swift, check its deps.
if not uses_swift:
deps = getattr(ctx.rule.attr, "deps", [])
providers = provider_support.matching_providers(
deps, AppleBundlingSwiftInfo)
uses_swift = any([p.uses_swift for p in providers])
swift_info_providers = providers.find_all(deps, AppleBundlingSwiftInfo)
uses_swift = any([p.uses_swift for p in swift_info_providers])

return AppleBundlingSwiftInfo(uses_swift=uses_swift)

Expand Down
56 changes: 0 additions & 56 deletions apple/bundling/attribute_support.bzl

This file was deleted.

12 changes: 6 additions & 6 deletions apple/bundling/binary_support.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ load(
"product_support",
)
load(
"@build_bazel_rules_apple//apple/bundling:provider_support.bzl",
"provider_support",
"@build_bazel_rules_apple//common:providers.bzl",
"providers",
)


Expand All @@ -46,11 +46,11 @@ def _get_binary_provider(deps, provider_key):
if len(deps) != 1:
fail("Only one dependency (a binary target) should be specified " +
"as a bundling rule dependency")
providers = provider_support.matching_providers(deps[0], provider_key)
if providers:
if len(providers) > 1:
matching_providers = providers.find_all(deps[0], provider_key)
if matching_providers:
if len(matching_providers) > 1:
fail("Expected only one binary provider")
return providers[0]
return matching_providers[0]
return None


Expand Down
52 changes: 32 additions & 20 deletions apple/bundling/bundler.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,6 @@ load(
"@build_bazel_rules_apple//apple/bundling:product_support.bzl",
"product_support",
)
load(
"@build_bazel_rules_apple//apple/bundling:provider_support.bzl",
"provider_support",
)
load(
"@build_bazel_rules_apple//apple/bundling:resource_actions.bzl",
"resource_actions",
Expand All @@ -104,6 +100,14 @@ load(
"@build_bazel_rules_apple//apple/bundling:swift_support.bzl",
"swift_support",
)
load(
"@build_bazel_rules_apple//common:attrs.bzl",
"attrs",
)
load(
"@build_bazel_rules_apple//common:providers.bzl",
"providers",
)


# Directories inside .frameworks that should not be included in final
Expand Down Expand Up @@ -491,9 +495,8 @@ def _experimental_create_and_sign_bundle(
[control_file]
)

entitlements = None
if hasattr(ctx.file, "entitlements") and ctx.file.entitlements:
entitlements = ctx.file.entitlements
entitlements = attrs.get(ctx.file, "entitlements")
if entitlements:
bundler_inputs.append(entitlements)

signing_command_lines = ""
Expand Down Expand Up @@ -542,7 +545,8 @@ def _run(
additional_resource_sets=[],
embedded_bundles=[],
framework_files=depset(),
is_dynamic_framework=False):
is_dynamic_framework=False,
deps_objc_providers=[]):
"""Implements the core bundling logic for an Apple bundle archive.
Args:
Expand Down Expand Up @@ -571,6 +575,8 @@ def _run(
provider keys (such as framework search paths) will be propagated
appropriately.
is_dynamic_framework: If True, create this bundle as a dynamic framework.
deps_objc_providers: objc providers containing information about the
dependencies of the binary target.
Returns:
A tuple containing three values:
1. A list of modern providers that should be propagated by the calling rule.
Expand All @@ -584,6 +590,11 @@ def _run(
# calling rule.
additional_outputs = []

# A list of output files included in the local_outputs output group. These are
# must be requested explicitly by including "local_outputs" in the
# --output_groups flag of the build command line.
local_outputs = []

# The name of the target is used as the name of the executable in the binary,
# which we also need to write into the Info.plist file over whatever the user
# already has there.
Expand Down Expand Up @@ -632,17 +643,16 @@ def _run(

framework_resource_sets = depset()

if (hasattr(ctx.attr, "exclude_resources") and ctx.attr.exclude_resources):
if attrs.get(ctx.attr, "exclude_resources"):
resource_sets.append(AppleResourceSet(infoplists=target_infoplists))
else:
if hasattr(ctx.attr, "frameworks"):
for framework in getattr(ctx.attr, "frameworks", []):
if _ResourceBundleInfo in framework:
framework_resource_sets = (
framework_resource_sets |
framework[_ResourceBundleInfo].resource_sets)
if ctx.attr._propagates_frameworks:
propagated_framework_zips.append(framework[AppleBundleInfo].archive)
for framework in attrs.get(ctx.attr, "frameworks", []):
if _ResourceBundleInfo in framework:
framework_resource_sets = (
framework_resource_sets |
framework[_ResourceBundleInfo].resource_sets)
if ctx.attr._propagates_frameworks:
propagated_framework_zips.append(framework[AppleBundleInfo].archive)

# Add the transitive resource sets, except for those that have already been
# included by a framework dependency.
Expand Down Expand Up @@ -795,9 +805,8 @@ def _run(
root_merge_zips.extend(list(apple_bundle.root_merge_zips))

# Merge in any prebuilt frameworks (i.e., objc_framework dependencies).
objc_providers = provider_support.matching_providers(ctx.attr.deps[0], "objc")
propagated_framework_files = []
for objc in objc_providers:
for objc in deps_objc_providers:
files = objc.dynamic_framework_file
if ctx.attr._propagates_frameworks:
propagated_framework_files.extend(list(files))
Expand Down Expand Up @@ -826,6 +835,7 @@ def _run(
bundle_merge_zips, mnemonic, progress_description)

work_dir = None
bundle_dir = None
additional_outputs.append(ctx.outputs.archive)
if experimental_bundling in ("bundle_and_archive", "off"):
unprocessed_archive = _create_unprocessed_archive(
Expand Down Expand Up @@ -875,7 +885,7 @@ def _run(
objc_provider_args["framework_dir"] = depset([framework_dir])
objc_provider_args["static_framework_file"] = bundled_framework_files

objc_provider_args["providers"] = objc_providers
objc_provider_args["providers"] = deps_objc_providers
legacy_objc_provider = apple_common.new_objc_provider(**objc_provider_args)
if is_dynamic_framework:
framework_provider = apple_common.new_dynamic_framework_provider(
Expand All @@ -889,6 +899,7 @@ def _run(
getattr(ctx.attr, "_extension_safe", False))
apple_bundle_info_args = {
"archive": ctx.outputs.archive,
"bundle_dir": bundle_dir,
"bundle_id": bundle_id,
"bundle_name": bundle_name,
"extension_safe": extension_safe,
Expand All @@ -906,6 +917,7 @@ def _run(
legacy_providers["apple_bundle"] = struct(**apple_bundle_info_args)
additional_providers.extend([
AppleBundleInfo(**apple_bundle_info_args),
OutputGroupInfo(local_outputs=depset(local_outputs)),
_ResourceBundleInfo(resource_sets=resource_sets),
])

Expand Down
24 changes: 14 additions & 10 deletions apple/bundling/entitlements.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,23 @@ load(
)


AppleEntitlementsInfo = provider()
"""Propagates information about entitlements to the bundling rules.
AppleEntitlementsInfo = provider(
doc="""
Propagates information about entitlements to the bundling rules.
This provider is an internal implementation detail of the bundling rules and
should not be used directly by users.
Args:
signing_entitlements: A `File` representing the `.entitlements` file that
should be used during code signing of device builds. May be `None` if
there are no entitlements or if this is a simulator build where the
entitlements are embedded in the binary instead of being applied during
signing.
""",
fields={
"signing_entitlements": """
A `File` representing the `.entitlements` file that
should be used during code signing of device builds. May be `None` if
there are no entitlements or if this is a simulator build where the
entitlements are embedded in the binary instead of being applied during
signing.
"""

}
)

def _new_entitlements_artifact(ctx, extension):
"""Returns a new file artifact for entitlements.
Expand Down Expand Up @@ -362,6 +365,7 @@ entitlements = rule(
allow_files=[".mobileprovision", ".provisionprofile"],
single_file=True,
),
"_xcode_config": attr.label(default=Label("@bazel_tools//tools/osx:current_xcode_config")),
},
fragments=["apple", "objc"],
)
Loading

0 comments on commit 2a7c5f5

Please sign in to comment.