bundle 3.1 KB

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