about summary refs log tree commit diff
path: root/pkgs/development/ruby-modules/bundled-common/gen-bin-stubs.rb
diff options
context:
space:
mode:
authorJudson <nyarly@gmail.com>2017-05-27 15:19:34 -0700
committerJudson <nyarly@gmail.com>2017-05-27 15:19:34 -0700
commit998d011e426c2f8c51946ebbc4931a464f531db9 (patch)
treef7c29caa5789057980f0627fd4e9435b35e34000 /pkgs/development/ruby-modules/bundled-common/gen-bin-stubs.rb
parent022be78eb26de958e50e32ac40574e93ac81bee3 (diff)
downloadnixlib-998d011e426c2f8c51946ebbc4931a464f531db9.tar
nixlib-998d011e426c2f8c51946ebbc4931a464f531db9.tar.gz
nixlib-998d011e426c2f8c51946ebbc4931a464f531db9.tar.bz2
nixlib-998d011e426c2f8c51946ebbc4931a464f531db9.tar.lz
nixlib-998d011e426c2f8c51946ebbc4931a464f531db9.tar.xz
nixlib-998d011e426c2f8c51946ebbc4931a464f531db9.tar.zst
nixlib-998d011e426c2f8c51946ebbc4931a464f531db9.zip
Restructuring files
Diffstat (limited to 'pkgs/development/ruby-modules/bundled-common/gen-bin-stubs.rb')
-rw-r--r--pkgs/development/ruby-modules/bundled-common/gen-bin-stubs.rb47
1 files changed, 47 insertions, 0 deletions
diff --git a/pkgs/development/ruby-modules/bundled-common/gen-bin-stubs.rb b/pkgs/development/ruby-modules/bundled-common/gen-bin-stubs.rb
new file mode 100644
index 000000000000..92321d6427dc
--- /dev/null
+++ b/pkgs/development/ruby-modules/bundled-common/gen-bin-stubs.rb
@@ -0,0 +1,47 @@
+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
+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").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'
+
+Gem.use_paths(#{bundler_gem_path.dump}, ENV["GEM_PATH"])
+
+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