diff options
author | zimbatm <zimbatm@zimbatm.com> | 2016-03-15 20:49:07 +0000 |
---|---|---|
committer | zimbatm <zimbatm@zimbatm.com> | 2016-03-19 22:06:26 +0000 |
commit | 5a64bc44ead7099857e5ecec339e87a80a60796e (patch) | |
tree | 8130746780b4d7c7e636e4e70433418b86951478 /pkgs/development/ruby-modules/gem/gem-post-build.rb | |
parent | 3547ffa89fec408e93627c03f8bf0b3c98bde0e2 (diff) |
move all ruby modules to development/ruby-modules
Diffstat (limited to 'pkgs/development/ruby-modules/gem/gem-post-build.rb')
-rw-r--r-- | pkgs/development/ruby-modules/gem/gem-post-build.rb | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/pkgs/development/ruby-modules/gem/gem-post-build.rb b/pkgs/development/ruby-modules/gem/gem-post-build.rb new file mode 100644 index 0000000000000..4480c525bf16e --- /dev/null +++ b/pkgs/development/ruby-modules/gem/gem-post-build.rb @@ -0,0 +1,76 @@ +require 'rbconfig' +require 'rubygems' +require 'rubygems/specification' +require 'fileutils' + +ruby = File.join(ENV["ruby"], "bin", RbConfig::CONFIG['ruby_install_name']) +out = ENV["out"] +bin_path = File.join(ENV["out"], "bin") +gem_home = ENV["GEM_HOME"] +gem_path = ENV["GEM_PATH"].split(":") +install_path = Dir.glob("#{gem_home}/gems/*").first +gemspec_path = ARGV[0] + +if defined?(Encoding.default_internal) + Encoding.default_internal = Encoding::UTF_8 + Encoding.default_external = Encoding::UTF_8 +end + +gemspec_content = File.read(gemspec_path) +spec = nil +if gemspec_content[0..2] == "---" # YAML header + spec = Gem::Specification.from_yaml(gemspec_content) +else + spec = Gem::Specification.load(gemspec_path) +end + +FileUtils.mkdir_p("#{out}/nix-support") + +# write meta-data +meta = "#{out}/nix-support/gem-meta" +FileUtils.mkdir_p(meta) +FileUtils.ln_s(gemspec_path, "#{meta}/spec") +File.open("#{meta}/name", "w") do |f| + f.write(spec.name) +end +File.open("#{meta}/install-path", "w") do |f| + f.write(install_path) +end +File.open("#{meta}/require-paths", "w") do |f| + f.write(spec.require_paths.join(" ")) +end +File.open("#{meta}/executables", "w") do |f| + f.write(spec.executables.join(" ")) +end + +# add this gem to the GEM_PATH for dependencies +File.open("#{out}/nix-support/setup-hook", "a") do |f| + f.puts("addToSearchPath GEM_PATH #{gem_home}") + spec.require_paths.each do |dir| + f.puts("addToSearchPath RUBYLIB #{install_path}/#{dir}") + end +end + +# create regular rubygems binstubs +FileUtils.mkdir_p(bin_path) +spec.executables.each do |exe| + File.open("#{bin_path}/#{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. +# + +Gem.use_paths "#{gem_home}", #{gem_path.to_s} + +require 'rubygems' + +load Gem.bin_path(#{spec.name.inspect}, #{exe.inspect}) + EOF + end + + FileUtils.chmod("+x", "#{bin_path}/#{exe}") +end |