From 64541e1b6b11264f48e222e70134ca519b417dce Mon Sep 17 00:00:00 2001 From: Dimitris Koutsogiorgas Date: Wed, 14 Dec 2022 18:05:36 -0800 Subject: [PATCH 1/2] Add support for specifying external source pods. --- lib/cocoapods/generate/configuration.rb | 6 ++ lib/cocoapods/generate/installer.rb | 2 + lib/cocoapods/generate/podfile_generator.rb | 26 +++++- spec/cocoapods/generate/configuration_spec.rb | 6 +- .../generate/podfile_generator_spec.rb | 93 ++++++++++++++++++- .../after/execution_output.txt | 3 +- .../fork/after/execution_output.txt | 3 +- .../after/execution_output.txt | 3 +- .../local_sources/after/execution_output.txt | 3 +- .../monorepo/after/execution_output.txt | 3 +- .../single_podspec/after/execution_output.txt | 3 +- .../after/execution_output.txt | 3 +- .../after/execution_output.txt | 3 +- .../use_libraries/after/execution_output.txt | 3 +- 14 files changed, 146 insertions(+), 14 deletions(-) diff --git a/lib/cocoapods/generate/configuration.rb b/lib/cocoapods/generate/configuration.rb index 11c7385..d9890e1 100644 --- a/lib/cocoapods/generate/configuration.rb +++ b/lib/cocoapods/generate/configuration.rb @@ -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| diff --git a/lib/cocoapods/generate/installer.rb b/lib/cocoapods/generate/installer.rb index 758e465..8fb9d0d 100644 --- a/lib/cocoapods/generate/installer.rb +++ b/lib/cocoapods/generate/installer.rb @@ -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, diff --git a/lib/cocoapods/generate/podfile_generator.rb b/lib/cocoapods/generate/podfile_generator.rb index 90f3353..6241bb6 100644 --- a/lib/cocoapods/generate/podfile_generator.rb +++ b/lib/cocoapods/generate/podfile_generator.rb @@ -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" @@ -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. @@ -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>] + # 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 diff --git a/spec/cocoapods/generate/configuration_spec.rb b/spec/cocoapods/generate/configuration_spec.rb index 89d42e4..2329759 100644 --- a/spec/cocoapods/generate/configuration_spec.rb +++ b/spec/cocoapods/generate/configuration_spec.rb @@ -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 @@ -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 diff --git a/spec/cocoapods/generate/podfile_generator_spec.rb b/spec/cocoapods/generate/podfile_generator_spec.rb index 89691d8..5990f4b 100644 --- a/spec/cocoapods/generate/podfile_generator_spec.rb +++ b/spec/cocoapods/generate/podfile_generator_spec.rb @@ -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')] } } @@ -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 diff --git a/spec/integration/app_host_source_dir/after/execution_output.txt b/spec/integration/app_host_source_dir/after/execution_output.txt index f26803d..3ccd889 100644 --- a/spec/integration/app_host_source_dir/after/execution_output.txt +++ b/spec/integration/app_host_source_dir/after/execution_output.txt @@ -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 diff --git a/spec/integration/fork/after/execution_output.txt b/spec/integration/fork/after/execution_output.txt index 8cf909e..c0da370 100644 --- a/spec/integration/fork/after/execution_output.txt +++ b/spec/integration/fork/after/execution_output.txt @@ -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 diff --git a/spec/integration/local-version-of-published-podspec/after/execution_output.txt b/spec/integration/local-version-of-published-podspec/after/execution_output.txt index f458a5f..f4cff4d 100644 --- a/spec/integration/local-version-of-published-podspec/after/execution_output.txt +++ b/spec/integration/local-version-of-published-podspec/after/execution_output.txt @@ -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 diff --git a/spec/integration/local_sources/after/execution_output.txt b/spec/integration/local_sources/after/execution_output.txt index 9895c81..9e028c7 100644 --- a/spec/integration/local_sources/after/execution_output.txt +++ b/spec/integration/local_sources/after/execution_output.txt @@ -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 diff --git a/spec/integration/monorepo/after/execution_output.txt b/spec/integration/monorepo/after/execution_output.txt index f895680..0becd19 100644 --- a/spec/integration/monorepo/after/execution_output.txt +++ b/spec/integration/monorepo/after/execution_output.txt @@ -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 diff --git a/spec/integration/single_podspec/after/execution_output.txt b/spec/integration/single_podspec/after/execution_output.txt index 73e24ee..dcf1d0c 100644 --- a/spec/integration/single_podspec/after/execution_output.txt +++ b/spec/integration/single_podspec/after/execution_output.txt @@ -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 diff --git a/spec/integration/single_workspace/after/execution_output.txt b/spec/integration/single_workspace/after/execution_output.txt index 72a4d3d..de5a4f3 100644 --- a/spec/integration/single_workspace/after/execution_output.txt +++ b/spec/integration/single_workspace/after/execution_output.txt @@ -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 diff --git a/spec/integration/swift-objc-bridging-header/after/execution_output.txt b/spec/integration/swift-objc-bridging-header/after/execution_output.txt index dbce68c..08e7c20 100644 --- a/spec/integration/swift-objc-bridging-header/after/execution_output.txt +++ b/spec/integration/swift-objc-bridging-header/after/execution_output.txt @@ -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 diff --git a/spec/integration/use_libraries/after/execution_output.txt b/spec/integration/use_libraries/after/execution_output.txt index 366bbca..cb2c62d 100644 --- a/spec/integration/use_libraries/after/execution_output.txt +++ b/spec/integration/use_libraries/after/execution_output.txt @@ -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 From 234083fbb22140fb51f7c2914414c6131b25bc8b Mon Sep 17 00:00:00 2001 From: Dimitris Koutsogiorgas Date: Thu, 15 Dec 2022 15:11:45 -0800 Subject: [PATCH 2/2] Bump Ubuntu --- .github/workflows/Specs.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/Specs.yml b/.github/workflows/Specs.yml index b7abaf8..f47cf2b 100644 --- a/.github/workflows/Specs.yml +++ b/.github/workflows/Specs.yml @@ -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 }}