setup 4.2.0 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY +47 -3
- data/MANIFEST +49 -16
- data/README.rdoc +148 -0
- data/bin/setup.rb +1 -5
- data/lib/setup.rb +2 -2
- data/lib/setup/base.rb +143 -0
- data/lib/setup/command.rb +218 -114
- data/lib/setup/compiler.rb +69 -0
- data/lib/setup/configuration.rb +822 -0
- data/lib/setup/constants.rb +12 -0
- data/lib/setup/{rubyver.rb → core_ext.rb} +0 -0
- data/lib/setup/documentor.rb +149 -0
- data/lib/setup/installer.rb +363 -0
- data/lib/setup/project.rb +68 -0
- data/lib/setup/rake.rb +44 -45
- data/lib/setup/session.rb +233 -0
- data/lib/setup/tester.rb +92 -0
- data/lib/setup/uninstaller.rb +76 -0
- data/meta/active +1 -0
- data/meta/collection +1 -0
- data/meta/{abstract → description} +0 -0
- data/meta/{package → name} +0 -0
- data/meta/repository +1 -0
- data/meta/ruby +3 -0
- data/meta/version +1 -1
- data/script/bstrap +5 -0
- data/script/bundle +64 -0
- data/script/setup +1338 -0
- data/script/test +3 -0
- data/test/cases/installer.rb +28 -0
- data/test/features/config.feature +16 -0
- data/test/features/document.feature +2 -0
- data/test/features/install.feature +72 -0
- data/test/features/make.feature +18 -0
- data/test/features/step_definitions/common_steps.rb +34 -0
- data/test/features/step_definitions/config_steps.rb +24 -0
- data/test/features/step_definitions/env.rb +37 -0
- data/test/features/step_definitions/install_steps.rb +75 -0
- data/test/features/step_definitions/setup_steps.rb +30 -0
- data/test/features/step_definitions/uninstall_steps.rb +8 -0
- data/test/features/test.feature +2 -0
- data/test/features/uninstall.feature +13 -0
- data/test/fixtures/faux-project/bin/faux +3 -0
- data/test/fixtures/faux-project/ext/faux/extconf.rb +12 -0
- data/test/fixtures/faux-project/ext/faux/faux.c +24 -0
- data/test/fixtures/faux-project/lib/faux.rb +1 -0
- metadata +58 -29
- data/README +0 -106
- data/RELEASE +0 -41
- data/lib/setup/build.rb +0 -2
- data/lib/setup/config.rb +0 -452
- data/lib/setup/error.rb +0 -4
- data/lib/setup/install.rb +0 -1007
- data/meta/setup/metaconfig.rb +0 -3
- data/test/test_installer.rb +0 -139
@@ -0,0 +1,822 @@
|
|
1
|
+
require 'rbconfig'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'erb'
|
4
|
+
require 'yaml'
|
5
|
+
require 'setup/core_ext'
|
6
|
+
require 'setup/constants'
|
7
|
+
|
8
|
+
module Setup
|
9
|
+
|
10
|
+
# Stores platform information and general install settings.
|
11
|
+
#
|
12
|
+
class Configuration
|
13
|
+
|
14
|
+
# Ruby System Configuration
|
15
|
+
RBCONFIG = ::Config::CONFIG
|
16
|
+
|
17
|
+
# Confgiuration file
|
18
|
+
CONFIG_FILE = 'SetupConfig' # '.cache/setup/config'
|
19
|
+
|
20
|
+
# Custom configuration file.
|
21
|
+
META_CONFIG_FILE = META_EXTENSION_DIR + '/configuration.rb'
|
22
|
+
|
23
|
+
#
|
24
|
+
def self.options
|
25
|
+
@@options ||= []
|
26
|
+
end
|
27
|
+
|
28
|
+
# TODO: better methods for path type
|
29
|
+
def self.option(name, *args) #type, description)
|
30
|
+
options << [name.to_s, *args] #type, description]
|
31
|
+
attr_accessor(name)
|
32
|
+
end
|
33
|
+
|
34
|
+
option :prefix , :path, 'path prefix of target environment'
|
35
|
+
option :bindir , :path, 'directory for commands'
|
36
|
+
option :libdir , :path, 'directory for libraries'
|
37
|
+
option :datadir , :path, 'directory for shared data'
|
38
|
+
option :mandir , :path, 'directory for man pages'
|
39
|
+
option :docdir , :path, 'directory for documentation'
|
40
|
+
option :rbdir , :path, 'directory for ruby scripts'
|
41
|
+
option :sodir , :path, 'directory for ruby extentions'
|
42
|
+
option :sysconfdir , :path, 'directory for system configuration files'
|
43
|
+
option :localstatedir , :path, 'directory for local state data'
|
44
|
+
|
45
|
+
option :libruby , :path, 'directory for ruby libraries'
|
46
|
+
option :librubyver , :path, 'directory for standard ruby libraries'
|
47
|
+
option :librubyverarch , :path, 'directory for standard ruby extensions'
|
48
|
+
option :siteruby , :path, 'directory for version-independent aux ruby libraries'
|
49
|
+
option :siterubyver , :path, 'directory for aux ruby libraries'
|
50
|
+
option :siterubyverarch , :path, 'directory for aux ruby binaries'
|
51
|
+
|
52
|
+
option :rubypath , :prog, 'path to set to #! line'
|
53
|
+
option :rubyprog , :prog, 'ruby program used for installation'
|
54
|
+
option :makeprog , :prog, 'make program to compile ruby extentions'
|
55
|
+
|
56
|
+
option :extconfopt , :opts, 'options to pass-thru to extconf.rb'
|
57
|
+
|
58
|
+
option :shebang , :pick, 'shebang line (#!) editing mode (all,ruby,never)'
|
59
|
+
|
60
|
+
option :no_test, :t , :bool, 'run pre-installation tests'
|
61
|
+
option :no_ri, :d , :bool, 'generate ri documentation'
|
62
|
+
option :no_doc , :bool, 'install doc/ directory'
|
63
|
+
option :no_ext , :bool, 'compile/install ruby extentions'
|
64
|
+
|
65
|
+
#option :rdoc , :pick, 'generate rdoc documentation'
|
66
|
+
#option :rdoc_template , :pick, 'rdoc document template to use'
|
67
|
+
#option :testrunner , :pick, 'Runner to use for testing (auto|console|tk|gtk|gtk2)'
|
68
|
+
|
69
|
+
option :install_prefix , :path, 'install to alternate root location'
|
70
|
+
option :root , :path, 'install to alternate root location'
|
71
|
+
|
72
|
+
option :installdirs , :pick, 'install location mode (site,std,home)' #, local)
|
73
|
+
option :type , :pick, 'install location mode (site,std,home)'
|
74
|
+
|
75
|
+
# Turn all of CONFIG into methods.
|
76
|
+
|
77
|
+
::Config::CONFIG.each do |key,val|
|
78
|
+
next if key == "configure_args"
|
79
|
+
name = key.to_s.downcase
|
80
|
+
#name = name.sub(/^--/,'')
|
81
|
+
#name = name.gsub(/-/,'_')
|
82
|
+
define_method(name){ val }
|
83
|
+
end
|
84
|
+
|
85
|
+
# Turn all of CONFIG["configure_args"] into methods.
|
86
|
+
|
87
|
+
::Config::CONFIG["configure_args"].each do |ent|
|
88
|
+
key, val = *ent.split("=")
|
89
|
+
name = key.downcase
|
90
|
+
name = name.sub(/^--/,'')
|
91
|
+
name = name.gsub(/-/,'_')
|
92
|
+
define_method(name){ val }
|
93
|
+
end
|
94
|
+
|
95
|
+
#
|
96
|
+
def options
|
97
|
+
#(class << self ; self ; end).options
|
98
|
+
self.class.options
|
99
|
+
end
|
100
|
+
|
101
|
+
# # I N I T I A L I Z E # #
|
102
|
+
|
103
|
+
# New ConfigTable
|
104
|
+
def initialize(values={})
|
105
|
+
initialize_metaconfig
|
106
|
+
initialize_defaults
|
107
|
+
initialize_environment
|
108
|
+
initialize_configfile
|
109
|
+
values.each{ |k,v| __send__("#{k}=", v) }
|
110
|
+
yeild(self) if block_given?
|
111
|
+
end
|
112
|
+
|
113
|
+
#
|
114
|
+
def initialize_metaconfig
|
115
|
+
if File.exist?(META_CONFIG_FILE)
|
116
|
+
script = File.read(META_CONFIG_FILE)
|
117
|
+
(class << self; self; end).class_eval(script)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
# By default installation is to site locations, tests will
|
122
|
+
# not be run, ri documentation will not be generated, but
|
123
|
+
# the +doc/+ directory will be installed.
|
124
|
+
def initialize_defaults
|
125
|
+
self.type = 'site'
|
126
|
+
self.no_ri = true
|
127
|
+
self.no_test = true
|
128
|
+
self.no_doc = false
|
129
|
+
self.no_ext = false
|
130
|
+
#@rbdir = siterubyver #'$siterubyver'
|
131
|
+
#@sodir = siterubyverarch #'$siterubyverarch'
|
132
|
+
end
|
133
|
+
|
134
|
+
# Get configuration from environment.
|
135
|
+
def initialize_environment
|
136
|
+
options.each do |name, *args|
|
137
|
+
if value = ENV["RUBYSETUP_#{name.to_s.upcase}"]
|
138
|
+
__send__("#{name}=", value)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
# Load configuration.
|
144
|
+
def initialize_configfile
|
145
|
+
if File.exist?(CONFIG_FILE)
|
146
|
+
erb = ERB.new(File.read(CONFIG_FILE))
|
147
|
+
txt = erb.result(binding)
|
148
|
+
dat = YAML.load(txt)
|
149
|
+
dat.each do |k, v|
|
150
|
+
next if 'type' == k
|
151
|
+
next if 'installdirs' == k
|
152
|
+
k = k.gsub('-','_')
|
153
|
+
__send__("#{k}=", v)
|
154
|
+
end
|
155
|
+
# do these last
|
156
|
+
if dat['type']
|
157
|
+
self.type = dat['type']
|
158
|
+
end
|
159
|
+
if dat['installdirs']
|
160
|
+
self.installdirs = dat['installdirs']
|
161
|
+
end
|
162
|
+
#else
|
163
|
+
# raise Error, $!.message + "\n#{File.basename($0)} config first"
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
#def initialize_configfile
|
168
|
+
# begin
|
169
|
+
# File.foreach(CONFIG_FILE) do |line|
|
170
|
+
# k, v = *line.split(/=/, 2)
|
171
|
+
# k.gsub!('-','_')
|
172
|
+
# __send__("#{k}=",v.strip) #self[k] = v.strip
|
173
|
+
# end
|
174
|
+
# rescue Errno::ENOENT
|
175
|
+
# raise Error, $!.message + "\n#{File.basename($0)} config first"
|
176
|
+
# end
|
177
|
+
#end
|
178
|
+
|
179
|
+
# # B A S E D I R E C T O R I E S # #
|
180
|
+
|
181
|
+
#
|
182
|
+
#def base_libruby
|
183
|
+
# "lib/ruby"
|
184
|
+
#end
|
185
|
+
|
186
|
+
# Base bin directory
|
187
|
+
def base_bindir
|
188
|
+
@base_bindir ||= subprefix('bindir')
|
189
|
+
end
|
190
|
+
|
191
|
+
# Base libdir
|
192
|
+
def base_libdir
|
193
|
+
@base_libdir ||= subprefix('libdir')
|
194
|
+
end
|
195
|
+
|
196
|
+
#
|
197
|
+
def base_datadir
|
198
|
+
@base_datadir ||= subprefix('datadir')
|
199
|
+
end
|
200
|
+
|
201
|
+
#
|
202
|
+
def base_mandir
|
203
|
+
@base_mandir ||= subprefix('mandir')
|
204
|
+
end
|
205
|
+
|
206
|
+
# NOTE: This removed the trailing <tt>$(PACKAGE)</tt>.
|
207
|
+
def base_docdir
|
208
|
+
@base_docdir || File.dirname(subprefix('docdir'))
|
209
|
+
end
|
210
|
+
|
211
|
+
#
|
212
|
+
def base_rubylibdir
|
213
|
+
@rubylibdir ||= subprefix('rubylibdir')
|
214
|
+
end
|
215
|
+
|
216
|
+
#
|
217
|
+
def base_rubyarchdir
|
218
|
+
@base_rubyarchdir ||= subprefix('archdir')
|
219
|
+
end
|
220
|
+
|
221
|
+
# Base directory for system configuration files
|
222
|
+
def base_sysconfdir
|
223
|
+
@base_sysconfdir ||= subprefix('sysconfdir')
|
224
|
+
end
|
225
|
+
|
226
|
+
# Base directory for local state data
|
227
|
+
def base_localstatedir
|
228
|
+
@base_localstatedir ||= subprefix('localstatedir')
|
229
|
+
end
|
230
|
+
|
231
|
+
|
232
|
+
# # C O N F I G U R A T I O N # #
|
233
|
+
|
234
|
+
#
|
235
|
+
def type
|
236
|
+
@type ||= 'site'
|
237
|
+
end
|
238
|
+
|
239
|
+
#
|
240
|
+
def type=(val)
|
241
|
+
@type = val
|
242
|
+
case val.to_s
|
243
|
+
when 'std', 'ruby'
|
244
|
+
@rbdir = librubyver #'$librubyver'
|
245
|
+
@sodir = librubyverarch #'$librubyverarch'
|
246
|
+
when 'site'
|
247
|
+
@rbdir = siterubyver #'$siterubyver'
|
248
|
+
@sodir = siterubyverarch #'$siterubyverarch'
|
249
|
+
when 'home'
|
250
|
+
self.prefix = File.join(home, '.local') # TODO: Use XDG
|
251
|
+
@rbdir = nil #'$libdir/ruby'
|
252
|
+
@sodir = nil #'$libdir/ruby'
|
253
|
+
#when 'local'
|
254
|
+
# rbdir = subprefix(librubyver, '')
|
255
|
+
# sodir = subprefix(librubyverarch, '')
|
256
|
+
# self.prefix = '/usr/local' # FIXME: how?
|
257
|
+
# self.rbdir = File.join(prefix, rbdir) #'$libdir/ruby'
|
258
|
+
# self.sodir = File.join(prefix, sodir) #'$libdir/ruby'
|
259
|
+
else
|
260
|
+
raise Error, "bad config: use type=(std|site|home) [#{val}]"
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
264
|
+
#
|
265
|
+
alias_method :installdirs, :type
|
266
|
+
|
267
|
+
#
|
268
|
+
alias_method :installdirs=, :type=
|
269
|
+
|
270
|
+
|
271
|
+
#
|
272
|
+
alias_method :install_prefix, :root
|
273
|
+
|
274
|
+
#
|
275
|
+
alias_method :install_prefix=, :root=
|
276
|
+
|
277
|
+
|
278
|
+
# Path prefix of target environment
|
279
|
+
def prefix
|
280
|
+
@prefix ||= RBCONFIG['prefix']
|
281
|
+
end
|
282
|
+
|
283
|
+
# Set path prefix of target environment
|
284
|
+
def prefix=(path)
|
285
|
+
@prefix = pathname(path)
|
286
|
+
end
|
287
|
+
|
288
|
+
# Directory for ruby libraries
|
289
|
+
def libruby
|
290
|
+
@libruby ||= RBCONFIG['prefix'] + "/lib/ruby"
|
291
|
+
end
|
292
|
+
|
293
|
+
# Set directory for ruby libraries
|
294
|
+
def libruby=(path)
|
295
|
+
path = pathname(path)
|
296
|
+
@librubyver = librubyver.sub(libruby, path)
|
297
|
+
@librubyverarch = librubyverarch.sub(libruby, path)
|
298
|
+
@libruby = path
|
299
|
+
end
|
300
|
+
|
301
|
+
# Directory for standard ruby libraries
|
302
|
+
def librubyver
|
303
|
+
@librubyver ||= RBCONFIG['rubylibdir']
|
304
|
+
end
|
305
|
+
|
306
|
+
# Set directory for standard ruby libraries
|
307
|
+
def librubyver=(path)
|
308
|
+
@librubyver = pathname(path)
|
309
|
+
end
|
310
|
+
|
311
|
+
# Directory for standard ruby extensions
|
312
|
+
def librubyverarch
|
313
|
+
@librubyverarch ||= RBCONFIG['archdir']
|
314
|
+
end
|
315
|
+
|
316
|
+
# Set directory for standard ruby extensions
|
317
|
+
def librubyverarch=(path)
|
318
|
+
@librubyverarch = pathname(path)
|
319
|
+
end
|
320
|
+
|
321
|
+
# Directory for version-independent aux ruby libraries
|
322
|
+
def siteruby
|
323
|
+
@siteruby ||= RBCONFIG['sitedir']
|
324
|
+
end
|
325
|
+
|
326
|
+
# Set directory for version-independent aux ruby libraries
|
327
|
+
def siteruby=(path)
|
328
|
+
path = pathname(path)
|
329
|
+
@siterubyver = siterubyver.sub(siteruby, path)
|
330
|
+
@siterubyverarch = siterubyverarch.sub(siteruby, path)
|
331
|
+
@siteruby = path
|
332
|
+
end
|
333
|
+
|
334
|
+
# Directory for aux ruby libraries
|
335
|
+
def siterubyver
|
336
|
+
@siterubyver ||= RBCONFIG['sitelibdir']
|
337
|
+
end
|
338
|
+
|
339
|
+
# Set directory for aux ruby libraries
|
340
|
+
def siterubyver=(path)
|
341
|
+
@siterubyver = pathname(path)
|
342
|
+
end
|
343
|
+
|
344
|
+
# Directory for aux ruby binary libraries
|
345
|
+
def siterubyverarch
|
346
|
+
@siterubyverarch ||= RBCONFIG['sitearchdir']
|
347
|
+
end
|
348
|
+
|
349
|
+
# Set directory for aux arch ruby binaries
|
350
|
+
def siterubyverarch=(path)
|
351
|
+
@siterubyverarch = pathname(path)
|
352
|
+
end
|
353
|
+
|
354
|
+
# Directory for commands
|
355
|
+
def bindir
|
356
|
+
@bindir || File.join(prefix, base_bindir)
|
357
|
+
end
|
358
|
+
|
359
|
+
# Set directory for commands
|
360
|
+
def bindir=(path)
|
361
|
+
@bindir = pathname(path)
|
362
|
+
end
|
363
|
+
|
364
|
+
# Directory for libraries
|
365
|
+
def libdir
|
366
|
+
@libdir || File.join(prefix, base_libdir)
|
367
|
+
end
|
368
|
+
|
369
|
+
# Set directory for libraries
|
370
|
+
def libdir=(path)
|
371
|
+
@libdir = pathname(path)
|
372
|
+
end
|
373
|
+
|
374
|
+
# Directory for shared data
|
375
|
+
def datadir
|
376
|
+
@datadir || File.join(prefix, base_datadir)
|
377
|
+
end
|
378
|
+
|
379
|
+
# Set directory for shared data
|
380
|
+
def datadir=(path)
|
381
|
+
@datadir = pathname(path)
|
382
|
+
end
|
383
|
+
|
384
|
+
# Directory for man pages
|
385
|
+
def mandir
|
386
|
+
@mandir || File.join(prefix, base_mandir)
|
387
|
+
end
|
388
|
+
|
389
|
+
# Set directory for man pages
|
390
|
+
def mandir=(path)
|
391
|
+
@mandir = pathname(path)
|
392
|
+
end
|
393
|
+
|
394
|
+
# Directory for documentation
|
395
|
+
def docdir
|
396
|
+
@docdir || File.join(prefix, base_docdir)
|
397
|
+
end
|
398
|
+
|
399
|
+
# Set directory for documentation
|
400
|
+
def docdir=(path)
|
401
|
+
@docdir = pathname(path)
|
402
|
+
end
|
403
|
+
|
404
|
+
# Directory for ruby scripts
|
405
|
+
def rbdir
|
406
|
+
@rbdir || File.join(prefix, base_rubylibdir)
|
407
|
+
end
|
408
|
+
|
409
|
+
# Directory for ruby extentions
|
410
|
+
def sodir
|
411
|
+
@sodir || File.join(prefix, base_rubyarchdir)
|
412
|
+
end
|
413
|
+
|
414
|
+
# Directory for system configuration files
|
415
|
+
# TODO: Can this be prefixed?
|
416
|
+
def sysconfdir
|
417
|
+
@sysconfdir ||= base_sysconfdir
|
418
|
+
end
|
419
|
+
|
420
|
+
# Set directory for system configuration files
|
421
|
+
def sysconfdir=(path)
|
422
|
+
@sysconfdir = pathname(path)
|
423
|
+
end
|
424
|
+
|
425
|
+
# Directory for local state data
|
426
|
+
# TODO: Can this be prefixed?
|
427
|
+
def localstatedir
|
428
|
+
@localstatedir ||= base_localstatedir
|
429
|
+
end
|
430
|
+
|
431
|
+
# Set directory for local state data
|
432
|
+
def localstatedir=(path)
|
433
|
+
@localstatedir = pathname(path)
|
434
|
+
end
|
435
|
+
|
436
|
+
#
|
437
|
+
def rubypath
|
438
|
+
#@rubypath ||= RBCONFIG['libexecdir']
|
439
|
+
@rubypath ||= File.join(RBCONFIG['bindir'], RBCONFIG['ruby_install_name'] + RBCONFIG['EXEEXT'])
|
440
|
+
end
|
441
|
+
|
442
|
+
#
|
443
|
+
def rubypath=(path)
|
444
|
+
@rubypath = pathname(path)
|
445
|
+
end
|
446
|
+
|
447
|
+
#
|
448
|
+
def rubyprog
|
449
|
+
@rubyprog || rubypath
|
450
|
+
end
|
451
|
+
|
452
|
+
#
|
453
|
+
def rubyprog=(command)
|
454
|
+
@rubyprog = command
|
455
|
+
end
|
456
|
+
|
457
|
+
# TODO: Does this handle 'nmake' on windows?
|
458
|
+
def makeprog
|
459
|
+
@makeprog ||= (
|
460
|
+
if arg = RBCONFIG['configure_args'].split.detect {|arg| /--with-make-prog=/ =~ arg }
|
461
|
+
arg.sub(/'/, '').split(/=/, 2)[1]
|
462
|
+
else
|
463
|
+
'make'
|
464
|
+
end
|
465
|
+
)
|
466
|
+
end
|
467
|
+
|
468
|
+
#
|
469
|
+
def makeprog=(command)
|
470
|
+
@makeprog = command
|
471
|
+
end
|
472
|
+
|
473
|
+
#
|
474
|
+
def extconfopt
|
475
|
+
@extconfopt ||= ''
|
476
|
+
end
|
477
|
+
|
478
|
+
#
|
479
|
+
def extconfopt=(string)
|
480
|
+
@extconfopt = string
|
481
|
+
end
|
482
|
+
|
483
|
+
# Default is +ruby+.
|
484
|
+
def shebang
|
485
|
+
@shebang ||= 'ruby'
|
486
|
+
end
|
487
|
+
|
488
|
+
# There are three options: +all+, +ruby+, +never+.
|
489
|
+
def shebang=(val)
|
490
|
+
if %w(all ruby never).include?(val)
|
491
|
+
@shebang = val
|
492
|
+
else
|
493
|
+
raise Error, "bad config: use SHEBANG=(all|ruby|never) [#{val}]"
|
494
|
+
end
|
495
|
+
end
|
496
|
+
|
497
|
+
#
|
498
|
+
def no_ext
|
499
|
+
@no_ext
|
500
|
+
end
|
501
|
+
|
502
|
+
#
|
503
|
+
def no_ext=(val)
|
504
|
+
@no_ext = boolean(val)
|
505
|
+
end
|
506
|
+
|
507
|
+
#
|
508
|
+
def no_test
|
509
|
+
@no_test
|
510
|
+
end
|
511
|
+
|
512
|
+
#
|
513
|
+
def no_test=(val)
|
514
|
+
@no_test = boolean(val)
|
515
|
+
end
|
516
|
+
|
517
|
+
#
|
518
|
+
def no_doc
|
519
|
+
@no_doc
|
520
|
+
end
|
521
|
+
|
522
|
+
#
|
523
|
+
def no_doc=(val)
|
524
|
+
@no_doc = boolean(val)
|
525
|
+
end
|
526
|
+
|
527
|
+
#
|
528
|
+
def no_ri
|
529
|
+
@no_ri
|
530
|
+
end
|
531
|
+
|
532
|
+
#
|
533
|
+
def no_ri=(val)
|
534
|
+
@no_ri = boolean(val)
|
535
|
+
end
|
536
|
+
|
537
|
+
#def rdoc = 'no'
|
538
|
+
#def rdoctemplate = nil
|
539
|
+
#def testrunner = 'auto' # needed?
|
540
|
+
|
541
|
+
# Compile native extensions?
|
542
|
+
def compile?
|
543
|
+
!no_ext
|
544
|
+
end
|
545
|
+
|
546
|
+
# Run unit tests?
|
547
|
+
def test?
|
548
|
+
!no_test
|
549
|
+
end
|
550
|
+
|
551
|
+
# Generate ri documentation?
|
552
|
+
def ri?
|
553
|
+
!no_ri
|
554
|
+
end
|
555
|
+
|
556
|
+
# Install doc directory?
|
557
|
+
def doc?
|
558
|
+
!no_doc
|
559
|
+
end
|
560
|
+
|
561
|
+
|
562
|
+
# # C O N V E R S I O N # #
|
563
|
+
|
564
|
+
#
|
565
|
+
def to_h
|
566
|
+
h = {}
|
567
|
+
options.each do |name, *args|
|
568
|
+
h[name.to_s] = __send__(name)
|
569
|
+
end
|
570
|
+
h
|
571
|
+
end
|
572
|
+
|
573
|
+
#
|
574
|
+
def to_s
|
575
|
+
to_yaml.sub(/\A---\s*\n/,'')
|
576
|
+
end
|
577
|
+
|
578
|
+
#
|
579
|
+
def to_yaml(*args)
|
580
|
+
to_h.to_yaml(*args)
|
581
|
+
end
|
582
|
+
|
583
|
+
# Save configuration.
|
584
|
+
def save_config
|
585
|
+
out = to_yaml
|
586
|
+
if not File.exist?(File.dirname(CONFIG_FILE))
|
587
|
+
FileUtils.mkdir_p(File.dirname(CONFIG_FILE))
|
588
|
+
end
|
589
|
+
if File.exist?(CONFIG_FILE)
|
590
|
+
txt = File.read(CONFIG_FILE)
|
591
|
+
return nil if txt == out
|
592
|
+
end
|
593
|
+
File.open(CONFIG_FILE, 'w'){ |f| f << out }
|
594
|
+
true
|
595
|
+
end
|
596
|
+
|
597
|
+
# Does the configuration file exist?
|
598
|
+
def exist?
|
599
|
+
File.exist?(CONFIG_FILE)
|
600
|
+
end
|
601
|
+
|
602
|
+
#
|
603
|
+
#def show
|
604
|
+
# fmt = "%-20s %s\n"
|
605
|
+
# OPTIONS.each do |name|
|
606
|
+
# value = self[name]
|
607
|
+
# reslv = __send__(name)
|
608
|
+
# case reslv
|
609
|
+
# when String
|
610
|
+
# reslv = "(none)" if reslv.empty?
|
611
|
+
# when false, nil
|
612
|
+
# reslv = "no"
|
613
|
+
# when true
|
614
|
+
# reslv = "yes"
|
615
|
+
# end
|
616
|
+
# printf fmt, name, reslv
|
617
|
+
# end
|
618
|
+
#end
|
619
|
+
|
620
|
+
private
|
621
|
+
|
622
|
+
def pathname(path)
|
623
|
+
path.gsub(%r<\\$([^/]+)>){ self[$1] }
|
624
|
+
end
|
625
|
+
|
626
|
+
#def absolute_pathname(path)
|
627
|
+
# File.expand_path(path).gsub(%r<\\$([^/]+)>){ self[$1] }
|
628
|
+
#end
|
629
|
+
|
630
|
+
# Boolean attribute. Can be assigned true, false, nil, or
|
631
|
+
# a string matching yes|true|y|t or no|false|n|f.
|
632
|
+
def boolean(val, name=nil)
|
633
|
+
case val
|
634
|
+
when true, false, nil
|
635
|
+
val
|
636
|
+
else
|
637
|
+
case val.to_s.downcase
|
638
|
+
when 'y', 'yes', 't', 'true'
|
639
|
+
true
|
640
|
+
when 'n', 'no', 'f', 'false'
|
641
|
+
false
|
642
|
+
else
|
643
|
+
raise Error, "bad config: use --#{name}=(yes|no) [\#{val}]"
|
644
|
+
end
|
645
|
+
end
|
646
|
+
end
|
647
|
+
|
648
|
+
#
|
649
|
+
def subprefix(path, with='')
|
650
|
+
val = RBCONFIG[path]
|
651
|
+
raise "Unknown path -- #{path}" if val.nil?
|
652
|
+
prefix = Regexp.quote(RBCONFIG['prefix'])
|
653
|
+
val.sub(/\A#{prefix}/, with)
|
654
|
+
end
|
655
|
+
|
656
|
+
#
|
657
|
+
def home
|
658
|
+
ENV['HOME'] || raise(Error, 'HOME is not set.')
|
659
|
+
end
|
660
|
+
|
661
|
+
# Get unresloved attribute.
|
662
|
+
#def [](name)
|
663
|
+
# instance_variable_get("@#{name}")
|
664
|
+
#end
|
665
|
+
|
666
|
+
# Set attribute.
|
667
|
+
#def []=(name, value)
|
668
|
+
# instance_variable_set("@#{name}", value)
|
669
|
+
#end
|
670
|
+
|
671
|
+
# Resolved attribute. (for paths)
|
672
|
+
#def resolve(name)
|
673
|
+
# self[name].gsub(%r<\\$([^/]+)>){ self[$1] }
|
674
|
+
#end
|
675
|
+
|
676
|
+
end #class ConfigTable
|
677
|
+
|
678
|
+
end #module Setup
|
679
|
+
|
680
|
+
|
681
|
+
|
682
|
+
|
683
|
+
|
684
|
+
|
685
|
+
|
686
|
+
|
687
|
+
# Pathname attribute. Pathnames are automatically expanded
|
688
|
+
# unless they start with '$', a path variable.
|
689
|
+
#def self.attr_pathname(name)
|
690
|
+
# class_eval %{
|
691
|
+
# def #{name}
|
692
|
+
# @#{name}.gsub(%r<\\$([^/]+)>){ self[$1] }
|
693
|
+
# end
|
694
|
+
# def #{name}=(path)
|
695
|
+
# raise Error, "bad config: #{name.to_s.upcase} requires argument" unless path
|
696
|
+
# @#{name} = (path[0,1] == '$' ? path : File.expand_path(path))
|
697
|
+
# end
|
698
|
+
# }
|
699
|
+
#end
|
700
|
+
|
701
|
+
# List of pathnames. These are not expanded though.
|
702
|
+
#def self.attr_pathlist(name)
|
703
|
+
# class_eval %{
|
704
|
+
# def #{name}
|
705
|
+
# @#{name}
|
706
|
+
# end
|
707
|
+
# def #{name}=(pathlist)
|
708
|
+
# case pathlist
|
709
|
+
# when Array
|
710
|
+
# @#{name} = pathlist
|
711
|
+
# else
|
712
|
+
# @#{name} = pathlist.to_s.split(/[:;,]/)
|
713
|
+
# end
|
714
|
+
# end
|
715
|
+
# }
|
716
|
+
#end
|
717
|
+
|
718
|
+
# Adds boolean support.
|
719
|
+
#def self.attr_accessor(*names)
|
720
|
+
# bools, attrs = names.partition{ |name| name.to_s =~ /\?$/ }
|
721
|
+
# attr_boolean *bools
|
722
|
+
# super *attrs
|
723
|
+
#end
|
724
|
+
|
725
|
+
|
726
|
+
# # provide verbosity (default is true)
|
727
|
+
# attr_accessor :verbose?
|
728
|
+
|
729
|
+
# # don't actually write files to system
|
730
|
+
# attr_accessor :no_harm?
|
731
|
+
|
732
|
+
=begin
|
733
|
+
# Metaconfig file is '.config/setup/metaconfig{,.rb}'.
|
734
|
+
def inintialize_metaconfig
|
735
|
+
path = Dir.glob(METACONFIG_FILE).first
|
736
|
+
if path && File.file?(path)
|
737
|
+
MetaConfigEnvironment.new(self).instance_eval(File.read(path), path)
|
738
|
+
end
|
739
|
+
end
|
740
|
+
|
741
|
+
#= Meta Configuration
|
742
|
+
# This works a bit differently from 3.4.1.
|
743
|
+
# Defaults are currently not supported but remain in the method interfaces.
|
744
|
+
class MetaConfigEnvironment
|
745
|
+
def initialize(config) #, installer)
|
746
|
+
@config = config
|
747
|
+
#@installer = installer
|
748
|
+
end
|
749
|
+
|
750
|
+
#
|
751
|
+
def config_names
|
752
|
+
@config.descriptions.collect{ |n, t, d| n.to_s }
|
753
|
+
end
|
754
|
+
|
755
|
+
#
|
756
|
+
def config?(name)
|
757
|
+
@config.descriptions.find do |sym, type, desc|
|
758
|
+
sym.to_s == name.to_s
|
759
|
+
end
|
760
|
+
end
|
761
|
+
|
762
|
+
#
|
763
|
+
def bool_config?(name)
|
764
|
+
@config.descriptions.find do |sym, type, desc|
|
765
|
+
sym.to_s == name.to_s && type == :bool
|
766
|
+
end
|
767
|
+
#@config.lookup(name).config_type == 'bool'
|
768
|
+
end
|
769
|
+
|
770
|
+
#
|
771
|
+
def path_config?(name)
|
772
|
+
@config.descriptions.find do |sym, type, desc|
|
773
|
+
sym.to_s == name.to_s && type == :path
|
774
|
+
end
|
775
|
+
#@config.lookup(name).config_type == 'path'
|
776
|
+
end
|
777
|
+
|
778
|
+
#
|
779
|
+
def value_config?(name)
|
780
|
+
@config.descriptions.find do |sym, type, desc|
|
781
|
+
sym.to_s == name.to_s && type != :prog
|
782
|
+
end
|
783
|
+
#@config.lookup(name).config_type != 'exec'
|
784
|
+
end
|
785
|
+
|
786
|
+
#
|
787
|
+
def add_config(name, default, desc)
|
788
|
+
@config.descriptions << [name.to_sym, nil, desc]
|
789
|
+
#@config.add item
|
790
|
+
end
|
791
|
+
|
792
|
+
#
|
793
|
+
def add_bool_config(name, default, desc)
|
794
|
+
@config.descriptions << [name.to_sym, :bool, desc]
|
795
|
+
#@config.add BoolItem.new(name, 'yes/no', default ? 'yes' : 'no', desc)
|
796
|
+
end
|
797
|
+
|
798
|
+
#
|
799
|
+
def add_path_config(name, default, desc)
|
800
|
+
@config.descriptions << [name.to_sym, :path, desc]
|
801
|
+
#@config.add PathItem.new(name, 'path', default, desc)
|
802
|
+
end
|
803
|
+
|
804
|
+
#
|
805
|
+
def set_config_default(name, default)
|
806
|
+
@config[name] = default
|
807
|
+
end
|
808
|
+
|
809
|
+
#
|
810
|
+
def remove_config(name)
|
811
|
+
item = @config.descriptions.find do |sym, type, desc|
|
812
|
+
sym.to_s == name.to_s
|
813
|
+
end
|
814
|
+
index = @config.descriptions.index(item)
|
815
|
+
@config.descriptions.delete(index)
|
816
|
+
#@config.remove(name)
|
817
|
+
end
|
818
|
+
end
|
819
|
+
=end
|
820
|
+
|
821
|
+
# Designed to work with Ruby 1.6.3 or greater.
|
822
|
+
|