You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

114 lines
2.9 KiB

1 year ago
  1. #!/usr/bin/env ruby
  2. # frozen_string_literal: true
  3. #
  4. # This file was generated by Bundler.
  5. #
  6. # The application 'bundle' is installed as part of a gem, and
  7. # this file is here to facilitate running it.
  8. #
  9. require "rubygems"
  10. m = Module.new do
  11. module_function
  12. def invoked_as_script?
  13. File.expand_path($0) == File.expand_path(__FILE__)
  14. end
  15. def env_var_version
  16. ENV["BUNDLER_VERSION"]
  17. end
  18. def cli_arg_version
  19. return unless invoked_as_script? # don't want to hijack other binstubs
  20. return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update`
  21. bundler_version = nil
  22. update_index = nil
  23. ARGV.each_with_index do |a, i|
  24. if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN
  25. bundler_version = a
  26. end
  27. next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/
  28. bundler_version = $1
  29. update_index = i
  30. end
  31. bundler_version
  32. end
  33. def gemfile
  34. gemfile = ENV["BUNDLE_GEMFILE"]
  35. return gemfile if gemfile && !gemfile.empty?
  36. File.expand_path("../Gemfile", __dir__)
  37. end
  38. def lockfile
  39. lockfile =
  40. case File.basename(gemfile)
  41. when "gems.rb" then gemfile.sub(/\.rb$/, gemfile)
  42. else "#{gemfile}.lock"
  43. end
  44. File.expand_path(lockfile)
  45. end
  46. def lockfile_version
  47. return unless File.file?(lockfile)
  48. lockfile_contents = File.read(lockfile)
  49. return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/
  50. Regexp.last_match(1)
  51. end
  52. def bundler_requirement
  53. @bundler_requirement ||=
  54. env_var_version || cli_arg_version ||
  55. bundler_requirement_for(lockfile_version)
  56. end
  57. def bundler_requirement_for(version)
  58. return "#{Gem::Requirement.default}.a" unless version
  59. bundler_gem_version = Gem::Version.new(version)
  60. requirement = bundler_gem_version.approximate_recommendation
  61. return requirement unless Gem.rubygems_version < Gem::Version.new("2.7.0")
  62. requirement += ".a" if bundler_gem_version.prerelease?
  63. requirement
  64. end
  65. def load_bundler!
  66. ENV["BUNDLE_GEMFILE"] ||= gemfile
  67. activate_bundler
  68. end
  69. def activate_bundler
  70. gem_error = activation_error_handling do
  71. gem "bundler", bundler_requirement
  72. end
  73. return if gem_error.nil?
  74. require_error = activation_error_handling do
  75. require "bundler/version"
  76. end
  77. return if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION))
  78. warn "Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`"
  79. exit 42
  80. end
  81. def activation_error_handling
  82. yield
  83. nil
  84. rescue StandardError, LoadError => e
  85. e
  86. end
  87. end
  88. m.load_bundler!
  89. if m.invoked_as_script?
  90. load Gem.bin_path("bundler", "bundle")
  91. end