Skip to content

Commit

Permalink
Merge pull request #164 from square/external_sources_support
Browse files Browse the repository at this point in the history
Add support for specifying external source pods.
  • Loading branch information
dnkoutso authored Jan 23, 2023
2 parents b7a7c14 + 234083f commit 164e8b6
Show file tree
Hide file tree
Showing 15 changed files with 147 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/Specs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
matrix:
task: [SPECS]
ruby: [2.6, 2.7]
os: [ubuntu-18.04]
os: [ubuntu-20.04]

name: ${{ matrix.task }} / ${{ matrix.os }} / Ruby ${{ matrix.ruby }}
runs-on: ${{ matrix.os }}
Expand Down
6 changes: 6 additions & 0 deletions lib/cocoapods/generate/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,12 @@ def ===(other)
option :use_modular_headers, BOOLEAN, 'false', 'Whether the target should be generated as a clang module, treating dependencies as modules, as if `use_modular_headers!` were specified. Will error if both this option and a podfile are specified', nil, nil, coerce_to_bool
option :single_workspace, BOOLEAN, 'false', 'Whether to produce a single workspace for all podspecs specified.', nil, nil, coerce_to_bool
option :xcode_version, Pod::Version, 'Pod::Version.new(\'9.3\')', 'The Xcode version to use for producing the consumer sample project', 'xcode_version', nil, coerce_to_version
option :external_source_pods, ArrayOf.new(HashOf.new(keys: [String], values: [ArrayOf.new(HashOf.new(keys: [String], values: [String]))])),
[],
nil,
nil,
nil,
->(external_sources) { Array(external_sources) }

options.freeze
options.each do |o|
Expand Down
2 changes: 2 additions & 0 deletions lib/cocoapods/generate/installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ class Installer
DEFAULT_XCODE_VERSION = '9.3'.freeze

XCODE_VERSION_TO_OBJECT_VERSION = {
'14.0' => 56,
'13.0' => 55,
'12.0' => 54,
'11.4' => 53,
'11.0' => 52,
Expand Down
26 changes: 24 additions & 2 deletions lib/cocoapods/generate/podfile_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def podfile_for_specs(specs)
generator = self
dir = configuration.gen_dir_for_specs(specs)
project_name = configuration.project_name_for_specs(specs)
external_source_pods = configuration.external_source_pods

Pod::Podfile.new do
project "#{project_name}.xcodeproj"
Expand Down Expand Up @@ -93,9 +94,19 @@ def podfile_for_specs(specs)
.reject { |d| spec_names.include?(d.root_name) }

dependencies.each do |dependency|
pod_args = generator.pod_args_for_dependency(self, dependency)
pod_args = generator.pod_args_for_podfile_dependency(self, dependency)
pod(*pod_args)
end

external_source_pods.each do |hash|
hash.each do |name, attrs|
next if spec_names.include?(name)

dependency = Dependency.new(name, attrs.first.deep_symbolize_keys)
pod_args = generator.pod_args_for_dependency(nil, dependency)
pod(*pod_args)
end
end
end

# Add platform-specific concrete targets that inherit the `pod` declaration for the local pod.
Expand Down Expand Up @@ -291,12 +302,23 @@ def lockfile_versions
#
# @param [Dependency] dependency
#
def pod_args_for_dependency(podfile, dependency)
def pod_args_for_podfile_dependency(podfile, dependency)
dependency = podfile_dependencies[dependency.root_name]
.map { |dep| dep.dup.tap { |d| d.name = dependency.name } }
.push(dependency)
.reduce(&:merge)
pod_args_for_dependency(podfile, dependency)
end

# @return [Hash<String,Array<Dependency>>]
# returns the arguments that should be passed to the Podfile DSL's
# `pod` method.
#
# @param [Podfile] podfile
#
# @param [Dependency] dependency
#
def pod_args_for_dependency(podfile, dependency)
options = dependency_compilation_kwargs(dependency.name)
options[:source] = dependency.podspec_repo if dependency.podspec_repo
options.update(dependency.external_source) if dependency.external_source
Expand Down
6 changes: 4 additions & 2 deletions spec/cocoapods/generate/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
use_podfile: false,
use_podfile_plugins: false,
warn_for_multiple_pod_sources: false,
xcode_version: Pod::Version.new('9.3')
xcode_version: Pod::Version.new('9.3'),
external_source_pods: []
)
end
end
Expand Down Expand Up @@ -64,7 +65,8 @@
warn_for_multiple_pod_sources: false,
use_modular_headers: false,
single_workspace: false,
xcode_version: 9.3 }
xcode_version: 9.3,
external_source_pods: [] }
TO_S
end

Expand Down
93 changes: 92 additions & 1 deletion spec/cocoapods/generate/podfile_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
end
end

describe_method 'pod_args_for_dependency' do
describe_method 'pod_args_for_podfile_dependency' do
let(:lockfile_versions) { { 'A' => '= 1' } }
let(:podfile_dependencies) { { 'A' => [Pod::Dependency.new('A')] } }

Expand Down Expand Up @@ -613,6 +613,97 @@
end
end

context 'with external source pods specified' do
let(:config_options) { super().merge(external_source_pods: ['B' => [{ 'git' => 'https://github.com/pod.git' }]], use_podfile: false, use_lockfile: false, lockfile: nil, use_lockfile_versions: false) }

it 'generates the expected podfile' do
test = self
expected = Pod::Podfile.new do
self.defined_in_file = test.config.gen_dir_for_specs([Pod::Spec.new(nil, 'A')]).join('Podfile.yaml')

workspace 'A.xcworkspace'
project 'A.xcodeproj'

plugin 'cocoapods-disable-podfile-validations', 'no_abstract_only_pods' => true
plugin 'cocoapods-generate'

source 'https://cdn.cocoapods.org/'
source 'https://github.com/CocoaPods/Specs.git'
source 'https://github.com/Private/SpecsForks.git'

install! 'cocoapods',
deterministic_uuids: false,
disable_input_output_paths: false,
generate_multiple_pod_projects: false,
incremental_installation: false,
share_schemes_for_development_pods: true,
warn_for_multiple_pod_sources: false

use_frameworks!(true)

pod 'A', path: '../../Frameworks/A/A.podspec', testspecs: %w[Tests]

abstract_target 'Transitive Dependencies' do
pod 'B', git: 'https://github.com/pod.git'
end

target 'App-iOS' do
end
target 'App-macOS' do
end
target 'App-tvOS' do
end
target 'App-watchOS' do
end
end

expect(podfile_for_specs.to_yaml).to eq expected.to_yaml
end
end

context 'with external source pods specified as part of the ones being generated' do
let(:config_options) { super().merge(external_source_pods: ['A' => [{ 'git' => 'https://github.com/pod.git' }]]) }

it 'generates the expected podfile' do
test = self
expected = Pod::Podfile.new do
self.defined_in_file = test.config.gen_dir_for_specs([Pod::Spec.new(nil, 'A')]).join('Podfile.yaml')

workspace 'A.xcworkspace'
project 'A.xcodeproj'

plugin 'cocoapods-disable-podfile-validations', 'no_abstract_only_pods' => true
plugin 'cocoapods-generate'

install! 'cocoapods',
deterministic_uuids: true,
disable_input_output_paths: false,
generate_multiple_pod_projects: false,
incremental_installation: false,
share_schemes_for_development_pods: false,
warn_for_multiple_pod_sources: true

use_frameworks!(false)

pod 'A', path: '../../Frameworks/A/A.podspec', testspecs: %w[Tests]

abstract_target 'Transitive Dependencies' do
end

target 'App-iOS' do
end
target 'App-macOS' do
end
target 'App-tvOS' do
end
target 'App-watchOS' do
end
end

expect(podfile_for_specs.to_yaml).to eq expected.to_yaml
end
end

context 'when the podfile specifies use_frameworks! as a hash' do
let(:podfile) do
Pod::Podfile.new do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ CLAIDE_DISABLE_AUTO_WRAP=TRUE COCOAPODS_SKIP_CACHE=TRUE COCOAPODS_VALIDATOR_SKIP
warn_for_multiple_pod_sources: false,
use_modular_headers: false,
single_workspace: false,
xcode_version: 9.3 }
xcode_version: 9.3,
external_source_pods: [] }

Generating workspace in `gen/Foo`
Cleaning gen install directory
Expand Down
3 changes: 2 additions & 1 deletion spec/integration/fork/after/execution_output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ CLAIDE_DISABLE_AUTO_WRAP=TRUE COCOAPODS_SKIP_CACHE=TRUE COCOAPODS_VALIDATOR_SKIP
warn_for_multiple_pod_sources: true,
use_modular_headers: false,
single_workspace: false,
xcode_version: 9.3 }
xcode_version: 9.3,
external_source_pods: [] }

Generating workspace in `gen/Foo`
Cleaning gen install directory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ CLAIDE_DISABLE_AUTO_WRAP=TRUE COCOAPODS_SKIP_CACHE=TRUE COCOAPODS_VALIDATOR_SKIP
warn_for_multiple_pod_sources: false,
use_modular_headers: false,
single_workspace: false,
xcode_version: 9.3 }
xcode_version: 9.3,
external_source_pods: [] }

Generating workspace in `gen/Foo`
Creating stub application
Expand Down
3 changes: 2 additions & 1 deletion spec/integration/local_sources/after/execution_output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ CLAIDE_DISABLE_AUTO_WRAP=TRUE COCOAPODS_SKIP_CACHE=TRUE COCOAPODS_VALIDATOR_SKIP
warn_for_multiple_pod_sources: true,
use_modular_headers: false,
single_workspace: false,
xcode_version: 9.3 }
xcode_version: 9.3,
external_source_pods: [] }

Generating workspace in `gen/E`
Creating stub application
Expand Down
3 changes: 2 additions & 1 deletion spec/integration/monorepo/after/execution_output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ CLAIDE_DISABLE_AUTO_WRAP=TRUE COCOAPODS_SKIP_CACHE=TRUE COCOAPODS_VALIDATOR_SKIP
warn_for_multiple_pod_sources: true,
use_modular_headers: false,
single_workspace: false,
xcode_version: 9.3 }
xcode_version: 9.3,
external_source_pods: [] }

Generating workspace in `gen/A`
Creating stub application
Expand Down
3 changes: 2 additions & 1 deletion spec/integration/single_podspec/after/execution_output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ CLAIDE_DISABLE_AUTO_WRAP=TRUE COCOAPODS_SKIP_CACHE=TRUE COCOAPODS_VALIDATOR_SKIP
warn_for_multiple_pod_sources: false,
use_modular_headers: false,
single_workspace: false,
xcode_version: 9.3 }
xcode_version: 9.3,
external_source_pods: [] }

Generating workspace in `gen/Foo`
Creating stub application
Expand Down
3 changes: 2 additions & 1 deletion spec/integration/single_workspace/after/execution_output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ CLAIDE_DISABLE_AUTO_WRAP=TRUE COCOAPODS_SKIP_CACHE=TRUE COCOAPODS_VALIDATOR_SKIP
warn_for_multiple_pod_sources: true,
use_modular_headers: false,
single_workspace: true,
xcode_version: 9.3 }
xcode_version: 9.3,
external_source_pods: [] }

Generating workspace in `gen/Workspace`
Creating stub application
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ CLAIDE_DISABLE_AUTO_WRAP=TRUE COCOAPODS_SKIP_CACHE=TRUE COCOAPODS_VALIDATOR_SKIP
warn_for_multiple_pod_sources: false,
use_modular_headers: false,
single_workspace: false,
xcode_version: 9.3 }
xcode_version: 9.3,
external_source_pods: [] }

Generating workspace in `gen/Foo`
Cleaning gen install directory
Expand Down
3 changes: 2 additions & 1 deletion spec/integration/use_libraries/after/execution_output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ CLAIDE_DISABLE_AUTO_WRAP=TRUE COCOAPODS_SKIP_CACHE=TRUE COCOAPODS_VALIDATOR_SKIP
warn_for_multiple_pod_sources: false,
use_modular_headers: false,
single_workspace: false,
xcode_version: 9.3 }
xcode_version: 9.3,
external_source_pods: [] }

Generating workspace in `gen/Foo`
Creating stub application
Expand Down

0 comments on commit 164e8b6

Please sign in to comment.