gemrage 0.1.1 → 0.1.2

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 (151) hide show
  1. data/Gemfile +2 -0
  2. data/Gemfile.lock +5 -0
  3. data/VERSION +1 -1
  4. data/gemrage.gemspec +148 -3
  5. data/lib/rubygems/commands/scan_command.rb +77 -4
  6. data/vendor/ruby/1.8/bin/rvm-install +19 -0
  7. data/vendor/ruby/1.8/cache/macaddr-1.0.0.gem +0 -0
  8. data/vendor/ruby/1.8/cache/rvm-1.0.14.gem +0 -0
  9. data/vendor/ruby/1.8/gems/macaddr-1.0.0/README +33 -0
  10. data/vendor/ruby/1.8/gems/macaddr-1.0.0/gemspec.rb +27 -0
  11. data/vendor/ruby/1.8/gems/macaddr-1.0.0/install.rb +210 -0
  12. data/vendor/ruby/1.8/gems/macaddr-1.0.0/lib/macaddr.rb +69 -0
  13. data/vendor/ruby/1.8/gems/rvm-1.0.14/LICENCE +18 -0
  14. data/vendor/ruby/1.8/gems/rvm-1.0.14/README +127 -0
  15. data/vendor/ruby/1.8/gems/rvm-1.0.14/bin/rvm-install +5 -0
  16. data/vendor/ruby/1.8/gems/rvm-1.0.14/binscripts/rvm +76 -0
  17. data/vendor/ruby/1.8/gems/rvm-1.0.14/binscripts/rvm-auto-ruby +24 -0
  18. data/vendor/ruby/1.8/gems/rvm-1.0.14/binscripts/rvm-prompt +204 -0
  19. data/vendor/ruby/1.8/gems/rvm-1.0.14/binscripts/rvm-shell +35 -0
  20. data/vendor/ruby/1.8/gems/rvm-1.0.14/binscripts/rvm-update-head +35 -0
  21. data/vendor/ruby/1.8/gems/rvm-1.0.14/binscripts/rvm-update-latest +27 -0
  22. data/vendor/ruby/1.8/gems/rvm-1.0.14/binscripts/rvmsudo +24 -0
  23. data/vendor/ruby/1.8/gems/rvm-1.0.14/config/db +71 -0
  24. data/vendor/ruby/1.8/gems/rvm-1.0.14/config/known +55 -0
  25. data/vendor/ruby/1.8/gems/rvm-1.0.14/config/md5 +87 -0
  26. data/vendor/ruby/1.8/gems/rvm-1.0.14/contrib/gemset_snapshot +25 -0
  27. data/vendor/ruby/1.8/gems/rvm-1.0.14/contrib/install-system-wide +191 -0
  28. data/vendor/ruby/1.8/gems/rvm-1.0.14/contrib/r +44 -0
  29. data/vendor/ruby/1.8/gems/rvm-1.0.14/examples/rvmrc +47 -0
  30. data/vendor/ruby/1.8/gems/rvm-1.0.14/gemsets/default.gems +1 -0
  31. data/vendor/ruby/1.8/gems/rvm-1.0.14/gemsets/global.gems +1 -0
  32. data/vendor/ruby/1.8/gems/rvm-1.0.14/help/alias +46 -0
  33. data/vendor/ruby/1.8/gems/rvm-1.0.14/help/benchmark +17 -0
  34. data/vendor/ruby/1.8/gems/rvm-1.0.14/help/cleanup +23 -0
  35. data/vendor/ruby/1.8/gems/rvm-1.0.14/help/debug +8 -0
  36. data/vendor/ruby/1.8/gems/rvm-1.0.14/help/disk-usage +15 -0
  37. data/vendor/ruby/1.8/gems/rvm-1.0.14/help/docs +22 -0
  38. data/vendor/ruby/1.8/gems/rvm-1.0.14/help/exec +33 -0
  39. data/vendor/ruby/1.8/gems/rvm-1.0.14/help/fetch +5 -0
  40. data/vendor/ruby/1.8/gems/rvm-1.0.14/help/gem +0 -0
  41. data/vendor/ruby/1.8/gems/rvm-1.0.14/help/gemdir +0 -0
  42. data/vendor/ruby/1.8/gems/rvm-1.0.14/help/gemset +0 -0
  43. data/vendor/ruby/1.8/gems/rvm-1.0.14/help/implode +0 -0
  44. data/vendor/ruby/1.8/gems/rvm-1.0.14/help/info +64 -0
  45. data/vendor/ruby/1.8/gems/rvm-1.0.14/help/install +0 -0
  46. data/vendor/ruby/1.8/gems/rvm-1.0.14/help/list +0 -0
  47. data/vendor/ruby/1.8/gems/rvm-1.0.14/help/migrate +15 -0
  48. data/vendor/ruby/1.8/gems/rvm-1.0.14/help/monitor +0 -0
  49. data/vendor/ruby/1.8/gems/rvm-1.0.14/help/notes +0 -0
  50. data/vendor/ruby/1.8/gems/rvm-1.0.14/help/package +0 -0
  51. data/vendor/ruby/1.8/gems/rvm-1.0.14/help/rake +14 -0
  52. data/vendor/ruby/1.8/gems/rvm-1.0.14/help/remove +0 -0
  53. data/vendor/ruby/1.8/gems/rvm-1.0.14/help/repair +23 -0
  54. data/vendor/ruby/1.8/gems/rvm-1.0.14/help/reset +0 -0
  55. data/vendor/ruby/1.8/gems/rvm-1.0.14/help/ruby +84 -0
  56. data/vendor/ruby/1.8/gems/rvm-1.0.14/help/rubygems +11 -0
  57. data/vendor/ruby/1.8/gems/rvm-1.0.14/help/rvmrc +34 -0
  58. data/vendor/ruby/1.8/gems/rvm-1.0.14/help/snapshot +15 -0
  59. data/vendor/ruby/1.8/gems/rvm-1.0.14/help/specs +0 -0
  60. data/vendor/ruby/1.8/gems/rvm-1.0.14/help/srcdir +0 -0
  61. data/vendor/ruby/1.8/gems/rvm-1.0.14/help/tests +0 -0
  62. data/vendor/ruby/1.8/gems/rvm-1.0.14/help/tools +22 -0
  63. data/vendor/ruby/1.8/gems/rvm-1.0.14/help/uninstall +0 -0
  64. data/vendor/ruby/1.8/gems/rvm-1.0.14/help/update +0 -0
  65. data/vendor/ruby/1.8/gems/rvm-1.0.14/help/upgrade +18 -0
  66. data/vendor/ruby/1.8/gems/rvm-1.0.14/help/use +0 -0
  67. data/vendor/ruby/1.8/gems/rvm-1.0.14/help/wrapper +41 -0
  68. data/vendor/ruby/1.8/gems/rvm-1.0.14/install +631 -0
  69. data/vendor/ruby/1.8/gems/rvm-1.0.14/lib/VERSION.yml +4 -0
  70. data/vendor/ruby/1.8/gems/rvm-1.0.14/lib/rvm/capistrano.rb +45 -0
  71. data/vendor/ruby/1.8/gems/rvm-1.0.14/lib/rvm/environment/alias.rb +69 -0
  72. data/vendor/ruby/1.8/gems/rvm-1.0.14/lib/rvm/environment/cleanup.rb +54 -0
  73. data/vendor/ruby/1.8/gems/rvm-1.0.14/lib/rvm/environment/configuration.rb +60 -0
  74. data/vendor/ruby/1.8/gems/rvm-1.0.14/lib/rvm/environment/env.rb +52 -0
  75. data/vendor/ruby/1.8/gems/rvm-1.0.14/lib/rvm/environment/gemset.rb +222 -0
  76. data/vendor/ruby/1.8/gems/rvm-1.0.14/lib/rvm/environment/info.rb +13 -0
  77. data/vendor/ruby/1.8/gems/rvm-1.0.14/lib/rvm/environment/list.rb +124 -0
  78. data/vendor/ruby/1.8/gems/rvm-1.0.14/lib/rvm/environment/rubies.rb +50 -0
  79. data/vendor/ruby/1.8/gems/rvm-1.0.14/lib/rvm/environment/sets.rb +123 -0
  80. data/vendor/ruby/1.8/gems/rvm-1.0.14/lib/rvm/environment/tools.rb +68 -0
  81. data/vendor/ruby/1.8/gems/rvm-1.0.14/lib/rvm/environment/utility.rb +173 -0
  82. data/vendor/ruby/1.8/gems/rvm-1.0.14/lib/rvm/environment/wrapper.rb +23 -0
  83. data/vendor/ruby/1.8/gems/rvm-1.0.14/lib/rvm/environment.rb +64 -0
  84. data/vendor/ruby/1.8/gems/rvm-1.0.14/lib/rvm/errors.rb +31 -0
  85. data/vendor/ruby/1.8/gems/rvm-1.0.14/lib/rvm/install_command_dumper.rb +51 -0
  86. data/vendor/ruby/1.8/gems/rvm-1.0.14/lib/rvm/shell/abstract_wrapper.rb +145 -0
  87. data/vendor/ruby/1.8/gems/rvm-1.0.14/lib/rvm/shell/calculate_rvm_path.sh +26 -0
  88. data/vendor/ruby/1.8/gems/rvm-1.0.14/lib/rvm/shell/result.rb +42 -0
  89. data/vendor/ruby/1.8/gems/rvm-1.0.14/lib/rvm/shell/shell_wrapper.sh +10 -0
  90. data/vendor/ruby/1.8/gems/rvm-1.0.14/lib/rvm/shell/single_shot_wrapper.rb +56 -0
  91. data/vendor/ruby/1.8/gems/rvm-1.0.14/lib/rvm/shell/utility.rb +37 -0
  92. data/vendor/ruby/1.8/gems/rvm-1.0.14/lib/rvm/shell.rb +25 -0
  93. data/vendor/ruby/1.8/gems/rvm-1.0.14/lib/rvm/version.rb +19 -0
  94. data/vendor/ruby/1.8/gems/rvm-1.0.14/lib/rvm.rb +156 -0
  95. data/vendor/ruby/1.8/gems/rvm-1.0.14/man/man1/rvm.1 +385 -0
  96. data/vendor/ruby/1.8/gems/rvm-1.0.14/man/man1/rvm.1.gz +0 -0
  97. data/vendor/ruby/1.8/gems/rvm-1.0.14/rvm.gemspec +184 -0
  98. data/vendor/ruby/1.8/gems/rvm-1.0.14/scripts/alias +225 -0
  99. data/vendor/ruby/1.8/gems/rvm-1.0.14/scripts/aliases +4 -0
  100. data/vendor/ruby/1.8/gems/rvm-1.0.14/scripts/array +32 -0
  101. data/vendor/ruby/1.8/gems/rvm-1.0.14/scripts/base +49 -0
  102. data/vendor/ruby/1.8/gems/rvm-1.0.14/scripts/cd +87 -0
  103. data/vendor/ruby/1.8/gems/rvm-1.0.14/scripts/cleanup +58 -0
  104. data/vendor/ruby/1.8/gems/rvm-1.0.14/scripts/cli +781 -0
  105. data/vendor/ruby/1.8/gems/rvm-1.0.14/scripts/color +49 -0
  106. data/vendor/ruby/1.8/gems/rvm-1.0.14/scripts/completion +151 -0
  107. data/vendor/ruby/1.8/gems/rvm-1.0.14/scripts/db +87 -0
  108. data/vendor/ruby/1.8/gems/rvm-1.0.14/scripts/default +64 -0
  109. data/vendor/ruby/1.8/gems/rvm-1.0.14/scripts/disk-usage +60 -0
  110. data/vendor/ruby/1.8/gems/rvm-1.0.14/scripts/docs +115 -0
  111. data/vendor/ruby/1.8/gems/rvm-1.0.14/scripts/env +46 -0
  112. data/vendor/ruby/1.8/gems/rvm-1.0.14/scripts/environment-convertor +74 -0
  113. data/vendor/ruby/1.8/gems/rvm-1.0.14/scripts/fetch +229 -0
  114. data/vendor/ruby/1.8/gems/rvm-1.0.14/scripts/gemsets +950 -0
  115. data/vendor/ruby/1.8/gems/rvm-1.0.14/scripts/hash +37 -0
  116. data/vendor/ruby/1.8/gems/rvm-1.0.14/scripts/help +46 -0
  117. data/vendor/ruby/1.8/gems/rvm-1.0.14/scripts/hook +23 -0
  118. data/vendor/ruby/1.8/gems/rvm-1.0.14/scripts/info +214 -0
  119. data/vendor/ruby/1.8/gems/rvm-1.0.14/scripts/initialize +29 -0
  120. data/vendor/ruby/1.8/gems/rvm-1.0.14/scripts/install +631 -0
  121. data/vendor/ruby/1.8/gems/rvm-1.0.14/scripts/irbrc +9 -0
  122. data/vendor/ruby/1.8/gems/rvm-1.0.14/scripts/irbrc.rb +63 -0
  123. data/vendor/ruby/1.8/gems/rvm-1.0.14/scripts/list +315 -0
  124. data/vendor/ruby/1.8/gems/rvm-1.0.14/scripts/log +38 -0
  125. data/vendor/ruby/1.8/gems/rvm-1.0.14/scripts/maglev +193 -0
  126. data/vendor/ruby/1.8/gems/rvm-1.0.14/scripts/manage +2094 -0
  127. data/vendor/ruby/1.8/gems/rvm-1.0.14/scripts/match +6 -0
  128. data/vendor/ruby/1.8/gems/rvm-1.0.14/scripts/md5 +22 -0
  129. data/vendor/ruby/1.8/gems/rvm-1.0.14/scripts/migrate +175 -0
  130. data/vendor/ruby/1.8/gems/rvm-1.0.14/scripts/monitor +105 -0
  131. data/vendor/ruby/1.8/gems/rvm-1.0.14/scripts/notes +121 -0
  132. data/vendor/ruby/1.8/gems/rvm-1.0.14/scripts/override_gem +14 -0
  133. data/vendor/ruby/1.8/gems/rvm-1.0.14/scripts/package +301 -0
  134. data/vendor/ruby/1.8/gems/rvm-1.0.14/scripts/patches +64 -0
  135. data/vendor/ruby/1.8/gems/rvm-1.0.14/scripts/patchsets +87 -0
  136. data/vendor/ruby/1.8/gems/rvm-1.0.14/scripts/repair +199 -0
  137. data/vendor/ruby/1.8/gems/rvm-1.0.14/scripts/rubygems +157 -0
  138. data/vendor/ruby/1.8/gems/rvm-1.0.14/scripts/rvm +120 -0
  139. data/vendor/ruby/1.8/gems/rvm-1.0.14/scripts/rvm-install +631 -0
  140. data/vendor/ruby/1.8/gems/rvm-1.0.14/scripts/selector +818 -0
  141. data/vendor/ruby/1.8/gems/rvm-1.0.14/scripts/set +301 -0
  142. data/vendor/ruby/1.8/gems/rvm-1.0.14/scripts/snapshot +262 -0
  143. data/vendor/ruby/1.8/gems/rvm-1.0.14/scripts/tools +58 -0
  144. data/vendor/ruby/1.8/gems/rvm-1.0.14/scripts/update +631 -0
  145. data/vendor/ruby/1.8/gems/rvm-1.0.14/scripts/upgrade +144 -0
  146. data/vendor/ruby/1.8/gems/rvm-1.0.14/scripts/utility +1557 -0
  147. data/vendor/ruby/1.8/gems/rvm-1.0.14/scripts/version +17 -0
  148. data/vendor/ruby/1.8/gems/rvm-1.0.14/scripts/wrapper +210 -0
  149. data/vendor/ruby/1.8/specifications/macaddr-1.0.0.gemspec +27 -0
  150. data/vendor/ruby/1.8/specifications/rvm-1.0.14.gemspec +42 -0
  151. metadata +149 -4
@@ -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,68 @@
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
+ path_identifier = rvm(:tools, "path-identifier", path.to_s)
12
+ if path_identifier.exit_status == 2
13
+ error_message = "The rvmrc located in '#{path}' could not be loaded, likely due to trust mechanisms."
14
+ error_message << " Please run 'rvm rvmrc {trust,untrust} \"#{path}\"' to continue, or set rvm_trust_rvmrcs to 1."
15
+ raise ErrorLoadingRVMRC, error_message
16
+ end
17
+ return normalize(path_identifier.stdout)
18
+ end
19
+
20
+ def tools_strings(*rubies)
21
+ rubies = rubies.flatten.join(",").split(",").uniq
22
+ names = {}
23
+ value = rvm(:tools, :strings, *rubies)
24
+ if value.successful?
25
+ parts = value.stdout.split
26
+ rubies.each_with_index do |key, index|
27
+ names[key] = normalize(parts[index])
28
+ end
29
+ end
30
+ names
31
+ end
32
+
33
+ # Return the tools wrapper.
34
+ def tools
35
+ @tools_wrapper ||= ToolsWrapper.new(self)
36
+ end
37
+
38
+ # Ruby like wrapper for tools
39
+ class ToolsWrapper
40
+
41
+ def initialize(parent)
42
+ @parent = parent
43
+ end
44
+
45
+ # Returns the current envs expanded identifier
46
+ def identifier
47
+ @parent.tools_identifier
48
+ end
49
+
50
+ # Returns the identifier for a path, taking into account
51
+ # things like an rvmrc
52
+ def path_identifier(path)
53
+ @parent.tools_path_identifier(File.expand_path(path))
54
+ end
55
+ alias identifier_for_path path_identifier
56
+
57
+ def strings(*rubies)
58
+ @parent.tools_strings(*rubies)
59
+ end
60
+
61
+ def expand_string(ruby)
62
+ strings(ruby)[ruby]
63
+ end
64
+
65
+ end
66
+
67
+ end
68
+ end
@@ -0,0 +1,173 @@
1
+ module RVM
2
+ class Environment
3
+
4
+ PREFIX_OPTIONS = [:trace, :json, :yaml]
5
+
6
+ def self.default_rvm_path
7
+ value = `bash '#{File.expand_path('../shell/calculate_rvm_path.sh', File.dirname(__FILE__))}'`.strip
8
+ $?.success? && !value.empty? ? File.expand_path(value) : nil
9
+ end
10
+
11
+ # Returns the environment identifier for the current environment,
12
+ # as determined from the GEM_HOME.
13
+ def self.current_environment_id
14
+ @current_environment_id ||= begin
15
+ gem_home = ENV['GEM_HOME'].to_s.strip
16
+ if !gem_home.empty? && gem_home =~ /rvm\/gems\//
17
+ File.basename(gem_home)
18
+ else
19
+ matching_path = $:.select { |item| item =~ /rvm\/rubies/ }.first
20
+ matching_path.to_s.gsub(/^.*rvm\/rubies\//, '').split('/')[0] || "system"
21
+ end
22
+ end
23
+ end
24
+
25
+ # Returns the ruby string that represents the current environment.
26
+ def self.current_ruby_string
27
+ identifier_to_ruby_string(current_environment_id)
28
+ end
29
+
30
+ # Converts a ruby identifier (string + gemset) to just the ruby string.
31
+ def self.identifier_to_ruby_string(identifier)
32
+ identifier.gsub(/@.*$/, '')
33
+ end
34
+
35
+ # Returns the currentl environment.
36
+ # Note that when the ruby is changed, this is reset - Also,
37
+ # if the gemset is changed it will also be reset.
38
+ def self.current
39
+ @current_environment ||= Environment.new(current_environment_id)
40
+ end
41
+
42
+ # Sets the current environment back to the currently running ruby
43
+ # or the system env (if it can't be determined from GEM_HOME).
44
+ def self.reset_current!
45
+ @current_environment = nil
46
+ end
47
+
48
+ # Lets you build a command up, without needing to see the output.
49
+ # As an example,
50
+ #
51
+ # rvm :use, "ree@rails3", :install => true
52
+ #
53
+ # Will call the following:
54
+ #
55
+ # rvm use ree@rails3 --install
56
+ #
57
+ def rvm(*args)
58
+ options = extract_options!(args)
59
+ silent = options.delete(:silent)
60
+ rearrange_options!(args, options)
61
+ args += hash_to_options(options)
62
+ args.map! { |a| a.to_s }
63
+
64
+ if silent
65
+ run_silently('rvm', *args)
66
+ else
67
+ run('rvm', *args)
68
+ end
69
+ end
70
+
71
+ # Run commands inside the given directory.
72
+ def chdir(dir)
73
+ run_silently :pushd, dir.to_s
74
+ result = Dir.chdir(dir) { yield }
75
+ run_silently :popd
76
+ result
77
+ end
78
+
79
+ protected
80
+
81
+ # Moves certain options (e.g. yaml, json etc) to the front
82
+ # of the arguments list, making stuff like sets work.
83
+ def rearrange_options!(args, options)
84
+ prefix_options = {}
85
+ (PREFIX_OPTIONS + PREFIX_OPTIONS.map { |o| o.to_s }).each do |k|
86
+ if options.has_key?(k)
87
+ value = options.delete(k)
88
+ prefix_options[k.to_sym] = value
89
+ end
90
+ end
91
+ hash_to_options(prefix_options).reverse.each { |o| args.unshift(o) }
92
+ end
93
+
94
+ def ruby_string(result)
95
+ if result && result[:rvm_ruby_string]
96
+ result[:rvm_ruby_string]
97
+ else
98
+ self.class.identifier_to_ruby_string(expanded_name)
99
+ end
100
+ end
101
+
102
+ # Checks whether the given environment is compatible with the current
103
+ # ruby interpeter.
104
+ def compatible_with_current?(result)
105
+ ruby_string(result) == self.class.current_ruby_string
106
+ end
107
+
108
+ # Given an environment identifier, it will add the the given
109
+ # gemset to the end to form a qualified identifier name.
110
+ def self.environment_with_gemset(environment, gemset)
111
+ environment_name, gemset_name = environment.split("@", 2)
112
+ environment_name = "default" if environment_name.to_s.empty?
113
+ environment_name << "@#{gemset}" unless gemset.to_s.empty?
114
+ environment_name
115
+ end
116
+
117
+ # Returns a value, or nil if it is blank.
118
+ def normalize(value)
119
+ value = value.to_s.strip
120
+ value.empty? ? nil : value
121
+ end
122
+
123
+ # Normalizes an array, removing blank lines.
124
+ def normalize_array(value)
125
+ value.split("\n").map { |line| line.strip }.reject { |line| line.empty? }
126
+ end
127
+
128
+ # Extract options from a hash.
129
+ def extract_options!(args)
130
+ args.last.is_a?(Hash) ? args.pop : {}
131
+ end
132
+
133
+ # Converts a hash of options to an array of command line argumets.
134
+ # If the value is false, it wont be added but if it is true only the
135
+ # key will be added. Lastly, when the value is neither true or false,
136
+ # to_s will becalled on it and it shall be added to the array.
137
+ def hash_to_options(options)
138
+ result = []
139
+ options.each_pair do |key, value|
140
+ real_key = "--#{key.to_s.gsub("_", "-")}"
141
+ if value == true
142
+ result << real_key
143
+ elsif value != false
144
+ result << real_key
145
+ result << value.to_s
146
+ end
147
+ end
148
+ result
149
+ end
150
+
151
+ # Recursively normalize options.
152
+ def normalize_option_value(value)
153
+ case value
154
+ when Array
155
+ value.map { |option| normalize_option_value(option) }.join(",")
156
+ else
157
+ value.to_s
158
+ end
159
+ end
160
+
161
+ def use_env_from_result!(result)
162
+ if compatible_with_current?(result)
163
+ ENV['GEM_HOME'] = result[:GEM_HOME]
164
+ ENV['GEM_PATH'] = result[:GEM_PATH]
165
+ ENV['BUNDLE_PATH'] = result[:BUNDLE_PATH]
166
+ Gem.clear_paths if defined?(Gem)
167
+ else
168
+ raise IncompatibleRubyError.new(result, "The given ruby environment requires #{ruby_string(result)} (versus #{self.class.current_ruby_string})")
169
+ end
170
+ end
171
+
172
+ end
173
+ end
@@ -0,0 +1,23 @@
1
+ module RVM
2
+ class Environment
3
+
4
+ # Generates wrappers with the specified prefix, pointing
5
+ # to ruby_string.
6
+ def wrapper(ruby_string, wrapper_prefix, *binaries)
7
+ rvm(:wrapper, ruby_string, wrapper_prefix, *binaries).successful?
8
+ end
9
+
10
+ # Generates the default wrappers.
11
+ def default_wrappers(ruby_string, *binaries)
12
+ wrapper ruby_string, '', *binaries
13
+ end
14
+
15
+ # If available, return the path to the wrapper for
16
+ # the given executable. Will return ni if the wrapper
17
+ # is unavailable.
18
+ def wrapper_path_for(executable)
19
+ raise NotImplementedError
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,64 @@
1
+ require 'forwardable'
2
+
3
+ module RVM
4
+ # Implements the actual wrapper around the api. For more information
5
+ # about this design, see the RVM module.
6
+ class Environment
7
+ extend Forwardable
8
+
9
+ %w(configuration utility alias list gemset rubies cleanup sets env tools info).each do |key|
10
+ require File.join("rvm", "environment", key)
11
+ end
12
+
13
+ # The default config has rvm_silence_logging so that log doesn't print anything to stdout.
14
+ merge_config! :rvm_silence_logging => 1,
15
+ :rvm_promptless => 1,
16
+ :rvm_ruby_api => 1
17
+
18
+ attr_reader :environment_name, :shell_wrapper
19
+
20
+ # Creates a new environment with the given name and optionally
21
+ # a set of extra environment variables to be set on load.
22
+ def initialize(environment_name = "default", options = {})
23
+ merge_config! options
24
+ @environment_name = environment_name
25
+ @shell_wrapper = Shell.default_wrapper.new
26
+ @shell_wrapper.setup do |s|
27
+ source_rvm_environment
28
+ use_rvm_environment
29
+ end
30
+ end
31
+
32
+ def inspect
33
+ "#<#{self.class.name} environment_name=#{@environment_name.inspect}>"
34
+ end
35
+
36
+ # Returns the expanded name, using the same method as used by the rvm command line.
37
+ def expanded_name
38
+ @expanded_name ||= tools_identifier.to_s
39
+ end
40
+
41
+ # Actually define methods to interact with the shell wrapper.
42
+ def_delegators :@shell_wrapper, :run, :run_silently, :run_command_without_output,
43
+ :run_command, :[], :escape_argument
44
+
45
+ protected
46
+
47
+ # Automatically load rvm config from the multiple sources.
48
+ def source_rvm_environment
49
+ rvm_path = config_value_for(:rvm_path, self.class.default_rvm_path, false)
50
+ actual_config = defined_config.merge('rvm_path' => rvm_path)
51
+ config = []
52
+ actual_config.each_pair do |k, v|
53
+ config << "#{k}=#{escape_argument(v.to_s)}"
54
+ end
55
+ run_silently :export, config.join(" ")
56
+ run_silently :source, File.join(rvm_path, "scripts", "rvm")
57
+ end
58
+
59
+ def use_rvm_environment
60
+ rvm :use, @environment_name, :silent => true
61
+ end
62
+
63
+ end
64
+ end
@@ -0,0 +1,31 @@
1
+ module RVM
2
+
3
+ # Generic error in RVM
4
+ class Error < StandardError; end
5
+
6
+ # Generic error with the shell command output attached.
7
+ # The RVM::Shell::Result instance is available via +#result+.
8
+ class ErrorWithResult < Error
9
+ attr_reader :result
10
+
11
+ def initialize(result, message = nil)
12
+ @result = result
13
+ super message
14
+ end
15
+
16
+ end
17
+
18
+ # Something occured processing the command and rvm couldn't parse the results.
19
+ class IncompleteCommandError < Error; end
20
+
21
+ # The given action can't replace the env for the current process.
22
+ # Typically raised by RVM::Environment#gemset_use when the gemset
23
+ # is for another, incompatible ruby interpreter.
24
+ #
25
+ # Provides access to the output of the shell command via +#result+.
26
+ class IncompatibleRubyError < ErrorWithResult; end
27
+
28
+ # Called when tools.path_identifier is called on a dir with an untrusted rvmrc.
29
+ class ErrorLoadingRVMRC < Error; end
30
+
31
+ end
@@ -0,0 +1,51 @@
1
+ # Prints out the rvm command (minus rvm install) to install this ruby.
2
+
3
+ RUBY_NAME = File.basename(ENV['MY_RUBY_HOME'])
4
+ RVM_HOME = ENV['rvm_path']
5
+
6
+ def ruby?(*names)
7
+ names.map { |n| n.to_s }.include?(RUBY_NAME.split("-").first)
8
+ end
9
+
10
+ def quote(value)
11
+ value = value.to_s.strip
12
+ value.empty? ? "" : "'#{value.gsub("'", "'\'\'")}'"
13
+ end
14
+
15
+ def normalize_argument(arg)
16
+ real_value, arg_value = arg.split("=", 2)
17
+ if !arg_value.nil?
18
+ real_value << "=#{quote(arg_value)}"
19
+ end
20
+ real_value.gsub("'#{RVM_HOME}", "'\"$rvm_path\"'")
21
+ end
22
+
23
+ def arguments_for_install
24
+ if ruby?(:ruby, :mput, :ree)
25
+ begin
26
+ require 'rbconfig'
27
+ require 'shellwords'
28
+ # Get the full arguments
29
+ config_args = Shellwords.shellwords(Config::CONFIG['configure_args'].to_s.strip)
30
+ real_arguments = []
31
+ config_args.each do |arg|
32
+ if ruby?(:ree) && arg == "--enable-mbari-api"
33
+ next
34
+ elsif arg =~ /^--prefix/
35
+ next
36
+ elsif arg =~ /^[^\-]/
37
+ next
38
+ else
39
+ real_arguments << normalize_argument(arg)
40
+ end
41
+ end
42
+ config_args = real_arguments.join(",")
43
+ return "-C #{quote(config_args)}" unless config_args.strip.empty?
44
+ rescue LoadError
45
+ end
46
+ end
47
+ return ""
48
+ end
49
+
50
+ # Finally, print the string to install it.
51
+ puts "rvm install #{RUBY_NAME} #{arguments_for_install.gsub(/''+/, "'")}".strip
@@ -0,0 +1,145 @@
1
+ require 'yaml'
2
+
3
+ module RVM
4
+ module Shell
5
+ # Provides the most common functionality expected of a shell wrapper.
6
+ # Namely, implements general utility methods and tools to extract output
7
+ # from a given command but doesn't actually run any commands itself,
8
+ # leaving that up to concrete implementations.
9
+ #
10
+ # == Usage
11
+ #
12
+ # Commands are run inside of a shell (usually bash) and can either be exectuted in
13
+ # two situations (each with wrapper methods available) - silently or verbosely.
14
+ #
15
+ # Silent commands (via run_silently and run_command) do exactly as
16
+ # they say - that can modify the environment etc but anything they print (to stdout
17
+ # or stderr) will be discarded.
18
+ #
19
+ # Verbose commands will run the command and then print the command epilog (which
20
+ # contains the output stastus and the current env in yaml format). This allows us
21
+ # to not only capture all output but to also return the exit status and environment
22
+ # variables in a way that makes persisted shell sessions possible.
23
+ #
24
+ # Under the hood, #run and run_silently are the preferred ways of invoking commands - if
25
+ # passed a single command, they'll run it as is (much like system in ruby) but when
26
+ # given multiple arguments anything after the first will be escaped (e.g. you can
27
+ # hence pass code etc). #run will also parse the results of this epilog into a usable
28
+ # RVM::Shell::Result object.
29
+ #
30
+ # run_command and run_command_silently do the actual hard work for these behind the scenes,
31
+ # running a string as the shell command. Hence, these two commands are what must be
32
+ # implemented in non-abstract wrappers.
33
+ #
34
+ # For an example of the shell wrapper functionality in action, see RVM::Environment
35
+ # which delegates most of the work to a shell wrapper.
36
+ class AbstractWrapper
37
+
38
+ # Used the mark the end of a commands output and the start of the rvm env.
39
+ COMMAND_EPILOG_START = "---------------RVM-RESULTS-START---------------"
40
+ # Used to mark the end of the commands epilog.
41
+ COMMAND_EPILOG_END = "----------------RVM-RESULTS-END----------------"
42
+ # The location of the shell file with the epilog function definition.
43
+ WRAPPER_LOCATION = File.expand_path('./shell_wrapper.sh', File.dirname(__FILE__))
44
+
45
+ # Defines the shell exectuable.
46
+ attr_reader :shell_executable
47
+
48
+ # Initializes a new shell wrapper, including setting the
49
+ # default setup block. Implementations must override this method
50
+ # but must ensure that they call super to perform the expected
51
+ # standard setup.
52
+ def initialize(sh = 'bash', &setup_block)
53
+ setup &setup_block
54
+ @shell_executable = sh
55
+ end
56
+
57
+ # Defines a setup block to be run when initiating a wrapper session.
58
+ # Usually used for doing things such as sourcing the rvm file. Please note
59
+ # that the wrapper file is automatically source.
60
+ #
61
+ # The setup block should be automatically run by wrapper implementations.
62
+ def setup(&blk)
63
+ @setup_block = blk
64
+ end
65
+
66
+ # Runs the gives command (with optional arguments), returning an
67
+ # RVM::Shell::Result object, including stdout / stderr streams.
68
+ # Under the hood, uses run_command to actually process it all.
69
+ def run(command, *arguments)
70
+ expanded_command = build_cli_call(command, arguments)
71
+ status, out, err = run_command(expanded_command)
72
+ Result.new(expanded_command, status, out, err)
73
+ end
74
+
75
+ # Wrapper around run_command_silently that correctly escapes arguments.
76
+ # Essentially, #run but using run_command_silently.
77
+ def run_silently(command, *arguments)
78
+ run_command_silently build_cli_call(command, arguments)
79
+ end
80
+
81
+ # Given a command, it will execute it in the current wrapper
82
+ # and once done, will return:
83
+ # - the hash from the epilog output.
84
+ # - a string representing stdout.
85
+ # - a string representing stderr.
86
+ def run_command(full_command)
87
+ raise NotImplementedError.new("run_command is only available in concrete implementations")
88
+ end
89
+
90
+ # Like run_command, but doesn't care about output.
91
+ def run_command_silently(full_command)
92
+ raise NotImplementedError.new("run_command_silently is only available in concrete implementations")
93
+ end
94
+
95
+ # Returns a given environment variables' value.
96
+ def [](var_name)
97
+ run(:true)[var_name]
98
+ end
99
+
100
+ protected
101
+
102
+ # When called, will use the current environment to source the wrapper scripts
103
+ # as well as invoking the current setup block. as defined on initialization / via #setup.
104
+ def invoke_setup!
105
+ source_command_wrapper
106
+ @setup_block.call(self) if @setup_block
107
+ end
108
+
109
+ # Uses run_silently to source the wrapper file.
110
+ def source_command_wrapper
111
+ run_silently :source, WRAPPER_LOCATION
112
+ end
113
+
114
+ # Returns a command followed by the call to show the epilog.
115
+ def wrapped_command(command)
116
+ "#{command}; __rvm_show_command_epilog"
117
+ end
118
+
119
+ # Wraps a command in a way that it prints no output.
120
+ def silent_command(command)
121
+ "{ #{command}; } >/dev/null 2>&1"
122
+ end
123
+
124
+ # Checks whether the given command includes a epilog, marked by
125
+ # epilog start and end lines.
126
+ def command_complete?(c)
127
+ start_index, end_index = c.index(COMMAND_EPILOG_START), c.index(COMMAND_EPILOG_END)
128
+ start_index && end_index && start_index < end_index
129
+ end
130
+
131
+ # Takes a raw string from a processes STDIO and returns three things:
132
+ # 1. The actual stdout, minus epilogue.
133
+ # 2. YAML output of the process results.
134
+ # 3. Any left over from the STDIO text.
135
+ def raw_stdout_to_parts(c)
136
+ raise IncompleteCommandError if !command_complete?(c)
137
+ before, after = c.split(COMMAND_EPILOG_START, 2)
138
+ epilog, after = after.split(COMMAND_EPILOG_END, 2)
139
+ return before, YAML.load(epilog.strip), after
140
+ end
141
+
142
+ include RVM::Shell::Utility
143
+ end
144
+ end
145
+ end