summary refs log tree commit diff
path: root/pkgs/development/ruby-modules/bundler-env/gen-bin-stubs.rb
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/development/ruby-modules/bundler-env/gen-bin-stubs.rb')
-rw-r--r--pkgs/development/ruby-modules/bundler-env/gen-bin-stubs.rb44
1 files changed, 44 insertions, 0 deletions
diff --git a/pkgs/development/ruby-modules/bundler-env/gen-bin-stubs.rb b/pkgs/development/ruby-modules/bundler-env/gen-bin-stubs.rb
new file mode 100644
index 00000000000..fa77682cfd5
--- /dev/null
+++ b/pkgs/development/ruby-modules/bundler-env/gen-bin-stubs.rb
@@ -0,0 +1,44 @@
+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_gem_path = ARGV[3]
+paths = ARGV[4].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").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}"
+ENV["BUNDLE_PATH"] = "#{bundle_path}"
+
+Gem.use_paths("#{bundler_gem_path}", ENV["GEM_PATH"])
+
+require 'bundler/setup'
+
+load Gem.bin_path(#{name.inspect}, #{exe.inspect})
+EOF
+      FileUtils.chmod("+x", "#{out}/bin/#{exe}")
+    end
+  end
+end