buguibu / ios-notes-issues-lessons

Notes, issues and lessons about my iOS development experience
2 stars 0 forks source link

Private subspaces and multi target apps workspace #33

Open buguibu opened 2 years ago

buguibu commented 2 years ago

Given a private pod repo with several subspecs like

Pod::Spec.new do |s|
    s.name = "Networking"
    # ...
    s.source_files = [
        "Networking/**/*.{h,swift}"
    ]

    s.ios.vendored_frameworks = "Networking.xcframework"

    s.dependency 'Environment', '~> 1.0d'

    s.default_subspecs = 'Common'

    s.subspec 'Common' do |common|
        common.source_files = [
            "Networking/**/*.{h,swift}", 
            "DLog-iOS/Sources/DLog/*.swift"
        ]
    end

    s.subspec 'Account' do |account|
        account.dependency "Networking/Common"
        account.source_files = [
            "Account/**/*.{h,swift}"
        ]
    end

    s.subspec 'AppBasics' do |appbasics|
        appbasics.dependency "Networking/Common"
        appbasics.source_files = [
            "AppBasics/**/*.{h,swift}"
        ]
    end

    s.subspec 'Athing' do |thing|
        thing.dependency "Networking/Common"
        thing.source_files = [
            "Athing/**/*.{h,swift}"
        ]
    end

    s.subspec 'OtherThing' do |otherthing|
        otherthing.dependency "Networking/Common"
        otherthing.source_files = [
            "OtherThing/**/*.{h,swift}"
        ]
    end
end

If you have a workspace with different target that uses different subspecs of the one above, this solution works:

platform :ios, '12.1'
use_frameworks!

abstract_target "Abstract" do
  pod 'GoogleUtilities', '~> 7.1.1'

  pod 'Environment', :path => '../Environment-iOS'
  pod 'Networking/Account', :path => '../Networking-iOS'

  target 'AppOne' do
    inhibit_all_warnings!
    common_app_pods
    ds_core_challenge_pod
    pod 'Networking/Athing', :path => '../Networking-iOS'
    pod 'Networking/OtherThing', :path => '../Networking-iOS'
  end

  target 'AppTwo' do
    inhibit_all_warnings!
    common_app_pods
    ds_core_challenge_pod
    pod 'Networking/Athing', :path => '../Networking-iOS'
  end
end