CocoaPods 0.29.0 does not inherit/know 'source_files' from parent spec. #1835

Closed
dsuppiger opened this Issue Feb 24, 2014 · 15 comments

Projects

None yet

7 participants

@dsuppiger

Importing a header file pertaining to the parent spec within the source file of a child spec results in a 'file not found' error when I push/lint the .podspec.

Adding the 'missing' file to the parent as well as to the child spec's source_files results in a successful push/lint but duplicate entries in the pod's build phases.

The same .podspec works flawlessly in CocoaPods 0.28.0.

@kylef
Contributor
kylef commented Mar 11, 2014

I don't think you should be putting the same files in multiple specs. Can you elaborate on what your use-case is?

@dsuppiger

I just did that as a workaround because inheritance/dependency mechanism didn't seem to work. And to be clear the .podspec which worked flawlessly in CocoaPods 0.28.0 is the the 'correct' one with no duplicate source files.

The scenario is this:
Spec A has source file A and a nested subspec B.
Subspec B has source file B which has an #import of source file A.

pod lint/push throws an error telling me source file B cannot import source file A because it is missing.

@kylef
Contributor
kylef commented Mar 12, 2014

I'm not entirely sure about doing this in the way you have mentioned. I would instead do this a different way with two sub-specs, one which depends on the other. See the below example:

Pod::Spec.new do |spec|
  spec.name = 'DemoSpec'

  spec.subspec 'Core' do |corespec|
    corespec.source_files = 'Core/*.{h,m}'
  end

  spec.subspec 'UI' do |uispec|
    uispec.dependency 'DemoSpec/Core'
    uispec.source_files = 'UI/*.{h,m}'
  end
end

This would allow you to install pod 'DemoSpec' which includes both Core and UI sub-specs. It also allows you to depend on pod 'DemoSpec/Core' to just get Core. You can also depend on pod 'DemoSpec/UI' which will depend on the UI spec which includes Core as a dependency.

Sub-spec documentation.

@kylef kylef closed this Mar 12, 2014
@dsuppiger

But then what is the point of subspecs? The podspec reference explicitly states:

a ‘sub-specification’ inherits the value of the attributes of the parents so common values for attributes can be specified in the ancestors."

I want to be able to install either the whole package:

pod 'Module',  '1.0'

Or only some submodules like:

pod 'Module/FeatureA',  '1.0'
pod 'Module/FeatureB', '1.0'

Or is it that only leaf specs can contain code?

@kylef
Contributor
kylef commented Mar 15, 2014

@dsuppiger Yes, some properties inherit from it's parent. But you are explicitly overriding it so it won't be inherited.

@fabiopelosin
Member

That bit of documentation needs to be updated: subspecs inherit only the Build Settings and the Platform attributes (as correctly indicated in the description of the groups).

@rcarlsen

Documentation from the wiki directly contradicts that statement, @kylef:
https://github.com/CocoaPods/CocoaPods/wiki/The-podspec-format

"Attributes that are chained upstream with the value of the parent specs if any. For example if a specification includes some source_files any of its subspecs will include those source files in addition to their source files."

In my case, I have a file that should be shared across all/any of the subspecs:

Pod::Spec.new do |spec|
  spec.name = 'DemoSpec'
  spec.source_files = 'DemoSpec.h'

  spec.subspec 'Core' do |corespec|
    corespec.source_files = 'Core/*.{h,m}'
  end

  spec.subspec 'UI' do |uispec|
    uispec.dependency 'DemoSpec/Core'
    uispec.source_files = 'UI/*.{h,m}'
  end
end

When using pod 'DemoSpec' the DemoSpec.h file would be included, but when using pod 'DemoSpec/Core' it is omitted.

@fabiopelosin
Member

The wiki is outdated and it should be removed in my opinion /c @orta & @mtitolo.

@kylef
Contributor
kylef commented Mar 26, 2014

@rcarlsen If that was the case with source_files, you would come into issues when using implementation files with duplicate symbols when linking because it's compiled and linked multiple times.

You should put any source_files in a sub spec and depend on this sub spec from any spec's that need it. Since you have a Core sub spec which the other depends on, then you should move the DemoSpec.h file over to that sub spec.

@orta
Member
orta commented Mar 26, 2014

the wiki has been dealt with. It's now just a collection of links to the guides.

@rcarlsen

@kylef I suppose that the source_files implementation could have aggregated/coalesced the file globbing, preventing duplicates.

Nevertheless, your approach will work with a "Core" subspec and other subspecs which declare it as a dependency. Should that be more clearly described as a pattern in the podspec documentation?
http://guides.cocoapods.org/syntax/podspec.html#subspec

@fabiopelosin
Member

@rcarlsen It used to do that but it was confusing for the users and made the implementation much more complicated that what it should be... so a lot of time ago we switched.

@blork blork added a commit to 3squared/SQKDataKit that referenced this issue Feb 12, 2015
@blork blork Errors need to be shared, but duplicating path leads to duplicate sym…
…bol errors.

Spec dependancies don't work how I expected, see here: CocoaPods/CocoaPods#1835
3b27814
@Ashton-W
Contributor

The documentation on guides.cocoapods.org is still wrong or just confusing on this matter.

@segiddins
Member

@Ashton-W A PR improving the docs would be very welcome!

@Ashton-W
Contributor

I'm not even sure I know how subspecs work to write that PR myself :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment