gem-sane-binary 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.md +70 -0
  2. data/Rakefile +22 -0
  3. data/lib/rubygems_plugin.rb +29 -0
  4. metadata +57 -0
@@ -0,0 +1,70 @@
1
+ gem-sane-binary
2
+ ===============
3
+
4
+ MIT License © 2009 by Loren Segal
5
+
6
+ SYNOPSIS
7
+ --------
8
+
9
+ Right now RubyGems rewrites the shebang for the binaries it generates in a gem
10
+ using the current Ruby executable name, which inadvertently causes the binary
11
+ to be tied to the specific Ruby version. This means you need to reinstall a gem
12
+ everytime you switch Ruby interpreters to regenerate the binaries.
13
+
14
+ This gem adds a RubyGems plugin to change the shebang behaviour to use a `ruby`
15
+ symlink if one is available in the same directory as the Ruby interpreter being
16
+ used. This allows you to symlink `ruby` to whichever current Ruby interpreter
17
+ is being used, making it easier for 1.8/1.9 to co-exist on a system.
18
+
19
+ INSTALL
20
+ -------
21
+
22
+ $ gem install gem-sane-binary
23
+
24
+ USING
25
+ -----
26
+
27
+ To use the gem, you just need to have a `ruby` symlink pointing to your correct
28
+ Ruby interpreter in the same directory as the interpreter that gem uses when
29
+ installing your gems.
30
+
31
+ SETTING UP RUBY 1.8 AND RUBY 1.9
32
+ --------------------------------
33
+
34
+ If you don't already have two Ruby installs, you should probably read bellow
35
+ to get setup, otherwise this gem won't be very helpful to you.
36
+
37
+ This gem works best for Ruby 1.8/1.9 compatibility. If you want to install Ruby
38
+ 1.8 and Ruby 1.9 side by side, recompile Ruby 1.9 with:
39
+
40
+ ruby-1.9.1...$ ./configure --program-suffix=19
41
+
42
+ You'll then want to rename any ruby 1.8 binaries to use their suffix names as
43
+ well (I'm assuming you already have 1.8 installed. If not, install 1.8 with
44
+ a suffix as well and skip this step):
45
+
46
+ $ sudo mv /usr/local/bin/ruby /usr/local/bin/ruby18
47
+ $ sudo mv /usr/local/bin/irb /usr/local/bin/irb18
48
+ $ sudo mv /usr/local/bin/gem /usr/local/bin/gem18
49
+
50
+ Then create your ruby/irb/gem symlinks to point to whichever Ruby install you're
51
+ using:
52
+
53
+ $ ln -fs /usr/local/bin/ruby19 /usr/local/bin/ruby
54
+ $ ...
55
+
56
+ I use the following aliases in my `~/.profile` to switch between Ruby installs:
57
+
58
+ alias ruby-switch-18='sudo ln -fs /usr/local/bin/ruby18 /usr/local/bin/ruby &&
59
+ sudo ln -fs /usr/local/bin/irb18 /usr/local/bin/irb &&
60
+ sudo ln -fs /usr/local/bin/gem18 /usr/local/bin/gem'
61
+ alias ruby-switch-19='sudo ln -fs /usr/local/bin/ruby19 /usr/local/bin/ruby &&
62
+ sudo ln -fs /usr/local/bin/irb19 /usr/local/bin/irb &&
63
+ sudo ln -fs /usr/local/bin/gem19 /usr/local/bin/gem'
64
+
65
+ Then I get:
66
+
67
+ ~$ ruby-switch-18 && ruby --version
68
+ ruby 1.8.7 (2009-01-28 patchlevel 99) [i686-darwin9.6.0]
69
+ ~$ ruby-switch-19 && ruby --version
70
+ ruby 1.9.1p0 (2009-01-30 revision 21907) [i386-darwin9.6.0]
@@ -0,0 +1,22 @@
1
+ require 'rubygems'
2
+ require 'rake/gempackagetask'
3
+ require 'spec'
4
+ require 'spec/rake/spectask'
5
+
6
+ WINDOWS = (PLATFORM =~ /win32|cygwin/ ? true : false) rescue false
7
+ SUDO = WINDOWS ? '' : 'sudo'
8
+
9
+ task :default => :install
10
+
11
+ desc "Install the gem locally"
12
+ task :install => :package do
13
+ sh "#{SUDO} gem install pkg/#{SPEC.name}-#{SPEC.version}.gem --local"
14
+ sh "rm -rf pkg/#{SPEC.name}-#{SPEC.version}" unless ENV['KEEP_FILES']
15
+ end
16
+
17
+ load 'gem-sane-binary.gemspec'
18
+ Rake::GemPackageTask.new(SPEC) do |pkg|
19
+ pkg.gem_spec = SPEC
20
+ pkg.need_zip = true
21
+ pkg.need_tar = true
22
+ end
@@ -0,0 +1,29 @@
1
+ require 'rubygems/installer'
2
+
3
+ class Gem::Installer
4
+ def shebang(bin_file_name)
5
+ if @env_shebang then
6
+ "#!/usr/bin/env " + Gem::ConfigMap[:ruby_install_name]
7
+ else
8
+ path = File.join @gem_dir, @spec.bindir, bin_file_name
9
+
10
+ ruby_bin_file = File.join(File.dirname(Gem.ruby), 'ruby')
11
+ unless File.symlink?(ruby_bin_file)
12
+ ruby_bin_file = Gem.ruby
13
+ end
14
+
15
+ File.open(path, "rb") do |file|
16
+ first_line = file.gets
17
+ if first_line =~ /^#!/ then
18
+ # Preserve extra words on shebang line, like "-w". Thanks RPA.
19
+ shebang = first_line.sub(/\A\#!.*?ruby\S*/, "#!#{ruby_bin_file}")
20
+ else
21
+ # Create a plain shebang line.
22
+ shebang = "#!#{ruby_bin_file}"
23
+ end
24
+
25
+ shebang.strip # Avoid nasty ^M issues.
26
+ end
27
+ end
28
+ end
29
+ end
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gem-sane-binary
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Loren Segal
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-06-14 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: lsegal@soen.ca
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - lib/rubygems_plugin.rb
26
+ - README.md
27
+ - Rakefile
28
+ has_rdoc: false
29
+ homepage: http://gnuu.org
30
+ licenses: []
31
+
32
+ post_install_message:
33
+ rdoc_options: []
34
+
35
+ require_paths:
36
+ - lib
37
+ required_ruby_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: "0"
42
+ version:
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: "0"
48
+ version:
49
+ requirements: []
50
+
51
+ rubyforge_project: gem-sane-binary
52
+ rubygems_version: 1.3.4
53
+ signing_key:
54
+ specification_version: 3
55
+ summary: RubyGems plugin to allow gem install to generate binaries that work for both Ruby 1.8 and 1.9
56
+ test_files: []
57
+