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

Use the podspec :subspec=>'xx' to load dependencies from a subspec #456

Merged
merged 1 commit into from
Aug 21, 2018

Conversation

Whirlwind
Copy link
Contributor

Sometimes, I use the podspec in a Podfile to load dependencies from a .podspec file. But I often just load one or some subspec(s) from the podspec file, not load all dependencies.
eg: this is a Podspec:

s.dependency 'SDWebImage'
s.subspec 'ASI' do |s1|
    s1.dependency 'ASIHTTPRequest'
end
s.subspec 'AF' do |s2|
    s2.dependency 'AFNetworking'
end

this is a Podfile:

target :SDKForASI do
    podspec :subspec=>'ASI'
end
target :SDKForAF do
    podspec :subspec=>'AF'
end

I need the target have different dependencies from different subspecs. This PR will add a option subspec(subspecs) to the podspec DSL.

@amorde
Copy link
Member

amorde commented Aug 8, 2018

I don't understand the issue this is trying to fix. How is this different from just specifying the subspec directly? Like this:

target :SDKForASI do
    pod 'MySDK/ASI'
end
target :SDKForAF do
    pod 'MySDK/AF'
end

@Whirlwind
Copy link
Contributor Author

Whirlwind commented Aug 9, 2018

Maybe I lost some description. The project and targets are the development pods.
The MySDK/ASI's source_files will be installed in Pods project and build target Pods-MySDK-ASI.a. But my target SDKForASI includes the source_files and has been compiled by xcode. So If I use pod 'MySDK/ASI', I will get duplicate symbols and classes.

If I use podspec, CocoaPods will only pick the dependencies from podspec file, will not install the MySDK.

@amorde
Copy link
Member

amorde commented Aug 9, 2018

Ah, okay. So you're using this syntax https://guides.cocoapods.org/syntax/podfile.html#podspec to load the dependencies of the podspec.

Is the issue that you want only the dependencies of the subspec, and not the dependencies of the root spec? Does podspec :name => 'MySDK/ASI' not support what you're trying to do?

@Whirlwind
Copy link
Contributor Author

The name is used to search the podspec file, it could not pick the dependencies from subspec.

@amorde
Copy link
Member

amorde commented Aug 9, 2018

Ok thanks, I think I understand now

Copy link
Member

@amorde amorde left a comment

Choose a reason for hiding this comment

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

Looks good! A couple comments, and would like a least 1 other person to review

else
get_hash_value('podspecs', []) << { :autodetect => true }
options ||= {}
unless options.keys.all? { |key| [:name, :path, :subspecs, :subspec].include?(key) }
Copy link
Member

Choose a reason for hiding this comment

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

I think its worth adding only the plural :subspecs option to keep the implementation simpler. If you only want 1 subspec, that could just be :subspecs => ['Subspec']

Copy link
Contributor Author

@Whirlwind Whirlwind Aug 10, 2018

Choose a reason for hiding this comment

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

I think about it. But I found that I often only use one subspec in a target, so the :subspec=>'xx' is very simple and very common.

all_deps = all_specs.map { |s| s.dependencies(platform) }.flatten
all_deps.reject { |dep| dep.root_name == spec.root.name }
subspec_names = options[:subspecs] || options[:subspec]
specs = if subspec_names.blank?
Copy link
Member

Choose a reason for hiding this comment

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

Could this raise an error if the type is incorrect? Like if we receive :subspecs => [1234]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is it strange that each parameter determines the type?

Copy link
Member

Choose a reason for hiding this comment

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

Well they sort of have a type already, even if its implicit rather than explicit. Passing a Hash or something else into :subspecs doesn't really make sense

Copy link
Contributor Author

Choose a reason for hiding this comment

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

add subspec_names.map!(&:to_s) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seams that it will not raise an error if the subspecs => [1234].

          subspec_names = options[:subspecs] || options[:subspec]
          specs = if subspec_names.blank?
                    [spec]
                  else
                    subspec_names = [subspec_names] if subspec_names.is_a?(String)
                    subspec_names.map { |subspec_name| spec.subspec_by_name("#{spec.name}/#{subspec_name}") }
                  end

It will raise an error if :subspec=>123.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I'd rather not just convert everything to a String since that becomes an expected functionality of the API

It makes sense that if you are specifying a subspec name, it should be a String.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I add the type checking in the store_podspec method.

podfile.dependencies.map(&:name).should == %w(monkey AFNetworking SDWebImage)
end

it 'it can use use the dependencies of a podspec\'s subspec' do
Copy link
Member

Choose a reason for hiding this comment

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

nit: remove the extra 'it'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

😂I just copy the description from last spec ( Line 402 ). Should I remove them?

Copy link
Member

@amorde amorde Aug 10, 2018

Choose a reason for hiding this comment

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

just the beginning so it's it 'can use the dependencies of a podspec\'s subspec' do

@Whirlwind
Copy link
Contributor Author

@amorde What description should I add into the changelog?

@amorde
Copy link
Member

amorde commented Aug 10, 2018

Something like

Add support for specifying subspecs when using the `podspec` Podfile attribute

@amorde
Copy link
Member

amorde commented Aug 20, 2018

@Whirlwind I think this is good to go! Could you squash the commits?

@dnkoutso dnkoutso added this to the 1.6 milestone Aug 20, 2018
@dnkoutso
Copy link
Contributor

dnkoutso commented Aug 20, 2018

+1 on squashing commits before we merge this

@Whirlwind
Copy link
Contributor Author

@amorde @dnkoutso done. Thanks.

@dnkoutso dnkoutso merged commit 9138a1f into CocoaPods:master Aug 21, 2018
@Whirlwind Whirlwind deleted the podspec_support_subspec branch August 21, 2018 04:44
@amorde
Copy link
Member

amorde commented Aug 21, 2018

Thanks @Whirlwind!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants