setup 4.2.0 → 5.0.0

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 (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
@@ -0,0 +1,68 @@
1
+ module Setup
2
+
3
+ # The Project class encapsulates information
4
+ # about the project/package setup is effecting.
5
+
6
+ class Project
7
+
8
+ # Match used to determine the root dir of a project.
9
+ ROOT_MARKER = '{setup.rb,script/setup,meta/,MANIFEST,lib/}'
10
+
11
+ # TODO: locate project root via some marker
12
+ def rootdir
13
+ @rootdir ||= (
14
+ root = Dir[File.join(Dir.pwd, ROOT_MARKER)].first
15
+ if !root
16
+ raise Error, "not a project directory"
17
+ else
18
+ Dir.pwd
19
+ end
20
+ )
21
+ end
22
+
23
+ # The name of the package, used to install docs in system doc/ruby-{name}/ location.
24
+ # The information must be provided in a file called meta/package.
25
+ def name
26
+ @name = (
27
+ if file = Dir["{script/setup,meta,.meta}/name"].first
28
+ File.read(file).strip
29
+ else
30
+ nil
31
+ end
32
+ )
33
+ end
34
+
35
+ # This is needed if a project has loadpaths other than the standard lib/.
36
+ # Note the routine is designed to handle YAML arrays or line by line list.
37
+ def loadpath
38
+ @loadpath ||= (
39
+ if file = Dir.glob('{script/setup,meta,.meta}/loadpath').first
40
+ raw = File.read(file).strip.chomp(']')
41
+ raw.split(/[\n,]/).map do |e|
42
+ e.strip.sub(/^[\[-]\s*/,'')
43
+ end
44
+ else
45
+ nil
46
+ end
47
+ )
48
+ end
49
+
50
+ #
51
+ def extconfs
52
+ @extconfs ||= Dir['ext/**/extconf.rb']
53
+ end
54
+
55
+ #
56
+ def extensions
57
+ @extensions ||= extconfs.collect{ |f| File.dirname(f) }
58
+ end
59
+
60
+ #
61
+ def compiles?
62
+ !extensions.empty?
63
+ end
64
+
65
+ end
66
+
67
+ end
68
+
@@ -1,62 +1,61 @@
1
1
  require 'setup/install'
2
2
  require 'rake/clean'
3
3
 
4
- setup = Setup::Installer.new
5
-
6
- desc 'Config, setup and then install'
7
- task :all => [:config, :setup, :install]
8
-
9
- desc 'Saves your configurations'
10
- task :config do
11
- setup.exec_config
4
+ def session
5
+ @session ||= Setup::Session.new(:io=>$stdout)
12
6
  end
13
7
 
14
- desc 'Compiles ruby extentions'
15
- task :setup do
16
- setup.exec_setup
17
- end
8
+ namespace :setup do
18
9
 
19
- desc 'Runs unit tests'
20
- task :test do
21
- setup.exec_test
22
- end
10
+ desc 'Config, setup and then install'
11
+ task :all => [:config, :setup, :install]
23
12
 
24
- desc 'Generate rdoc documentation'
25
- task :rdoc do
26
- setup.exec_rdoc
27
- end
13
+ desc 'Saves your configurations'
14
+ task :config do
15
+ session.config
16
+ end
28
17
 
29
- desc 'Generate ri documentation'
30
- task :ri do
31
- setup.exec_ri
32
- end
18
+ desc 'Compiles ruby extentions'
19
+ task :make do
20
+ session.make
21
+ end
33
22
 
34
- desc 'Installs files'
35
- task :install do
36
- setup.exec_install
37
- end
23
+ desc 'Runs unit tests'
24
+ task :test do
25
+ session.test
26
+ end
38
27
 
39
- desc 'Uninstalls files'
40
- task :uninstall do
41
- setup.exec_uninstall
42
- end
28
+ desc 'Generate ri documentation'
29
+ task :rdoc do
30
+ session.document
31
+ end
43
32
 
44
- #desc "Does `make clean' for each extention"
45
- task :makeclean do
46
- setup.exec_clean
47
- end
33
+ desc 'Installs files'
34
+ task :install do
35
+ session.install
36
+ end
48
37
 
49
- task :clean => [:makeclean]
38
+ desc 'Uninstalls files'
39
+ task :uninstall do
40
+ session.uninstall
41
+ end
50
42
 
51
- #desc "Does `make distclean' for each extention"
52
- task :distclean do
53
- exec_distclean
54
- end
43
+ desc "Does `make clean' for each extention"
44
+ task :clean do
45
+ session.clean
46
+ end
55
47
 
56
- task :clobber => [:distclean]
48
+ desc "Does `make distclean' for each extention"
49
+ task :distclean do
50
+ session.distclean
51
+ end
57
52
 
58
- desc 'Shows current configuration'
59
- task :show do
60
- setup.exec_show
53
+ desc 'Shows current configuration'
54
+ task :show do
55
+ session.show
56
+ end
61
57
  end
62
58
 
59
+ task :clean => ['setup:clean']
60
+ task :clobber => ['setup:distclean']
61
+
@@ -0,0 +1,233 @@
1
+ require 'setup/core_ext'
2
+ require 'setup/constants'
3
+ require 'setup/project'
4
+ require 'setup/configuration'
5
+ require 'setup/compiler'
6
+ require 'setup/installer'
7
+ require 'setup/tester'
8
+ require 'setup/documentor'
9
+ require 'setup/uninstaller'
10
+
11
+ module Setup
12
+
13
+ #
14
+ class Session
15
+
16
+ # Session options.
17
+ attr :options
18
+
19
+ # New Session
20
+ def initialize(options={})
21
+ @options = options
22
+ self.io ||= StringIO.new # log instead ?
23
+ end
24
+
25
+ # # O P T I O N S # #
26
+
27
+ #
28
+ def io
29
+ @options[:io]
30
+ end
31
+
32
+ #
33
+ def io=(anyio)
34
+ @options[:io] = anyio
35
+ end
36
+
37
+ #
38
+ def trace?; @options[:trace]; end
39
+
40
+ #
41
+ def trace=(val)
42
+ @options[:trace] = val
43
+ end
44
+
45
+ #
46
+ def trial?; @options[:trial]; end
47
+
48
+ #
49
+ def trial=(val)
50
+ @options[:trial] = val
51
+ end
52
+
53
+ #
54
+ def quiet?; @options[:quiet]; end
55
+
56
+ #
57
+ def quiet=(val)
58
+ @options[:quiet] = val
59
+ end
60
+
61
+ #
62
+ def force?; @options[:force]; end
63
+
64
+ #
65
+ def force=(val)
66
+ @options[:force] = val
67
+ end
68
+
69
+ #
70
+ def compile?
71
+ configuration.compile? && project.compiles?
72
+ end
73
+
74
+ # # S E T U P T A S K S # #
75
+
76
+ # Run all tasks in sequence.
77
+ #
78
+ # * config
79
+ # * make
80
+ # * test (if selected)
81
+ # * install
82
+ # * document (if selected)
83
+ #
84
+ # Note that ri documentation is not easy to uninstall.
85
+ # So use the --ri option knowledgably. You can alwasy
86
+ # Use <tt>setup.rb document</tt> at a later time.
87
+ #
88
+ def all
89
+ config
90
+ if compile?
91
+ make
92
+ end
93
+ if configuration.test?
94
+ ok = test
95
+ exit 1 unless ok
96
+ end
97
+ install
98
+ if configuration.ri?
99
+ document
100
+ end
101
+ end
102
+
103
+ #
104
+ def config
105
+ log_header('Configure')
106
+ if configuration.save_config
107
+ io.puts "Configuration saved." unless quiet?
108
+ else
109
+ io.puts "Configuration current." unless quiet?
110
+ end
111
+ puts configuration if trace? && !quiet?
112
+ compiler.configure if compile? #compiler.compiles?
113
+ end
114
+
115
+ #
116
+ def make
117
+ abort "must setup config first" unless configuration.exist?
118
+ log_header('Compile')
119
+ compiler.compile
120
+ end
121
+
122
+ # What #make used to be called.
123
+ alias_method :setup, :make
124
+
125
+ #
126
+ def install
127
+ abort "must setup config first" unless configuration.exist?
128
+ log_header('Install')
129
+ installer.install
130
+ end
131
+
132
+ #
133
+ def test
134
+ return true unless tester.testable?
135
+ log_header('Test')
136
+ tester.test
137
+ end
138
+
139
+ #
140
+ def document
141
+ #return unless configuration.doc?
142
+ log_header('Document')
143
+ documentor.document
144
+ end
145
+
146
+ #
147
+ def clean
148
+ log_header('Clean')
149
+ compiler.clean
150
+ end
151
+
152
+ #
153
+ def distclean
154
+ log_header('Distclean')
155
+ compiler.distclean
156
+ end
157
+
158
+ #
159
+ def uninstall
160
+ if !File.exist?(INSTALL_RECORD)
161
+ io.puts "Nothing is installed."
162
+ return
163
+ end
164
+ log_header('Uninstall')
165
+ uninstaller.uninstall
166
+ io.puts('Ok.')
167
+ end
168
+
169
+ #
170
+ def show
171
+ #configuration.show
172
+ puts configuration
173
+ end
174
+
175
+ # # C O N T R O L L E R S / M O D E L S # #
176
+
177
+ #
178
+ def project
179
+ @project ||= Project.new
180
+ end
181
+ #
182
+ def configuration
183
+ @configuration ||= Configuration.new
184
+ end
185
+ #
186
+ def compiler
187
+ @compiler ||= Compiler.new(project, configuration, options)
188
+ end
189
+ #
190
+ def installer
191
+ @installer ||= Installer.new(project, configuration, options)
192
+ end
193
+ #
194
+ def tester
195
+ @tester ||= Tester.new(project, configuration, options)
196
+ end
197
+ #
198
+ def documentor
199
+ @documentor ||= Documentor.new(project, configuration, options)
200
+ end
201
+ #
202
+ def uninstaller
203
+ @uninstaller ||= Uninstaller.new(project, configuration, options)
204
+ end
205
+
206
+ # # S U P P O R T # #
207
+
208
+ #
209
+ def log_header(phase)
210
+ return if quiet?
211
+ if trial?
212
+ str = "#{phase.upcase} (trail run)"
213
+ else
214
+ str = "#{phase.upcase}"
215
+ end
216
+ line = "- " * 35
217
+ line[0..str.size+3] = str
218
+ io.puts("\n- - #{line}\n\n")
219
+ end
220
+
221
+ # #center = " "
222
+ # #c = (center.size - phase.size) / 2
223
+ # #center[c,phase.size] = phase.to_s.upcase
224
+ # line = '- ' * 4 + ' -' * 28
225
+ # #c = (line.size - phase.size) / 2
226
+ # line[5,phase.size] = " #{phase.to_s.upcase} "
227
+ # io.puts "\n" + line + "\n\n"
228
+ #end
229
+
230
+ end
231
+
232
+ end
233
+
@@ -0,0 +1,92 @@
1
+ require 'setup/constants'
2
+
3
+ module Setup
4
+
5
+ # Complexities arise in trying to figure out what test framework
6
+ # is used, and how to run tests. To simplify the process, this
7
+ # class simply looks for a special script, this can be a shell
8
+ # script at <tt>script/test</tt>, or a ruby script that
9
+ # <tt>.setup/testrc.rb</tt> will be used instead if it exists.
10
+
11
+ class Tester < Base
12
+
13
+ RUBYSCRIPT = META_EXTENSION_DIR + '/testrc.rb'
14
+
15
+ SHELLSCRIPT = 'script/test'
16
+
17
+ #
18
+ def testable?
19
+ return false if config.no_test
20
+ return true if File.exist?(RUBYSCRIPT)
21
+ return true if File.exist?(SHELLSCRIPT)
22
+ false
23
+ end
24
+
25
+ #
26
+ def test
27
+ return true if !testable?
28
+ if File.exist?(RUBYSCRIPT)
29
+ test_rubyscript
30
+ elsif File.exist?(SHELLSCRIPT)
31
+ test_shellscript
32
+ end
33
+ end
34
+
35
+ #
36
+ def test_shellscript
37
+ bash(SHELLSCRIPT)
38
+ end
39
+
40
+ #
41
+ def test_rubyscript
42
+ ruby(RUBYSCRIPT)
43
+ end
44
+
45
+
46
+ # DEPRECATED
47
+ #def test
48
+ #runner = config.testrunner
49
+ #case runner
50
+ #when 'testrb' # TODO: needs work
51
+ # opt = []
52
+ # opt << " -v" if trace?
53
+ # opt << " --runner #{runner}"
54
+ # if File.file?('test/suite.rb')
55
+ # notests = false
56
+ # opt << "test/suite.rb"
57
+ # else
58
+ # notests = Dir["test/**/*.rb"].empty?
59
+ # lib = ["lib"] + config.extensions.collect{ |d| File.dirname(d) }
60
+ # opt << "-I" + lib.join(':')
61
+ # opt << Dir["test/**/{test,tc}*.rb"]
62
+ # end
63
+ # opt = opt.flatten.join(' ').strip
64
+ # # run tests
65
+ # if notests
66
+ # $stderr.puts 'no test in this package' if trace?
67
+ # else
68
+ # cmd = "testrb #{opt}"
69
+ # $stderr.puts cmd if trace?
70
+ # system cmd #config.ruby "-S testrb", opt
71
+ # end
72
+ #else # autorunner
73
+ # unless File.directory?('test')
74
+ # $stderr.puts 'no test in this package' if trace?
75
+ # return
76
+ # end
77
+ # begin
78
+ # require 'test/unit'
79
+ # rescue LoadError
80
+ # setup_rb_error 'test/unit cannot loaded. You need Ruby 1.8 or later to invoke this task.'
81
+ # end
82
+ # lib = ["lib"] + config.extensions.collect{ |d| File.dirname(d) }
83
+ # lib.each{ |l| $LOAD_PATH << l }
84
+ # autorunner = Test::Unit::AutoRunner.new(true)
85
+ # autorunner.to_run << 'test'
86
+ # autorunner.run
87
+ #end
88
+ #end
89
+
90
+ end
91
+
92
+ end