Cocoapods: Allow :local in podfile

Created on 19 Mar 2012  Â·  38Comments  Â·  Source: CocoaPods/CocoaPods

Currently it is possible to specify a local dependency in a podspec file. It would be nice to support this feature in the podfile as well.

Example:

dependency 'MyAwesomeLib', :local, '~/path/to/MyAwesomeLib'
enhancement

Most helpful comment

Any update on this? Being able to specify a local dependency in a podspec would be a huge help.

All 38 comments

You can do this already with :path => "/path/to/folder".

Also handy: :git => pod_repo and :podspec => "path/to/custom/podspec".

On Mar 19, 2012, at 11:00 AM, Fabio Pelosin wrote:

Currently it is possible to specify a local dependency in a podspec file. It would be nice to support this feature in the podfile as well.

Example:

dependency 'MyAwesomeLib', :local, '~/path/to/MyAwesomeLib'

Reply to this email directly or view it on GitHub:
https://github.com/CocoaPods/CocoaPods/issues/178

Is this merged to master? because I get

Unknown external source parameters for MyAwesomeLib: path~/Documents/XcodeProjects/Libs/MyAwesomeLib

I also find only one symbol called :path that seems unrelated

(in .../CocoaPods/lib) 
$ ack ":path" 
cocoapods/installer/target_installer.rb
84:        xcconfig_file = support_files_group.files.where(:path => xcconfig_filename)

I'm using the :git version in a project today. I was using :path before I pushed this pod to my private repo. Is the :git version working for you? What about :podspec?

On Mar 19, 2012, at 11:30 AM, Fabio Pelosin wrote:

Is this merged to master? because I get

Unknown external source parameters for MyAwesomeLib: path~/Documents/XcodeProjects/Libs/MyAwesomeLib

I also find only one symbol called :path that seems unrelated

(in .../CocoaPods/lib) 
$ ack ":path" 
cocoapods/installer/target_installer.rb
84:        xcconfig_file = support_files_group.files.where(:path => xcconfig_filename)

Reply to this email directly or view it on GitHub:
https://github.com/CocoaPods/CocoaPods/issues/178#issuecomment-4577230

The :git version works. However there is no trace of :path in the code. Maybe it was there?

Btw sorry I forgot to mention that I'm on the bleeding edge (with no errors in rake spec).

Maybe I'm taking crazy pills, but I believe it used to work. I can't seem to find a reference to this either. @lukeredpath?

On Mar 19, 2012, at 12:52 PM, Fabio Pelosin wrote:

The :git version works. However there is no trace of :path in the code. Maybe it was there?

Btw sorry I forgot to mention that I'm on the bleeding edge.


Reply to this email directly or view it on GitHub:
https://github.com/CocoaPods/CocoaPods/issues/178#issuecomment-4579457

The option is :local, rather than :path.

ah, thanks for clearing that up.

On Mar 19, 2012, at 1:12 PM, Luke Redpath wrote:

The option is :local, rather than :path.


Reply to this email directly or view it on GitHub:
https://github.com/CocoaPods/CocoaPods/issues/178#issuecomment-4579900

Currently it is possible to specify a local dependency in a podspec file. It would be nice to support this feature in the > podfile as well.

Hmm, afaik the :local option is only for use in a Podfile, not a podspec. I.e., if you have made a git clone (or git submodule, etc) in the sandbox, then you can use this option to make CocoaPods read the specification from there.

However, I’m not fully up-to-date with the current code. @lukeredpath Can you correct me if I’m wrong?

The :path option has never existed, only :podspec which takes a file path, HTTP URL, and even a FTP URL iirc :)

Finally, the options should be a hash (and we should probably raise an ArgumentError if it's not), so:

dependency 'MyAwesomeLib', :local => 'MyAwesomeLib' # Which is ./Pods/MyAwesomeLib/MyAwesomeLib.podspec

Also, if you have a git repo somewhere on disk and want to use that instead of a physical remote, then just use the :git option with a file path. (That requires the root of the repo to contain the podspec, though!)

EDIT: Although that obviously means you need to explicitly update the pod after each change in the repo…

Finally, the options should be a hash...

Sorry it was a typo.

...(and we should probably raise an ArgumentError if it's not)

It looks like it is already implemented.

Hmm, afaik the :local option is only for use in a Podfile, not a podspec.

Do you mean used in an inline spec? Because dependency 'MyAwesomeLib', :local => 'MyAwesomeLib' throws an error. A dependency followed by a hash raises an informative if it doesn't contain the :git or :podspec keys.

Also, if you have a git repo somewhere on disk and want to use that instead of a physical remote, then just use the :git option with a file path. (That requires the root of the repo to contain the podspec, though!)
EDIT: Although that obviously means you need to explicitly update the pod after each change in the repo…

It also means that:

  • you need to commit every single change that you want to test, which is hassle is some situations like bug hunting.
  • you can't edit the pods from your app workspace. But you need to edit the files separately. For libraries that don't have a project this is also annoying because you can't ensure that they build without committing, pod install.
  • you can't take advantage of the xcode workspace aware refactoring tools (they are a bit capricious but I still hope they will get better).

This is just my opinion, but I'm a strong advocate of live editing (intended as directly using the files in the working directory) of the pods in the final app for development purposes.

I think this is related to #156. I have been experimenting with many solutions to find an elegant (read decent) way to solve this problem. As explained in this comment, instead, I found hacky way.

Now finally I found the local? option of the Specification. Mistakenly, I assumed that was meant for this feature. Yet it seems it would work fine with the following changes:

  • Enable pod local from an arbitrary folder in the system [#179].

    • I can confirm that this little patch works in a project and doesn't break rake spec. I'm not sure if there are any side effects.

  • Support it in the podfile as well. In this way there is no need to commit to the spec repo or modify its working directory to enter in live editing. In development groups it is possible to

    1. edit but avoid to commit the podfile.

    2. make changes and commit a new version of the pod and of the app.

    3. revert the podfile to normal versioning.

Any update on this? Being able to specify a local dependency in a podspec would be a huge help.

The :local option is supported in the Podfile, and consequently in podspecs. However there is little usage for the latter case. I think that you might be interesting in creating a private repo to manage your podspecs.

Hm, it looks like this _is_ working now, in a podspec. Could have sworn it was not working yesterday:

s.dependency 'SomePod', :local => '~/Projects/SomePod'

I agree there is not a _ton_ of value in this, but it is nice to be able to work on something without first having to commit it. Thanks for your help.

@irace Maybe for you there isn't much value in it; but for me and others, lack of this feature would be a major deal breaker for Cocoapods. I am developing several modules simultaneously and need the ability to edit them and execute debug cycles, without having to make a huge number of commits.

@chris-hatton there should be no problem in using this feature.

The only thing you should need to be aware of is that :local is deprecated and replaced with :path.
For an example, here's a snippet of my Podfile:

platform :ios, :deployment_target => '5.0'
  pod 'ObjectiveSugar'
  pod 'ObjectiveRecord', :path => '../ObjectiveRecord.podspec'
target :SampleProjectTests, :exclusive => true do
  pod 'Kiwi'
end

@mneorr Thanks for the follow up. Unfortunately it seem the ability to use fully local dependencies has been removed, in the past few months. I have configured a basic example Podfile+podspecs structure to use :path specifiers and 'pod install' fails with '[!] Unsupported version requirements'. More detail and a fuller post from me here: https://github.com/CocoaPods/CocoaPods/issues/922#issuecomment-19701164

@chris-hatton Please post those Podfile+podspecs somewhere and add a comment with link to #922. (Or a redacted/simplified example.)

@alloy Here is a link to a project containing Podfile+podspecs, illustrating the configuration I would expect to work for local folder pod references:
https://docs.google.com/file/d/0Bx7-OG-TjZUqVUFGQkJ0T0QzMk0/edit?usp=sharing
Dependency paths are:
Project->A->C
Project->B->C
This is relevant to: https://github.com/CocoaPods/CocoaPods/issues/922

I'll join in here! I would greatly appreciate it when a Podspec would allow to refer to a local pod. This makes developing with Pods a lot easier.

@chris-hatton Your linked project is not working because you are specifying path everywhere in the podspecs.

Pod::Spec.new do |s|
  s.name         = "DependencyA"
  s.version      = "0.0.1"
  s.summary      = "A description of DependencyA."
  s.homepage     = "http://www.appdelegate.com"
  s.license      = { :type => 'Custom', :file => 'LICENSE' }
  s.author       = { "chris-hatton" => "[email protected]" }
  s.source       = { :path => ".", :tag => "0.0.1" }
  s.source_files = 'Classes', '**/*.{h,m}'
  s.requires_arc = true
  s.dependency 'DependencyC', :path => '../DependencyC/DependencyC.podspec'
end

The source should raise as path is an unsupported key (maybe this is only checked on validation). Use :git => 'example.com' if it is giving issues. Also the dependency should not specify the path key. Fixing those issues and with you current Podfile it should work.

@irrationalfab but, then, how will CocoaPods know where to find the dependency, if there is no path?

@chris-hatton from the Podfile:

platform :ios
pod 'DependencyA', :path => '../DependencyA'
pod 'DependencyB', :path => '../DependencyB'

@irrationalfab Thanks, I see that, but how about Dependency C. Do I need another Podfile in A and B, to provide a path to C in the same way?

Just add it a the top of the Podfile. As I have commented in the issue that you linked this is a temporary limitation of the resolver.

platform :ios
pod 'DependencyC', :path => '../DependencyC'
pod 'DependencyA', :path => '../DependencyA'
pod 'DependencyB', :path => '../DependencyB'

How is this done if the repo doesn't contain a podspec? Can an external or local podspec be referenced for it in the Podfile?

I'm going batty with this. Spent more than an hour of solid investigation and can't get it working.

Read through #178 (this issue), #156, #179, #922, SO 1, SO 2, dependency docs. Will post an example if I can figure it out.

I've tried referencing the dependency in the spec with no version, or with '~> 1.0'. I've tried referencing from the spec with a path, which I understand is not meant to work. I tried referencing from the Podfile at the very top, and within the target. I tried referencing in the Podfile using paths relative to the Podfile location, and to the podspec location. (My understanding is relative to the Podfile location is correct.) Tried sudo gem update cocoapods, but no updates available.

I made two libs with awesome new pod lib create. I'm in the Example from the main lib, trying to reference the second lib.

CCCNYC02PXJ-3:Example pjenkins$ pod install
Analyzing dependencies

[!] Invalid `Main.podspec` file: [!] Unsupported version requirements. Updating CocoaPods might fix the issue.

 #  from /Users/pjenkins/repos/Main/Example/Pods/Local Podspecs/Main.podspec:28
 #  -------------------------------------------
 #    # s.frameworks = 'UIKit', 'MapKit'
 >    s.dependency 'Second', :path => "../Second"
 #  end
 #  -------------------------------------------
CCCNYC02PXJ-3:Example pjenkins$

Like I said, batty. I'm sure there's an easy-ish solution, but damned if I can get it working.

As an aside, would be neat if there was a way to do something like pod lib develop Main and it would pull down local copies of the all the repositories of all the source code that gets generated into Main's xcworkspace, and then you can live edit any of it and then make the commits in the respective repos once you've got things working as desired. That's outside the scope of this issue of course, and I won't file a new issue for it now.

But I will be happy if I can just get this working. Will post back with a gist or something if I do.

Here's my cocoa pods version info, also: 0.33.1.

the s.dependency can only refer to the name of a pod. It's the podfile's job to state where that is. So in your case you want something like this in your spec

s.dependency 'Second', "~> 1.0"

and then in the Podfile,

pod "Second", :path => "../Second"
pod "Main"

@orta You helped me get it working! Here are the magic chunks of text.

In /Main.podspec:

s.dependency 'Second'

That path (/ relates to the root of the git repository, not my hard drive.) Note no version at all.

In /Example/Podfile:

pod "Second", :path => "../../Second"

This is the very first line of the Podfile. (:0 in vim.)

No other references to Second in the Podfile. (e.g. in the targets.)

This works! It's also well-designed--my pod spec stays clean. Sweet.

Couple notes for other people facing this issue:

  • Those lines are copy/pastes, so single vs. double quotes, etc is exactly as specified. Don't think that matters
  • Note the reference to the pod in the Podfile tells you where to get it. Doesn't tell you who needs it.
  • The pod spec says what it needs, not where to get it
  • The path is relative to the Podfile! So I needed ../../Second.

Finally, directory structure for me ended up being something like this:

~/repos/
    Main/
        Main.podspec
        Example
            Podfile
    Second/
        Second.podspec

So in ~/repos/Main/Example/Podfile, it needed to be able to find ~/repos/Second/Second.podspec. That's why I needed this line:

pod "Second", :path => "../../Second"

That's the same line as above. I _very much_ hope this is helpful to someone else jumping between all the issues I referenced above :+1:

Thanks again @orta for the pointers that led me to this working example. And thanks to everyone who contributes to CocoaPods!

Spent a bit of time reviewing the error messages I was experiencing previously. I did a nice little trick with git. (Warning, sidebar.)

I like to modify the non-generated files (e.g. Podfile), then add the changes into the index (e.g. git add --all). Then I run pod install or lint or whatever, and I'll see the generated changes in red vs my normal changes in green. Then I take the full output from running pod install and use that as my commit message. (Sometimes as a separate commit from the manual changes.) I grab my prompt at the beginning and end too so I know I got the whole thing. Anyway, minor tip for those that like to check in their generated files--I've found it super helpful.

(End sidebar.)

Soooo.... my point. Yes, so I was able to go back and review exactly what was happening, which I didn't have time to do before. But from the proliferation of issues I linked before, lots of people are trying to do this and failing. So I have some more info I can share.

[!] Unable to find a specification for `Main`.

The above error occurred when I listed pod "Main" at the top of my Podfile in the Example folder in Main's repository. (Outside any target.) Removing that line got rid of the error. Still needed it in the target. (Which had been added automatically by the still awesome and new pod lib create.)

CCCNYC02PXJ-3:Example pjenkins$ pod install
    Analyzing dependencies
    Fetching podspec for `Main` from `../`
    Fetching podspec for `Second` from `../../Second`
    [!] Unable to satisfy the following requirements:

    - `Second (from `../../Second`)` required by `Podfile`
    - `Second (~> 1.0)` required by `Main (0.1.0)`

    CCCNYC02PXJ-3:Example pjenkins$

This one took me a few tries to figure out. I had to remove the version from Main.podspec. Because the Podfile in the /Main/Example had this line:

pod "Second", :path => "../../Second"

But Main.podspec had this line:

s.dependency 'Second', "~> 1.0"

Since CocoaPods can only have one version of each Pod (like Bower, and unlike npm), it couldn't resolve the different versions being referenced. Removing the version specifier altogether from Main.podspec made the error go away. Note that the version in the Podspec in that path was the default 0.1.0, so it should have matched. But it didn't like it.

CCCNYC02PXJ-3:Example pjenkins$ pod install
Analyzing dependencies

[!] Invalid `Main.podspec` file: [!] Unsupported version requirements. Updating CocoaPods might fix the issue.

 #  from /Users/pjenkins/repos/Main/Example/Pods/Local Podspecs/Main.podspec:28
 #  -------------------------------------------
 #    # s.frameworks = 'UIKit', 'MapKit'
 >    s.dependency 'Second', :path => "../Second"
 #  end
 #  -------------------------------------------
CCCNYC02PXJ-3:Example pjenkins$

This was the original error that brought me here. You can't put the path in the podspec. Good decision, for reasons described elsewhere. But that's what makes this error pop up. You need to remove the version altogether. (As I've said already.)

Whew, that was some legwork. But hey, I spent an hour on this with no luck. If I spend another hour writing up all this stuff, and then it helps 10 people save an hour each--good karma :+1:

Sorry, can not understand, how to use custom :podspec! I need custom spec for ReactiveCocoa from this repo https://github.com/mhuusko5/Podspecs. How should I set up my podfile?

screen shot 2015-10-26 at 08 39 17

These are all in CocoaPods/Specs - you don't need to do anything special to access them.

Thanks @orta!
But in case I need it in distant future, how to use custom :podspec stored at GitHub?

You can consult the guide on it here: https://guides.cocoapods.org/syntax/podfile.html#pod :+1:

@orte, mkay, good 'ole rtfm.
Thanks!

@pjenkins-cc :+1: thanks for taking the time to outline the issues that you ran into and how you solved them.

_I'm using CocoaPods 0.39 by the way, with use_frameworks! in each Podfile_

@pjenkins-cc Looks like after following in your footsteps, I'm unable to setup something like the following:

----Pod1
--------Pod2

Pod2 is a local dev pod for Pod1, and Pod1 is a local dev pod for MainApp.

MainApp's Podfile has an entry like this assigned to its main target:

pod 'Pod1', :path => './pod1_framework'

Pod1's .podspec has a dependency on Pod2 like this:

s.dependency 'Pod2'

while Pod1's Podfile has the following as the first line:

pod "Pod2", :path => "./pod2_framework"

Pod2's Pod2.podspec is in a folder "pod2_framework" in the Pod1 subfolder, which is itself a subfolder under MainApp.

When I try to do a pod install within the MainApp folder, the error I get is:

Fetching external sources
-> Fetching podspec for `Pod1` from `./pod1_framework`

Resolving dependencies of `Podfile`
[!] Unable to find a specification for `Pod2` depended upon by `Pod1`

When I modify the Main Podfile to have the path to the Pod2 Podfile:

pod 'Pod2', :path => './pod1_framework/pod2_framework'

and remove what I had originally at the top of Pod1's Podfile, replacing it with the original target base local dependency on Pod2, pod install is successful (but with warnings -- see below) and the workspace appears to be correct. However, what ends up happening is that there is an additional Pods target in the Pods project, along side the Pods-Main and Pods-MainTests targets that you would expect. There are also Pod1 and Pod2 framework targets, as expected.

This extra Pods target causes the pod install to generate a warning:

[!] CocoaPods did not set the base configuration of your project because your project already has a custom config set. In order for CocoaPods integration to work at all, please either set the base configurations of the target `Main` to `Pods/Target Support Files/Pods-Main/Pods-Main.debug.xcconfig` or include the `Pods/Target Support Files/Pods-Main/Pods-Main.debug.xcconfig` in your build configuration.

I tried resetting the project build configurations for debug and release, doing a pod clean, and then running pod install again but I get the same result.

I created a separate issue for my problem: https://github.com/CocoaPods/CocoaPods/issues/4570

Was this page helpful?
0 / 5 - 0 ratings