From 7be0b33862a02e864ef1a5e59143ffe158059820 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikl=C3=B3s=20Fazekas?= Date: Fri, 25 Mar 2022 20:36:16 +0100 Subject: [PATCH] Remove safeExtGet from buildscipt, check for Mapbox in SPM if we're using cocoapods --- CHANGELOG.md | 5 +++-- android/rctmgl/build.gradle | 2 +- example/android/build.gradle | 4 ---- rnmapbox-maps.podspec | 40 +++++++++++++++++++++++++++++++++++- 4 files changed, 43 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c52daad28..3ede1b1c7f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,8 +12,9 @@ Updated MapLibre on Android to 9.5.2 ([#1780](https://github.com/rnmapbox/maps/p #### Breaking changes: The setup was changed - see install instructions for more details. In a nuthsell: -* On both android and ios to select mapbox implementation use `RNMabpoxMapsImpl` variable which can be one of (`maplibre`,`mapbox`(aka v10),`mapbox-gl`) -* Package name was changed from `@react-native-mapbox-gl/maps` to `@rnmapbox/maps`. If you just testing with the v10 branch you can use something like [babel-plugin-transform-rename-import](https://www.npmjs.com/package/babel-plugin-transform-rename-import) to change all your source files. +* On both android/ios to select mapbox implementation use `RNMabpoxMapsImpl`/`$RNMapboxMaps` variable which can be one of (`maplibre`,`mapbox`(aka v10),`mapbox-gl`) +* On Podfile `$RNMBGL.(pre|post)_install` was changed `$RNMapboxMaps.(pre|post)_install` +* Package name was changed from `@react-native-mapbox-gl/maps` to `@rnmapbox/maps`. If you just testing with the v10 version you can use something like [babel-plugin-transform-rename-import](https://www.npmjs.com/package/babel-plugin-transform-rename-import) to keep using the old imports for a while. #### Changes: diff --git a/android/rctmgl/build.gradle b/android/rctmgl/build.gradle index be12f258f7..61c4943c8e 100644 --- a/android/rctmgl/build.gradle +++ b/android/rctmgl/build.gradle @@ -11,7 +11,7 @@ buildscript { } dependencies { - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${safeExtGet('kotlinVersion', '1.4.10')}" + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${rootProject.ext.has('kotlinVersion') ? rootProject.ext.get('kotlinVersion') : '1.4.10'}" } } diff --git a/example/android/build.gradle b/example/android/build.gradle index 3e9a180156..2fa238c1e2 100644 --- a/example/android/build.gradle +++ b/example/android/build.gradle @@ -50,10 +50,6 @@ buildscript { } } -def safeExtGet(prop, fallback) { - rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback -} - allprojects { repositories { mavenCentral() diff --git a/rnmapbox-maps.podspec b/rnmapbox-maps.podspec index 07cfb0e682..26c9ea6c40 100644 --- a/rnmapbox-maps.podspec +++ b/rnmapbox-maps.podspec @@ -1,3 +1,19 @@ +# Customization: +# $RNMapboxMapsImpl - one of (maplibre, mapbox, mapbox-gl) +# $RNMapboxMapsVersion - version specification ("~> 10.4.0", "~> 5.9.0" or "exactVersion 5.12.1" mapblibre/SPM) +# $RNMapboxMapsSwiftPackageManager can be either +# "manual" - you're responsible for the Mapbox lib dependency either using cocoapods or SPM +# Hash - ``` +# { +# url: "https://github.com/maplibre/maplibre-gl-native-distribution", +# requirement: { +# kind: 'exactVersion', +# version: 5.12.1, +# }, +# product_name: "Mapbox" +# } +# ``` + require 'json' package = JSON.parse(File.read(File.join(__dir__, 'package.json'))) @@ -84,7 +100,6 @@ when 'maplibre' end unless $RNMapboxMapsSwiftPackageManager - puts "Init SPM" $RNMapboxMapsSwiftPackageManager = { url: "https://github.com/maplibre/maplibre-gl-native-distribution", requirement: { @@ -100,6 +115,18 @@ end $RNMapboxMaps = Object.new +def $RNMapboxMaps._check_no_mapbox_spm(project) + pkg_class = Xcodeproj::Project::Object::XCRemoteSwiftPackageReference + ref_class = Xcodeproj::Project::Object::XCSwiftPackageProductDependency + pkg = project.root_object.package_references.find { |p| p.class == pkg_class && [ + "https://github.com/maplibre/maplibre-gl-native-distribution", + "https://github.com/mapbox/mapbox-maps-ios.git" + ].include?(p.repositoryURL) } + if pkg + puts "!!! Warning: Duplicate Mapbox dependency found, it's consumed by both SwiftPackageManager and CocoaPods" + end +end + def $RNMapboxMaps._add_spm_to_target(project, target, url, requirement, product_name) pkg_class = Xcodeproj::Project::Object::XCRemoteSwiftPackageReference ref_class = Xcodeproj::Project::Object::XCSwiftPackageProductDependency @@ -121,6 +148,8 @@ end def $RNMapboxMaps.post_install(installer) if $RNMapboxMapsSwiftPackageManager + return if $RNMapboxMapsSwiftPackageManager == "manual" + spm_spec = $RNMapboxMapsSwiftPackageManager project = installer.pods_project self._add_spm_to_target( @@ -144,6 +173,15 @@ def $RNMapboxMaps.post_install(installer) end end end + else + self._check_no_mapbox_spm(installer.pods_project) + installer.aggregate_targets.group_by(&:user_project).each do |project, targets| + targets.each do |target| + target.user_targets.each do |user_target| + self._check_no_mapbox_spm(project) + end + end + end end end