From 62a5f9fd8c044f095f21c581005eed93f46d7c6d Mon Sep 17 00:00:00 2001 From: mpapis Date: Sun, 12 Jun 2011 23:44:10 +0200 Subject: [PATCH] added bundler_wrapper --- README.md | 25 +++++------- bin/bundler_wrapper | 17 +++++++++ ext/wrapper_installer/extconf.rb | 16 ++++++++ .../rubygems_bundler_installer.rb | 2 +- rubygems-bundler.gemspec | 38 ++++++++++--------- 5 files changed, 65 insertions(+), 33 deletions(-) create mode 100644 bin/bundler_wrapper create mode 100644 ext/wrapper_installer/extconf.rb diff --git a/README.md b/README.md index b4e2855..baf8b1a 100644 --- a/README.md +++ b/README.md @@ -6,12 +6,14 @@ generated by rubygems aware of bundler. # Installation gem install rubygems-bundler - gem regenerate_binstubs [-V] + +And follow the on screen instructions # Description This gem is intended to fill in the integration gap between -Bundler and Rubygems +Bundler and Rubygems, it also backoports shebang customization +from rubygems 1.9 to older versions - down to 1.3.7. With this gem rubygems generated wrappers will allow to use bundler when asked for. @@ -19,20 +21,16 @@ use bundler when asked for. Using this gem solves problem of calling `bundle exec ...` with your every command. -

NOTE

- -Please note that method introduced by this gem is not approved -by rubygems neither bundler teams becouse of the following problem: - -Beware, it is important you understand that this gem can make -your gem executables load in versions specified in Gemfile! +Please note that this gem can make your gem executables +load in versions specified in Gemfile! The problem with Gemfile is that you can have few of them, so expect that gem version for executable will be taken from `~/Gemfile` when your project is in `~/projects/my_project` and does not contain `Gemfile` -Last note is that bundler handling can be used only when bundler is installed. +Last note is that bundler handling can be used only when bundler is +installed, but you will be warned when it is # Controlling the wrapper @@ -47,7 +45,7 @@ To force usage of bundler: export USE_BUNDLER=force -To make your choice persistent put this into `~/.rvmrc` or `~/.bashrc`. +To make your choice persistent put this into `~/.bashrc` or `~/.rvmrc`. # How it works @@ -56,10 +54,7 @@ aware wrapper: gem install rubygems-bundler -To make gems already installed aware of bundler call the following command, -it will detect gems with executables and regenerate those executables: - - gem regenerate_binstubs [-V] +Follow onscreen instructions. Now for running haml can be controlled if it will using bundler code or not: diff --git a/bin/bundler_wrapper b/bin/bundler_wrapper new file mode 100644 index 0000000..40fc42b --- /dev/null +++ b/bin/bundler_wrapper @@ -0,0 +1,17 @@ +#!/usr/bin/env ruby + +require 'rubygems' + +use_bundler = (ENV['USE_BUNDLER']||'').downcase +try_bundler = %w{try check possibly}.include? use_bundler +force_bundler = %w{force require yes true on}.include? use_bundler + +if try_bundler || force_bundler + begin + require 'bundler/setup' + rescue LoadError + raise "\n\nPlease 'gem install bundler' first.\n\n" if force_bundler + end +end + +eval File.read(ARGV[0]) diff --git a/ext/wrapper_installer/extconf.rb b/ext/wrapper_installer/extconf.rb new file mode 100644 index 0000000..33f3f4c --- /dev/null +++ b/ext/wrapper_installer/extconf.rb @@ -0,0 +1,16 @@ +# Fake building extension +File.open('Makefile', 'w') { |f| f.write "all:\n\ninstall:\n\n" } +File.open('make', 'w') do |f| + f.write '#!/bin/sh' + f.chmod f.stat.mode | 0111 +end +File.open('wrapper_installer.so', 'w') {} +File.open('wrapper_installer.dll', 'w') {} +File.open('nmake.bat', 'w') { |f| } + +# Copy wrapper +require 'fileutils' +wrapper=File.expand_path('../../../bin/bundler_wrapper',File.absolute_path(__FILE__)) +destination=File.expand_path('bin/bundler_wrapper',Gem.dir) +FileUtils.cp(wrapper, destination, :verbose => true) +File.chmod(0755, destination) diff --git a/lib/rubygems_bundler/rubygems_bundler_installer.rb b/lib/rubygems_bundler/rubygems_bundler_installer.rb index b710481..d57aada 100644 --- a/lib/rubygems_bundler/rubygems_bundler_installer.rb +++ b/lib/rubygems_bundler/rubygems_bundler_installer.rb @@ -26,7 +26,7 @@ def self.shebang(inst, bin_file_name) ruby_name = Gem::ConfigMap[:ruby_install_name] if @env_shebang path = inst.spec.bin_file bin_file_name first_line = File.open(path, "rb") {|file| file.gets} - @@env_path ||= inst::ENV_PATHS.find {|env_path| File.executable? env_path } + @@env_path ||= Gem::Installer::ENV_PATHS.find {|env_path| File.executable? env_path } if /\A#!/ =~ first_line then # Preserve extra words on shebang line, like "-w". Thanks RPA. diff --git a/rubygems-bundler.gemspec b/rubygems-bundler.gemspec index b5dd0b9..67cc846 100644 --- a/rubygems-bundler.gemspec +++ b/rubygems-bundler.gemspec @@ -1,29 +1,33 @@ Gem::Specification.new do |s| s.name = "rubygems-bundler" - s.version = "0.1.5" - s.date = "2011-06-08" + s.version = "0.2.0" + s.date = "2011-06-12" s.summary = "Make rubygems generate bundler aware executable wrappers" s.email = "mpapis@gmail.com" s.homepage = "https://github.com/mpapis/rubygems-bundler" - s.description = "Integrate Rubygems, Bundler and RVM" + s.description = "Integrate Rubygems and Bundler" s.has_rdoc = false s.authors = ["Michal Papis"] s.files = [ - "lib/rubygems_bundler/regenerate_binstubs_command.rb", - "lib/rubygems_bundler/rubygems_bundler_installer.rb", - "lib/rubygems_bundler/fix_wrapper.rb", - "lib/rubygems_plugin.rb", - "README.md", - "rubygems-bundler.gemspec", - "LICENSE", - ] + "bin/bundler_wrapper", + "ext/wrapper_installer/extconf.rb", + "lib/rubygems_bundler/regenerate_binstubs_command.rb", + "lib/rubygems_bundler/rubygems_bundler_installer.rb", + "lib/rubygems_bundler/fix_wrapper.rb", + "lib/rubygems_plugin.rb", + "LICENSE", + "README.md", + "rubygems-bundler.gemspec", + ] + s.extensions = ["ext/wrapper_installer/extconf.rb"] s.post_install_message = <<-TEXT -======================================================================== +=============================================================================== -Thanks for installing rubygems-bundler! +rubygems-bundler allows running gem executables in Gemfile specified versions! -It is important you understand that this gem can make your gem -executables load in versions specified in Gemfile! +First step is to add following line to ~/.gemrc + + custom_shebang: $env bundler_wrapper To make all the executables bundler compatible run: @@ -33,7 +37,7 @@ To always use bundler add the following line to ~/.rvmrc or ~/.bashrc export USE_BUNDLER=force -now relogin or call in every open shell: +Relogin or call in every open shell: export USE_BUNDLER=force @@ -41,6 +45,6 @@ For more information read: https://github.com/mpapis/rubygems-bundler -======================================================================== +=============================================================================== TEXT end