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

Update our Package.swift to build MapboxMaps from source #125

Merged
merged 1 commit into from
Feb 20, 2021

Conversation

jmkiley
Copy link
Contributor

@jmkiley jmkiley commented Feb 19, 2021

Pull request checklist:

  • Briefly describe the changes in this PR.
  • Apply changelog label ('breaking change', 'bug 🪲', 'build', 'docs', 'feature 🍏', 'performance ⚡', 'testing 💯') or use the label 'skip changelog'
  • Add an entry inside this element for inclusion in the mapbox-maps-ios changelog: <changelog>MapboxMaps can now be built and tested using Swift Package Manager</changelog>.

Summary of changes

Configuration Changes

  • Updated Package.swift to build the project from source
  • Reorganized the source files according to SPM conventions
  • Updated the paths of the groups in the MapboxMaps Xcode project to point to the new file locations
  • Marked OrnamentsLocalizable.strings as a localized resource
  • Updated MBXGeometry.swift to conditionally compile the @unknown default: of a switch statement with an expression of type Geometry from Turf. This is required since when we build the SDK as an XCFramework, Turf is compiled in library evolution mode, so a default case is required, but when we build the SDK as a Swift package, Turf is not built in library evolution mode, so the default case is unnecessary (and the compiler warns if it is present).
  • .gitignore updates:
    • Stopped ignoring IDEWorkspaceCHecks.plist
    • Stopped ignoring .swiftpm
    • Stopped ignoring Package.resolved
    • Started ignoring MapboxAccessToken

Dependency Version Changes

  • Switched to MapboxMobileEvents v0.10.8 (Carthage & SPM only)
  • Switched to Turf v1.2.0 (SPM only)

Bundle & Info.plist Usage Changes

  • Added a Build Pre-Action to MapboxMaps's SPM scheme to copy the Mapbox access token from either ~/.mapbox or ~/mapbox into the new MapboxAccessToken file. The integration tests need this token. Previously, they looked for it in the test bundle's Info.plist, but this approach does not work for SPM. IntegrationTestCase.setupAccessToken() has been updated accordingly.
  • Added Bundle.mapboxMaps and Bundle.mapboxMapsTests abstractions to allow accessing the SDK's resources. These abstractions handle differences that occur when building the SDK as a Swift package vs building it as a framework. In the SDK source, Bundle.main is used when the intent is to access the bundle of the containing application, and Bundle.mapboxMaps is used when the intent is to use the SDK's bundle.
  • Replaced usages of Bundle.object(forInfoDictionaryKey:) with Bundle.infoDictionary?[]
  • Hard-coded the SDK version in EventsManager.swift because we will not be able to customize the SDK's Info.plist when the SDK is built as a Swift package.

Fixes

  • Fixed an issue in MapViewIntegrationTests.setUpWithError() in which super.setUpWithError() was invoked with try? instead of try, preventing it from being able to skip the test.
  • Reviewed Xcode 12.4's upgrade recommendations
  • Fixed a canImport in MapboxMapsAnnotationsTests.swift

Deletions

  • Deleted unused installation tests
  • Deleted some placeholder SPM-style tests in the Tests directory
  • Deleted some unused source files and dangling file references

@jmkiley jmkiley self-assigned this Feb 19, 2021
@codecov
Copy link

codecov bot commented Feb 19, 2021

Codecov Report

Merging #125 (f298012) into main (3b56750) will increase coverage by 0.03%.
The diff coverage is 61.90%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #125      +/-   ##
==========================================
+ Coverage   48.93%   48.97%   +0.03%     
==========================================
  Files         101      102       +1     
  Lines        5683     5687       +4     
==========================================
+ Hits         2781     2785       +4     
  Misses       2902     2902              
Flag Coverage Δ
unit-tests 48.97% <61.90%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...ces/MapboxMaps/Annotations/AnnotationManager.swift 60.64% <ø> (ø)
...boxMaps/Annotations/AnnotationSupportableMap.swift 3.84% <ø> (ø)
...ources/MapboxMaps/Annotations/LineAnnotation.swift 66.66% <ø> (ø)
...urces/MapboxMaps/Annotations/PointAnnotation.swift 94.59% <ø> (ø)
...ces/MapboxMaps/Annotations/PolygonAnnotation.swift 71.42% <ø> (ø)
Sources/MapboxMaps/Foundation/AccountManager.swift 0.00% <0.00%> (ø)
Sources/MapboxMaps/Foundation/BaseMapView.swift 69.58% <0.00%> (ø)
...ces/MapboxMaps/Foundation/Camera/CameraLayer.swift 60.46% <ø> (ø)
...s/MapboxMaps/Foundation/Camera/CameraManager.swift 76.71% <ø> (ø)
...s/MapboxMaps/Foundation/Camera/CameraOptions.swift 50.00% <ø> (ø)
... and 93 more

@macdrevx macdrevx changed the title [WIP] Update our Package.swift to build MapboxMaps from source Update our Package.swift to build MapboxMaps from source Feb 19, 2021
Package.swift Outdated Show resolved Hide resolved
let bundle = Bundle(for: type(of: self))
var sdkVersionOptional = bundle.infoDictionary?["MGLSemanticVersionString"]
if sdkVersionOptional == nil {
sdkVersionOptional = bundle.infoDictionary?["CFBundleShortVersionString"]
}
guard let sdkVersion = sdkVersionOptional as? String else { return }
let sdkVersion = "10.0.0"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create a ticket to find a better solution

@@ -1,4 +1,4 @@
binary "https://api.mapbox.com/downloads/v2/carthage/mapbox-common/MapboxCommon-ios.json" "10.0.0-beta.11"
binary "https://api.mapbox.com/downloads/v2/carthage/mobile-maps-core/MapboxCoreMaps-dynamic.json" "10.0.0-beta.15"
github "mapbox/mapbox-events-ios" "v0.10.7"
github "mapbox/mapbox-events-ios" "v0.10.8"
github "mapbox/turf-swift" "v2.0.0-alpha.2"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to update Turf here and in the podspec as well?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we still need this version for Carthage so that it gets built in library evolution mode. For CocoaPods, we will switch to 1.2.0 as part of #118.

@macdrevx macdrevx force-pushed the jk/package.swift branch 2 times, most recently from 3c9e79b to f298012 Compare February 20, 2021 03:06
Configuration Changes:

- Updated Package.swift to build the project from source
- Reorganized the source files according to SPM conventions
- Updated the paths of the groups in the MapboxMaps Xcode project to
  point to the new file locations
- Marked OrnamentsLocalizable.strings as a localized resource
- Updated MBXGeometry.swift to conditionally compile the @unknown
  default: of a switch statement with an expression of type Geometry
  from Turf. This is required since when we build the SDK as an
  XCFramework, Turf is compiled in library evolution mode, so a default
  case is required, but when we build the SDK as a Swift package, Turf
  is not built in library evolution mode, so the default case is
  unnecessary (and the compiler warns if it is present).
- .gitignore updates:
  - Stopped ignoring IDEWorkspaceCHecks.plist
  - Stopped ignoring .swiftpm
  - Stopped ignoring Package.resolved
  - Started ignoring MapboxAccessToken

Dependency Version Changes:

- Switched to MapboxMobileEvents v0.10.8 (Carthage & SPM only)
- Switched to Turf v1.2.0 (SPM only)

Bundle & Info.plist Usage Changes:

- Added a Build Pre-Action to MapboxMaps's SPM scheme to copy the Mapbox
  access token from either ~/.mapbox or ~/mapbox into the new
  MapboxAccessToken file. The integration tests need this token.
  Previously, they looked for it in the test bundle's Info.plist, but
  this approach does not work for SPM.
  IntegrationTestCase.setupAccessToken() has been updated accordingly.
- Added Bundle.mapboxMaps and Bundle.mapboxMapsTests abstractions to
  allow accessing the SDK's resources. These abstractions handle
  differences that occur when building the SDK as a Swift package vs
  building it as a framework. In the SDK source, Bundle.main is used
  when the intent is to access the bundle of the containing application,
  and Bundle.mapboxMaps is used when the intent is to use the SDK's
  bundle.
- Replaced usages of Bundle.object(forInfoDictionaryKey:) with
  Bundle.infoDictionary?[]
- Hard-coded the SDK version in EventsManager.swift because we will not
  be able to customize the SDK's Info.plist when the SDK is built as a
  Swift package.

Fixes:

- Fixed an issue in MapViewIntegrationTests.setUpWithError() in which
  super.setUpWithError() was invoked with try? instead of try,
  preventing it from being able to skip the test.
- Reviewed Xcode 12.4's upgrade recommendations
- Fixed a canImport in MapboxMapsAnnotationsTests.swift

Deletions:

- Deleted unused installation tests
- Deleted some placeholder SPM-style tests in the Tests directory
- Deleted some unused source files and dangling file references
@macdrevx macdrevx added the feature 🍏 When working on a new feature or feature enhancement label Feb 20, 2021
@macdrevx macdrevx merged commit 6f0555d into main Feb 20, 2021
@macdrevx macdrevx deleted the jk/package.swift branch February 20, 2021 03:34
macdrevx added a commit that referenced this pull request Feb 21, 2021
The change broke building the Examples scheme for testing.
@1ec5 1ec5 mentioned this pull request Feb 22, 2021
3 tasks
dependencies: [
.package(name: "MapboxCommon", url: "https://github.com/mapbox/mapbox-common-ios.git", .exact("10.0.0-beta.11")),
.package(name: "MapboxCoreMaps", url: "https://github.com/mapbox/mapbox-core-maps-ios.git", .exact("10.0.0-beta.15")),
.package(name: "MapboxMobileEvents", url: "https://github.com/mapbox/mapbox-events-ios.git", .exact("0.10.8")),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be exact, or can it be from: like the Turf dependency and Cartfile?

macdrevx added a commit that referenced this pull request Feb 22, 2021
@1ec5 1ec5 mentioned this pull request Feb 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature 🍏 When working on a new feature or feature enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants