ionic-team / capacitor

Build cross-platform Native Progressive Web Apps for iOS, Android, and the Web ⚡️
https://capacitorjs.com
MIT License
11.31k stars 962 forks source link

feat(ios): Add Bundler support #5205

Closed saschpe closed 1 year ago

saschpe commented 2 years ago

Bundler isolates RubGems dependencies from the host operating system and creates a consistent environment. Gem dependencies can be pinned to exact versions by using a Gemfile. CocoaPods is modeled after Bundler.

This ensures all developers and CI machines use the same CocoaPods version. It's also conveniently used to install CocoaPods plugins, e.g. cocoapods-art, or additional iOS development tools, such as xcpretty.

Multiple cases are now handled correctly. If a Gemfile is found:

Then:

  1. Use Bundler to install RubyGems, including CocoaPods:
    1. If Bundler is outdated, update first by executing gem install bundler
    2. If RubyGems bundle is outdated, update first by executing bundle install
    3. Install CocoaPods and other gems by executing bundle exec pod install

Or, just like before, if:

  1. CocoaPods is available on PATH, execute pod install
  2. Neither global CocoaPods nor Gemfile are found Skip CocoaPods install entirely

Implements #5177

Remarks

The following screenshots demonstrate the CLI output and actions that now occur (in reverse order but with increasing coolness):

Case 5

Screenshot 2021-11-04 at 10 25 04

Case 4

Screenshot 2021-11-04 at 10 25 53

Case 1.2 and 1.3

Screenshot 2021-11-04 at 10 24 32

Case 1.1 and 1.3

Screenshot 2021-11-04 at 09 40 26
saschpe commented 2 years ago

I didn't dare to touch the iOS project template just yet. Once this change is accepted, it might make sense to do that as well to better isolate iOS builds from the host machine used.

saschpe commented 2 years ago

I addressed the eslint issues but now need a workflow approval / re-run. TIA.

saschpe commented 2 years ago

Any remarks or comments?

saschpe commented 2 years ago

Once again, any news, decisions or comments on the matter?

saschpe commented 1 year ago

It would be nice if this could get some feedback, I just rebased onto most recent main changes.

fxsalazar commented 1 year ago

This is awesome 👍🏽 hope this can be merged as fast as possible.

ffluk3 commented 1 year ago

Hey, bump on this one, does the Ionic team see any value in bringing this into the project?

markemer commented 1 year ago

Let me take a look - I do know that bundler is popular along side cocoapods - I know I used it.

markemer commented 1 year ago

Hey, please update this with the latest from main as well. As best as you can anyway - I know we're coming fast and furious with commits - but I don't like to update other peoples forks unless I'm about to merge any minute.

saschpe commented 1 year ago

And so I keep it current even though I already gave up hope that contributing to CapacitorJS is a thing at all.

saschpe commented 1 year ago

Now that some attention is on this one, may I shamelessly point you guys to https://github.com/ionic-team/capacitor/pull/5195 as well? It's equally important when trying to use latest Android SDK versions

markemer commented 1 year ago

Now that some attention is on this one, may I shamelessly point you guys to #5195 as well? It's equally important when trying to use latest Android SDK versions

Sure - but I'm more iOS leaning so I'll have to pull in some help - we are bumping the target to 33 in Cap5 (now in alpha!)

saschpe commented 1 year ago

Let's see wait they say. I'd be happy to adjust the default project template afterwards.

markemer commented 1 year ago

@saschpe You have a conflict here since I removed the deletion of the Podfile.lock as that was done a while back to work around a bug. Should be an easy fix. I can even fix it if you like.

saschpe commented 1 year ago

I'm currently rebasing all my open pull requests...

ffluk3 commented 1 year ago

@saschpe @markemer Thank you so much for driving this forward by the way, appreciate it!

markemer commented 1 year ago

I haven't forgotten about this - I'm going to see if we can get this into the 5-rc or if not that, the next point release.

IT-MikeS commented 1 year ago

Please see my new comment:

https://github.com/ionic-team/capacitor/pull/5205#discussion_r1156179404

jskrepnek commented 9 months ago

Is there a way to tell Capacitor 5 to ignore or opt-out of the bundler integration? We have a Gemfile for automation purposes, but don't want it used for development at all (at least not yet).

jskrepnek commented 9 months ago

@markemer @IT-MikeS

I'm trying to figure out if I'm seeing an issue with this change.

Running capacitor sync ios I see the logs:

[capacitor] [info] Using Gemfile: RubyGems bundle installed
...
[capacitor] [warn] Skipping pod install because CocoaPods is not installed
[capacitor] ✔ Updating iOS native dependencies with pod install in 1.27s

The update code appears to confusingly think that it's not using bundler, despite the earlier message.

Tracing down further, I think the issue is that it's using single quotes in the test to determine if Cocoapods is referenced in the Gemfile, but it's valid to use double quotes here and our file does.

saschpe commented 8 months ago

Double quoted strings allow interpolation which is a bit unusual in the case of gem names. They're rather fixed. Then again, Ruby has another string literal variant, percent strings like %q{hello}.

While it's straightforward to expand the test to check for double-quoted strings, I am not sure we'd want to support percent strings as well. I can already see someone who is using regex strings :-)

toxaq commented 4 months ago

Yes, how do I opt out of this? We have a Gemfile for fastlane but this is trying to install bundler on xcode cloud build?

saschpe commented 4 months ago

Yes, how do I opt out of this? We have a Gemfile for fastlane but this is trying to install bundler on xcode cloud build?

You're using Fastlane and Xcode Cloud? There aren't many reasons left these days to still use Fastlane. Almost everything can be achieved with xcodebuild. But if you want to avoid Bundler, you could simply rm Gemfile in the Xcode Cloud build phase.

toxaq commented 4 months ago

You’re using bundled to install cocoa pods?