about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/ruby-modules/bundled-common/gen-bin-stubs.rb
diff options
context:
space:
mode:
authorAlyssa Ross <hi@alyssa.is>2019-01-07 02:18:36 +0000
committerAlyssa Ross <hi@alyssa.is>2019-01-07 02:18:47 +0000
commit36f56d99fa0a0765c9f1de4a5f17a9b05830c3f2 (patch)
treeb3faaf573407b32aa645237a4d16b82778a39a92 /nixpkgs/pkgs/development/ruby-modules/bundled-common/gen-bin-stubs.rb
parent4e31070265257dc67d120c27e0f75c2344fdfa9a (diff)
parentabf060725d7614bd3b9f96764262dfbc2f9c2199 (diff)
downloadnixlib-36f56d99fa0a0765c9f1de4a5f17a9b05830c3f2.tar
nixlib-36f56d99fa0a0765c9f1de4a5f17a9b05830c3f2.tar.gz
nixlib-36f56d99fa0a0765c9f1de4a5f17a9b05830c3f2.tar.bz2
nixlib-36f56d99fa0a0765c9f1de4a5f17a9b05830c3f2.tar.lz
nixlib-36f56d99fa0a0765c9f1de4a5f17a9b05830c3f2.tar.xz
nixlib-36f56d99fa0a0765c9f1de4a5f17a9b05830c3f2.tar.zst
nixlib-36f56d99fa0a0765c9f1de4a5f17a9b05830c3f2.zip
Add 'nixpkgs/' from commit 'abf060725d7614bd3b9f96764262dfbc2f9c2199'
git-subtree-dir: nixpkgs
git-subtree-mainline: 4e31070265257dc67d120c27e0f75c2344fdfa9a
git-subtree-split: abf060725d7614bd3b9f96764262dfbc2f9c2199
Diffstat (limited to 'nixpkgs/pkgs/development/ruby-modules/bundled-common/gen-bin-stubs.rb')
-rw-r--r--nixpkgs/pkgs/development/ruby-modules/bundled-common/gen-bin-stubs.rb48
1 files changed, 48 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/development/ruby-modules/bundled-common/gen-bin-stubs.rb b/nixpkgs/pkgs/development/ruby-modules/bundled-common/gen-bin-stubs.rb
new file mode 100644
index 000000000000..fe8c43f55ed1
--- /dev/null
+++ b/nixpkgs/pkgs/development/ruby-modules/bundled-common/gen-bin-stubs.rb
@@ -0,0 +1,48 @@
+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")
+    .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'
+
+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