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

Keys for multiple targets #72

Closed
abbeycode opened this issue May 15, 2015 · 19 comments
Closed

Keys for multiple targets #72

abbeycode opened this issue May 15, 2015 · 19 comments

Comments

@abbeycode
Copy link
Contributor

I use API keys in files that are parts of different targets in my app. It's not totally clear how to do this, so I tried having the following in my Podfile:

plugin 'cocoapods-keys', {
    :project => "Comickaze",
    :target => "AppTarget",
    :keys => [
        "CrashlyticsAPIKey",
        "PaddleAPIKey"
    ]
}

plugin 'cocoapods-keys', {
    :project => "Comickaze",
    :target => "XPCServiceTarget",
    :keys => [
        "AmazonS3SecretKey",
        "FogBugzToken"
    ]
}

This way, the last one wins, and my AppTarget doesn't get linked against the generated Keys project. Any ideas?

@abbeycode
Copy link
Contributor Author

I tried placing each plugin block inside of the target do block for their respective targets, with and without the :target specified, and that didn't make a difference.

@orta
Copy link
Owner

orta commented May 15, 2015

We ( Artsy) don't have any projects that use multiple targets, so I'm afraid right now that is totally untested, probably wouldn't be too hard to support though - the codebase is pretty small.

@abbeycode
Copy link
Contributor Author

Why do you think the second call to the plugin removes what was done by the first call?

@segiddins
Copy link
Collaborator

You can only have one plugin call per plugin in your podfile.

@abbeycode
Copy link
Contributor Author

@segiddins Ah, thanks, so then would the proper fix be to allow the target property to specify a list of targets?

@abbeycode
Copy link
Contributor Author

Also, if I wanted to take a look at fixing this, what's the easiest way to switch to using a local clone from CocoaPods for debugging? I'm not familiar enough with Ruby or Gems to configure that.

@orta
Copy link
Owner

orta commented May 16, 2015

You want to use a Gemfile - you can then use gem "cocoapods-keys", :path => '/path/to/local-clone'to specify a local gem. Here's an example ( without the path ).

You can only give a plugin a hash/dictionary, so it might make sense to do something like:

plugin 'cocoapods-keys', {
    :targets => {
        :project => "Comickaze",
        :target => "AppTarget",
        :keys => [
            "CrashlyticsAPIKey",
            "PaddleAPIKey"
      },
      {
        :project => "Comickaze",
        :target => "XPCServiceTarget",
        :keys => [
            "AmazonS3SecretKey",
            "FogBugzToken"
     }]
}

@abbeycode
Copy link
Contributor Author

I've gotten something working now, using a list of target names. I'll submit a pull request once I'm comfortable with it.

The solution requires all targets to share a list of keys, which should be fine, and allowed for a simple implementation. Thanks for the help getting up and running.

The Podfile plugin call looks like this:

plugin 'cocoapods-keys', {
    :project => "Comickaze",
    :target => ["AppTarget", "XPCServiceTarget"],
    :keys => [
        "AmazonS3SecretKey",
        "CrashlyticsAPIKey",
        "FogBugzToken",
        "PaddleAPIKey"
    ]
}

@orta
Copy link
Owner

orta commented May 18, 2015

Yeah, do it! ( If you can make target work for both strings/arrays ( and ideally target/targets) that'd be amaze. )

@abbeycode
Copy link
Contributor Author

I have it working for strings and arrays inside target - if I add targets, how strict should it be about enforcing strings in target and an array in targets?

@orta
Copy link
Owner

orta commented May 18, 2015

It shouldn't

@abbeycode
Copy link
Contributor Author

I updated the pull request to pass the build

abbeycode added a commit to abbeycode/cocoapods-keys that referenced this issue May 19, 2015
abbeycode added a commit to abbeycode/cocoapods-keys that referenced this issue May 19, 2015
abbeycode added a commit to abbeycode/cocoapods-keys that referenced this issue May 19, 2015
abbeycode added a commit to abbeycode/cocoapods-keys that referenced this issue May 19, 2015
abbeycode added a commit to abbeycode/cocoapods-keys that referenced this issue May 19, 2015
abbeycode added a commit to abbeycode/cocoapods-keys that referenced this issue May 19, 2015
abbeycode added a commit to abbeycode/cocoapods-keys that referenced this issue May 19, 2015
abbeycode added a commit to abbeycode/cocoapods-keys that referenced this issue May 19, 2015
@abbeycode
Copy link
Contributor Author

I added specs for the new code

@orta
Copy link
Owner

orta commented May 23, 2015

Fixed 👍

@orta orta closed this as completed May 23, 2015
@loudmouth
Copy link

This does not work for nested test targets as described in the Cocoapod's Podfile documentation.

Output of pod install is as follows:

Could not find a target named 'TEST_TARGET_NAME' in your Podfile. Stopping keys

@orta
Copy link
Owner

orta commented May 9, 2017

You're welcome to take a look at fixing this 👍

@loudmouth
Copy link

Sounds good @orta. I will start tackling this tomorrow. Would you prefer that I open a new issue? Or continue by link relevant comments/code here?

@orta
Copy link
Owner

orta commented May 9, 2017

New please :)

@cuddle-sujeet
Copy link

cuddle-sujeet commented Dec 13, 2018

Hi, Thanks for this awesome Pod. I am facing the same issue that @loudmouth faced.

Could not find a target named 'TEST_TARGET_NAME' in your Podfile. Stopping keys

This is how my PodFile Looks like:-
--------------Pod file---------------
plugin 'cocoapods-keys', {
:project => "project1",
:target => ["project1", "project2"],
:keys => [
"somekeyA",
"somekeyB",
"somekeyC",
"somekeyD",
]
}

abstract_target 'AbstractPod' do
use_frameworks!
pod 'somePodA'
pod 'somePodB'

#pod for project2
target 'project2' do
    use_frameworks!
    # Pods for project2
end

#pod for project1
target 'project1' do
  
    use_frameworks!
    
    # Pods for project1
    
    target 'project1Tests' do
        inherit! :search_paths
        # Pods for testing
    end
    
    target 'project1UITests' do
        inherit! :search_paths
        # Pods for testing
    end
end

end

Can you help me with this?
Thanks

oliveroneill added a commit to oliveroneill/wilt-ios that referenced this issue Sep 19, 2019
These tests are currently crashing. I think I should just delete these tests,
but I'll spend a bit more time on this. I'm not currently using these tests
to the full extent because it seems difficult to get it all setup with
external libraries.

Reason for the crash: I need to install the relevant libraries in the Podfile
for WiltUITests. Cocoapods-keys doesn't support multiple targets with the
same keys, which makes it unworkable. Relevant issue:
orta/cocoapods-keys#72
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

No branches or pull requests

5 participants