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.

106 lines
2.8KB

  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 || ">= 0.a"
  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", __FILE__)
  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_version
  53. @bundler_version ||= begin
  54. env_var_version || cli_arg_version ||
  55. lockfile_version || "#{Gem::Requirement.default}.a"
  56. end
  57. end
  58. def load_bundler!
  59. ENV["BUNDLE_GEMFILE"] ||= gemfile
  60. # must dup string for RG < 1.8 compatibility
  61. activate_bundler(bundler_version.dup)
  62. end
  63. def activate_bundler(bundler_version)
  64. if Gem::Version.correct?(bundler_version) && Gem::Version.new(bundler_version).release < Gem::Version.new("2.0")
  65. bundler_version = "< 2"
  66. end
  67. gem_error = activation_error_handling do
  68. gem "bundler", bundler_version
  69. end
  70. return if gem_error.nil?
  71. require_error = activation_error_handling do
  72. require "bundler/version"
  73. end
  74. return if require_error.nil? && Gem::Requirement.new(bundler_version).satisfied_by?(Gem::Version.new(Bundler::VERSION))
  75. warn "Activating bundler (#{bundler_version}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_version}'`"
  76. exit 42
  77. end
  78. def activation_error_handling
  79. yield
  80. nil
  81. rescue StandardError, LoadError => e
  82. e
  83. end
  84. end
  85. m.load_bundler!
  86. if m.invoked_as_script?
  87. load Gem.bin_path("bundler", "bundle")
  88. end