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

Duplicate code in generated prefix header file for Pods with subspecs #1449

Closed
rivera-ernesto opened this issue Oct 8, 2013 · 17 comments
Closed

Comments

@rivera-ernesto
Copy link
Contributor

@rivera-ernesto rivera-ernesto commented Oct 8, 2013

The current prefix_header generator adds the prefix_header_contents or prefix_header_file multiple times:

  • Once for the Pod spec.
  • Additional times for each subspec.

For instance the following Podspec:

Pod::Spec.new do |s|
    s.name          = "NBUCore"
    # ...
    s. prefix_header_contents = '#import "NBUCorePrivate.h"'

    s.subspec 'UI' do |su|
        su.source_files = 'Source/UI/*.{h,m}'
    end

    s.subspec 'Helpers' do |sh|
        sh.source_files = 'Source/Helpers/*.{h,m}'
    end

    s.subspec 'Additions' do |sa|
        sa.source_files = 'Source/Additions/*.{h,m}'
    end

    s.subspec 'Dashboard' do |sd|
        sd.source_files = 'Source/Dashboard/*.{h,m}'
        sd.resources    = 'Source/Dashboard/*.{xib}'
    end
end

Results in the following prefix file:

#ifdef __OBJC__
#import <UIKit/UIKit.h>
#endif

#import "Pods-environment.h"
#import "NBUCorePrivate.h"

#import "NBUCorePrivate.h"

#import "NBUCorePrivate.h"

#import "NBUCorePrivate.h"

#import "NBUCorePrivate.h"
@fabiopelosin
Copy link
Member

@fabiopelosin fabiopelosin commented Oct 8, 2013

The prefix headers are a build setting and thus they are inherited by subspecs. Indeed, it would be a good idea to use only unique entries in the list of the prefix headers. Are you interested in submitting a patch?

In any case I would discourage the usage shown above.

@rivera-ernesto
Copy link
Contributor Author

@rivera-ernesto rivera-ernesto commented Oct 8, 2013

I tried to setup a Ruby environment to do it now to try to test it but I have some things to finish first here.
It seems that it would suffice to stop using a loop here.

Also I would discourage it in most cases but could be useful for some projects.

@fabiopelosin
Copy link
Member

@fabiopelosin fabiopelosin commented Oct 8, 2013

I tried to setup a Ruby environment to do it now to try to test it but I have some things to finish first here.
It seems that it would suffice to stop using a loop here.

Doing that would just limit the import to the first Pod (and ignore any custom prefix header of the subspecs). Instead of writing them as we get them we should map them in an array, call #uniq, and write them to the file at that point.

@rivera-ernesto
Copy link
Contributor Author

@rivera-ernesto rivera-ernesto commented Oct 8, 2013

The thing is that the prefix header is shared among/affects all subspecs, so probably it doesn't make sense to define them in a subspec.
The #uniq solution should be ok though.

@fabiopelosin
Copy link
Member

@fabiopelosin fabiopelosin commented Oct 8, 2013

The thing is that the prefix header is shared among/affects all subspecs, so probably it doesn't make sense to define them in a subspec.

Consider that a library might need a shared prefix header which should be included even if only a subspec is installed and that a single subspec might want to have a custom prefix header.

@rivera-ernesto
Copy link
Contributor Author

@rivera-ernesto rivera-ernesto commented Oct 9, 2013

Right

@frosty
Copy link

@frosty frosty commented Jan 17, 2014

I'm interested in having a go at tackling this if nobody else is already. This would be my first contribution to Cocoapods - would people recommend I add a new test fixture for a Podspec like the example above?

@swizzlr
Copy link
Contributor

@swizzlr swizzlr commented Jan 17, 2014

There may already be one – check the integration tests folder, write a new one if you have to, and familiarize yourself with the Rakefile.

@CocoaPodsBot
Copy link

@CocoaPodsBot CocoaPodsBot commented Mar 29, 2014

Issue has been confirmed by @segiddins

@luisdelarosa
Copy link
Contributor

@luisdelarosa luisdelarosa commented Mar 30, 2014

I'm looking into this now.

luisdelarosa added a commit to luisdelarosa/CocoaPods that referenced this issue Mar 30, 2014
…t the unit level so

I suspect that the issue will need to be tested at the integration test level.
@luisdelarosa
Copy link
Contributor

@luisdelarosa luisdelarosa commented Mar 31, 2014

I confirmed it with the AWSiOSSDK pod.

luisdelarosa added a commit to luisdelarosa/cocoapods-integration-specs that referenced this issue Mar 31, 2014
… issue #1449.

CocoaPods/CocoaPods#1449
"Duplicate code in generated prefix header file for Pods with subspecs".
@luisdelarosa
Copy link
Contributor

@luisdelarosa luisdelarosa commented Mar 31, 2014

Failing test is available in the pull request: CocoaPods/cocoapods-integration-specs#8

luisdelarosa added a commit to luisdelarosa/CocoaPods that referenced this issue Mar 31, 2014
luisdelarosa added a commit to luisdelarosa/CocoaPods that referenced this issue Mar 31, 2014
@luisdelarosa
Copy link
Contributor

@luisdelarosa luisdelarosa commented Mar 31, 2014

Fix and integration test are available in the pull request: #1981

luisdelarosa added a commit to luisdelarosa/cocoapods-integration-specs that referenced this issue Apr 8, 2014
… issue #1449.

CocoaPods/CocoaPods#1449
"Duplicate code in generated prefix header file for Pods with subspecs".
fabiopelosin added a commit that referenced this issue Apr 8, 2014
…/github.com/luisdelarosa/CocoaPods into luisdelarosa-issue_1449_duplicate_prefix_header_contents

* 'issue_1449_duplicate_prefix_header_contents' of https://github.com/luisdelarosa/CocoaPods:
  Addressed comments from @irrationalfab: - simplified collection of unique prefix_header_contents - reduced sub specs in spec from 4 to 2 Removed inline documentation and added @notes and @todos. Added entry to Changelog.
  Fix issue #1449 by collecting the prefix_header_contents and uniq-ing them.
  Add integration test for issue #1449.
  Added two tests for issue #1449 - however both are passing at the unit level so I suspect that the issue will need to be tested at the integration test level.

Conflicts:
	CHANGELOG.md
@rivera-ernesto
Copy link
Contributor Author

@rivera-ernesto rivera-ernesto commented Apr 9, 2014

Thank you @luisdelarosa !

@yairsz
Copy link

@yairsz yairsz commented Feb 19, 2015

Hello, I'd like to report that the duplication behavior is still happening for prefix_header_file.
This is in version 0.35.0.
To work around it, I set the variable inside only one of the subspecs. The header file was injected only once into the pods .pch
Thank you @luisdelarosa . This information was very useful!

@lemonkey
Copy link

@lemonkey lemonkey commented Mar 1, 2015

Confirmed this is happening in 0.35.0.

@sstadelman
Copy link

@sstadelman sstadelman commented Mar 17, 2015

confirmed also in 0.35.0. opening new issue for prefix_header_file.

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

Successfully merging a pull request may close this issue.

9 participants
You can’t perform that action at this time.