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

Subspecs support on the MergeFile #22

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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 PodMergeExample/MergeFile
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ end

group 'MergedSwiftPods' do
# Swift Pods
swift_version! '5.0'

pod 'SnapKit', '5.0.1'
pod 'SwiftyJSON', '5.0.0'
pod 'youtube-ios-player-helper'
end

group 'AlamofireGroup' do
Expand All @@ -26,3 +29,8 @@ group 'AlamofireGroup' do
pod 'AlamofireImage', '3.6.0'
pod 'AlamofireActivityLogger', '2.5.0'
end

group 'Subspecs'
pod 'AppAuth/Core'
pod 'AppAuth/ExternalUserAgent'
end
6 changes: 6 additions & 0 deletions PodMergeExample/PodMergeExample/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import UI.TTTAttributedLabel

import Networking.AFNetworking
import Networking.SDWebImage
import Subspecs.AppAuth

// Merged Swift Pods cannot be import individually, only all or none.
import MergedSwiftPods
Expand Down Expand Up @@ -50,6 +51,11 @@ class ViewController: UIViewController {
// SnapKit Usage
let box = UIView()
box.snp.makeConstraints { _ in }

let authorizationEndpoint = URL(string: "https://accounts.google.com/o/oauth2/v2/auth")!
let tokenEndpoint = URL(string: "https://www.googleapis.com/oauth2/v4/token")!
let configuration = OIDServiceConfiguration(authorizationEndpoint: authorizationEndpoint,
tokenEndpoint: tokenEndpoint)
}
}

1 change: 1 addition & 0 deletions PodMergeExample/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ target 'PodMergeExample' do
pod 'UI', :path => 'MergedPods/UI'
pod 'AlamofireGroup', :path => 'MergedPods/AlamofireGroup'
pod 'MergedSwiftPods', :path => 'MergedPods/MergedSwiftPods'
pod 'Subspecs', :path => 'MergedPods/Subspecs'
end
9 changes: 7 additions & 2 deletions PodMergeExample/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ PODS:
- MergedSwiftPods (1.0.0)
- Networking (1.0.0)
- Nuke (8.3.1)
- Subspecs (1.0.0)
- UI (1.0.0)

DEPENDENCIES:
- AlamofireGroup (from `MergedPods/AlamofireGroup`)
- MergedSwiftPods (from `MergedPods/MergedSwiftPods`)
- Networking (from `MergedPods/Networking`)
- Nuke
- Subspecs (from `MergedPods/Subspecs`)
- UI (from `MergedPods/UI`)

SPEC REPOS:
Expand All @@ -23,16 +25,19 @@ EXTERNAL SOURCES:
:path: MergedPods/MergedSwiftPods
Networking:
:path: MergedPods/Networking
Subspecs:
:path: MergedPods/Subspecs
UI:
:path: MergedPods/UI

SPEC CHECKSUMS:
AlamofireGroup: 113f3ab321b31b75a748378909f3f96305b771a2
MergedSwiftPods: 86f52fdd7411987cd39e6c80e709ef0de0126fd3
MergedSwiftPods: 1d3174c8375d5c332021c20accaedaf11b5e58d0
Networking: 844633d13d2328a829083b24ffaee99aea51c1de
Nuke: 85fb80f8df0cb26c28d2f4e0cb7fb93bcd6548d3
Subspecs: 634e12dffc5b250b231410781ffa7b7c2c665b7a
UI: 2aa82721ee430cd2f0ab314904bbe1a281fa2ff9

PODFILE CHECKSUM: 689012d73798a7fea312905128d4dadb72554cf1
PODFILE CHECKSUM: cf932697df9d1e546ce24dd892661e3d0e6d57ec

COCOAPODS: 1.10.1
12 changes: 9 additions & 3 deletions lib/cocoapods-pod-merge/Main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ def parse_mergefile
def merge(merged_framework_name, group_contents, podfile_info)
Pod::UI.puts "Preparing to Merge: #{merged_framework_name}"

pods_to_merge = group_contents['titles']
# Replace the Subspecs notation (e.g AppAuth/Core) for `AppAuth` only as the folder AppAuth/Core would not exist
pods_to_merge = group_contents['titles'].map { |pod_name| pod_name.sub /(\/[a-zA-Z]+)/,''}.uniq

Choose a reason for hiding this comment

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

Can elaborate exactly what this regex does? Will it remove any other symbols from a Pod name except /? Asking because I've come across pod names with symbols like _ , -

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure the purpose of the regex is to replace subspecs like AppAuth/Core for AppAuth as the folder AppAuth/Core would not exist. Do you have any names of pods with the _, - in mind we can test ? Maybe I missed those cases 😞.

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That one doesn't have sub-specs so it doesn't affect anything related to the changes. Also that one is a vendor framework so it would fail. For example I added this youtube-ios-player-helper to the MergedSwiftPods and it works successfully.

Nevertheless I detected an error that could be worth to fix later and it's related to the dashes in the module map. If I add the youtube-ios-player-helper to the Subspecs group it would fail because the module.modulemap doesn't like dashes in the definition of modules

explicit module youtube-ios-player-helper {
     header "YTPlayerView.h"
}

And I think that's why most of the pods using dashes they also define module_name (I have a PR coming soon to fix an issue related to this with lottie-ios as pods with module_name defined should use the module_name instead of the name of the pod specification for imports)

flags = group_contents['flags']
forced_swift_language_version = group_contents['swift_version']
platforms_in_target = group_contents['platforms']
Expand Down Expand Up @@ -231,7 +232,7 @@ def merge(merged_framework_name, group_contents, podfile_info)
FileUtils.mkdir("#{InstallationDirectory}/#{merged_framework_name}/Sources")

Pod::UI.puts 'Merging Pods'.cyan
pods_to_merge.each do |pod|
pods_to_merge.each_with_index do |pod, index|
# Capture all resources to specify in the final podspec
Pod::UI.puts "\t#{pod.cyan}"

Expand Down Expand Up @@ -293,8 +294,13 @@ def merge(merged_framework_name, group_contents, podfile_info)

# Read each pod's podspec, and collect configuration for the final merged podspec
Pod::UI.puts "\t\tExtracting Detailed Podspecs".magenta

# The originals pods name with the subspecs from the MergeFile. The subspecs are renamed to
# PodspecName_Subspec instead of PodspecName/Subspec
pods_to_merge_with_subspecs = group_contents['titles'].map { |pod_name| pod_name.sub '/','_'}

Dir.chdir("#{CacheDirectory}/Podspecs") do
info = extract_info_from_podspec(pod, mixed_language_group)
info = extract_info_from_podspec(pods_to_merge_with_subspecs[index], mixed_language_group)
frameworks += info.frameworks
prefix_header_contents += info.prefix_header_contents
private_header_files += info.private_header_files
Expand Down