Capacitor: feat: configurable `pod` command / try local `bundle exec pod`

Created on 23 Sep 2020  ยท  6Comments  ยท  Source: ionic-team/capacitor

Feature Request

Description

Some projects may chose to not install pod globally, but locally via bundle. In this case, pod is normally not in the $PATH. However, it would be accessible via bundle exec pod.

Because cap expects pod to be accessible from the $PATH, any command using pod would fail with that setup.

Currently we work around this in our project by generating a binstub for pod (bundle binstubs cocoapods) and adding it to the $PATH using an .envrc file like this:

# Add the gem binstubs directory to `PATH`.
export PATH="$PWD/bin:$PATH"

Platform(s)

macOS / iOS

Preferred Solution

Not entirely sure.

It would be nice, if the command for pod could be configured or alternatively the path to the bin could be configured explicitly. Both solutions could be supported simultaneously. I would not put this in the capacitor.config.json, but rather add a capacitor key to the package.json:

{
  "capacitor": {
    "pod": "bundle exec pod"
    // or alternatively:
    "pod": "./bin/pod"
  }
}
cli enhancement ios

Most helpful comment

Thanks for mentioning. That'd be fine as well though. If users for some reason cannot use binstubs, they could create an executable (chmod +x) shell script instead:

#!/usr/bin/env sh
bundle exec pod $@
export CAPACITOR_COCOAPODS_PATH="./bin/custom-pod"

All 6 comments

Just curious, where is your Gemfile in your project?

We use a monorepo setup that looks like this: (irrelevant files & directories omitted)

.
โ”œโ”€โ”€ .bundle
โ”‚  โ””โ”€โ”€ config
โ”œโ”€โ”€ bin
|  |   # These binstubs were generated via
|  |   # `bundle binstubs cocoapods`
|  |   # and are checked into the repo.
โ”‚  โ”œโ”€โ”€ pod
โ”‚  โ””โ”€โ”€ sandbox-pod
โ”œโ”€โ”€ gems
โ”‚  โ””โ”€โ”€ ruby/
|      # Contains the `Gemfile` dependencies. Created by
|      # `bundle install`
|      # Not checked into the repository.
|      # See further down this comment for the contents.
โ”œโ”€โ”€ packages
โ”‚  โ”œโ”€โ”€ capacitor-app/
โ”‚  ...
โ”‚  โ”œโ”€โ”€ plugin.auth/
โ”‚  โ”œโ”€โ”€ plugin.pdf/
โ”‚  โ””โ”€โ”€ scripts/
โ”œโ”€โ”€ .envrc
โ”œโ”€โ”€ .gitignore
โ”œโ”€โ”€ .ruby-version
โ”œโ”€โ”€ Brewfile
โ”œโ”€โ”€ Gemfile
โ”œโ”€โ”€ Gemfile.lock
โ”œโ”€โ”€ lerna.json
โ”œโ”€โ”€ package.json
โ”œโ”€โ”€ README.md
โ””โ”€โ”€ yarn.lock

For our tool chain version management we have (among others) these entries in our Brewfile:

brew "direnv"
brew "volta"
brew "rbenv"
brew "openjdk@11"

And this .envrc:

# Add the gem binstubs directory and the JDK@11 to the `PATH`.
export PATH="$(dirname "$0")/bin:$(brew --prefix openjdk@11)/bin:$PATH"

And this .bundle/config:

---
BUNDLE_PATH: "./gems"
BUNDLE_FROZEN: "true"

And here's the contents created by bundle install:

./gems/ruby/2.7.0
โ”œโ”€โ”€ bin
โ”‚  โ”œโ”€โ”€ bin-proxy
โ”‚  โ”œโ”€โ”€ dotenv
โ”‚  โ”œโ”€โ”€ fastlane
โ”‚  โ”œโ”€โ”€ fuzzy_match
โ”‚  โ”œโ”€โ”€ generate-api
โ”‚  โ”œโ”€โ”€ httpclient
โ”‚  โ”œโ”€โ”€ pod
โ”‚  โ”œโ”€โ”€ rake
โ”‚  โ”œโ”€โ”€ rougify
โ”‚  โ”œโ”€โ”€ sandbox-pod
โ”‚  โ”œโ”€โ”€ terminal-notifier
โ”‚  โ”œโ”€โ”€ ww
โ”‚  โ”œโ”€โ”€ xcodeproj
โ”‚  โ”œโ”€โ”€ xcpretty
โ”‚  โ””โ”€โ”€ xcpretty-travis-formatter
โ”œโ”€โ”€ build_info
โ”œโ”€โ”€ cache
โ”‚  โ”œโ”€โ”€ activesupport-4.2.11.3.gem
โ”‚  ...
โ”‚  โ””โ”€โ”€ xcpretty-travis-formatter-1.0.0.gem
โ”œโ”€โ”€ doc
โ”œโ”€โ”€ extensions
โ”‚  โ””โ”€โ”€ x86_64-darwin-19
โ”œโ”€โ”€ gems
โ”‚  โ”œโ”€โ”€ activesupport-4.2.11.3
โ”‚  ...
โ”‚  โ””โ”€โ”€ xcpretty-travis-formatter-1.0.0
โ””โ”€โ”€ specifications
   โ”œโ”€โ”€ activesupport-4.2.11.3.gemspec
   ...
   โ””โ”€โ”€ xcpretty-travis-formatter-1.0.0.gemspec

Our Gemfile looks like this:

source "https://rubygems.org"

gem "fastlane"
gem "cocoapods"
# ...

fastlane_plugins_path = File.join(
  File.dirname(__FILE__),
  'packages',
  'capacitor-app',
  'ios',
  'App',
  'fastlane',
  'Pluginfile'
)
eval_gemfile(fastlane_plugins_path) if File.exist?(fastlane_plugins_path)

And the Pluginfile:

# Autogenerated by fastlane
#
# Ensure this file is checked in to source control!

gem 'fastlane-plugin-sentry'

@buschtoens Take a look at https://github.com/ionic-team/capacitor/pull/3811--this should be the feature you're looking for (coming in Capacitor 3). For system/environment configuration, we would prefer to use environment variables rather than a file that gets checked into source control. This feature is most similar to the environment variable we added for configuring the path of Android Studio: https://github.com/ionic-team/capacitor/pull/3755

@dwieeb this is perfect! Thank you.

FWIW for anyone following along at home or future Googlers: direnv is a fantastic tool to automatically set env vars when entering a directory, e.g. your repo.

Forgot to mention, the environment variable will only work for file paths, e.g: export CAPACITOR_COCOAPODS_PATH="./bin/pod"

(You can't do CAPACITOR_COCOAPODS_PATH="bundle exec pod")

Thanks for mentioning. That'd be fine as well though. If users for some reason cannot use binstubs, they could create an executable (chmod +x) shell script instead:

#!/usr/bin/env sh
bundle exec pod $@
export CAPACITOR_COCOAPODS_PATH="./bin/custom-pod"
Was this page helpful?
0 / 5 - 0 ratings

Related issues

json-derulo picture json-derulo  ยท  3Comments

gnesher picture gnesher  ยท  3Comments

MatanYadaev picture MatanYadaev  ยท  3Comments

mlynch picture mlynch  ยท  3Comments

peterpeterparker picture peterpeterparker  ยท  3Comments