setup 4.2.0 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. data/HISTORY +47 -3
  2. data/MANIFEST +49 -16
  3. data/README.rdoc +148 -0
  4. data/bin/setup.rb +1 -5
  5. data/lib/setup.rb +2 -2
  6. data/lib/setup/base.rb +143 -0
  7. data/lib/setup/command.rb +218 -114
  8. data/lib/setup/compiler.rb +69 -0
  9. data/lib/setup/configuration.rb +822 -0
  10. data/lib/setup/constants.rb +12 -0
  11. data/lib/setup/{rubyver.rb → core_ext.rb} +0 -0
  12. data/lib/setup/documentor.rb +149 -0
  13. data/lib/setup/installer.rb +363 -0
  14. data/lib/setup/project.rb +68 -0
  15. data/lib/setup/rake.rb +44 -45
  16. data/lib/setup/session.rb +233 -0
  17. data/lib/setup/tester.rb +92 -0
  18. data/lib/setup/uninstaller.rb +76 -0
  19. data/meta/active +1 -0
  20. data/meta/collection +1 -0
  21. data/meta/{abstract → description} +0 -0
  22. data/meta/{package → name} +0 -0
  23. data/meta/repository +1 -0
  24. data/meta/ruby +3 -0
  25. data/meta/version +1 -1
  26. data/script/bstrap +5 -0
  27. data/script/bundle +64 -0
  28. data/script/setup +1338 -0
  29. data/script/test +3 -0
  30. data/test/cases/installer.rb +28 -0
  31. data/test/features/config.feature +16 -0
  32. data/test/features/document.feature +2 -0
  33. data/test/features/install.feature +72 -0
  34. data/test/features/make.feature +18 -0
  35. data/test/features/step_definitions/common_steps.rb +34 -0
  36. data/test/features/step_definitions/config_steps.rb +24 -0
  37. data/test/features/step_definitions/env.rb +37 -0
  38. data/test/features/step_definitions/install_steps.rb +75 -0
  39. data/test/features/step_definitions/setup_steps.rb +30 -0
  40. data/test/features/step_definitions/uninstall_steps.rb +8 -0
  41. data/test/features/test.feature +2 -0
  42. data/test/features/uninstall.feature +13 -0
  43. data/test/fixtures/faux-project/bin/faux +3 -0
  44. data/test/fixtures/faux-project/ext/faux/extconf.rb +12 -0
  45. data/test/fixtures/faux-project/ext/faux/faux.c +24 -0
  46. data/test/fixtures/faux-project/lib/faux.rb +1 -0
  47. metadata +58 -29
  48. data/README +0 -106
  49. data/RELEASE +0 -41
  50. data/lib/setup/build.rb +0 -2
  51. data/lib/setup/config.rb +0 -452
  52. data/lib/setup/error.rb +0 -4
  53. data/lib/setup/install.rb +0 -1007
  54. data/meta/setup/metaconfig.rb +0 -3
  55. data/test/test_installer.rb +0 -139
@@ -1,174 +1,278 @@
1
- require 'setup/config'
2
- require 'setup/build'
3
- require 'setup/install'
4
- require 'setup/error'
1
+ require 'setup/session'
2
+ require 'optparse'
5
3
 
6
4
  module Setup
7
5
 
8
- # CLI for Setup.rb
6
+ # Command-line interface for Setup.rb.
7
+
9
8
  class Command
10
9
 
11
- TASKS = %w(all config show setup test install uninstall rdoc ri clean distclean)
12
-
13
- TASK_DESCRIPTIONS = [
14
- [ 'all', "do config, setup, then install" ],
15
- [ 'config', "saves your configurations" ],
16
- [ 'show', "shows current configuration" ],
17
- [ 'setup', "compiles ruby extentions and others" ],
18
- [ 'rdoc', "generate rdoc documentation" ],
19
- [ 'ri', "generate ri documentation" ],
20
- [ 'install', "installs files" ],
21
- [ 'uninstall', "uninstalls files" ],
22
- [ 'test', "run all tests in test/" ],
23
- [ 'clean', "does `make clean' for each extention" ],
24
- [ 'distclean', "does `make distclean' for each extention" ]
25
- ]
10
+ # Initialize and run.
26
11
 
27
- #
28
12
  def self.run(*argv)
29
13
  new.run(*argv)
30
14
  end
31
15
 
32
- #
16
+ # Hash of <tt>task => description</tt>.
17
+
18
+ def self.tasks
19
+ @tasks ||= {}
20
+ end
21
+
22
+ # Task names listed in order of information.
23
+
24
+ def self.order
25
+ @order ||= []
26
+ end
27
+
28
+ # Define a task.
29
+
30
+ def self.task(name, description)
31
+ tasks[name] = description
32
+ order << name
33
+ end
34
+
35
+ task 'all' , "config, setup, test, install"
36
+ task 'config' , "saves your configuration"
37
+ task 'show' , "show current configuration"
38
+ task 'make' , "compile ruby extentions"
39
+ task 'test' , "run test suite"
40
+ task 'doc' , "generate ri documentation"
41
+ task 'install' , "install project files"
42
+ task 'uninstall', "uninstall previously installed files"
43
+ task 'clean' , "does `make clean' for each extention"
44
+ task 'distclean', "does `make distclean' for each extention"
45
+
46
+ # Run command.
47
+
33
48
  def run(*argv)
34
49
  ARGV.replace(argv) unless argv.empty?
35
50
 
36
- config = ConfigTable.new
37
- installer = Installer.new(config)
51
+ #session = Session.new(:io=>$stdio)
52
+ #config = session.configuration
38
53
 
39
54
  task = ARGV.find{ |a| a !~ /^[-]/ }
40
55
  task = 'all' unless task
41
56
 
42
- unless TASKS.include?(task)
57
+ unless task_names.include?(task)
43
58
  $stderr.puts "Not a valid task -- #{task}"
44
59
  exit 1
45
60
  end
46
61
 
47
- opts = OptionParser.new
62
+ parser = OptionParser.new
63
+ options = {}
48
64
 
49
- opts.banner = "Usage: #{File.basename($0)} [task] [options]"
65
+ parser.banner = "Usage: #{File.basename($0)} [TASK] [OPTIONS]"
50
66
 
51
- if task == 'config' or task == 'all'
52
- opts.separator ""
53
- opts.separator "Config options:"
54
- config.descriptions.each do |name, type, desc|
55
- opts.on("--#{name} #{type.to_s.upcase}", desc) do |val|
56
- ENV[name.to_s] = val.to_s
57
- end
58
- end
67
+ optparse_header(parser, options)
68
+ case task
69
+ when 'all'
70
+ optparse_all(parser, options)
71
+ when 'config'
72
+ optparse_config(parser, options)
73
+ when 'install'
74
+ optparse_install(parser, options)
59
75
  end
76
+ optparse_common(parser, options)
60
77
 
61
- if task == 'install'
62
- opts.separator ""
63
- opts.separator "Install options:"
78
+ begin
79
+ parser.parse!(ARGV)
80
+ rescue OptionParser::InvalidOption
81
+ $stderr.puts $!.to_s.capitalize
82
+ exit 1
83
+ end
64
84
 
65
- opts.on("--prefix PATH", "Installation prefix") do |val|
66
- installer.install_prefix = val
67
- end
85
+ # This ensures we are in a project directory.
86
+ rootdir = session.project.rootdir
68
87
 
69
- opts.on("--no-test", "Do not run tests") do |val|
70
- installer.install_no_test = true
71
- end
88
+ print_header
89
+
90
+ begin
91
+ session.__send__(task)
92
+ rescue Error
93
+ raise if $DEBUG
94
+ $stderr.puts $!.message
95
+ $stderr.puts "Try 'setup.rb --help' for detailed usage."
96
+ exit 1
72
97
  end
73
98
 
74
- #if task == 'test'
75
- # opts.separator ""
76
- # opts.separator "Install options:"
77
- #
78
- # opts.on("--runner TYPE", "Test runner (auto|console|gtk|gtk2|tk)") do |val|
79
- # installer.config.testrunner = val
80
- # end
99
+ puts unless session.quiet?
100
+ end
101
+
102
+ # Setup session.
103
+
104
+ def session
105
+ @session ||= Session.new(:io=>$stdout)
106
+ end
107
+
108
+ # Setup configuration. This comes from the +session+ object.
109
+
110
+ def configuration
111
+ @configuration ||= session.configuration
112
+ end
113
+
114
+ #
115
+ def optparse_header(parser, options)
116
+ parser.banner = "USAGE: #{File.basename($0)} [command] [options]"
117
+ end
118
+
119
+ # Setup options for +all+ task.
120
+
121
+ def optparse_all(parser, options)
122
+ optparse_config(parser, options)
123
+ #optparse_install(parser, options)
124
+ #parser.on("-t", "--[no-]test", "run tests") do |val|
125
+ # configuration.no_test = val
126
+ #end
127
+ #parser.on("--[no-]ri", "generate ri documentation") do |val|
128
+ # configuration.no_doc = val
81
129
  #end
130
+ #parser.on("--[no-]doc", "do not install documentation") do |val|
131
+ # configuration.no_doc = val
132
+ #end
133
+ end
134
+
135
+ # Setup options for +config+ task.
136
+
137
+ def optparse_config(parser, options)
138
+ parser.separator ""
139
+ parser.separator "Configuration options:"
140
+ configuration.options.each do |args|
141
+ args = args.dup
142
+ desc = args.pop
143
+ type = args.pop
144
+ name, shortcut = *args
145
+ #raise ArgumentError unless name, type, desc
146
+ optname = name.to_s.gsub('_', '-')
147
+ case type
148
+ when :bool
149
+ if optname.index('no-') == 0
150
+ optname = "[no-]" + optname.sub(/^no-/, '')
151
+ opts = shortcut ? ["-#{shortcut}", "--#{optname}", desc] : ["--#{optname}", desc]
152
+ parser.on(*opts) do |val|
153
+ configuration.__send__("#{name}=", !val)
154
+ end
155
+ else
156
+ optname = "[no-]" + optname.sub(/^no-/, '')
157
+ opts = shortcut ? ["-#{shortcut}", "--#{optname}", desc] : ["--#{optname}", desc]
158
+ parser.on(*opts) do |val|
159
+ configuration.__send__("#{name}=", val)
160
+ end
161
+ end
162
+ else
163
+ opts = shortcut ? ["-#{shortcut}", "--#{optname} #{type.to_s.upcase}", desc] : ["--#{optname} #{type.to_s.upcase}", desc]
164
+ parser.on(*opts) do |val|
165
+ configuration.__send__("#{name}=", val)
166
+ end
167
+ end
168
+ end
169
+ end
170
+
171
+ # Setup options for +install+ task.
172
+
173
+ def optparse_install(parser, options)
174
+ parser.separator ""
175
+ parser.separator "Install options:"
176
+ parser.on("--prefix PATH", "Installation prefix") do |val|
177
+ #session.options[:install_prefix] = val
178
+ configuration.install_prefix = val
179
+ end
180
+ end
181
+
182
+ # Setup options for +test+ task.
183
+
184
+ #def optparse_test(parser, options)
185
+ # parser.separator ""
186
+ # parser.separator "Test options:"
187
+ # parser.on("--runner TYPE", "Test runner (auto|console|gtk|gtk2|tk)") do |val|
188
+ # ENV['RUBYSETUP_TESTRUNNER'] = val
189
+ # end
190
+ #end
191
+
192
+ # Setup options for +uninstall+ task.
193
+
194
+ #def optparse_uninstall(parser, options)
195
+ # parser.separator ""
196
+ # parser.separator "Uninstall options:"
197
+ # parser.on("--prefix [PATH]", "Installation prefix") do |val|
198
+ # session.options[:install_prefix] = val
199
+ # end
200
+ #end
201
+
202
+ # Common options for every task.
82
203
 
83
- # common options
84
- opts.separator ""
85
- opts.separator "General options:"
204
+ def optparse_common(parser, options)
205
+ parser.separator ""
206
+ parser.separator "General options:"
86
207
 
87
- opts.on("-q", "--quiet", "Silence output") do |val|
88
- installer.quiet = val
208
+ parser.on("-q", "--quiet", "Suppress output") do
209
+ session.quiet = true
89
210
  end
90
211
 
91
- opts.on("--verbose", "Provide verbose output") do |val|
92
- installer.verbose = val
212
+ parser.on("-f", "--force", "Force operation") do
213
+ session.force = true
93
214
  end
94
215
 
95
- opts.on("--no-write", "Do not write to disk") do |val|
96
- installer.no_harm = !val
216
+ parser.on("--trace", "--verbose", "Watch execution") do |val|
217
+ session.trace = true
97
218
  end
98
219
 
99
- opts.on("-n", "--dryrun", "Same as --no-write") do |val|
100
- installer.no_harm = val
220
+ parser.on("--trial", "--no-harm", "Do not write to disk") do |val|
221
+ session.trial = true
101
222
  end
102
223
 
103
- # common options
104
- opts.separator ""
105
- opts.separator "Inform options:"
224
+ parser.on("--debug", "Turn on debug mode") do |val|
225
+ $DEBUG = true
226
+ end
227
+
228
+ parser.separator ""
229
+ parser.separator "Inform options:"
106
230
 
107
231
  # Tail options (eg. commands in option form)
108
- opts.on_tail("-h", "--help", "display this help information") do
109
- puts help
232
+ parser.on_tail("-h", "--help", "display this help information") do
233
+ #puts help
234
+ puts parser
110
235
  exit
111
236
  end
112
237
 
113
- opts.on_tail("--version", "Show version") do
238
+ parser.on_tail("--version", "-v", "Show version") do
114
239
  puts File.basename($0) + ' v' + Setup::VERSION #Version.join('.')
115
240
  exit
116
241
  end
117
242
 
118
- opts.on_tail("--copyright", "Show copyright") do
243
+ parser.on_tail("--copyright", "Show copyright") do
119
244
  puts Setup::COPYRIGHT #opyright
120
245
  exit
121
246
  end
122
-
123
- begin
124
- opts.parse!(ARGV)
125
- rescue OptionParser::InvalidOption
126
- $stderr.puts $!.to_s.capitalize
127
- exit 1
128
- end
129
-
130
- begin
131
- installer.__send__("exec_#{task}")
132
- rescue Error
133
- raise if $DEBUG
134
- $stderr.puts $!.message
135
- $stderr.puts "Try 'ruby #{$0} --help' for detailed usage."
136
- exit 1
137
- end
138
247
  end
139
248
 
140
- # Generate help text
141
- def help
142
- fmt = " " * 10 + "%-10s %s"
143
- commands = TASK_DESCRIPTIONS.collect do |k,d|
144
- (fmt % ["#{k}", d])
145
- end.join("\n").strip
146
-
147
- fmt = " " * 13 + "%-20s %s"
148
- configs = ConfigTable::DESCRIPTIONS.collect do |k,t,d|
149
- (fmt % ["--#{k}", d])
150
- end.join("\n").strip
249
+ # List of task names.
250
+ #--
251
+ # TODO: shouldn't this use +self.class.order+ ?
252
+ #++
151
253
 
152
- text = <<-END
153
- USAGE: #{File.basename($0)} [command] [options]
154
-
155
- Commands:
156
- #{commands}
157
-
158
- Options for CONFIG:
159
- #{configs}
160
-
161
- Options for INSTALL:
162
- --prefix Set the install prefix
163
-
164
- Options in common:
165
- -q --quiet Silence output
166
- --verbose Provide verbose output
167
- -n --no-write Do not write to disk
254
+ def task_names
255
+ #self.class.order
256
+ self.class.tasks.keys
257
+ end
168
258
 
169
- END
170
- text.gsub(/^ \ \ \ \ \ /, '')
259
+ # Output Header.
260
+ #
261
+ # TODO: This is not yet used. It might be nice to have,
262
+ # but not sure what it should contain or look like.
263
+
264
+ def print_header
265
+ #unless session.quiet?
266
+ # if session.project.name
267
+ # puts "= #{session.project.name} (#{rootdir})"
268
+ # else
269
+ # puts "= #{rootdir}"
270
+ # end
271
+ #end
272
+ #$stderr << "#{session.options.inspect}\n" if session.trace? or session.trial?
171
273
  end
172
274
 
173
275
  end
276
+
174
277
  end
278
+
@@ -0,0 +1,69 @@
1
+ require 'setup/base'
2
+
3
+ module Setup
4
+
5
+ #
6
+ class Compiler < Base
7
+
8
+ #
9
+ def compiles?
10
+ !extdirs.empty?
11
+ #extdirs.any?{ |dir| File.exist?(File.join(dir, 'extconf.rb')) }
12
+ end
13
+
14
+ #
15
+ def configure
16
+ extdirs.each do |dir|
17
+ Dir.chdir(dir) do
18
+ if File.exist?('extconf.rb') && !FileUtils.uptodate?('Makefile', ['extconf.rb'])
19
+ #load("extconf.rb", true)
20
+ ruby("extconf.rb")
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+ #
27
+ def compile
28
+ extdirs.each do |dir|
29
+ Dir.chdir(dir) do
30
+ make
31
+ end
32
+ end
33
+ end
34
+
35
+ #
36
+ def clean
37
+ extdirs.each do |dir|
38
+ Dir.chdir(dir) do
39
+ make('clean')
40
+ end
41
+ end
42
+ end
43
+
44
+ #
45
+ def distclean
46
+ extdirs.each do |dir|
47
+ Dir.chdir(dir) do
48
+ make('distclean')
49
+ end
50
+ end
51
+ end
52
+
53
+ # TODO: get from project
54
+ def extdirs
55
+ Dir['ext/**/*/{MANIFEST,extconf.rb}'].map do |f|
56
+ File.dirname(f)
57
+ end.uniq
58
+ end
59
+
60
+ #
61
+ def make(task=nil)
62
+ return unless File.exist?('Makefile')
63
+ bash(*[config.makeprog, task].compact)
64
+ end
65
+
66
+ end
67
+
68
+ end
69
+