Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ios_bundle_test #1110

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions test/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,14 @@ apple_multi_shell_test(
shard_count = 16,
)

apple_multi_shell_test(
name = "ios_bundle_test",
size = "medium",
src = "ios_bundle_test.sh",
configurations = IOS_CONFIGURATIONS,
shard_count = 3,
)

apple_multi_shell_test(
name = "ios_application_resources_test",
size = "large",
Expand Down
148 changes: 148 additions & 0 deletions test/ios_bundle_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
#!/bin/bash

# Copyright 2017 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -eu

# Integration tests for bundling simple iOS loadable bundles.

function set_up() {
mkdir -p app
}

function tear_down() {
rm -rf app
}

# Creates common source, targets, and basic plist for iOS loadable bundles.
function create_common_files() {
cat > app/BUILD <<EOF
load("@build_bazel_rules_apple//apple:ios.bzl", "ios_bundle")

objc_library(
name = "lib",
srcs = ["main.m"],
)
EOF

cat > app/main.m <<EOF
int main(int argc, char **argv) {
return 0;
}
EOF

cat > app/Info.plist <<EOF
{
CFBundleIdentifier = "\${PRODUCT_BUNDLE_IDENTIFIER}";
CFBundleName = "\${PRODUCT_NAME}";
CFBundlePackageType = "BNDL";
CFBundleShortVersionString = "1.0";
CFBundleVersion = "1.0";
}
EOF
}

# Creates a minimal iOS loadable bundle target.
function create_minimal_ios_bundle() {
if [[ ! -f app/BUILD ]]; then
fail "create_common_files must be called first."
fi

cat >> app/BUILD <<EOF
ios_bundle(
name = "app",
bundle_id = "my.bundle.id",
infoplists = ["Info.plist"],
families = ["iphone"],
minimum_os_version = "12.0",
provisioning_profile = "@build_bazel_rules_apple//test/testdata/provisioning:integration_testing_ios.mobileprovision",
deps = [":lib"],
)
EOF
}

# Test missing the CFBundleVersion fails the build.
function test_missing_version_fails() {
create_common_files
create_minimal_ios_bundle

# Replace the file, but without CFBundleVersion.
cat > app/Info.plist <<EOF
{
CFBundleIdentifier = "\${PRODUCT_BUNDLE_IDENTIFIER}";
CFBundleName = "\${PRODUCT_NAME}";
CFBundlePackageType = "BNDL";
CFBundleShortVersionString = "1.0";
}
EOF

! do_build ios //app:app \
|| fail "Should fail build"

expect_log 'Target "//app:app" is missing CFBundleVersion.'
}

# Test missing the CFBundleShortVersionString fails the build.
function test_missing_short_version_fails() {
create_common_files
create_minimal_ios_bundle

# Replace the file, but without CFBundleShortVersionString.
cat > app/Info.plist <<EOF
{
CFBundleIdentifier = "\${PRODUCT_BUNDLE_IDENTIFIER}";
CFBundleName = "\${PRODUCT_NAME}";
CFBundlePackageType = "BNDL";
CFBundleVersion = "1.0";
}
EOF

! do_build ios //app:app \
|| fail "Should fail build"

expect_log 'Target "//app:app" is missing CFBundleShortVersionString.'
}

# Tests that the IPA post-processor is executed and can modify the bundle.
function test_ipa_post_processor() {
create_common_files

cat >> app/BUILD <<EOF
ios_bundle(
name = "app",
bundle_id = "my.bundle.id",
infoplists = ["Info.plist"],
families = ["iphone"],
ipa_post_processor = "post_processor.sh",
minimum_os_version = "12.0",
provisioning_profile = "@build_bazel_rules_apple//test/testdata/provisioning:integration_testing_ios.mobileprovision",
deps = [":lib"],
)
EOF

cat > app/post_processor.sh <<EOF
#!/bin/bash
WORKDIR="\$1"
mkdir "\$WORKDIR/app.bundle/Resources"
echo "foo" > "\$WORKDIR/app.bundle/Resources/inserted_by_post_processor.txt"
EOF
chmod +x app/post_processor.sh

do_build ios //app:app || fail "Should build"
assert_equals "foo" "$(unzip_single_file "test-bin/app/app.zip" \
"app.bundle/Resources/inserted_by_post_processor.txt")"
}

run_suite "ios_bundle bundling tests"