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

Add ability to specify source with each dependency #4486

Merged
merged 1 commit into from
Nov 13, 2015

Conversation

efirestone
Copy link
Contributor

This adds the ability to add a :source flag to pod dependencies in a Podfile. This behavior mirrors in Gemfiles, allowing a dependency to be specified as such:

pod 'JSONKit', '1.4', :source => 'http://github.com/MyOrg/Specs.git'

Depends on CocoaPods/Core#278

@efirestone
Copy link
Contributor Author

I didn't see a specific existing issue regarding this enhancement. There's some discussion here, and I can file a new issue if you want one.

@segiddins
Copy link
Member

No need to file an issue

@segiddins
Copy link
Member

How does this handle transitive dependencies?

@jafara
Copy link

jafara commented Nov 3, 2015

👍 this is a great improvement!

@efirestone
Copy link
Contributor Author

@segiddins Transitive dependencies are handled like so:

  • If a dependency is explicitly specified in the Podfile, then the :source repo will be used for that dependency if it comes up as a transitive dependency
  • If a dependency is not explicitly specified anywhere in the Podfile, then the normal file source rules apply (unchanged from before)

The simplest way to summarize is that it has the exact same behavior as a podspec given using :podspec or :path. Podfile dependencies get resolved first and are cached and reused for all subsequent requirements.

One small thing I noticed: as mentioned, the resolver relies on caching to make sure dependency resolutions are consistent. This works fine when calling resolve, but it means that if you call search_for directly before calling resolve then the wrong thing might be cached. This is true with the existing code for external sources (:path) as well.

To illustrate:

  1. Have a Podfile with the dependency pod 'MyPod', :path => '/path/to/1.0/MyPod.podspec'
  2. Use that podfile as a constructor argument in creating a Resolver
  3. Before calling resolve, call search_for(Dependency.new('MyPod', '1.0'))

I would expect the resolver to give me back the Spec from the local path, but instead it will actually use the sources passed to the resolver constructor instead. If you call resolve first then the dependencies from the podfile will get passed to search_for first and will be the ones that are cached. The new :source flag behaves the same way.

Again, I think this is all fine, but I figured I'd call it out. Root cause here seems to be that search_for should be private so that you can't abuse it in this way but in reality has to be public to conform to Molinillo::SpecificationProvider.

@efirestone
Copy link
Contributor Author

Also, the code has a dependency on CocoaPods/Core#278, so the tests should go green once we can point them at that. It looks like everything is pegged to HEAD, so is the standard development flow to merge the other PR first?

@segiddins
Copy link
Member

You'll need to point the Gemfile in this repo to your Core PR so the tests here can pass.
And I'm still not seeing tests for what will happen to transitive dependencies of dependencies with a custom source set -- one could argue that they ought to use the source for their parent dependency, though you then get into conflict situations... Either way, that scenario needs to be sufficiently tested.

@aggregates_by_repos ||= {}

# Use the cached version if it exists.
if result = @aggregates_by_repos[repos]
Copy link
Member

Choose a reason for hiding this comment

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

all this can be replaced with @aggregates_by_repos[repos] ||= Source::Aggregate.new(repos)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@efirestone efirestone force-pushed the firestone/source-flag branch 2 times, most recently from fa9358e to f2ee737 Compare November 3, 2015 21:17
@@ -62,6 +62,19 @@ module Pod
@analyzer.update_repositories
end

it 'does not update sources if there are no dependencies' do
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a small optimization that came along with my changes. If a Podfile has no dependencies specified, then it won't bother updating any of the sources. This seems safe to me, but I'd like confirmation from the veterans on this.

@efirestone
Copy link
Contributor Author

Added some transitive dependency tests. See other comments for discussion on the behavior. Also updated the Gemfile and addressed your comments. Thanks for looking it over @segiddins!

@efirestone
Copy link
Contributor Author

This is ready for a review. Much appreciated!

[Eric Firestone](https://github.com/efirestone)
[#4486](https://github.com/CocoaPods/CocoaPods/pull/4486)

* Improve `pod search` performance while using _`--full`_ flag
Copy link
Member

Choose a reason for hiding this comment

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

this line shouldn't be there

@segiddins
Copy link
Member

Generally looks good to me, but I'd like someone else on the team to also have a look.

@efirestone
Copy link
Contributor Author

Comments addressed. Thanks for looking it over.

@efirestone
Copy link
Contributor Author

Who are good candidates to take a second look at this? @orta? @neonichu?

@@ -20,6 +20,10 @@ To install release candidates run `[sudo] gem install cocoapods --pre`
[Marcelo Fabri](https://github.com/marcelofabri)
[#4487](https://github.com/CocoaPods/CocoaPods/pull/4487)

* Add support for specifying :source with a pod dependency.
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 your changelog entry should be at the top in order to preserve historical flow.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done and done.

@neonichu
Copy link
Member

Looks good to me as well — thanks for the comprehensive comments, @efirestone 👍

@manuyavuz
Copy link
Member

@efirestone, it just needs a rebase to be 🚀. Thank you for your effort !

@manuyavuz
Copy link
Member

And you should revert the Gemfile because changes in Core repo has been merged.

Enables specifying a :source flag with each pod dependency
@efirestone
Copy link
Contributor Author

Should be good to go! Thanks all!

@neonichu
Copy link
Member

Awesome, thank you 👍

neonichu added a commit that referenced this pull request Nov 13, 2015
Add ability to specify source with each dependency
@neonichu neonichu merged commit 2e89214 into CocoaPods:master Nov 13, 2015
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.

5 participants