setup 5.1.0 → 5.2.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.
@@ -1 +0,0 @@
1
- false
@@ -1,5 +0,0 @@
1
- ---
2
- - 7rans <transfire@gmail.com>
3
- - Minero Aoki <aamine@loveruby.net>
4
-
5
-
@@ -1,4 +0,0 @@
1
- ---
2
- - 2009 Rubyworks (BSD-2-Clause)
3
- - 2005 Minero Aoki (LGPL-2.0+)
4
-
@@ -1 +0,0 @@
1
- 2008-08-01
@@ -1,8 +0,0 @@
1
- Every Rubyist is aware of Minero Aoki's ever useful
2
- setup.rb script. It's how most of us used to install
3
- our ruby programs before RubyGems came along. And it's
4
- still mighty useful in certain scenarios, not the least
5
- of which is the job of the distribution package managers.
6
- Setup converts setup.rb into a stand-alone application.
7
- No longer will you need distribute setup.rb with you
8
- Ruby packages. Just instruct your users to use Setup.
data/meta/name DELETED
@@ -1 +0,0 @@
1
- setup
@@ -1 +0,0 @@
1
- rubyworks
@@ -1,2 +0,0 @@
1
- ---
2
- upstream: git://github.com/rubyworks/setup.git
@@ -1,4 +0,0 @@
1
- ---
2
- - detroit (build)
3
- - cucumber (test)
4
- - ae (test)
@@ -1,6 +0,0 @@
1
- ---
2
- home: http://rubyworks.github.com/setup
3
- code: http://github.com/rubyworks/setup
4
- bugs: http://github.com/rubyworks/setup/issues
5
- old : http://setup.rubyforge.org
6
-
@@ -1 +0,0 @@
1
- Setup.rb as a stand-alone application.
@@ -1 +0,0 @@
1
- 5.1.0
@@ -1,5 +0,0 @@
1
- #!/usr/bin/env ruby
2
- $LOAD_PATH.unshift('lib')
3
- require 'setup/command'
4
- Setup::Command.run(*ARGV)
5
-
@@ -1,81 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'fileutils'
4
-
5
- raise "Not the right place #{Dir.pwd}" unless File.directory?('lib')
6
-
7
- #scripts = (Dir['lib/*.rb'] + Dir['lib/**/*']).uniq
8
- #scripts = scripts.reject{ |f| File.directory?(f) }
9
- # We don't want the rake helper.
10
- #scripts = scripts - ["lib/setup/rake.rb"]
11
- #scripts = scripts + ["bin/setup.rb"]
12
-
13
- scripts = %w{
14
- lib/setup.rb
15
- lib/setup/core_ext.rb
16
- lib/setup/constants.rb
17
- lib/setup/project.rb
18
- lib/setup/session.rb
19
- lib/setup/base.rb
20
- lib/setup/compiler.rb
21
- lib/setup/configuration.rb
22
- lib/setup/installer.rb
23
- lib/setup/tester.rb
24
- lib/setup/uninstaller.rb
25
- lib/setup/command.rb
26
- }
27
-
28
- version = YAML.load_file('.ruby')['version']
29
-
30
- comment = <<-HERE
31
- # Setup.rb v#{version}
32
- #
33
- # This is a stand-alone bundle of the setup.rb application.
34
- # You can place it in your projects script/ directory, or
35
- # call it 'setup.rb' and place it in your project's
36
- # root directory (just like old times).
37
- #
38
- # NOTE: As of version 5.1.0 this bundled rendition is also
39
- # being used for the bin/setup.rb exe. Rather than the previous:
40
- #
41
- # require 'setup/command'
42
- # Setup::Command.run
43
- #
44
- # By doing so, +rvm+ should be able to use it across all rubies
45
- # without issue and without needing to install it for each.
46
- HERE
47
-
48
- #
49
- bundle = ""
50
-
51
- # insert scripts
52
- scripts.each do |script|
53
- bundle << "\n\n# %-16s #{"#" * 60}\n\n" % File.basename(script)
54
- bundle << File.read(script)
55
- end
56
- bundle << "\nSetup::Command.run"
57
-
58
- # remove setup requires
59
- bundle.gsub!(/require\s+["']setup\/(.*?)["']\s*$/, '')
60
-
61
- # remove blank lines
62
- bundle.gsub!(/^\s*\n/, '')
63
-
64
- # remove comments
65
- bundle.gsub!(/^\s*\#.*?\n/, '')
66
-
67
- # save
68
- File.open('script/setup', 'w') do |f|
69
- f << "#!/usr/bin/env ruby\n"
70
- f << comment
71
- f << bundle
72
- end
73
- FileUtils.chmod(0744, 'script/setup')
74
-
75
- File.open('bin/setup.rb', 'w') do |f|
76
- f << "#!/usr/bin/env ruby\n"
77
- f << comment
78
- f << bundle
79
- end
80
- FileUtils.chmod(0744, 'bin/setup.rb')
81
-
@@ -1,1302 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # Setup.rb v5.1.0
3
- #
4
- # This is a stand-alone bundle of the setup.rb application.
5
- # You can place it in your projects script/ directory, or
6
- # call it 'setup.rb' and place it in your project's
7
- # root directory (just like old times).
8
- #
9
- # NOTE: As of version 5.1.0 this bundled rendition is also
10
- # being used for the bin/setup.rb exe. Rather than the previous:
11
- #
12
- # require 'setup/command'
13
- # Setup::Command.run
14
- #
15
- # By doing so, +rvm+ should be able to use it across all rubies
16
- # without issue and without needing to install it for each.
17
- require 'yaml'
18
- module Setup
19
- DIRECTORY = File.dirname(__FILE__) + '/setup'
20
- PROFILE = YAML.load(File.new(DIRECTORY + '/profile.yml'))
21
- verfile = YAML.load(File.new(DIRECTORY + '/version.yml'))
22
- VERSION = verfile.values_at('major','minor','patch','state','build').compact.join('.')
23
- def self.const_missing(name)
24
- key = name.to_s.downcase
25
- if verfile.key?(key)
26
- verfile[key]
27
- elsif profile.key?(key)
28
- PROFILE[key]
29
- else
30
- super(name)
31
- end
32
- end
33
- end
34
- class << File #:nodoc: all
35
- unless respond_to?(:read) # Ruby 1.6 and less
36
- def read(fname)
37
- open(fname){ |f| return f.read }
38
- end
39
- end
40
- def dir?(path)
41
- directory?((path[-1,1] == '/') ? path : path + '/')
42
- end
43
- end
44
- unless Errno.const_defined?(:ENOTEMPTY) # Windows?
45
- module Errno #:nodoc:
46
- class ENOTEMPTY #:nodoc:
47
- end
48
- end
49
- end
50
- module Setup
51
- META_EXTENSION_DIR = '.setup'
52
- FILETYPES = %w( bin lib ext data etc man doc )
53
- INSTALL_RECORD = 'SetupReceipt'
54
- CONFIG_FILE = 'SetupConfig'
55
- end
56
- module Setup
57
- class Project
58
- ROOT_MARKER = '{.ruby,setup.rb,.setup,lib/}'
59
- def initialize
60
- @dotruby_file = find('.ruby')
61
- @dotruby = YAML.load_file(@dotruby_file) if @dotruby_file
62
- @name = nil
63
- @version = nil
64
- @loadpath = ['lib']
65
- if @dotruby
66
- @name = @dotruby['name']
67
- @version = @dotruby['version']
68
- @loadpath = @dotruby['load_path']
69
- else
70
- if file = find('.setup/name')
71
- @name = File.read(file).strip
72
- end
73
- if file = find('.setup/version')
74
- @version = File.read(file).strip
75
- end
76
- if file = find('.setup/loadpath')
77
- @loadpath = File.read(file).strip
78
- end
79
- end
80
- end
81
- attr :dotruby
82
- attr :name
83
- attr :version
84
- attr :loadpath
85
- alias load_path loadpath
86
- def rootdir
87
- @rootdir ||= (
88
- root = Dir.glob(File.join(Dir.pwd, ROOT_MARKER), File::FNM_CASEFOLD).first
89
- if !root
90
- raise Error, "not a project directory"
91
- else
92
- Dir.pwd
93
- end
94
- )
95
- end
96
- def extconfs
97
- @extconfs ||= Dir['ext/**/extconf.rb']
98
- end
99
- def extensions
100
- @extensions ||= extconfs.collect{ |f| File.dirname(f) }
101
- end
102
- def compiles?
103
- !extensions.empty?
104
- end
105
- def yardopts
106
- Dir.glob(File.join(rootdir, '.yardopts')).first
107
- end
108
- def document
109
- Dir.glob(File.join(rootdir, '.document')).first
110
- end
111
- def find(glob, flags=0)
112
- case flags
113
- when :casefold
114
- flags = File::FNM_CASEFOLD
115
- else
116
- flags = flags.to_i
117
- end
118
- Dir.glob(File.join(rootdir, glob), flags).first
119
- end
120
- end
121
- end
122
- module Setup
123
- class Session
124
- attr :options
125
- def initialize(options={})
126
- @options = options
127
- self.io ||= StringIO.new # log instead ?
128
- end
129
- def io
130
- @options[:io]
131
- end
132
- def io=(anyio)
133
- @options[:io] = anyio
134
- end
135
- def trace?; @options[:trace]; end
136
- def trace=(val)
137
- @options[:trace] = val
138
- end
139
- def trial?; @options[:trial]; end
140
- alias_method :dryrun?, :trial?
141
- def trial=(val)
142
- @options[:trial] = val
143
- end
144
- alias_method :dryrun=, :trial=
145
- def quiet?; @options[:quiet]; end
146
- def quiet=(val)
147
- @options[:quiet] = val
148
- end
149
- def force?; @options[:force]; end
150
- def force=(val)
151
- @options[:force] = val
152
- end
153
- def compile?
154
- configuration.compile? && project.compiles?
155
- end
156
- def all
157
- config
158
- compile
159
- if configuration.test?
160
- ok = test
161
- exit 1 unless ok
162
- end
163
- install
164
- end
165
- def config
166
- log_header('Preconfig')
167
- if configuration.save_config
168
- io.print "#{CONFIG_FILE} was saved. " unless quiet?
169
- else
170
- io.print "#{CONFIG_FILE} is current. " unless quiet?
171
- end
172
- io.puts "Edit to customize configuration." unless quiet?
173
- puts configuration if trace? && !quiet?
174
- end
175
- def compile
176
- if compile?
177
- log_header('Compile')
178
- compiler.configure
179
- compiler.compile
180
- end
181
- end
182
- alias_method :make, :compile
183
- alias_method :setup, :make
184
- def install
185
- log_header('Install')
186
- installer.install
187
- end
188
- def test
189
- return true unless tester.testable?
190
- log_header('Test')
191
- tester.test
192
- end
193
- def clean
194
- log_header('Clean')
195
- compiler.clean
196
- end
197
- def distclean
198
- log_header('Distclean')
199
- compiler.distclean
200
- end
201
- def uninstall
202
- if !File.exist?(INSTALL_RECORD)
203
- io.puts "Nothing is installed."
204
- return
205
- end
206
- log_header('Uninstall')
207
- uninstaller.uninstall
208
- io.puts('Ok.')
209
- end
210
- def show
211
- puts configuration
212
- end
213
- def project
214
- @project ||= Project.new
215
- end
216
- def configuration
217
- @configuration ||= Configuration.new
218
- end
219
- def compiler
220
- @compiler ||= Compiler.new(project, configuration, options)
221
- end
222
- def installer
223
- @installer ||= Installer.new(project, configuration, options)
224
- end
225
- def tester
226
- @tester ||= Tester.new(project, configuration, options)
227
- end
228
- def uninstaller
229
- @uninstaller ||= Uninstaller.new(project, configuration, options)
230
- end
231
- def log_header(phase)
232
- return if quiet?
233
- if trial?
234
- str = "#{phase.upcase} (trail run)"
235
- else
236
- str = "#{phase.upcase}"
237
- end
238
- line = "- " * 35
239
- line[0..str.size+3] = str
240
- io.puts("\n- - #{line}\n\n")
241
- end
242
- end
243
- end
244
- module Setup
245
- class Base
246
- attr :project
247
- attr :config
248
- attr_accessor :trial
249
- attr_accessor :trace
250
- attr_accessor :quiet
251
- attr_accessor :force
252
- attr_accessor :io
253
- def initialize(project, configuration, options={})
254
- @project = project
255
- @config = configuration
256
- initialize_hooks
257
- options.each do |k,v|
258
- __send__("#{k}=", v) if respond_to?("#{k}=")
259
- end
260
- end
261
- def initialize_hooks
262
- file = META_EXTENSION_DIR + "/#{self.class.name.downcase}.rb"
263
- if File.exist?(file)
264
- script = File.read(file)
265
- (class << self; self; end).class_eval(script)
266
- end
267
- end
268
- def trial? ; @trial ; end
269
- def trace? ; @trace ; end
270
- def quiet? ; @quiet ; end
271
- def force? ; @force ; end
272
- def rootdir
273
- project.rootdir
274
- end
275
- def bash(*args)
276
- $stderr.puts args.join(' ') if trace?
277
- system(*args) or raise RuntimeError, "system(#{args.map{|a| a.inspect }.join(' ')}) failed"
278
- end
279
- alias_method :command, :bash
280
- def ruby(*args)
281
- bash(config.rubyprog, *args)
282
- end
283
- def trace_off #:yield:
284
- begin
285
- save, @trace = trace?, false
286
- yield
287
- ensure
288
- @trace = save
289
- end
290
- end
291
- def rm_f(path)
292
- io.puts "rm -f #{path}" if trace? or trial?
293
- return if trial?
294
- force_remove_file(path)
295
- end
296
- def force_remove_file(path)
297
- begin
298
- remove_file(path)
299
- rescue
300
- end
301
- end
302
- def remove_file(path)
303
- File.chmod 0777, path
304
- File.unlink(path)
305
- end
306
- def rmdir(path)
307
- io.puts "rmdir #{path}" if trace? or trial?
308
- return if trial?
309
- Dir.rmdir(path)
310
- end
311
- end
312
- class Error < StandardError
313
- end
314
- end
315
- module Setup
316
- class Compiler < Base
317
- def compiles?
318
- !extdirs.empty?
319
- end
320
- def configure
321
- extdirs.each do |dir|
322
- Dir.chdir(dir) do
323
- if File.exist?('extconf.rb') && !FileUtils.uptodate?('Makefile', ['extconf.rb'])
324
- ruby("extconf.rb")
325
- end
326
- end
327
- end
328
- end
329
- def compile
330
- extdirs.each do |dir|
331
- Dir.chdir(dir) do
332
- make
333
- end
334
- end
335
- end
336
- def clean
337
- extdirs.each do |dir|
338
- Dir.chdir(dir) do
339
- make('clean')
340
- end
341
- end
342
- end
343
- def distclean
344
- extdirs.each do |dir|
345
- Dir.chdir(dir) do
346
- make('distclean')
347
- end
348
- end
349
- end
350
- def extdirs
351
- Dir['ext/**/*/{MANIFEST,extconf.rb}'].map do |f|
352
- File.dirname(f)
353
- end.uniq
354
- end
355
- def make(task=nil)
356
- return unless File.exist?('Makefile')
357
- bash(*[config.makeprog, task].compact)
358
- end
359
- end
360
- end
361
- require 'rbconfig'
362
- require 'fileutils'
363
- require 'erb'
364
- require 'yaml'
365
- require 'shellwords'
366
- module Setup
367
- class Configuration
368
- RBCONFIG = ::Config::CONFIG
369
- META_CONFIG_FILE = META_EXTENSION_DIR + '/metaconfig.rb'
370
- def self.options
371
- @@options ||= []
372
- end
373
- def self.option(name, *args) #type, description)
374
- options << [name.to_s, *args] #type, description]
375
- attr_accessor(name)
376
- end
377
- option :prefix , :path, 'path prefix of target environment'
378
- option :bindir , :path, 'directory for commands'
379
- option :libdir , :path, 'directory for libraries'
380
- option :datadir , :path, 'directory for shared data'
381
- option :mandir , :path, 'directory for man pages'
382
- option :docdir , :path, 'directory for documentation'
383
- option :rbdir , :path, 'directory for ruby scripts'
384
- option :sodir , :path, 'directory for ruby extentions'
385
- option :sysconfdir , :path, 'directory for system configuration files'
386
- option :localstatedir , :path, 'directory for local state data'
387
- option :libruby , :path, 'directory for ruby libraries'
388
- option :librubyver , :path, 'directory for standard ruby libraries'
389
- option :librubyverarch , :path, 'directory for standard ruby extensions'
390
- option :siteruby , :path, 'directory for version-independent aux ruby libraries'
391
- option :siterubyver , :path, 'directory for aux ruby libraries'
392
- option :siterubyverarch , :path, 'directory for aux ruby binaries'
393
- option :rubypath , :prog, 'path to set to #! line'
394
- option :rubyprog , :prog, 'ruby program used for installation'
395
- option :makeprog , :prog, 'make program to compile ruby extentions'
396
- option :extconfopt , :opts, 'options to pass-thru to extconf.rb'
397
- option :shebang , :pick, 'shebang line (#!) editing mode (all,ruby,never)'
398
- option :no_test, :t , :bool, 'run pre-installation tests'
399
- option :no_doc , :bool, 'install doc/ directory'
400
- option :no_ext , :bool, 'compile/install ruby extentions'
401
- option :install_prefix , :path, 'install to alternate root location'
402
- option :root , :path, 'install to alternate root location'
403
- option :installdirs , :pick, 'install location mode (site,std,home)' #, local)
404
- option :type , :pick, 'install location mode (site,std,home)'
405
- ::Config::CONFIG.each do |key,val|
406
- next if key == "configure_args"
407
- name = key.to_s.downcase
408
- define_method(name){ val }
409
- end
410
- config_args = Shellwords.shellwords(::Config::CONFIG["configure_args"])
411
- config_args.each do |ent|
412
- if ent.index("=")
413
- key, val = *ent.split("=")
414
- else
415
- key, val = ent, true
416
- end
417
- name = key.downcase
418
- name = name.sub(/^--/,'')
419
- name = name.gsub(/-/,'_')
420
- define_method(name){ val }
421
- end
422
- def options
423
- self.class.options
424
- end
425
- def initialize(values={})
426
- initialize_metaconfig
427
- initialize_defaults
428
- initialize_environment
429
- initialize_configfile unless values[:reset]
430
- values.each{ |k,v| __send__("#{k}=", v) }
431
- yield(self) if block_given?
432
- end
433
- def initialize_metaconfig
434
- if File.exist?(META_CONFIG_FILE)
435
- script = File.read(META_CONFIG_FILE)
436
- (class << self; self; end).class_eval(script)
437
- end
438
- end
439
- def initialize_defaults
440
- self.type = 'site'
441
- self.no_ri = true
442
- self.no_test = true
443
- self.no_doc = true
444
- self.no_ext = false
445
- end
446
- def initialize_environment
447
- options.each do |name, *args|
448
- if value = ENV["RUBYSETUP_#{name.to_s.upcase}"]
449
- __send__("#{name}=", value)
450
- end
451
- end
452
- end
453
- def initialize_configfile
454
- if exist?
455
- erb = ERB.new(File.read(CONFIG_FILE))
456
- txt = erb.result(binding)
457
- dat = YAML.load(txt)
458
- dat.each do |k, v|
459
- next if 'type' == k
460
- next if 'installdirs' == k
461
- k = k.gsub('-','_')
462
- __send__("#{k}=", v)
463
- end
464
- if dat['type']
465
- self.type = dat['type']
466
- end
467
- if dat['installdirs']
468
- self.installdirs = dat['installdirs']
469
- end
470
- end
471
- end
472
- attr_accessor :reset
473
- def base_bindir
474
- @base_bindir ||= subprefix('bindir')
475
- end
476
- def base_libdir
477
- @base_libdir ||= subprefix('libdir')
478
- end
479
- def base_datadir
480
- @base_datadir ||= subprefix('datadir')
481
- end
482
- def base_mandir
483
- @base_mandir ||= subprefix('mandir')
484
- end
485
- def base_docdir
486
- @base_docdir || File.dirname(subprefix('docdir'))
487
- end
488
- def base_rubylibdir
489
- @rubylibdir ||= subprefix('rubylibdir')
490
- end
491
- def base_rubyarchdir
492
- @base_rubyarchdir ||= subprefix('archdir')
493
- end
494
- def base_sysconfdir
495
- @base_sysconfdir ||= subprefix('sysconfdir')
496
- end
497
- def base_localstatedir
498
- @base_localstatedir ||= subprefix('localstatedir')
499
- end
500
- def type
501
- @type ||= 'site'
502
- end
503
- def type=(val)
504
- @type = val
505
- case val.to_s
506
- when 'std', 'ruby'
507
- @rbdir = librubyver #'$librubyver'
508
- @sodir = librubyverarch #'$librubyverarch'
509
- when 'site'
510
- @rbdir = siterubyver #'$siterubyver'
511
- @sodir = siterubyverarch #'$siterubyverarch'
512
- when 'home'
513
- self.prefix = File.join(home, '.local') # TODO: Use XDG
514
- @rbdir = nil #'$libdir/ruby'
515
- @sodir = nil #'$libdir/ruby'
516
- else
517
- raise Error, "bad config: use type=(std|site|home) [#{val}]"
518
- end
519
- end
520
- alias_method :installdirs, :type
521
- alias_method :installdirs=, :type=
522
- alias_method :install_prefix, :root
523
- alias_method :install_prefix=, :root=
524
- def prefix
525
- @prefix ||= RBCONFIG['prefix']
526
- end
527
- def prefix=(path)
528
- @prefix = pathname(path)
529
- end
530
- def libruby
531
- @libruby ||= RBCONFIG['prefix'] + "/lib/ruby"
532
- end
533
- def libruby=(path)
534
- path = pathname(path)
535
- @librubyver = librubyver.sub(libruby, path)
536
- @librubyverarch = librubyverarch.sub(libruby, path)
537
- @libruby = path
538
- end
539
- def librubyver
540
- @librubyver ||= RBCONFIG['rubylibdir']
541
- end
542
- def librubyver=(path)
543
- @librubyver = pathname(path)
544
- end
545
- def librubyverarch
546
- @librubyverarch ||= RBCONFIG['archdir']
547
- end
548
- def librubyverarch=(path)
549
- @librubyverarch = pathname(path)
550
- end
551
- def siteruby
552
- @siteruby ||= RBCONFIG['sitedir']
553
- end
554
- def siteruby=(path)
555
- path = pathname(path)
556
- @siterubyver = siterubyver.sub(siteruby, path)
557
- @siterubyverarch = siterubyverarch.sub(siteruby, path)
558
- @siteruby = path
559
- end
560
- def siterubyver
561
- @siterubyver ||= RBCONFIG['sitelibdir']
562
- end
563
- def siterubyver=(path)
564
- @siterubyver = pathname(path)
565
- end
566
- def siterubyverarch
567
- @siterubyverarch ||= RBCONFIG['sitearchdir']
568
- end
569
- def siterubyverarch=(path)
570
- @siterubyverarch = pathname(path)
571
- end
572
- def bindir
573
- @bindir || File.join(prefix, base_bindir)
574
- end
575
- def bindir=(path)
576
- @bindir = pathname(path)
577
- end
578
- def libdir
579
- @libdir || File.join(prefix, base_libdir)
580
- end
581
- def libdir=(path)
582
- @libdir = pathname(path)
583
- end
584
- def datadir
585
- @datadir || File.join(prefix, base_datadir)
586
- end
587
- def datadir=(path)
588
- @datadir = pathname(path)
589
- end
590
- def mandir
591
- @mandir || File.join(prefix, base_mandir)
592
- end
593
- def mandir=(path)
594
- @mandir = pathname(path)
595
- end
596
- def docdir
597
- @docdir || File.join(prefix, base_docdir)
598
- end
599
- def docdir=(path)
600
- @docdir = pathname(path)
601
- end
602
- def rbdir
603
- @rbdir || File.join(prefix, base_rubylibdir)
604
- end
605
- def sodir
606
- @sodir || File.join(prefix, base_rubyarchdir)
607
- end
608
- def sysconfdir
609
- @sysconfdir ||= base_sysconfdir
610
- end
611
- def sysconfdir=(path)
612
- @sysconfdir = pathname(path)
613
- end
614
- def localstatedir
615
- @localstatedir ||= base_localstatedir
616
- end
617
- def localstatedir=(path)
618
- @localstatedir = pathname(path)
619
- end
620
- def rubypath
621
- @rubypath ||= File.join(RBCONFIG['bindir'], RBCONFIG['ruby_install_name'] + RBCONFIG['EXEEXT'])
622
- end
623
- def rubypath=(path)
624
- @rubypath = pathname(path)
625
- end
626
- def rubyprog
627
- @rubyprog || rubypath
628
- end
629
- def rubyprog=(command)
630
- @rubyprog = command
631
- end
632
- def makeprog
633
- @makeprog ||= (
634
- if arg = RBCONFIG['configure_args'].split.detect {|arg| /--with-make-prog=/ =~ arg }
635
- arg.sub(/'/, '').split(/=/, 2)[1]
636
- else
637
- 'make'
638
- end
639
- )
640
- end
641
- def makeprog=(command)
642
- @makeprog = command
643
- end
644
- def extconfopt
645
- @extconfopt ||= ''
646
- end
647
- def extconfopt=(string)
648
- @extconfopt = string
649
- end
650
- def shebang
651
- @shebang ||= 'ruby'
652
- end
653
- def shebang=(val)
654
- if %w(all ruby never).include?(val)
655
- @shebang = val
656
- else
657
- raise Error, "bad config: use SHEBANG=(all|ruby|never) [#{val}]"
658
- end
659
- end
660
- def no_ext
661
- @no_ext
662
- end
663
- def no_ext=(val)
664
- @no_ext = boolean(val)
665
- end
666
- def no_test
667
- @no_test
668
- end
669
- def no_test=(val)
670
- @no_test = boolean(val)
671
- end
672
- def no_doc
673
- @no_doc
674
- end
675
- def no_doc=(val)
676
- @no_doc = boolean(val)
677
- end
678
- def no_ri
679
- @no_ri
680
- end
681
- def no_ri=(val)
682
- @no_ri = boolean(val)
683
- end
684
- def compile?
685
- !no_ext
686
- end
687
- def test?
688
- !no_test
689
- end
690
- def doc?
691
- !no_doc
692
- end
693
- def to_h
694
- h = {}
695
- options.each do |name, *args|
696
- h[name.to_s] = __send__(name)
697
- end
698
- h
699
- end
700
- def to_s
701
- to_yaml.sub(/\A---\s*\n/,'')
702
- end
703
- def to_yaml(*args)
704
- to_h.to_yaml(*args)
705
- end
706
- def save_config
707
- out = to_yaml
708
- if not File.exist?(File.dirname(CONFIG_FILE))
709
- FileUtils.mkdir_p(File.dirname(CONFIG_FILE))
710
- end
711
- if File.exist?(CONFIG_FILE)
712
- txt = File.read(CONFIG_FILE)
713
- return nil if txt == out
714
- end
715
- File.open(CONFIG_FILE, 'w'){ |f| f << out }
716
- true
717
- end
718
- def exist?
719
- File.exist?(CONFIG_FILE)
720
- end
721
- private
722
- def pathname(path)
723
- path.gsub(%r<\\$([^/]+)>){ self[$1] }
724
- end
725
- def boolean(val, name=nil)
726
- case val
727
- when true, false, nil
728
- val
729
- else
730
- case val.to_s.downcase
731
- when 'y', 'yes', 't', 'true'
732
- true
733
- when 'n', 'no', 'f', 'false'
734
- false
735
- else
736
- raise Error, "bad config: use --#{name}=(yes|no) [\#{val}]"
737
- end
738
- end
739
- end
740
- def subprefix(path, with='')
741
- val = RBCONFIG[path]
742
- raise "Unknown path -- #{path}" if val.nil?
743
- prefix = Regexp.quote(RBCONFIG['prefix'])
744
- val.sub(/\A#{prefix}/, with)
745
- end
746
- def home
747
- ENV['HOME'] || raise(Error, 'HOME is not set.')
748
- end
749
- end #class ConfigTable
750
- end #module Setup
751
- =begin
752
- def inintialize_metaconfig
753
- path = Dir.glob(METACONFIG_FILE).first
754
- if path && File.file?(path)
755
- MetaConfigEnvironment.new(self).instance_eval(File.read(path), path)
756
- end
757
- end
758
- class MetaConfigEnvironment
759
- def initialize(config) #, installer)
760
- @config = config
761
- end
762
- def config_names
763
- @config.descriptions.collect{ |n, t, d| n.to_s }
764
- end
765
- def config?(name)
766
- @config.descriptions.find do |sym, type, desc|
767
- sym.to_s == name.to_s
768
- end
769
- end
770
- def bool_config?(name)
771
- @config.descriptions.find do |sym, type, desc|
772
- sym.to_s == name.to_s && type == :bool
773
- end
774
- end
775
- def path_config?(name)
776
- @config.descriptions.find do |sym, type, desc|
777
- sym.to_s == name.to_s && type == :path
778
- end
779
- end
780
- def value_config?(name)
781
- @config.descriptions.find do |sym, type, desc|
782
- sym.to_s == name.to_s && type != :prog
783
- end
784
- end
785
- def add_config(name, default, desc)
786
- @config.descriptions << [name.to_sym, nil, desc]
787
- end
788
- def add_bool_config(name, default, desc)
789
- @config.descriptions << [name.to_sym, :bool, desc]
790
- end
791
- def add_path_config(name, default, desc)
792
- @config.descriptions << [name.to_sym, :path, desc]
793
- end
794
- def set_config_default(name, default)
795
- @config[name] = default
796
- end
797
- def remove_config(name)
798
- item = @config.descriptions.find do |sym, type, desc|
799
- sym.to_s == name.to_s
800
- end
801
- index = @config.descriptions.index(item)
802
- @config.descriptions.delete(index)
803
- end
804
- end
805
- =end
806
- module Setup
807
- class Installer < Base
808
- def install_prefix
809
- config.install_prefix
810
- end
811
- def install
812
- Dir.chdir(rootdir) do
813
- install_bin
814
- install_ext
815
- install_lib
816
- install_data
817
- install_man
818
- install_doc
819
- install_etc
820
- prune_install_record
821
- end
822
- end
823
- def install_bin
824
- return unless directory?('bin')
825
- report_transfer('bin', config.bindir)
826
- files = files('bin')
827
- install_files('bin', files, config.bindir, 0755)
828
- end
829
- def install_ext
830
- return unless directory?('ext')
831
- report_transfer('ext', config.sodir)
832
- files = files('ext')
833
- files = select_dllext(files)
834
- files.each do |file|
835
- name = File.join(File.dirname(File.dirname(file)), File.basename(file))
836
- dest = destination(config.sodir, name)
837
- install_file('ext', file, dest, 0555, install_prefix)
838
- end
839
- end
840
- def install_lib
841
- return unless directory?('lib')
842
- report_transfer('lib', config.rbdir)
843
- files = files('lib')
844
- install_files('lib', files, config.rbdir, 0644)
845
- end
846
- def install_data
847
- return unless directory?('data')
848
- report_transfer('data', config.datadir)
849
- files = files('data')
850
- install_files('data', files, config.datadir, 0644)
851
- end
852
- def install_etc
853
- return unless directory?('etc')
854
- report_transfer('etc', config.sysconfdir)
855
- files = files('etc')
856
- install_files('etc', files, config.sysconfdir, 0644)
857
- end
858
- def install_man
859
- return unless directory?('man')
860
- report_transfer('man', config.mandir)
861
- files = files('man')
862
- install_files('man', files, config.mandir, 0644)
863
- end
864
- def install_doc
865
- return unless config.doc?
866
- return unless directory?('doc')
867
- return unless project.name
868
- dir = File.join(config.docdir, "ruby-#{project.name}")
869
- report_transfer('doc', dir)
870
- files = files('doc')
871
- install_files('doc', files, dir, 0644)
872
- end
873
- private
874
- def report_transfer(source, directory)
875
- unless quiet?
876
- if install_prefix
877
- out = File.join(install_prefix, directory)
878
- else
879
- out = directory
880
- end
881
- io.puts "* #{source} -> #{out}"
882
- end
883
- end
884
- def directory?(path)
885
- File.directory?(path)
886
- end
887
- def files(dir)
888
- files = Dir["#{dir}/**/*"]
889
- files = files.select{ |f| File.file?(f) }
890
- files = files.map{ |f| f.sub("#{dir}/", '') }
891
- files
892
- end
893
- def select_dllext(files)
894
- ents = files.select do |file|
895
- File.extname(file) == ".#{dllext}"
896
- end
897
- if ents.empty? && !files.empty?
898
- raise Error, "ruby extention not compiled: 'setup.rb make' first"
899
- end
900
- ents
901
- end
902
- def dllext
903
- config.dlext
904
- end
905
- def install_files(dir, list, dest, mode)
906
- list.each do |fname|
907
- rdest = destination(dest, fname)
908
- install_file(dir, fname, rdest, mode, install_prefix)
909
- end
910
- end
911
- def install_file(dir, from, dest, mode, prefix=nil)
912
- mkdir_p(File.dirname(dest))
913
- if trace? or trial?
914
- io.puts "install #{dir}/#{from} #{dest}"
915
- end
916
- return if trial?
917
- str = binread(File.join(dir, from))
918
- if diff?(str, dest)
919
- trace_off {
920
- rm_f(dest) if File.exist?(dest)
921
- }
922
- File.open(dest, 'wb'){ |f| f.write(str) }
923
- File.chmod(mode, dest)
924
- end
925
- record_installation(dest) # record file as installed
926
- end
927
- def mkdir_p(dirname) #, prefix=nil)
928
- return if File.directory?(dirname)
929
- io.puts "mkdir -p #{dirname}" if trace? or trial?
930
- return if trial?
931
- dirs = File.expand_path(dirname).split(%r<(?=/)>)
932
- if /\A[a-z]:\z/i =~ dirs[0]
933
- disk = dirs.shift
934
- dirs[0] = disk + dirs[0]
935
- end
936
- dirs.each_index do |idx|
937
- path = dirs[0..idx].join('')
938
- unless File.dir?(path)
939
- Dir.mkdir(path)
940
- end
941
- record_installation(path) # record directories made
942
- end
943
- end
944
- def record_installation(path)
945
- File.open(install_record, 'a') do |f|
946
- f.puts(path)
947
- end
948
- end
949
- def prune_install_record
950
- entries = File.read(install_record).split("\n")
951
- entries.uniq!
952
- File.open(install_record, 'w') do |f|
953
- f << entries.join("\n")
954
- f << "\n"
955
- end
956
- end
957
- def install_record
958
- @install_record ||= (
959
- file = INSTALL_RECORD
960
- dir = File.dirname(file)
961
- unless File.directory?(dir)
962
- FileUtils.mkdir_p(dir)
963
- end
964
- file
965
- )
966
- end
967
- def destination(dir, file)
968
- dest = install_prefix ? File.join(install_prefix, File.expand_path(dir)) : dir
969
- dest = File.join(dest, file) #if File.dir?(dest)
970
- dest = File.expand_path(dest)
971
- dest
972
- end
973
- def diff?(new_content, path)
974
- return true unless File.exist?(path)
975
- new_content != binread(path)
976
- end
977
- def binread(fname)
978
- File.open(fname, 'rb') do |f|
979
- return f.read
980
- end
981
- end
982
- def install_shebang(files, dir)
983
- files.each do |file|
984
- path = File.join(dir, File.basename(file))
985
- update_shebang_line(path)
986
- end
987
- end
988
- def update_shebang_line(path)
989
- return if trial?
990
- return if config.shebang == 'never'
991
- old = Shebang.load(path)
992
- if old
993
- if old.args.size > 1
994
- $stderr.puts "warning: #{path}"
995
- $stderr.puts "Shebang line has too many args."
996
- $stderr.puts "It is not portable and your program may not work."
997
- end
998
- new = new_shebang(old)
999
- return if new.to_s == old.to_s
1000
- else
1001
- return unless config.shebang == 'all'
1002
- new = Shebang.new(config.rubypath)
1003
- end
1004
- $stderr.puts "updating shebang: #{File.basename(path)}" if trace?
1005
- open_atomic_writer(path) do |output|
1006
- File.open(path, 'rb') do |f|
1007
- f.gets if old # discard
1008
- output.puts new.to_s
1009
- output.print f.read
1010
- end
1011
- end
1012
- end
1013
- def new_shebang(old)
1014
- if /\Aruby/ =~ File.basename(old.cmd)
1015
- Shebang.new(config.rubypath, old.args)
1016
- elsif File.basename(old.cmd) == 'env' and old.args.first == 'ruby'
1017
- Shebang.new(config.rubypath, old.args[1..-1])
1018
- else
1019
- return old unless config.shebang == 'all'
1020
- Shebang.new(config.rubypath)
1021
- end
1022
- end
1023
- def open_atomic_writer(path, &block)
1024
- tmpfile = File.basename(path) + '.tmp'
1025
- begin
1026
- File.open(tmpfile, 'wb', &block)
1027
- File.rename tmpfile, File.basename(path)
1028
- ensure
1029
- File.unlink tmpfile if File.exist?(tmpfile)
1030
- end
1031
- end
1032
- class Shebang
1033
- def Shebang.load(path)
1034
- line = nil
1035
- File.open(path) {|f|
1036
- line = f.gets
1037
- }
1038
- return nil unless /\A#!/ =~ line
1039
- parse(line)
1040
- end
1041
- def Shebang.parse(line)
1042
- cmd, *args = *line.strip.sub(/\A\#!/, '').split(' ')
1043
- new(cmd, args)
1044
- end
1045
- def initialize(cmd, args = [])
1046
- @cmd = cmd
1047
- @args = args
1048
- end
1049
- attr_reader :cmd
1050
- attr_reader :args
1051
- def to_s
1052
- "#! #{@cmd}" + (@args.empty? ? '' : " #{@args.join(' ')}")
1053
- end
1054
- end
1055
- end
1056
- end
1057
- module Setup
1058
- class Tester < Base
1059
- RUBYSCRIPT = META_EXTENSION_DIR + '/testrc.rb'
1060
- SHELLSCRIPT = 'script/test'
1061
- def testable?
1062
- return false if config.no_test
1063
- return true if File.exist?(RUBYSCRIPT)
1064
- return true if File.exist?(SHELLSCRIPT)
1065
- false
1066
- end
1067
- def test
1068
- return true if !testable?
1069
- if File.exist?(RUBYSCRIPT)
1070
- test_rubyscript
1071
- elsif File.exist?(SHELLSCRIPT)
1072
- test_shellscript
1073
- end
1074
- end
1075
- def test_shellscript
1076
- bash(SHELLSCRIPT)
1077
- end
1078
- def test_rubyscript
1079
- ruby(RUBYSCRIPT)
1080
- end
1081
- end
1082
- end
1083
- module Setup
1084
- class Uninstaller < Base
1085
- def uninstall
1086
- return unless File.exist?(INSTALL_RECORD)
1087
- files = []
1088
- dirs = []
1089
- paths.each do |path|
1090
- dirs << path if File.dir?(path)
1091
- files << path if File.file?(path)
1092
- end
1093
- if dirs.empty? && files.empty?
1094
- io.outs "Nothing to remove."
1095
- return
1096
- end
1097
- files.sort!{ |a,b| b.size <=> a.size }
1098
- dirs.sort!{ |a,b| b.size <=> a.size }
1099
- if !force? && !trial?
1100
- puts (files + dirs).collect{ |f| "#{f}" }.join("\n")
1101
- puts
1102
- puts "Must use --force option to remove these files and directories that become empty."
1103
- return
1104
- end
1105
- files.each do |file|
1106
- rm_f(file)
1107
- end
1108
- dirs.each do |dir|
1109
- entries = Dir.entries(dir)
1110
- entries.delete('.')
1111
- entries.delete('..')
1112
- rmdir(dir) if entries.empty?
1113
- end
1114
- rm_f(INSTALL_RECORD)
1115
- end
1116
- private
1117
- def paths
1118
- @paths ||= (
1119
- lines = File.read(INSTALL_RECORD).split(/\s*\n/)
1120
- lines = lines.map{ |line| line.strip }
1121
- lines = lines.uniq
1122
- lines = lines.reject{ |line| line.empty? } # skip blank lines
1123
- lines = lines.reject{ |line| line[0,1] == '#' } # skip blank lines
1124
- lines
1125
- )
1126
- end
1127
- end
1128
- end
1129
- require 'optparse'
1130
- module Setup
1131
- class Command
1132
- def self.run(*argv)
1133
- new.run(*argv)
1134
- end
1135
- def self.tasks
1136
- @tasks ||= {}
1137
- end
1138
- def self.order
1139
- @order ||= []
1140
- end
1141
- def self.task(name, description)
1142
- tasks[name] = description
1143
- order << name
1144
- end
1145
- task 'show' , "show current configuration"
1146
- task 'all' , "config, compile and install"
1147
- task 'config' , "save/customize configuration settings"
1148
- task 'compile' , "compile ruby extentions"
1149
- task 'test' , "run test suite"
1150
- task 'install' , "install project files"
1151
- task 'clean' , "does `make clean' for each extention"
1152
- task 'distclean', "does `make distclean' for each extention"
1153
- task 'uninstall', "uninstall previously installed files"
1154
- def run(*argv)
1155
- ARGV.replace(argv) unless argv.empty?
1156
- task = ARGV.find{ |a| a !~ /^[-]/ }
1157
- task = 'all' unless task
1158
- unless task_names.include?(task)
1159
- $stderr.puts "Not a valid task -- #{task}"
1160
- exit 1
1161
- end
1162
- parser = OptionParser.new
1163
- options = {}
1164
- parser.banner = "Usage: #{File.basename($0)} [TASK] [OPTIONS]"
1165
- optparse_header(parser, options)
1166
- case task
1167
- when 'config'
1168
- optparse_config(parser, options)
1169
- when 'compile'
1170
- optparse_compile(parser, options)
1171
- when 'install'
1172
- optparse_install(parser, options)
1173
- when 'all'
1174
- optparse_all(parser, options)
1175
- end
1176
- optparse_common(parser, options)
1177
- begin
1178
- parser.parse!(ARGV)
1179
- rescue OptionParser::InvalidOption
1180
- $stderr.puts $!.to_s.capitalize
1181
- exit 1
1182
- end
1183
- rootdir = session.project.rootdir
1184
- print_header
1185
- begin
1186
- $stderr.puts "(#{RUBY_ENGINE} #{RUBY_VERSION} #{RUBY_PLATFORM})"
1187
- rescue
1188
- $stderr.puts "(#{RUBY_VERSION} #{RUBY_PLATFORM})"
1189
- end
1190
- begin
1191
- session.__send__(task)
1192
- rescue Error => err
1193
- raise err if $DEBUG
1194
- $stderr.puts $!.message
1195
- $stderr.puts "Try 'setup.rb --help' for detailed usage."
1196
- abort $!.message #exit 1
1197
- end
1198
- puts unless session.quiet?
1199
- end
1200
- def session
1201
- @session ||= Session.new(:io=>$stdout)
1202
- end
1203
- def configuration
1204
- @configuration ||= session.configuration
1205
- end
1206
- def optparse_header(parser, options)
1207
- parser.banner = "USAGE: #{File.basename($0)} [command] [options]"
1208
- end
1209
- def optparse_all(parser, options)
1210
- optparse_config(parser, options)
1211
- optparse_compile(parser, options)
1212
- optparse_install(parser, options) # TODO: why was this remarked out ?
1213
- end
1214
- def optparse_config(parser, options)
1215
- parser.separator ""
1216
- parser.separator "Configuration options:"
1217
- configuration.options.each do |args|
1218
- args = args.dup
1219
- desc = args.pop
1220
- type = args.pop
1221
- name, shortcut = *args
1222
- optname = name.to_s.gsub('_', '-')
1223
- case type
1224
- when :bool
1225
- if optname.index('no-') == 0
1226
- optname = "[no-]" + optname.sub(/^no-/, '')
1227
- opts = shortcut ? ["-#{shortcut}", "--#{optname}", desc] : ["--#{optname}", desc]
1228
- parser.on(*opts) do |val|
1229
- configuration.__send__("#{name}=", !val)
1230
- end
1231
- else
1232
- optname = "[no-]" + optname.sub(/^no-/, '')
1233
- opts = shortcut ? ["-#{shortcut}", "--#{optname}", desc] : ["--#{optname}", desc]
1234
- parser.on(*opts) do |val|
1235
- configuration.__send__("#{name}=", val)
1236
- end
1237
- end
1238
- else
1239
- opts = shortcut ? ["-#{shortcut}", "--#{optname} #{type.to_s.upcase}", desc] :
1240
- ["--#{optname} #{type.to_s.upcase}", desc]
1241
- parser.on(*opts) do |val|
1242
- configuration.__send__("#{name}=", val)
1243
- end
1244
- end
1245
- end
1246
- end
1247
- def optparse_compile(parser, options)
1248
- end
1249
- def optparse_install(parser, options)
1250
- parser.separator ''
1251
- parser.separator 'Install options:'
1252
- parser.on('--prefix PATH', 'install to alternate root location') do |val|
1253
- configuration.install_prefix = val
1254
- end
1255
- parser.on('--type TYPE', "install location mode (site,std,home)") do |val|
1256
- configuration.type = val
1257
- end
1258
- parser.on('-t', '--[no-]test', "run pre-installation tests") do |bool|
1259
- configuration.test = bool
1260
- end
1261
- end
1262
- def optparse_common(parser, options)
1263
- parser.separator ""
1264
- parser.separator "General options:"
1265
- parser.on("-q", "--quiet", "Suppress output") do
1266
- session.quiet = true
1267
- end
1268
- parser.on("-f", "--force", "Force operation") do
1269
- session.force = true
1270
- end
1271
- parser.on("--trace", "--verbose", "Watch execution") do |val|
1272
- session.trace = true
1273
- end
1274
- parser.on("--trial", "--no-harm", "Do not write to disk") do |val|
1275
- session.trial = true
1276
- end
1277
- parser.on("--debug", "Turn on debug mode") do |val|
1278
- $DEBUG = true
1279
- end
1280
- parser.separator ""
1281
- parser.separator "Inform options:"
1282
- parser.on_tail("-h", "--help", "display this help information") do
1283
- puts parser
1284
- exit
1285
- end
1286
- parser.on_tail("--version", "-v", "Show version") do
1287
- puts File.basename($0) + ' v' + Setup::VERSION #Version.join('.')
1288
- exit
1289
- end
1290
- parser.on_tail("--copyright", "Show copyright") do
1291
- puts Setup::COPYRIGHT #opyright
1292
- exit
1293
- end
1294
- end
1295
- def task_names
1296
- self.class.tasks.keys
1297
- end
1298
- def print_header
1299
- end
1300
- end
1301
- end
1302
- Setup::Command.run