From 1c97aaf6077e169aa5dbec1855ca2b32f95282ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikl=C3=B3s=20Fazekas?= Date: Wed, 14 Apr 2021 10:49:55 +0200 Subject: [PATCH] Allow to use Mapbox or MapLibre from SPM --- example/ios/Podfile | 9 ++++ .../project.pbxproj | 21 --------- react-native-mapbox-gl.podspec | 44 ++++++++++++++++++- 3 files changed, 52 insertions(+), 22 deletions(-) diff --git a/example/ios/Podfile b/example/ios/Podfile index 2be0e084a6..61fa4fd332 100644 --- a/example/ios/Podfile +++ b/example/ios/Podfile @@ -3,6 +3,15 @@ require_relative '../node_modules/@react-native-community/cli-platform-ios/nativ platform :ios, '10.0' +$RNMBGL_Use_SPM = { + url: "https://github.com/maplibre/maplibre-gl-native-distribution", + requirement: { + kind: "upToNextMajorVersion", + minimumVersion: "5.11.0" + }, + product_name: "Mapbox" +} + # We ingore warning except for RNMBGL INHIBIT_WARNING_BY_DEFAULT = true diff --git a/example/ios/RNMapboxGLExample.xcodeproj/project.pbxproj b/example/ios/RNMapboxGLExample.xcodeproj/project.pbxproj index 0d45a7a956..66aca98c1a 100644 --- a/example/ios/RNMapboxGLExample.xcodeproj/project.pbxproj +++ b/example/ios/RNMapboxGLExample.xcodeproj/project.pbxproj @@ -267,7 +267,6 @@ 13B07F8C1A680F5B00A75B9A /* Frameworks */, 13B07F8E1A680F5B00A75B9A /* Resources */, 00DD1BFF1BD5951E006B06BC /* Bundle React Native code and images */, - E8948F16DF738C997C01FB08 /* [CP] Embed Pods Frameworks */, 7BC27FFD4688D6914F2322C7 /* [CP] Copy Pods Resources */, ); buildRules = ( @@ -543,26 +542,6 @@ shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; showEnvVarsInLog = 0; }; - E8948F16DF738C997C01FB08 /* [CP] Embed Pods Frameworks */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - "${PODS_ROOT}/Target Support Files/Pods-RNMapboxGLExample/Pods-RNMapboxGLExample-frameworks.sh", - "${PODS_ROOT}/Mapbox-iOS-SDK/dynamic/Mapbox.framework", - "${BUILT_PRODUCTS_DIR}/MapboxMobileEvents/MapboxMobileEvents.framework", - ); - name = "[CP] Embed Pods Frameworks"; - outputPaths = ( - "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Mapbox.framework", - "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/MapboxMobileEvents.framework", - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-RNMapboxGLExample/Pods-RNMapboxGLExample-frameworks.sh\"\n"; - showEnvVarsInLog = 0; - }; FCA9706C7D689F287412B48F /* [CP] Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; diff --git a/react-native-mapbox-gl.podspec b/react-native-mapbox-gl.podspec index 279a132e50..c3b1c31c84 100644 --- a/react-native-mapbox-gl.podspec +++ b/react-native-mapbox-gl.podspec @@ -12,8 +12,48 @@ TargetsToChangeToDynamic = ['MapboxMobileEvents'] $RNMBGL = Object.new +def $RNMBGL._add_spm_to_target(project, target_name, url, requirement, product_name) + project.targets.each do |target| + if target.name == target_name + + pkg = project.new(Xcodeproj::Project::Object::XCRemoteSwiftPackageReference) + pkg.repositoryURL = url + pkg.requirement = requirement + ref = project.new(Xcodeproj::Project::Object::XCSwiftPackageProductDependency) + ref.package = pkg + ref.product_name = product_name + + target.package_product_dependencies << ref + + project.root_object.package_references << pkg + end + end + + project.save +end + def $RNMBGL.post_install(installer) - # Noop + if $RNMBGL_Use_SPM + rpm_spec = { + url: "https://github.com/maplibre/maplibre-gl-native-distribution", + requirement: { + kind: "upToNextMajorVersion", + minimumVersion: "5.11.0" + }, + product_name: "Mapbox" + } + + if $RNMBGL_Use_SPM.is_a?(Hash) + rpm_spec = $RNMBGL_Use_SPM + end + self._add_spm_to_target( + installer.pods_project, + "react-native-mapbox-gl", + rpm_spec[:url], + rpm_spec[:requirement], + rpm_spec[:product_name] + ) + end end def $RNMBGL.pre_install(installer) @@ -36,7 +76,9 @@ Pod::Spec.new do |s| s.license = "MIT" s.platform = :ios, "8.0" + if !$RNMBGL_Use_SPM s.dependency 'Mapbox-iOS-SDK', rnmbgl_ios_version + end s.dependency 'React-Core' s.dependency 'React'