-
Notifications
You must be signed in to change notification settings - Fork 2
/
minigem
67 lines (65 loc) · 2.64 KB
/
minigem
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env ruby
require 'rubygems'
require 'minigems/script_helper'
include Gem::MiniGems::ScriptHelper
if ARGV.empty? || %w[-H --help].detect { |o| ARGV.index(o) }
# Show some usage information.
program = File.basename($0)
puts "Usage:"
puts " #{program} [options]"
puts " #{program} GEMNAME [GEMNAME ...]"
puts " #{program} install GEMNAME [GEMNAME ...] [options] -- --build-flags [options]"
puts " #{program} update GEMNAME [GEMNAME ...] [options]"
puts " "
puts "Description:"
puts " Manage 'minigems': a lightweight drop-in replacement for the rubygems"
puts " to facilitate faster loading of gems as well as reducing memory"
puts " consumption considerably. Depending on the amount of gems you have"
puts " installed about 10-20 MB less RAM will be used, compared to the full"
puts " rubygems library version, which keeps a cache of all gems and files"
puts " referenced by them."
puts " "
puts " Minigems handles loading of required gems from your scripts. If however,"
puts " other functionality is needed, the full rubygems library will be loaded"
puts " automatically to continue normal operation."
puts " "
puts " To use minigems in your own scripts, use the following construct,"
puts " instead of the common 'require \"rubygems\"' statement:"
puts " "
puts " begin"
puts " require 'minigems'"
puts " rescue LoadError"
puts " require 'rubygems'"
puts " end"
puts " "
puts "Options:"
puts " -H, --help Show this message and quit."
puts " -v, --version Show the program version number and quit."
elsif ARGV[0] == 'setup'
# Install minigems.rb in the ruby search path.
ensure_in_load_path!(true)
elsif ARGV[0] == 'prepare'
# Adapt a gems' executable wrapper to use minigems.
ARGV.shift # skip prepare command argument
ensure_in_load_path!(ARGV.empty?)
ARGV.each do |gem_name|
next unless (gem_spec = Gem.source_index.search(gem_name).last)
adapt_executables_for(gem_spec)
end
elsif ARGV[0] == 'install' || ARGV[0] == 'update'
# Install or update a rubygem and prepare it for minigems.
command = ARGV.shift.to_sym # skip command argument
ensure_in_load_path!
cmd = Gem::GemRunner.new.run_command(command, ARGV)
cmd.get_all_referenced_gem_specs.each do |gemspec|
adapt_executables_for(gemspec)
end
else
# Proxy to rubygems for any other command.
#
# We need to preserve the original ARGV to use for passing gem options
# to source gems. If there is a -- in the line, strip all options after
# it...its for the source building process.
args = !ARGV.include?("--") ? ARGV.clone : ARGV[0...ARGV.index("--")]
Gem::GemRunner.new.run(args)
end