rvm 0.1.41 → 0.1.42

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. data/binscripts/rvm +1 -1
  2. data/binscripts/rvm-shell +32 -0
  3. data/binscripts/rvmsudo +1 -6
  4. data/config/db +2 -2
  5. data/config/known +2 -2
  6. data/config/md5 +6 -5
  7. data/contrib/install-system-wide +81 -0
  8. data/install +23 -24
  9. data/lib/VERSION.yml +1 -1
  10. data/lib/rvm.rb +156 -1
  11. data/lib/rvm/capistrano.rb +45 -0
  12. data/lib/rvm/environment.rb +62 -0
  13. data/lib/rvm/environment/alias.rb +69 -0
  14. data/lib/rvm/environment/cleanup.rb +54 -0
  15. data/lib/rvm/environment/configuration.rb +60 -0
  16. data/lib/rvm/environment/env.rb +52 -0
  17. data/lib/rvm/environment/gemset.rb +222 -0
  18. data/lib/rvm/environment/info.rb +13 -0
  19. data/lib/rvm/environment/list.rb +124 -0
  20. data/lib/rvm/environment/rubies.rb +50 -0
  21. data/lib/rvm/environment/sets.rb +123 -0
  22. data/lib/rvm/environment/tools.rb +41 -0
  23. data/lib/rvm/environment/utility.rb +167 -0
  24. data/lib/rvm/environment/wrapper.rb +23 -0
  25. data/lib/rvm/errors.rb +28 -0
  26. data/lib/rvm/shell.rb +21 -10
  27. data/lib/rvm/shell/abstract_wrapper.rb +145 -0
  28. data/lib/rvm/shell/result.rb +42 -0
  29. data/lib/rvm/shell/shell_wrapper.sh +10 -0
  30. data/lib/rvm/shell/single_shot_wrapper.rb +56 -0
  31. data/lib/rvm/shell/utility.rb +37 -0
  32. data/lib/rvm/version.rb +12 -8
  33. data/rvm.gemspec +27 -4
  34. data/scripts/cd +17 -32
  35. data/scripts/cli +46 -16
  36. data/scripts/completion +1 -1
  37. data/scripts/disk-usage +52 -0
  38. data/scripts/fetch +8 -2
  39. data/scripts/gemsets +15 -4
  40. data/scripts/initialize +3 -3
  41. data/scripts/install +23 -24
  42. data/scripts/list +16 -8
  43. data/scripts/log +4 -1
  44. data/scripts/man +0 -0
  45. data/scripts/manage +51 -34
  46. data/scripts/md5 +4 -5
  47. data/scripts/package +28 -6
  48. data/scripts/rubygems +2 -2
  49. data/scripts/rvm +2 -2
  50. data/scripts/rvm-install +23 -24
  51. data/scripts/selector +2 -2
  52. data/scripts/tools +34 -0
  53. data/scripts/update +23 -24
  54. data/scripts/utility +54 -12
  55. data/scripts/wrapper +21 -18
  56. metadata +29 -6
  57. data/lib/rvm/open4.rb +0 -395
  58. data/lib/rvm/rvm.rb +0 -14
@@ -0,0 +1,13 @@
1
+ require 'yaml'
2
+
3
+ module RVM
4
+ class Environment
5
+
6
+ def info(*ruby_strings)
7
+ ruby_string = normalize_ruby_string(ruby_strings)
8
+ res = rvm(:info, ruby_string)
9
+ res.successful? ? YAML.load(res.stdout) : {}
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,124 @@
1
+ module RVM
2
+ class Environment
3
+
4
+ # Returns a raw array list of ruby + gemset combinations.
5
+ def list_gemsets
6
+ normalize_listing_output rvm(:list, :gemsets, :strings).stdout
7
+ end
8
+
9
+ # Returns a raw array list of installed ruby strings, including aliases.
10
+ def list_strings
11
+ normalize_listing_output rvm(:list, :strings).stdout.tr(' ', "\n")
12
+ end
13
+
14
+ # Lists the default ruby (minus gemset)
15
+ def list_default
16
+ normalize rvm(:list, :default, :string).stdout
17
+ end
18
+
19
+ # Lists all known ruby strings (raw, filtered output)
20
+ def list_known
21
+ normalize_listing_output rvm(:list, :known).stdout
22
+ end
23
+
24
+ # Lists all known ruby strings
25
+ def list_known_strings
26
+ normalize_listing_output rvm(:list, :known_strings).stdout
27
+ end
28
+
29
+ # Lists all known svn tags.
30
+ def list_ruby_svn_tags
31
+ normalize_listing_output rvm(:list, :ruby_svn_tags).stdout
32
+ end
33
+
34
+ # Returns an interface to a more Ruby-like interface for list.
35
+ def list
36
+ @list_helper ||= ListWrapper.new(self)
37
+ end
38
+
39
+ # Provides a ruby-like interface to make listing rubies easier.
40
+ class ListWrapper
41
+
42
+ def initialize(parent)
43
+ @parent = parent
44
+ end
45
+
46
+ # Returns an array of ruby + gemset combinations.
47
+ def gemsets
48
+ @parent.list_gemsets
49
+ end
50
+
51
+ # Returns an array of installed rubies.
52
+ def rubies
53
+ @parent.list_strings
54
+ end
55
+ alias installed rubies
56
+ alias strings rubies
57
+
58
+ # Shows the current default. If :gemset is passed in and is
59
+ # true, it will include the gemset in the output.
60
+ def default(options = {})
61
+ options[:gemset] ? @parent.show_alias(:default) : @parent.list_default
62
+ end
63
+
64
+ # A raw list of known rubies.
65
+ def raw_known
66
+ @parent.list_known
67
+ end
68
+
69
+ def known_strings
70
+ @parent.list_known_strings
71
+ end
72
+
73
+ # A list of known ruby strings, minus svn tags.
74
+ def expanded_known
75
+ raw_known.map do |raw|
76
+ expand_variants(raw)
77
+ end.flatten.uniq.sort
78
+ end
79
+
80
+ # Raw list of svn tagged version
81
+ def raw_ruby_svn_tags
82
+ @parent.list_ruby_svn_tags
83
+ end
84
+
85
+ # Normalized list of ruby svn tags.
86
+ def ruby_svn_tags
87
+ raw_ruby_svn_tags.map { |t| expand_variants(t) }.flatten.uniq.sort
88
+ end
89
+ alias from_svn ruby_svn_tags
90
+
91
+ # Most installable ruby strings.
92
+ def installable
93
+ (expanded_known + ruby_svn_tags).uniq.sort
94
+ end
95
+
96
+ protected
97
+
98
+ # Expands strings to include optional parts (surrounded in brackets),
99
+ # given a useable string.
100
+ def expand_variants(s)
101
+ if s =~ /(\([^\)]+\))/
102
+ part = $1
103
+ expand_variants(s.sub(part, "")) + expand_variants(s.sub(part, part[1..-2]))
104
+ else
105
+ [s]
106
+ end
107
+ end
108
+
109
+ end
110
+
111
+ protected
112
+
113
+ # Takes a list of rubies / items, 1 per line and strips comments and blank lines.
114
+ def normalize_listing_output(results)
115
+ lines = []
116
+ results.each_line do |line|
117
+ line = line.gsub(/#.*/, '').strip
118
+ lines << line unless line.empty?
119
+ end
120
+ lines.sort
121
+ end
122
+
123
+ end
124
+ end
@@ -0,0 +1,50 @@
1
+ module RVM
2
+ class Environment
3
+
4
+ # Installs the given ruby
5
+ def install(rubies, opts = {})
6
+ rvm(:install, normalize_ruby_string(rubies), opts).successful?
7
+ end
8
+
9
+ # Uninstalls a ruby (remove but keeps src etc)
10
+ def uninstall(rubies, opts = {})
11
+ rvm(:uninstall, normalize_ruby_string(rubies), opts).successful?
12
+ end
13
+
14
+ # Removes a given ruby from being managed by rvm.
15
+ def remove(rubies, opts = {})
16
+ rvm(:remove, normalize_ruby_string(rubies), opts).successful?
17
+ end
18
+
19
+ # Changes the ruby string for the current environment.
20
+ def use(ruby_string, opts = {})
21
+ ruby_string = ruby_string.to_s
22
+ result = rvm(:use, ruby_string)
23
+ if result.successful?
24
+ @environment_name = ruby_string
25
+ @expanded_name = nil
26
+ use_env_from_result! result if opts[:replace_env]
27
+ end
28
+ end
29
+
30
+ # Like use but with :replace_env defaulting to true.
31
+ def use!(ruby_string, opts = {})
32
+ use ruby_string, opts.merge(:replace_env => true)
33
+ end
34
+
35
+ # Will get the ruby from the given path. If there
36
+ # is a compatible ruby found, it will then attempt
37
+ # to use the associated gemset.
38
+ # e.g. RVM::Environment.current.use_from_path! Dir.pwd
39
+ def use_from_path!(path)
40
+ use! tools.path_identifier(path)
41
+ end
42
+
43
+ protected
44
+
45
+ def normalize_ruby_string(rubies)
46
+ Array(rubies).join(",")
47
+ end
48
+
49
+ end
50
+ end
@@ -0,0 +1,123 @@
1
+ module RVM
2
+ class Environment
3
+
4
+ # Passed either something containing ruby code or
5
+ # a path to a ruby file, will attempt to exectute
6
+ # it in the current environment.
7
+ def ruby(runnable, options = {})
8
+ if runnable.respond_to?(:path)
9
+ # Call the path
10
+ ruby_run runnable.path, options
11
+ elsif runnable.respond_to?(:to_str)
12
+ runnable = runnable.to_str
13
+ File.exist?(runnable) ? ruby_run(runnable, options) : ruby_eval(runnable, options)
14
+ elsif runnable.respond_to?(:read)
15
+ ruby_run runnable.read
16
+ end
17
+ end
18
+
19
+ # Eval the given code within ruby.
20
+ def ruby_eval(code, options = {})
21
+ perform_set_operation :ruby, "-e", code.to_s, options
22
+ end
23
+
24
+ # Run the given path as a ruby script.
25
+ def ruby_run(path, options = {})
26
+ perform_set_operation :ruby, path.to_s, options
27
+ end
28
+
29
+ # Execute rake (optionally taking the path to a rake file),
30
+ # then change back.
31
+ def rake(file = nil, options = {})
32
+ if file.nil?
33
+ perform_set_operation :rake, options
34
+ else
35
+ file = File.expand_path(file)
36
+ chdir(File.dirname(file)) do
37
+ perform_set_operation(:rake, options.merge(:rakefile => file))
38
+ end
39
+ end
40
+ end
41
+
42
+ # Use the rvm test runner for unit tests.
43
+ def tests(options = {})
44
+ perform_set_operation :tests, options
45
+ end
46
+
47
+ # Use the rvm spec runner for specs.
48
+ def specs(options = {})
49
+ perform_set_operation :specs, options
50
+ end
51
+
52
+ # Like Kernel.system, but evaluates it within the environment.
53
+ # Also note that it doesn't support redirection etc.
54
+ def system(command, *args)
55
+ identifier = extract_identifier!(args)
56
+ args = [identifier, :exec, command, *args].compact
57
+ rvm(*args).successful?
58
+ end
59
+
60
+ # Executes a command, replacing the current shell.
61
+ # exec is a bit of an odd ball compared to the others, since
62
+ # it has to use the Kernel.exec builtin.
63
+ def exec(command, *args)
64
+ command = @shell_wrapper.build_cli_call(:exec, [command] + args)
65
+ Kernel.exec "bash", "-c", "source '#{env_path}'; #{command}"
66
+ end
67
+
68
+ protected
69
+
70
+ # Converts the given identifier to a rvm-friendly form.
71
+ # Unlike using sets directly, a nil identifier is set
72
+ # to mean the current ruby (not all). :all or "all" will
73
+ # instead return the a blank identifier / run it against
74
+ # all rubies.
75
+ def normalize_set_identifier(identifier)
76
+ case identifier
77
+ when nil, ""
78
+ @environment_name
79
+ when :all, "all"
80
+ nil
81
+ when Array
82
+ identifier.map { |i| normalize_set_identifier(i) }.uniq.join(",")
83
+ else
84
+ identifier.to_s
85
+ end
86
+ end
87
+
88
+ # From an options hash, extract the environment identifier.
89
+ def extract_environment!(options)
90
+ values = []
91
+ [:environment, :env, :rubies, :ruby].each do |k|
92
+ values << options.delete(k)
93
+ end
94
+ values.compact.first
95
+ end
96
+
97
+ # Shorthand to extra an identifier from args.
98
+ # Since we
99
+ def extract_identifier!(args)
100
+ options = extract_options!(args)
101
+ identifier = normalize_set_identifier(extract_environment!(options))
102
+ args << options
103
+ identifier
104
+ end
105
+
106
+ # Performs a set operation. If the :env or :environment option is given,
107
+ # it will return a yaml summary (instead of the stdout / stderr etc via
108
+ # a Result object.
109
+ def perform_set_operation(*args)
110
+ options = extract_options!(args)
111
+ environment = extract_environment!(options)
112
+ identifier = normalize_set_identifier(environment)
113
+ # Uses yaml when we have multiple identifiers.
114
+ uses_yaml = !environment.nil?
115
+ options.merge!(:yaml => true) if uses_yaml
116
+ args.unshift(identifier) unless identifier.nil?
117
+ args << options
118
+ result = rvm(*args)
119
+ uses_yaml ? YAML.load(result.stdout) : result
120
+ end
121
+
122
+ end
123
+ end
@@ -0,0 +1,41 @@
1
+ module RVM
2
+ class Environment
3
+
4
+ # Gets the full name for the current env.
5
+ def tools_identifier
6
+ normalize rvm(:tools, :identifier).stdout
7
+ end
8
+
9
+ # Gets the identifier after cd'ing to a path, no destructive.
10
+ def tools_path_identifier(path)
11
+ normalize rvm(:tools, "path-identifier", path.to_s).stdout
12
+ end
13
+
14
+ # Return the tools wrapper.
15
+ def tools
16
+ @tools_wrapper ||= ToolsWrapper.new(self)
17
+ end
18
+
19
+ # Ruby like wrapper for tools
20
+ class ToolsWrapper
21
+
22
+ def initialize(parent)
23
+ @parent = parent
24
+ end
25
+
26
+ # Returns the current envs expanded identifier
27
+ def identifier
28
+ @parent.tools_identifier
29
+ end
30
+
31
+ # Returns the identifier for a path, taking into account
32
+ # things like an rvmrc
33
+ def path_identifier(path)
34
+ @parent.tools_path_identifier(File.expand_path(path))
35
+ end
36
+ alias identifier_for_path path_identifier
37
+
38
+ end
39
+
40
+ end
41
+ end
@@ -0,0 +1,167 @@
1
+ module RVM
2
+ class Environment
3
+
4
+ PREFIX_OPTIONS = [:trace, :json, :yaml]
5
+
6
+ # Returns the environment identifier for the current environment,
7
+ # as determined from the GEM_HOME.
8
+ def self.current_environment_id
9
+ @current_environment_id ||= begin
10
+ gem_home = ENV['GEM_HOME'].to_s.strip
11
+ if !gem_home.empty? && gem_home =~ /rvm\/gems\//
12
+ File.basename(gem_home)
13
+ else
14
+ matching_path = $:.select { |item| item =~ /rvm\/rubies/ }.first
15
+ matching_path.to_s.gsub(/^.*rvm\/rubies\//, '').split('/')[0] || "system"
16
+ end
17
+ end
18
+ end
19
+
20
+ # Returns the ruby string that represents the current environment.
21
+ def self.current_ruby_string
22
+ identifier_to_ruby_string current_environment_id
23
+ end
24
+
25
+ # Converts a ruby identifier (string + gemset) to just the ruby string.
26
+ def self.identifier_to_ruby_string(identifier)
27
+ identifier.gsub(/@.*$/, '')
28
+ end
29
+
30
+ # Returns the currentl environment.
31
+ # Note that when the ruby is changed, this is reset - Also,
32
+ # if the gemset is changed it will also be reset.
33
+ def self.current
34
+ @current_environment ||= Environment.new(current_environment_id)
35
+ end
36
+
37
+ # Sets the current environment back to the currently running ruby
38
+ # or the system env (if it can't be determined from GEM_HOME).
39
+ def self.reset_current!
40
+ @current_environment = nil
41
+ end
42
+
43
+ # Lets you build a command up, without needing to see the output.
44
+ # As an example,
45
+ #
46
+ # rvm :use, "ree@rails3", :install => true
47
+ #
48
+ # Will call the following:
49
+ #
50
+ # rvm use ree@rails3 --install
51
+ #
52
+ def rvm(*args)
53
+ options = extract_options!(args)
54
+ silent = options.delete(:silent)
55
+ rearrange_options!(args, options)
56
+ args += hash_to_options(options)
57
+ args.map! { |a| a.to_s }
58
+ if silent
59
+ run_silently 'rvm', *args
60
+ else
61
+ run 'rvm', *args
62
+ end
63
+ end
64
+
65
+ # Run commands inside the given directory.
66
+ def chdir(dir)
67
+ run_silently :pushd, dir.to_s
68
+ result = Dir.chdir(dir) { yield }
69
+ run_silently :popd
70
+ result
71
+ end
72
+
73
+ protected
74
+
75
+ # Moves certain options (e.g. yaml, json etc) to the front
76
+ # of the arguments list, making stuff like sets work.
77
+ def rearrange_options!(args, options)
78
+ prefix_options = {}
79
+ (PREFIX_OPTIONS + PREFIX_OPTIONS.map { |o| o.to_s }).each do |k|
80
+ if options.has_key?(k)
81
+ value = options.delete(k)
82
+ prefix_options[k.to_sym] = value
83
+ end
84
+ end
85
+ hash_to_options(prefix_options).reverse.each { |o| args.unshift(o) }
86
+ end
87
+
88
+ def ruby_string(result)
89
+ if result && result[:rvm_ruby_string]
90
+ result[:rvm_ruby_string]
91
+ else
92
+ self.class.identifier_to_ruby_string expanded_name
93
+ end
94
+ end
95
+
96
+ # Checks whether the given environment is compatible with the current
97
+ # ruby interpeter.
98
+ def compatible_with_current?(result)
99
+ ruby_string(result) == self.class.current_ruby_string
100
+ end
101
+
102
+ # Given an environment identifier, it will add the the given
103
+ # gemset to the end to form a qualified identifier name.
104
+ def self.environment_with_gemset(environment, gemset)
105
+ environment_name, gemset_name = environment.split("@", 2)
106
+ environment_name = "default" if environment_name.to_s.empty?
107
+ environment_name << "@#{gemset}" unless gemset.to_s.empty?
108
+ environment_name
109
+ end
110
+
111
+ # Returns a value, or nil if it is blank.
112
+ def normalize(value)
113
+ value = value.to_s.strip
114
+ value.empty? ? nil : value
115
+ end
116
+
117
+ # Normalizes an array, removing blank lines.
118
+ def normalize_array(value)
119
+ value.split("\n").map { |l| l.strip }.reject { |l| l.empty? }
120
+ end
121
+
122
+ # Extract options from a hash.
123
+ def extract_options!(args)
124
+ args.last.is_a?(Hash) ? args.pop : {}
125
+ end
126
+
127
+ # Converts a hash of options to an array of command line argumets.
128
+ # If the value is false, it wont be added but if it is true only the
129
+ # key will be added. Lastly, when the value is neither true or false,
130
+ # to_s will becalled on it and it shall be added to the array.
131
+ def hash_to_options(options)
132
+ result = []
133
+ options.each_pair do |key, value|
134
+ real_key = "--#{key.to_s.gsub("_", "-")}"
135
+ if value == true
136
+ result << real_key
137
+ elsif value != false
138
+ result << real_key
139
+ result << value.to_s
140
+ end
141
+ end
142
+ result
143
+ end
144
+
145
+ # Recursively normalize options.
146
+ def normalize_option_value(value)
147
+ case value
148
+ when Array
149
+ value.map { |v| normalize_option_value(v) }.join(",")
150
+ else
151
+ value.to_s
152
+ end
153
+ end
154
+
155
+ def use_env_from_result!(result)
156
+ if compatible_with_current?(result)
157
+ ENV['GEM_HOME'] = result[:GEM_HOME]
158
+ ENV['GEM_PATH'] = result[:GEM_PATH]
159
+ ENV['BUNDLE_PATH'] = result[:BUNDLE_PATH]
160
+ Gem.clear_paths if defined?(Gem)
161
+ else
162
+ raise IncompatibleRubyError.new(result, "The given ruby environment requires #{ruby_string(result)} (versus #{self.class.current_ruby_string})")
163
+ end
164
+ end
165
+
166
+ end
167
+ end