Running bundle or rspec adds line to Gemfile.lock

孤人 提交于 2021-02-11 14:35:37

问题


After running various commands (bundle and rspec for example) in a Ruby project, Gemfile.lock is updated and x86_64-darwin-17 is added to the PLATFORMS heading. Why is this happening? How can I prevent it?

Running gem env gives this interesting context:

○ → gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 2.7.6
  - RUBY VERSION: 2.5.1 (2018-03-29 patchlevel 57) [x86_64-darwin17]
  #...etc  
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-darwin-17

回答1:


This was caused by global bundler config. Setting to false stopped the behavior.

specific_platform (BUNDLE_SPECIFIC_PLATFORM): Allow bundler to resolve for the specific running platform and store it in the lockfile, instead of only using a generic platform. A specific platform is the exact platform triple reported by Gem::Platform.local, such as x86_64-darwin-16 or universal-java-1.8. On the other hand, generic platforms are those such as ruby, mswin, or java. In this example, x86_64-darwin-16 would map to ruby and universal-java-1.8 to java.




回答2:


The answer from @RangerRanger didn't work for me but I checked in the bundler doc as he did and find this who worked for me:

force_ruby_platform (BUNDLE_FORCE_RUBY_PLATFORM): Ignore the current machine's platform and install only ruby platform gems. As a result, gems with native extensions will be compiled from source.

Here is the command: bundle config force_ruby_platform true




回答3:


If you want to install dependencies without updating the Gemfile.lock, just use the --frozen option. e.g. bundle --frozen. This will install dependencies normally, except not update the Gemfile.lock

Edit

If this is not a good solution, probably the best bet is going to be adding the Gemfile.lock to a .gitignore specific to your local repo. You can create one at your_repo/.git/info/exclude as per this answer



来源:https://stackoverflow.com/questions/50765393/running-bundle-or-rspec-adds-line-to-gemfile-lock

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!