Skip to content

Commit

Permalink
Add support for bundling framework imports for macos_application targ…
Browse files Browse the repository at this point in the history
…ets.

RELNOTES: None
PiperOrigin-RevId: 224036641
  • Loading branch information
sergiocampama committed Dec 6, 2018
1 parent 4dcdccc commit 5910c11
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
3 changes: 3 additions & 0 deletions apple/internal/macos_rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ def macos_application_impl(ctx):
bundle_embedded_bundles = True,
embeddable_targets = ctx.attr.extensions,
),
partials.framework_import_partial(
targets = ctx.attr.deps + ctx.attr.extensions,
),
partials.macos_additional_contents_partial(),
partials.resources_partial(
bundle_id = bundle_id,
Expand Down
4 changes: 4 additions & 0 deletions test/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@ apple_multi_shell_test(
size = "medium",
src = "macos_application_test.sh",
configurations = MACOS_CONFIGURATIONS,
data = [
"//test/testdata/binaries:empty_dylib",
"//test/testdata/binaries:empty_staticlib",
],
shard_count = 8,
)

Expand Down
74 changes: 74 additions & 0 deletions test/macos_application_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ function create_common_files() {
load("@build_bazel_rules_apple//apple:macos.bzl",
"macos_application",
"macos_bundle")
load("@build_bazel_rules_apple//apple:apple.bzl",
"apple_framework_import")
objc_library(
name = "lib",
Expand Down Expand Up @@ -73,6 +75,55 @@ macos_application(
EOF
}

function create_minimal_macos_application_with_framework_import() {
cat >> app/BUILD <<EOF
macos_application(
name = "app",
bundle_id = "my.bundle.id",
infoplists = ["Info.plist"],
minimum_os_version = "10.11",
deps = [
":lib",
":frameworkDependingLib",
],
)
objc_library(
name = "frameworkDependingLib",
srcs = ["@bazel_tools//tools/objc:dummy.c"],
deps = [":fmwk"],
)
apple_framework_import(
name = "fmwk",
framework_imports = glob(["fmwk.framework/**"]),
is_dynamic = True,
)
EOF

mkdir -p app/fmwk.framework
cp $(rlocation build_bazel_rules_apple/test/testdata/binaries/empty_dylib_lipobin) \
app/fmwk.framework/fmwk

cat > app/fmwk.framework/Info.plist <<EOF
Dummy plist
EOF

cat > app/fmwk.framework/resource.txt <<EOF
Dummy resource
EOF

mkdir -p app/fmwk.framework/Headers
cat > app/fmwk.framework/Headers/fmwk.h <<EOF
This shouldn't get included
EOF

mkdir -p app/fmwk.framework/Modules
cat > app/fmwk.framework/Headers/module.modulemap <<EOF
This shouldn't get included
EOF
}

# Tests that the Info.plist in the packaged application has the correct content.
function test_plist_contents() {
create_common_files
Expand Down Expand Up @@ -404,4 +455,27 @@ EOF
assert_zip_contains "test-bin/app/app.zip" "app with space.app/"
}

# Tests that a prebuilt dynamic framework (i.e., objc_framework with is_dynamic
# set to True) is bundled properly with the application.
function test_prebuilt_dynamic_framework_dependency() {
create_common_files
create_minimal_macos_application_with_framework_import

do_build macos //app:app || fail "Should build"

# Verify that the binary, plist, and resources are included.
assert_zip_contains "test-bin/app/app.zip" \
"app.app/Contents/Frameworks/fmwk.framework/fmwk"
assert_zip_contains "test-bin/app/app.zip" \
"app.app/Contents/Frameworks/fmwk.framework/Info.plist"
assert_zip_contains "test-bin/app/app.zip" \
"app.app/Contents/Frameworks/fmwk.framework/resource.txt"

# Verify that Headers and Modules directories are excluded.
assert_zip_not_contains "test-bin/app/app.zip" \
"app.app/Contents/Frameworks/fmwk.framework/Headers/fmwk.h"
assert_zip_not_contains "test-bin/app/app.zip" \
"app.app/Contents/Frameworks/fmwk.framework/Modules/module.modulemap"
}

run_suite "macos_application bundling tests"

0 comments on commit 5910c11

Please sign in to comment.