Skip to content

Commit

Permalink
fix: add crashlytics example (#435)
Browse files Browse the repository at this point in the history
- Treat `maccatalyst` like `ios` instead of `macos`.
- Add `crashlytics` example to `firebase_example`.
- Ensure that `defines` values that contain spaces are escaped properly.
If not escaped, each space-separated part becomes its own define value.
- Do not trust the package manifests! Check that directories exist
before attempting to list their contents.
- Include `.mm` files (Objective-C++) as valid sources.

Closes #425.
  • Loading branch information
cgrindel authored Jul 1, 2023
1 parent cd81615 commit 1df27c6
Show file tree
Hide file tree
Showing 51 changed files with 1,180 additions and 118 deletions.
4 changes: 2 additions & 2 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# To update these lines, execute
# `bazel run @rules_bazel_integration_test//tools:update_deleted_packages`
build --deleted_packages=bzlmod/workspace,bzlmod/workspace/Sources/MyExecutable,bzlmod/workspace/Sources/MyLibrary,bzlmod/workspace/Tests/MyLibraryTests,examples/firebase_example,examples/firebase_example/abtesting,examples/firebase_example/abtesting/SharedApp,examples/firebase_example/analytics/AnalyticsExample,examples/firebase_example/appdistribution,examples/firebase_example/appdistribution/AppDistributionExample,examples/firebase_example/appdistribution/AppDistributionTests,examples/http_archive_ext_deps,examples/http_archive_ext_deps/Sources/MyDequeModule,examples/http_archive_ext_deps/Sources/PrintStuff,examples/http_archive_ext_deps/Tests/MyDequeModuleTests,examples/http_archive_ext_deps/third_party,examples/interesting_deps,examples/ios_sim,examples/ios_sim/Sources/Foo,examples/ios_sim/Tests/FooTests,examples/ios_sim/third-party/swift-cmark,examples/nimble_example,examples/nimble_example/Sources/NimbleExample,examples/objc_code,examples/phone_number_kit,examples/phone_number_kit/Tests/PhoneNumberKitTests,examples/pkg_manifest_minimal,examples/pkg_manifest_minimal/Sources/MyExecutable,examples/pkg_manifest_minimal/Sources/MyLibrary,examples/pkg_manifest_minimal/Tests/MyLibraryTests,examples/pkg_manifest_minimal/third_party,examples/resources_example,examples/resources_example/Sources/MyApp,examples/resources_example/Tests/MyAppTests,examples/resources_example/third_party,examples/soto_example,examples/soto_example/Tests/SotoTests,examples/tca_example,examples/tca_example/SwiftUICaseStudies,examples/tca_example/SwiftUICaseStudiesTests,examples/vapor_example,examples/vapor_example/Sources/App,examples/vapor_example/Sources/Run,examples/vapor_example/Tests/AppTests,examples/vapor_example/swift,examples/xcmetrics_example
query --deleted_packages=bzlmod/workspace,bzlmod/workspace/Sources/MyExecutable,bzlmod/workspace/Sources/MyLibrary,bzlmod/workspace/Tests/MyLibraryTests,examples/firebase_example,examples/firebase_example/abtesting,examples/firebase_example/abtesting/SharedApp,examples/firebase_example/analytics/AnalyticsExample,examples/firebase_example/appdistribution,examples/firebase_example/appdistribution/AppDistributionExample,examples/firebase_example/appdistribution/AppDistributionTests,examples/http_archive_ext_deps,examples/http_archive_ext_deps/Sources/MyDequeModule,examples/http_archive_ext_deps/Sources/PrintStuff,examples/http_archive_ext_deps/Tests/MyDequeModuleTests,examples/http_archive_ext_deps/third_party,examples/interesting_deps,examples/ios_sim,examples/ios_sim/Sources/Foo,examples/ios_sim/Tests/FooTests,examples/ios_sim/third-party/swift-cmark,examples/nimble_example,examples/nimble_example/Sources/NimbleExample,examples/objc_code,examples/phone_number_kit,examples/phone_number_kit/Tests/PhoneNumberKitTests,examples/pkg_manifest_minimal,examples/pkg_manifest_minimal/Sources/MyExecutable,examples/pkg_manifest_minimal/Sources/MyLibrary,examples/pkg_manifest_minimal/Tests/MyLibraryTests,examples/pkg_manifest_minimal/third_party,examples/resources_example,examples/resources_example/Sources/MyApp,examples/resources_example/Tests/MyAppTests,examples/resources_example/third_party,examples/soto_example,examples/soto_example/Tests/SotoTests,examples/tca_example,examples/tca_example/SwiftUICaseStudies,examples/tca_example/SwiftUICaseStudiesTests,examples/vapor_example,examples/vapor_example/Sources/App,examples/vapor_example/Sources/Run,examples/vapor_example/Tests/AppTests,examples/vapor_example/swift,examples/xcmetrics_example
build --deleted_packages=bzlmod/workspace,bzlmod/workspace/Sources/MyExecutable,bzlmod/workspace/Sources/MyLibrary,bzlmod/workspace/Tests/MyLibraryTests,examples/firebase_example,examples/firebase_example/abtesting,examples/firebase_example/abtesting/SharedApp,examples/firebase_example/analytics/AnalyticsExample,examples/firebase_example/appdistribution,examples/firebase_example/appdistribution/AppDistributionExample,examples/firebase_example/appdistribution/AppDistributionTests,examples/firebase_example/crashlytics,examples/http_archive_ext_deps,examples/http_archive_ext_deps/Sources/MyDequeModule,examples/http_archive_ext_deps/Sources/PrintStuff,examples/http_archive_ext_deps/Tests/MyDequeModuleTests,examples/http_archive_ext_deps/third_party,examples/interesting_deps,examples/ios_sim,examples/ios_sim/Sources/Foo,examples/ios_sim/Tests/FooTests,examples/ios_sim/third-party/swift-cmark,examples/nimble_example,examples/nimble_example/Sources/NimbleExample,examples/objc_code,examples/phone_number_kit,examples/phone_number_kit/Tests/PhoneNumberKitTests,examples/pkg_manifest_minimal,examples/pkg_manifest_minimal/Sources/MyExecutable,examples/pkg_manifest_minimal/Sources/MyLibrary,examples/pkg_manifest_minimal/Tests/MyLibraryTests,examples/pkg_manifest_minimal/third_party,examples/resources_example,examples/resources_example/Sources/MyApp,examples/resources_example/Tests/MyAppTests,examples/resources_example/third_party,examples/soto_example,examples/soto_example/Tests/SotoTests,examples/tca_example,examples/tca_example/SwiftUICaseStudies,examples/tca_example/SwiftUICaseStudiesTests,examples/vapor_example,examples/vapor_example/Sources/App,examples/vapor_example/Sources/Run,examples/vapor_example/Tests/AppTests,examples/vapor_example/swift,examples/xcmetrics_example
query --deleted_packages=bzlmod/workspace,bzlmod/workspace/Sources/MyExecutable,bzlmod/workspace/Sources/MyLibrary,bzlmod/workspace/Tests/MyLibraryTests,examples/firebase_example,examples/firebase_example/abtesting,examples/firebase_example/abtesting/SharedApp,examples/firebase_example/analytics/AnalyticsExample,examples/firebase_example/appdistribution,examples/firebase_example/appdistribution/AppDistributionExample,examples/firebase_example/appdistribution/AppDistributionTests,examples/firebase_example/crashlytics,examples/http_archive_ext_deps,examples/http_archive_ext_deps/Sources/MyDequeModule,examples/http_archive_ext_deps/Sources/PrintStuff,examples/http_archive_ext_deps/Tests/MyDequeModuleTests,examples/http_archive_ext_deps/third_party,examples/interesting_deps,examples/ios_sim,examples/ios_sim/Sources/Foo,examples/ios_sim/Tests/FooTests,examples/ios_sim/third-party/swift-cmark,examples/nimble_example,examples/nimble_example/Sources/NimbleExample,examples/objc_code,examples/phone_number_kit,examples/phone_number_kit/Tests/PhoneNumberKitTests,examples/pkg_manifest_minimal,examples/pkg_manifest_minimal/Sources/MyExecutable,examples/pkg_manifest_minimal/Sources/MyLibrary,examples/pkg_manifest_minimal/Tests/MyLibraryTests,examples/pkg_manifest_minimal/third_party,examples/resources_example,examples/resources_example/Sources/MyApp,examples/resources_example/Tests/MyAppTests,examples/resources_example/third_party,examples/soto_example,examples/soto_example/Tests/SotoTests,examples/tca_example,examples/tca_example/SwiftUICaseStudies,examples/tca_example/SwiftUICaseStudiesTests,examples/vapor_example,examples/vapor_example/Sources/App,examples/vapor_example/Sources/Run,examples/vapor_example/Tests/AppTests,examples/vapor_example/swift,examples/xcmetrics_example

# Import Shared settings
import %workspace%/shared.bazelrc
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/set_up_macos/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ inputs:
required: true
xcode_version:
description: The version of Xcode to use.
default: '14.0.1'
default: '14.3.1'

runs:
using: composite
Expand Down
5 changes: 4 additions & 1 deletion config_settings/spm/platform/platforms.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,11 @@ def _label(name):
Returns:
The condition label as a `string`.
"""

# There is currently no support Mac Catalyst in Bazel. These are Mac apps
# that use iOS frameworks. Treat it like iOS for now.
if name == "maccatalyst":
name = "macos"
name = "ios"
return "@rules_swift_package_manager//config_settings/spm/platform:{}".format(name)

platforms = struct(
Expand Down
8 changes: 5 additions & 3 deletions examples/firebase_example/.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import %workspace%/../../ci.bazelrc
# Try to import a local.rc file; typically, written by CI
try-import %workspace%/../../local.bazelrc

# The CNIOBoringSSL uses C++14 features like 'enable_if_t' macro support.
# For more details on how to enable this in Bazel:
# Per https://github.com/firebase/firebase-ios-sdk/blob/master/Package.swift#L1322-L1323
# NOTE: Puposefully not specifying --copt='-std=c99' as it is applied to
# objc_library targets that contain Objective-C++ files. Tried using
# --per_file_copt to exclude .mm files, but did not have success.
# https://stackoverflow.com/questions/40260242/how-to-set-c-standard-version-when-build-with-bazel/43388168#43388168
build --cxxopt='-std=c++14'
build --cxxopt='-std=gnu++14'

# Firebase SPM support requires `-ObjC` linker option.
# https://github.com/firebase/firebase-ios-sdk/blob/master/SwiftPackageManager.md#requirements
Expand Down
1 change: 1 addition & 0 deletions examples/firebase_example/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@ swift_deps.from_file(
use_repo(
swift_deps,
"swiftpkg_firebase_ios_sdk",
"swiftpkg_reachability.swift",
)
# swift_deps END
46 changes: 23 additions & 23 deletions examples/firebase_example/Package.resolved
Original file line number Diff line number Diff line change
@@ -1,39 +1,30 @@
{
"pins" : [
{
"identity" : "abseil-cpp-swiftpm",
"identity" : "abseil-cpp-binary",
"kind" : "remoteSourceControl",
"location" : "https://github.com/firebase/abseil-cpp-SwiftPM.git",
"location" : "https://github.com/google/abseil-cpp-binary.git",
"state" : {
"revision" : "583de9bd60f66b40e78d08599cc92036c2e7e4e1",
"version" : "0.20220203.2"
}
},
{
"identity" : "boringssl-swiftpm",
"kind" : "remoteSourceControl",
"location" : "https://github.com/firebase/boringssl-SwiftPM.git",
"state" : {
"revision" : "dd3eda2b05a3f459fc3073695ad1b28659066eab",
"version" : "0.9.1"
"revision" : "bfc0b6f81adc06ce5121eb23f628473638d67c5c",
"version" : "1.2022062300.0"
}
},
{
"identity" : "firebase-ios-sdk",
"kind" : "remoteSourceControl",
"location" : "https://github.com/firebase/firebase-ios-sdk",
"state" : {
"revision" : "f567ed9a2b30e29159df258049a9c662c517688e",
"version" : "10.5.0"
"revision" : "e700a8f40c87c31cab7984875fcc1225d96b25bf",
"version" : "10.11.0"
}
},
{
"identity" : "googleappmeasurement",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/GoogleAppMeasurement.git",
"state" : {
"revision" : "9a09ece724128e8d1e14c5133b87c0e236844ac0",
"version" : "10.4.0"
"revision" : "62e3a0c09a75e2637f5300d46f05a59313f1c286",
"version" : "10.11.0"
}
},
{
Expand All @@ -55,21 +46,21 @@
}
},
{
"identity" : "grpc-ios",
"identity" : "grpc-binary",
"kind" : "remoteSourceControl",
"location" : "https://github.com/grpc/grpc-ios.git",
"location" : "https://github.com/google/grpc-binary.git",
"state" : {
"revision" : "8440b914756e0d26d4f4d054a1c1581daedfc5b6",
"version" : "1.44.3-grpc"
"revision" : "f1b366129d1125be7db83247e003fc333104b569",
"version" : "1.50.2"
}
},
{
"identity" : "gtm-session-fetcher",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/gtm-session-fetcher.git",
"state" : {
"revision" : "96d7cc73a71ce950723aa3c50ce4fb275ae180b8",
"version" : "3.1.0"
"revision" : "5ccda3981422a84186387dbb763ba739178b529c",
"version" : "2.3.0"
}
},
{
Expand Down Expand Up @@ -99,6 +90,15 @@
"version" : "2.1.1"
}
},
{
"identity" : "reachability.swift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/ashleymills/Reachability.swift.git",
"state" : {
"revision" : "c01bbdf2d633cf049ae1ed1a68a2020a8bda32e2",
"version" : "5.1.0"
}
},
{
"identity" : "swift-protobuf",
"kind" : "remoteSourceControl",
Expand Down
2 changes: 2 additions & 0 deletions examples/firebase_example/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ let package = Package(
name: "firebase_example",
dependencies: [
.package(url: "https://github.com/firebase/firebase-ios-sdk", .upToNextMajor(from: "10.0.0")),
// Used by crashlytics example
.package(url: "https://github.com/ashleymills/Reachability.swift.git", .upToNextMajor(from: "5.1.0")),
]
)
62 changes: 62 additions & 0 deletions examples/firebase_example/crashlytics/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
load("@bazel_skylib//rules:build_test.bzl", "build_test")
load("@build_bazel_rules_apple//apple:ios.bzl", "ios_application")
load("@build_bazel_rules_apple//apple:macos.bzl", "macos_application")
load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library")

# Exclude this entire directory from having anything generated by Gazelle. That
# way the test cases won't be fixed by `bazel run //:update_build_files` when
# run in this repository.
# gazelle:exclude **

swift_library(
name = "CrashlyticsSwiftUIExample",
srcs = [
"Shared/ContentView.swift",
"Shared/CrashlyticsSwiftUIExampleApp.swift",
"Shared/ReachabililtyHelper.swift",
],
module_name = "CrashlyticsSwiftUIExample",
tags = ["manual"],
visibility = ["//visibility:public"],
deps = [
"@swiftpkg_firebase_ios_sdk//:Crashlytics_FirebaseCrashlytics",
"@swiftpkg_reachability.swift//:Sources_Reachability",
],
)

ios_application(
name = "iosapp",
bundle_id = "com.google.firebase.quickstart.CrashlyticsExample",
families = [
"iphone",
"ipad",
],
infoplists = [":iOS/Info.plist"],
minimum_os_version = "15.0",
resources = glob(
["CrashlyticsSwiftUIExample/Assets.xcassets/**"],
exclude = ["CrashlyticsSwiftUIExample/Assets.xcassets/AppIconTopShelfImage.brandassets/**"],
),
deps = [":CrashlyticsSwiftUIExample"],
)

macos_application(
name = "macosapp",
bundle_id = "com.google.firebase.quickstart.CrashlyticsExample",
entitlements = ":macOS/macOS.entitlements",
infoplists = [":macOS/Info.plist"],
minimum_os_version = "11.0",
resources = glob(
["CrashlyticsSwiftUIExample/Assets.xcassets/**"],
exclude = ["CrashlyticsSwiftUIExample/Assets.xcassets/AppIconTopShelfImage.brandassets/**"],
),
deps = [":CrashlyticsSwiftUIExample"],
)

build_test(
name = "iosapp_build_test",
targets = [
":iosapp",
":macosapp",
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"images" : [
{
"idiom" : "tv",
"scale" : "1x"
},
{
"idiom" : "tv",
"scale" : "2x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"info" : {
"author" : "xcode",
"version" : 1
},
"layers" : [
{
"filename" : "Front.imagestacklayer"
},
{
"filename" : "Middle.imagestacklayer"
},
{
"filename" : "Back.imagestacklayer"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"images" : [
{
"idiom" : "tv",
"scale" : "1x"
},
{
"idiom" : "tv",
"scale" : "2x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"images" : [
{
"idiom" : "tv",
"scale" : "1x"
},
{
"idiom" : "tv",
"scale" : "2x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"images" : [
{
"idiom" : "tv"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"info" : {
"author" : "xcode",
"version" : 1
},
"layers" : [
{
"filename" : "Front.imagestacklayer"
},
{
"filename" : "Middle.imagestacklayer"
},
{
"filename" : "Back.imagestacklayer"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"images" : [
{
"idiom" : "tv"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"images" : [
{
"idiom" : "tv"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading

0 comments on commit 1df27c6

Please sign in to comment.