mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-12-25 03:17:13 +00:00
106d0920d9
Setting a Bundler version with GEM_PATH doesn't seem to work in Ruby 2.7, so we need to use the LOAD_PATH instead. Without this, bundlerEnv environments will always use the version of Bundler that comes with Ruby, which won't necessarily work because it isn't the version that was used to generate the bundle. For example, building ronn with Ruby 2.7 without this change results in a broken executable, but it works (when built with all packaged Ruby versions) after this change.
49 lines
1.1 KiB
Ruby
49 lines
1.1 KiB
Ruby
require 'rbconfig'
|
|
require 'rubygems'
|
|
require 'rubygems/specification'
|
|
require 'fileutils'
|
|
|
|
# args/settings
|
|
out = ENV["out"]
|
|
ruby = ARGV[0]
|
|
gemfile = ARGV[1]
|
|
bundle_path = ARGV[2]
|
|
bundler_path = ARGV[3]
|
|
paths = ARGV[4].split
|
|
groups = ARGV[5].split
|
|
|
|
# generate binstubs
|
|
FileUtils.mkdir_p("#{out}/bin")
|
|
paths.each do |path|
|
|
next unless File.directory?("#{path}/nix-support/gem-meta")
|
|
|
|
name = File.read("#{path}/nix-support/gem-meta/name")
|
|
executables = File.read("#{path}/nix-support/gem-meta/executables")
|
|
.force_encoding('UTF-8').split
|
|
executables.each do |exe|
|
|
File.open("#{out}/bin/#{exe}", "w") do |f|
|
|
f.write(<<-EOF)
|
|
#!#{ruby}
|
|
#
|
|
# This file was generated by Nix.
|
|
#
|
|
# The application '#{exe}' is installed as part of a gem, and
|
|
# this file is here to facilitate running it.
|
|
#
|
|
|
|
ENV["BUNDLE_GEMFILE"] = #{gemfile.dump}
|
|
ENV["BUNDLE_PATH"] = #{bundle_path.dump}
|
|
ENV['BUNDLE_FROZEN'] = '1'
|
|
|
|
$LOAD_PATH.unshift #{bundler_path.dump} + "/lib"
|
|
|
|
require 'bundler'
|
|
Bundler.setup(#{groups.map(&:dump).join(', ')})
|
|
|
|
load Gem.bin_path(#{name.dump}, #{exe.dump})
|
|
EOF
|
|
FileUtils.chmod("+x", "#{out}/bin/#{exe}")
|
|
end
|
|
end
|
|
end
|