scout 2.0.4 → 2.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1,4 +1,158 @@
1
- require 'config/requirements'
2
- require 'config/hoe' # setup Hoe + all gem configuration
3
-
4
- Dir['tasks/**/*.rake'].each { |rake| load rake }
1
+ require "rake/rdoctask"
2
+ require "rake/testtask"
3
+ require "rake/gempackagetask"
4
+ require "rake/contrib/rubyforgepublisher"
5
+ require "net/ssh"
6
+
7
+ require "rubygems"
8
+ require "rubyforge"
9
+
10
+ dir = File.dirname(__FILE__)
11
+ lib = File.join(dir, "lib", "scout.rb")
12
+ version = File.read(lib)[/^\s*VERSION\s*=\s*(['"])(\d\.\d\.\d)\1/, 2]
13
+ history = File.read("CHANGELOG").split(/^(===.*)/)
14
+ changes ||= history[0..2].join.strip
15
+
16
+ need_tar = true
17
+ need_zip = true
18
+
19
+ task :default => [:test]
20
+
21
+ Rake::TestTask.new do |test|
22
+ test.libs << "test"
23
+ test.test_files = [ "test/scout_test.rb" ]
24
+ test.verbose = true
25
+ end
26
+
27
+ Rake::RDocTask.new do |rdoc|
28
+ rdoc.main = "README"
29
+ rdoc.rdoc_dir = "doc/html"
30
+ rdoc.title = "Scout Client Documentation"
31
+ rdoc.rdoc_files.include( "README", "INSTALL",
32
+ "TODO", "CHANGELOG",
33
+ "AUTHORS", "COPYING",
34
+ "LICENSE", "lib/" )
35
+ end
36
+
37
+ spec = Gem::Specification.new do |spec|
38
+ spec.name = "scout"
39
+ spec.version = version
40
+
41
+ spec.platform = Gem::Platform::RUBY
42
+ spec.summary = "Scout makes monitoring and reporting on your web applications as flexible and simple as possible."
43
+
44
+ # TODO: test suite
45
+ # spec.test_suite_file = "test/ts_all.rb"
46
+ spec.files = Dir.glob("{lib,test,examples}/**/*.rb").
47
+ reject { |item| item.include?(".svn") } +
48
+ Dir.glob("{test,examples}/**/*.csv").
49
+ reject { |item| item.include?(".svn") } +
50
+ ["Rakefile", "setup.rb"]
51
+ spec.executables = ["scout"]
52
+
53
+ spec.has_rdoc = true
54
+ spec.extra_rdoc_files = %w[ AUTHORS COPYING README INSTALL TODO CHANGELOG
55
+ LICENSE ]
56
+ spec.rdoc_options << "--title" << "Scout Client Documentation" <<
57
+ "--main" << "README"
58
+
59
+ spec.require_path = "lib"
60
+
61
+ spec.add_dependency "elif"
62
+ # spec.add_dependency "hpricot", "=0.6"
63
+
64
+ spec.author = "Highgroove Studios"
65
+ spec.email = "scout@highgroove.com"
66
+ spec.rubyforge_project = "scout"
67
+ spec.homepage = "http://scoutapp.com"
68
+ spec.description = <<END_DESC
69
+ Scout makes monitoring and reporting on your web applications as flexible and simple as possible.
70
+
71
+ Scout is a product of Highgroove Studios.
72
+ END_DESC
73
+ end
74
+
75
+ Rake::GemPackageTask.new(spec) do |pkg|
76
+ pkg.need_zip = need_tar
77
+ pkg.need_tar = need_zip
78
+ end
79
+
80
+ desc "Publishes to Scout Gem Server and Rubyforge"
81
+ task :publish => [:package, :publish_scout, :publish_rubyforge]
82
+
83
+ desc "Publish Gem to Scout Gem Server"
84
+ task :publish_scout => [:package] do
85
+
86
+ puts "Publishing on Scout Server"
87
+ sh "scp -r pkg/*.gem " +
88
+ "deploy@gems.scoutapp.com:/var/www/gems/gems"
89
+ ssh = Net::SSH.start('gems.scoutapp.com','deploy')
90
+ ssh_shell = ssh.shell.sync
91
+ ssh_out = ssh_shell.send_command "/usr/bin/gem generate_index -d /var/www/gems"
92
+ puts "Published, and updated gem server." if ssh_out.stdout.empty? && !ssh_out.stderr
93
+ end
94
+
95
+ desc "Publishes Gem to Rubyforge"
96
+ task :publish_rubyforge => [:package] do
97
+ pkg = "pkg/#{spec.name}-#{version}"
98
+
99
+ if $DEBUG then
100
+ puts "release_id = rf.add_release #{spec.rubyforge_project.inspect}, #{spec.name.inspect}, #{spec.version.inspect}, \"#{pkg}.tgz\""
101
+ puts "rf.add_file #{spec.rubyforge_project.inspect}, #{spec.name.inspect}, release_id, \"#{pkg}.gem\""
102
+ end
103
+
104
+ puts "Publishing on RubyForge"
105
+ rf = RubyForge.new
106
+ rf.configure
107
+ puts "Logging in"
108
+ puts rf.inspect
109
+ rf.login
110
+
111
+ c = rf.userconfig
112
+ c["release_notes"] = spec.description if spec.description
113
+ c["release_changes"] = changes if changes
114
+ c["preformatted"] = true
115
+
116
+ files = [(need_tar ? "#{pkg}.tgz" : nil),
117
+ (need_zip ? "#{pkg}.zip" : nil),
118
+ "#{pkg}.gem"].compact
119
+
120
+ puts "Releasing #{spec.name} v. #{version}"
121
+ rf.add_release spec.rubyforge_project, spec.name, version, *files
122
+ end
123
+
124
+ desc "Upload current documentation to Scout Gem Server and RubyForge"
125
+ task :upload_docs => [:rdoc] do
126
+ sh "scp -r doc/html/* " +
127
+ "deploy@gems.scoutapp.com:/var/www/gems/docs"
128
+
129
+ config = YAML.load(File.read(File.expand_path("~/.rubyforge/user-config.yml")))
130
+ host = "#{config["username"]}@rubyforge.org"
131
+
132
+ remote_dir = "/var/www/gforge-projects/#{spec.rubyforge_project}"
133
+ local_dir = 'doc/html'
134
+
135
+ sh %{rsync -av --delete #{local_dir}/ #{host}:#{remote_dir}}
136
+ end
137
+
138
+ desc "Publish Beta Gem to Scout Gem Server"
139
+ task :publish_beta_scout => [:package] do
140
+
141
+ puts "Publishing on Scout Server"
142
+ sh "scp -r pkg/*.gem " +
143
+ "deploy@gems.scoutapp.com:/var/www/beta-gems/gems"
144
+ ssh = Net::SSH.start('gems.scoutapp.com','deploy')
145
+ ssh_shell = ssh.shell.sync
146
+ ssh_out = ssh_shell.send_command "/usr/bin/gem generate_index -d /var/www/beta-gems"
147
+ puts "Published, and updated gem server." if ssh_out.stdout.empty? && !ssh_out.stderr
148
+
149
+ sh "scp -r doc/html/* " +
150
+ "deploy@gems.scoutapp.com:/var/www/beta-gems/docs"
151
+
152
+ end
153
+
154
+
155
+ desc "Add new files to Subersion"
156
+ task :svn_add do
157
+ system "svn status | grep '^\?' | sed -e 's/? *//' | sed -e 's/ /\ /g' | xargs svn add"
158
+ end
data/TODO ADDED
@@ -0,0 +1,6 @@
1
+ = To Do List
2
+
3
+ The following is a list of planned expansions for the Scout Client:
4
+
5
+ * optionally find the "nice" command if available and use that in the
6
+ crontab output
data/lib/scout.rb CHANGED
@@ -1,6 +1,9 @@
1
1
  #!/usr/bin/env ruby -wKU
2
2
 
3
- require "scout/version"
4
3
  require "scout/command"
5
4
  require "scout/plugin"
6
5
  require "scout/server"
6
+
7
+ module Scout
8
+ VERSION = "2.0.5".freeze
9
+ end
data/lib/scout/command.rb CHANGED
@@ -92,7 +92,7 @@ module Scout
92
92
 
93
93
  opts.on( "-V", "--version",
94
94
  "Display the current version") do |version|
95
- puts Scout::VERSION::STRING
95
+ puts Scout::VERSION
96
96
  exit
97
97
  end
98
98
 
data/lib/scout/server.rb CHANGED
@@ -248,7 +248,7 @@ module Scout
248
248
 
249
249
  def urlify(url_name, options = Hash.new)
250
250
  return unless @server
251
- options.merge!(:client_version => Scout::VERSION::STRING)
251
+ options.merge!(:client_version => Scout::VERSION)
252
252
  URI.join( @server,
253
253
  URLS[url_name].
254
254
  gsub(/\bCLIENT_KEY\b/, @client_key).
data/setup.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  #
2
2
  # setup.rb
3
3
  #
4
- # Copyright (c) 2000-2005 Minero Aoki
4
+ # Copyright (c) 2000-2004 Minero Aoki
5
5
  #
6
6
  # This program is free software.
7
7
  # You can distribute/modify this program under the terms of
@@ -22,68 +22,176 @@ unless File.respond_to?(:read) # Ruby 1.6
22
22
  end
23
23
  end
24
24
 
25
- unless Errno.const_defined?(:ENOTEMPTY) # Windows?
26
- module Errno
27
- class ENOTEMPTY
28
- # We do not raise this exception, implementation is not needed.
29
- end
30
- end
31
- end
32
-
33
25
  def File.binread(fname)
34
26
  open(fname, 'rb') {|f|
35
27
  return f.read
36
28
  }
37
29
  end
38
30
 
39
- # for corrupted Windows' stat(2)
31
+ # for corrupted windows stat(2)
40
32
  def File.dir?(path)
41
33
  File.directory?((path[-1,1] == '/') ? path : path + '/')
42
34
  end
43
35
 
44
36
 
45
- class ConfigTable
37
+ class SetupError < StandardError; end
46
38
 
47
- include Enumerable
39
+ def setup_rb_error(msg)
40
+ raise SetupError, msg
41
+ end
48
42
 
49
- def initialize(rbconfig)
50
- @rbconfig = rbconfig
51
- @items = []
52
- @table = {}
53
- # options
54
- @install_prefix = nil
55
- @config_opt = nil
56
- @verbose = true
57
- @no_harm = false
43
+ #
44
+ # Config
45
+ #
46
+
47
+ if arg = ARGV.detect {|arg| /\A--rbconfig=/ =~ arg }
48
+ ARGV.delete(arg)
49
+ require arg.split(/=/, 2)[1]
50
+ $".push 'rbconfig.rb'
51
+ else
52
+ require 'rbconfig'
53
+ end
54
+
55
+ def multipackage_install?
56
+ FileTest.directory?(File.dirname($0) + '/packages')
57
+ end
58
+
59
+
60
+ class ConfigItem
61
+ def initialize(name, template, default, desc)
62
+ @name = name.freeze
63
+ @template = template
64
+ @value = default
65
+ @default = default.dup.freeze
66
+ @description = desc
58
67
  end
59
68
 
60
- attr_accessor :install_prefix
61
- attr_accessor :config_opt
69
+ attr_reader :name
70
+ attr_reader :description
62
71
 
63
- attr_writer :verbose
72
+ attr_accessor :default
73
+ alias help_default default
64
74
 
65
- def verbose?
66
- @verbose
75
+ def help_opt
76
+ "--#{@name}=#{@template}"
67
77
  end
68
78
 
69
- attr_writer :no_harm
79
+ def value
80
+ @value
81
+ end
70
82
 
71
- def no_harm?
72
- @no_harm
83
+ def eval(table)
84
+ @value.gsub(%r<\$([^/]+)>) { table[$1] }
73
85
  end
74
86
 
75
- def [](key)
76
- lookup(key).resolve(self)
87
+ def set(val)
88
+ @value = check(val)
77
89
  end
78
90
 
79
- def []=(key, val)
80
- lookup(key).set val
91
+ private
92
+
93
+ def check(val)
94
+ setup_rb_error "config: --#{name} requires argument" unless val
95
+ val
96
+ end
97
+ end
98
+
99
+ class BoolItem < ConfigItem
100
+ def config_type
101
+ 'bool'
81
102
  end
82
103
 
83
- def names
84
- @items.map {|i| i.name }
104
+ def help_opt
105
+ "--#{@name}"
85
106
  end
86
107
 
108
+ private
109
+
110
+ def check(val)
111
+ return 'yes' unless val
112
+ unless /\A(y(es)?|n(o)?|t(rue)?|f(alse))\z/i =~ val
113
+ setup_rb_error "config: --#{@name} accepts only yes/no for argument"
114
+ end
115
+ (/\Ay(es)?|\At(rue)/i =~ value) ? 'yes' : 'no'
116
+ end
117
+ end
118
+
119
+ class PathItem < ConfigItem
120
+ def config_type
121
+ 'path'
122
+ end
123
+
124
+ private
125
+
126
+ def check(path)
127
+ setup_rb_error "config: --#{@name} requires argument" unless path
128
+ path[0,1] == '$' ? path : File.expand_path(path)
129
+ end
130
+ end
131
+
132
+ class ProgramItem < ConfigItem
133
+ def config_type
134
+ 'program'
135
+ end
136
+ end
137
+
138
+ class SelectItem < ConfigItem
139
+ def initialize(name, template, default, desc)
140
+ super
141
+ @ok = template.split('/')
142
+ end
143
+
144
+ def config_type
145
+ 'select'
146
+ end
147
+
148
+ private
149
+
150
+ def check(val)
151
+ unless @ok.include?(val.strip)
152
+ setup_rb_error "config: use --#{@name}=#{@template} (#{val})"
153
+ end
154
+ val.strip
155
+ end
156
+ end
157
+
158
+ class PackageSelectionItem < ConfigItem
159
+ def initialize(name, template, default, help_default, desc)
160
+ super name, template, default, desc
161
+ @help_default = help_default
162
+ end
163
+
164
+ attr_reader :help_default
165
+
166
+ def config_type
167
+ 'package'
168
+ end
169
+
170
+ private
171
+
172
+ def check(val)
173
+ unless File.dir?("packages/#{val}")
174
+ setup_rb_error "config: no such package: #{val}"
175
+ end
176
+ val
177
+ end
178
+ end
179
+
180
+ class ConfigTable_class
181
+
182
+ def initialize(items)
183
+ @items = items
184
+ @table = {}
185
+ items.each do |i|
186
+ @table[i.name] = i
187
+ end
188
+ ALIASES.each do |ali, name|
189
+ @table[ali] = @table[name]
190
+ end
191
+ end
192
+
193
+ include Enumerable
194
+
87
195
  def each(&block)
88
196
  @items.each(&block)
89
197
  end
@@ -93,7 +201,7 @@ class ConfigTable
93
201
  end
94
202
 
95
203
  def lookup(name)
96
- @table[name] or setup_rb_error "no such config item: #{name}"
204
+ @table[name] or raise ArgumentError, "no such config item: #{name}"
97
205
  end
98
206
 
99
207
  def add(item)
@@ -108,24 +216,24 @@ class ConfigTable
108
216
  item
109
217
  end
110
218
 
111
- def load_script(path, inst = nil)
112
- if File.file?(path)
113
- MetaConfigEnvironment.new(self, inst).instance_eval File.read(path), path
114
- end
219
+ def new
220
+ dup()
115
221
  end
116
222
 
117
223
  def savefile
118
224
  '.config'
119
225
  end
120
226
 
121
- def load_savefile
227
+ def load
122
228
  begin
229
+ t = dup()
123
230
  File.foreach(savefile()) do |line|
124
231
  k, v = *line.split(/=/, 2)
125
- self[k] = v.strip
232
+ t[k] = v.strip
126
233
  end
234
+ t
127
235
  rescue Errno::ENOENT
128
- setup_rb_error $!.message + "\n#{File.basename($0)} config first"
236
+ setup_rb_error $!.message + "#{File.basename($0)} config first"
129
237
  end
130
238
  end
131
239
 
@@ -133,151 +241,117 @@ class ConfigTable
133
241
  @items.each {|i| i.value }
134
242
  File.open(savefile(), 'w') {|f|
135
243
  @items.each do |i|
136
- f.printf "%s=%s\n", i.name, i.value if i.value? and i.value
244
+ f.printf "%s=%s\n", i.name, i.value if i.value
137
245
  end
138
246
  }
139
247
  end
140
248
 
141
- def load_standard_entries
142
- standard_entries(@rbconfig).each do |ent|
143
- add ent
144
- end
249
+ def [](key)
250
+ lookup(key).eval(self)
145
251
  end
146
252
 
147
- def standard_entries(rbconfig)
148
- c = rbconfig
149
-
150
- rubypath = File.join(c['bindir'], c['ruby_install_name'] + c['EXEEXT'])
151
-
152
- major = c['MAJOR'].to_i
153
- minor = c['MINOR'].to_i
154
- teeny = c['TEENY'].to_i
155
- version = "#{major}.#{minor}"
156
-
157
- # ruby ver. >= 1.4.4?
158
- newpath_p = ((major >= 2) or
159
- ((major == 1) and
160
- ((minor >= 5) or
161
- ((minor == 4) and (teeny >= 4)))))
162
-
163
- if c['rubylibdir']
164
- # V > 1.6.3
165
- libruby = "#{c['prefix']}/lib/ruby"
166
- librubyver = c['rubylibdir']
167
- librubyverarch = c['archdir']
168
- siteruby = c['sitedir']
169
- siterubyver = c['sitelibdir']
170
- siterubyverarch = c['sitearchdir']
171
- elsif newpath_p
172
- # 1.4.4 <= V <= 1.6.3
173
- libruby = "#{c['prefix']}/lib/ruby"
174
- librubyver = "#{c['prefix']}/lib/ruby/#{version}"
175
- librubyverarch = "#{c['prefix']}/lib/ruby/#{version}/#{c['arch']}"
176
- siteruby = c['sitedir']
177
- siterubyver = "$siteruby/#{version}"
178
- siterubyverarch = "$siterubyver/#{c['arch']}"
179
- else
180
- # V < 1.4.4
181
- libruby = "#{c['prefix']}/lib/ruby"
182
- librubyver = "#{c['prefix']}/lib/ruby/#{version}"
183
- librubyverarch = "#{c['prefix']}/lib/ruby/#{version}/#{c['arch']}"
184
- siteruby = "#{c['prefix']}/lib/ruby/#{version}/site_ruby"
185
- siterubyver = siteruby
186
- siterubyverarch = "$siterubyver/#{c['arch']}"
187
- end
188
- parameterize = lambda {|path|
189
- path.sub(/\A#{Regexp.quote(c['prefix'])}/, '$prefix')
190
- }
191
-
192
- if arg = c['configure_args'].split.detect {|arg| /--with-make-prog=/ =~ arg }
193
- makeprog = arg.sub(/'/, '').split(/=/, 2)[1]
194
- else
195
- makeprog = 'make'
196
- end
197
-
198
- [
199
- ExecItem.new('installdirs', 'std/site/home',
200
- 'std: install under libruby; site: install under site_ruby; home: install under $HOME')\
201
- {|val, table|
202
- case val
203
- when 'std'
204
- table['rbdir'] = '$librubyver'
205
- table['sodir'] = '$librubyverarch'
206
- when 'site'
207
- table['rbdir'] = '$siterubyver'
208
- table['sodir'] = '$siterubyverarch'
209
- when 'home'
210
- setup_rb_error '$HOME was not set' unless ENV['HOME']
211
- table['prefix'] = ENV['HOME']
212
- table['rbdir'] = '$libdir/ruby'
213
- table['sodir'] = '$libdir/ruby'
214
- end
215
- },
216
- PathItem.new('prefix', 'path', c['prefix'],
217
- 'path prefix of target environment'),
218
- PathItem.new('bindir', 'path', parameterize.call(c['bindir']),
219
- 'the directory for commands'),
220
- PathItem.new('libdir', 'path', parameterize.call(c['libdir']),
221
- 'the directory for libraries'),
222
- PathItem.new('datadir', 'path', parameterize.call(c['datadir']),
223
- 'the directory for shared data'),
224
- PathItem.new('mandir', 'path', parameterize.call(c['mandir']),
225
- 'the directory for man pages'),
226
- PathItem.new('sysconfdir', 'path', parameterize.call(c['sysconfdir']),
227
- 'the directory for system configuration files'),
228
- PathItem.new('localstatedir', 'path', parameterize.call(c['localstatedir']),
229
- 'the directory for local state data'),
230
- PathItem.new('libruby', 'path', libruby,
231
- 'the directory for ruby libraries'),
232
- PathItem.new('librubyver', 'path', librubyver,
233
- 'the directory for standard ruby libraries'),
234
- PathItem.new('librubyverarch', 'path', librubyverarch,
235
- 'the directory for standard ruby extensions'),
236
- PathItem.new('siteruby', 'path', siteruby,
237
- 'the directory for version-independent aux ruby libraries'),
238
- PathItem.new('siterubyver', 'path', siterubyver,
239
- 'the directory for aux ruby libraries'),
240
- PathItem.new('siterubyverarch', 'path', siterubyverarch,
241
- 'the directory for aux ruby binaries'),
242
- PathItem.new('rbdir', 'path', '$siterubyver',
243
- 'the directory for ruby scripts'),
244
- PathItem.new('sodir', 'path', '$siterubyverarch',
245
- 'the directory for ruby extentions'),
246
- PathItem.new('rubypath', 'path', rubypath,
247
- 'the path to set to #! line'),
248
- ProgramItem.new('rubyprog', 'name', rubypath,
249
- 'the ruby program using for installation'),
250
- ProgramItem.new('makeprog', 'name', makeprog,
251
- 'the make program to compile ruby extentions'),
252
- SelectItem.new('shebang', 'all/ruby/never', 'ruby',
253
- 'shebang line (#!) editing mode'),
254
- BoolItem.new('without-ext', 'yes/no', 'no',
255
- 'does not compile/install ruby extentions')
256
- ]
257
- end
258
- private :standard_entries
259
-
260
- def load_multipackage_entries
261
- multipackage_entries().each do |ent|
262
- add ent
263
- end
253
+ def []=(key, val)
254
+ lookup(key).set val
264
255
  end
265
256
 
266
- def multipackage_entries
267
- [
268
- PackageSelectionItem.new('with', 'name,name...', '', 'ALL',
269
- 'package names that you want to install'),
270
- PackageSelectionItem.new('without', 'name,name...', '', 'NONE',
271
- 'package names that you do not want to install')
272
- ]
273
- end
274
- private :multipackage_entries
257
+ end
275
258
 
259
+ c = ::Config::CONFIG
260
+
261
+ rubypath = c['bindir'] + '/' + c['ruby_install_name']
262
+
263
+ major = c['MAJOR'].to_i
264
+ minor = c['MINOR'].to_i
265
+ teeny = c['TEENY'].to_i
266
+ version = "#{major}.#{minor}"
267
+
268
+ # ruby ver. >= 1.4.4?
269
+ newpath_p = ((major >= 2) or
270
+ ((major == 1) and
271
+ ((minor >= 5) or
272
+ ((minor == 4) and (teeny >= 4)))))
273
+
274
+ if c['rubylibdir']
275
+ # V < 1.6.3
276
+ _stdruby = c['rubylibdir']
277
+ _siteruby = c['sitedir']
278
+ _siterubyver = c['sitelibdir']
279
+ _siterubyverarch = c['sitearchdir']
280
+ elsif newpath_p
281
+ # 1.4.4 <= V <= 1.6.3
282
+ _stdruby = "$prefix/lib/ruby/#{version}"
283
+ _siteruby = c['sitedir']
284
+ _siterubyver = "$siteruby/#{version}"
285
+ _siterubyverarch = "$siterubyver/#{c['arch']}"
286
+ else
287
+ # V < 1.4.4
288
+ _stdruby = "$prefix/lib/ruby/#{version}"
289
+ _siteruby = "$prefix/lib/ruby/#{version}/site_ruby"
290
+ _siterubyver = _siteruby
291
+ _siterubyverarch = "$siterubyver/#{c['arch']}"
292
+ end
293
+ libdir = '-* dummy libdir *-'
294
+ stdruby = '-* dummy rubylibdir *-'
295
+ siteruby = '-* dummy site_ruby *-'
296
+ siterubyver = '-* dummy site_ruby version *-'
297
+ parameterize = lambda {|path|
298
+ path.sub(/\A#{Regexp.quote(c['prefix'])}/, '$prefix')\
299
+ .sub(/\A#{Regexp.quote(libdir)}/, '$libdir')\
300
+ .sub(/\A#{Regexp.quote(stdruby)}/, '$stdruby')\
301
+ .sub(/\A#{Regexp.quote(siteruby)}/, '$siteruby')\
302
+ .sub(/\A#{Regexp.quote(siterubyver)}/, '$siterubyver')
303
+ }
304
+ libdir = parameterize.call(c['libdir'])
305
+ stdruby = parameterize.call(_stdruby)
306
+ siteruby = parameterize.call(_siteruby)
307
+ siterubyver = parameterize.call(_siterubyver)
308
+ siterubyverarch = parameterize.call(_siterubyverarch)
309
+
310
+ if arg = c['configure_args'].split.detect {|arg| /--with-make-prog=/ =~ arg }
311
+ makeprog = arg.sub(/'/, '').split(/=/, 2)[1]
312
+ else
313
+ makeprog = 'make'
314
+ end
315
+
316
+ common_conf = [
317
+ PathItem.new('prefix', 'path', c['prefix'],
318
+ 'path prefix of target environment'),
319
+ PathItem.new('bindir', 'path', parameterize.call(c['bindir']),
320
+ 'the directory for commands'),
321
+ PathItem.new('libdir', 'path', libdir,
322
+ 'the directory for libraries'),
323
+ PathItem.new('datadir', 'path', parameterize.call(c['datadir']),
324
+ 'the directory for shared data'),
325
+ PathItem.new('mandir', 'path', parameterize.call(c['mandir']),
326
+ 'the directory for man pages'),
327
+ PathItem.new('sysconfdir', 'path', parameterize.call(c['sysconfdir']),
328
+ 'the directory for man pages'),
329
+ PathItem.new('stdruby', 'path', stdruby,
330
+ 'the directory for standard ruby libraries'),
331
+ PathItem.new('siteruby', 'path', siteruby,
332
+ 'the directory for version-independent aux ruby libraries'),
333
+ PathItem.new('siterubyver', 'path', siterubyver,
334
+ 'the directory for aux ruby libraries'),
335
+ PathItem.new('siterubyverarch', 'path', siterubyverarch,
336
+ 'the directory for aux ruby binaries'),
337
+ PathItem.new('rbdir', 'path', '$siterubyver',
338
+ 'the directory for ruby scripts'),
339
+ PathItem.new('sodir', 'path', '$siterubyverarch',
340
+ 'the directory for ruby extentions'),
341
+ PathItem.new('rubypath', 'path', rubypath,
342
+ 'the path to set to #! line'),
343
+ ProgramItem.new('rubyprog', 'name', rubypath,
344
+ 'the ruby program using for installation'),
345
+ ProgramItem.new('makeprog', 'name', makeprog,
346
+ 'the make program to compile ruby extentions'),
347
+ SelectItem.new('shebang', 'all/ruby/never', 'ruby',
348
+ 'shebang line (#!) editing mode'),
349
+ BoolItem.new('without-ext', 'yes/no', 'no',
350
+ 'does not compile/install ruby extentions')
351
+ ]
352
+ class ConfigTable_class # open again
276
353
  ALIASES = {
277
- 'std-ruby' => 'librubyver',
278
- 'stdruby' => 'librubyver',
279
- 'rubylibdir' => 'librubyver',
280
- 'archdir' => 'librubyverarch',
354
+ 'std-ruby' => 'stdruby',
281
355
  'site-ruby-common' => 'siteruby', # For backward compatibility
282
356
  'site-ruby' => 'siterubyver', # For backward compatibility
283
357
  'bin-dir' => 'bindir',
@@ -291,248 +365,78 @@ class ConfigTable
291
365
  'make-prog' => 'makeprog',
292
366
  'make' => 'makeprog'
293
367
  }
368
+ end
369
+ multipackage_conf = [
370
+ PackageSelectionItem.new('with', 'name,name...', '', 'ALL',
371
+ 'package names that you want to install'),
372
+ PackageSelectionItem.new('without', 'name,name...', '', 'NONE',
373
+ 'package names that you do not want to install')
374
+ ]
375
+ if multipackage_install?
376
+ ConfigTable = ConfigTable_class.new(common_conf + multipackage_conf)
377
+ else
378
+ ConfigTable = ConfigTable_class.new(common_conf)
379
+ end
294
380
 
295
- def fixup
296
- ALIASES.each do |ali, name|
297
- @table[ali] = @table[name]
298
- end
299
- @items.freeze
300
- @table.freeze
301
- @options_re = /\A--(#{@table.keys.join('|')})(?:=(.*))?\z/
302
- end
303
381
 
304
- def parse_opt(opt)
305
- m = @options_re.match(opt) or setup_rb_error "config: unknown option #{opt}"
306
- m.to_a[1,2]
307
- end
382
+ module MetaConfigAPI
308
383
 
309
- def dllext
310
- @rbconfig['DLEXT']
384
+ def eval_file_ifexist(fname)
385
+ instance_eval File.read(fname), fname, 1 if File.file?(fname)
311
386
  end
312
387
 
313
- def value_config?(name)
314
- lookup(name).value?
388
+ def config_names
389
+ ConfigTable.map {|i| i.name }
315
390
  end
316
391
 
317
- class Item
318
- def initialize(name, template, default, desc)
319
- @name = name.freeze
320
- @template = template
321
- @value = default
322
- @default = default
323
- @description = desc
324
- end
325
-
326
- attr_reader :name
327
- attr_reader :description
328
-
329
- attr_accessor :default
330
- alias help_default default
331
-
332
- def help_opt
333
- "--#{@name}=#{@template}"
334
- end
335
-
336
- def value?
337
- true
338
- end
339
-
340
- def value
341
- @value
342
- end
343
-
344
- def resolve(table)
345
- @value.gsub(%r<\$([^/]+)>) { table[$1] }
346
- end
347
-
348
- def set(val)
349
- @value = check(val)
350
- end
351
-
352
- private
353
-
354
- def check(val)
355
- setup_rb_error "config: --#{name} requires argument" unless val
356
- val
357
- end
392
+ def config?(name)
393
+ ConfigTable.key?(name)
358
394
  end
359
395
 
360
- class BoolItem < Item
361
- def config_type
362
- 'bool'
363
- end
364
-
365
- def help_opt
366
- "--#{@name}"
367
- end
368
-
369
- private
370
-
371
- def check(val)
372
- return 'yes' unless val
373
- case val
374
- when /\Ay(es)?\z/i, /\At(rue)?\z/i then 'yes'
375
- when /\An(o)?\z/i, /\Af(alse)\z/i then 'no'
376
- else
377
- setup_rb_error "config: --#{@name} accepts only yes/no for argument"
378
- end
379
- end
396
+ def bool_config?(name)
397
+ ConfigTable.lookup(name).config_type == 'bool'
380
398
  end
381
399
 
382
- class PathItem < Item
383
- def config_type
384
- 'path'
385
- end
386
-
387
- private
388
-
389
- def check(path)
390
- setup_rb_error "config: --#{@name} requires argument" unless path
391
- path[0,1] == '$' ? path : File.expand_path(path)
392
- end
400
+ def path_config?(name)
401
+ ConfigTable.lookup(name).config_type == 'path'
393
402
  end
394
403
 
395
- class ProgramItem < Item
396
- def config_type
397
- 'program'
404
+ def value_config?(name)
405
+ case ConfigTable.lookup(name).config_type
406
+ when 'bool', 'path'
407
+ true
408
+ else
409
+ false
398
410
  end
399
411
  end
400
412
 
401
- class SelectItem < Item
402
- def initialize(name, selection, default, desc)
403
- super
404
- @ok = selection.split('/')
405
- end
406
-
407
- def config_type
408
- 'select'
409
- end
410
-
411
- private
412
-
413
- def check(val)
414
- unless @ok.include?(val.strip)
415
- setup_rb_error "config: use --#{@name}=#{@template} (#{val})"
416
- end
417
- val.strip
418
- end
413
+ def add_config(item)
414
+ ConfigTable.add item
419
415
  end
420
416
 
421
- class ExecItem < Item
422
- def initialize(name, selection, desc, &block)
423
- super name, selection, nil, desc
424
- @ok = selection.split('/')
425
- @action = block
426
- end
427
-
428
- def config_type
429
- 'exec'
430
- end
431
-
432
- def value?
433
- false
434
- end
435
-
436
- def resolve(table)
437
- setup_rb_error "$#{name()} wrongly used as option value"
438
- end
439
-
440
- undef set
441
-
442
- def evaluate(val, table)
443
- v = val.strip.downcase
444
- unless @ok.include?(v)
445
- setup_rb_error "invalid option --#{@name}=#{val} (use #{@template})"
446
- end
447
- @action.call v, table
448
- end
417
+ def add_bool_config(name, default, desc)
418
+ ConfigTable.add BoolItem.new(name, 'yes/no', default ? 'yes' : 'no', desc)
449
419
  end
450
420
 
451
- class PackageSelectionItem < Item
452
- def initialize(name, template, default, help_default, desc)
453
- super name, template, default, desc
454
- @help_default = help_default
455
- end
456
-
457
- attr_reader :help_default
458
-
459
- def config_type
460
- 'package'
461
- end
462
-
463
- private
464
-
465
- def check(val)
466
- unless File.dir?("packages/#{val}")
467
- setup_rb_error "config: no such package: #{val}"
468
- end
469
- val
470
- end
421
+ def add_path_config(name, default, desc)
422
+ ConfigTable.add PathItem.new(name, 'path', default, desc)
471
423
  end
472
424
 
473
- class MetaConfigEnvironment
474
- def initialize(config, installer)
475
- @config = config
476
- @installer = installer
477
- end
478
-
479
- def config_names
480
- @config.names
481
- end
482
-
483
- def config?(name)
484
- @config.key?(name)
485
- end
486
-
487
- def bool_config?(name)
488
- @config.lookup(name).config_type == 'bool'
489
- end
490
-
491
- def path_config?(name)
492
- @config.lookup(name).config_type == 'path'
493
- end
494
-
495
- def value_config?(name)
496
- @config.lookup(name).config_type != 'exec'
497
- end
498
-
499
- def add_config(item)
500
- @config.add item
501
- end
502
-
503
- def add_bool_config(name, default, desc)
504
- @config.add BoolItem.new(name, 'yes/no', default ? 'yes' : 'no', desc)
505
- end
506
-
507
- def add_path_config(name, default, desc)
508
- @config.add PathItem.new(name, 'path', default, desc)
509
- end
510
-
511
- def set_config_default(name, default)
512
- @config.lookup(name).default = default
513
- end
514
-
515
- def remove_config(name)
516
- @config.remove(name)
517
- end
518
-
519
- # For only multipackage
520
- def packages
521
- raise '[setup.rb fatal] multi-package metaconfig API packages() called for single-package; contact application package vendor' unless @installer
522
- @installer.packages
523
- end
425
+ def set_config_default(name, default)
426
+ ConfigTable.lookup(name).default = default
427
+ end
524
428
 
525
- # For only multipackage
526
- def declare_packages(list)
527
- raise '[setup.rb fatal] multi-package metaconfig API declare_packages() called for single-package; contact application package vendor' unless @installer
528
- @installer.packages = list
529
- end
429
+ def remove_config(name)
430
+ ConfigTable.remove(name)
530
431
  end
531
432
 
532
- end # class ConfigTable
433
+ end
434
+
533
435
 
436
+ #
437
+ # File Operations
438
+ #
534
439
 
535
- # This module requires: #verbose?, #no_harm?
536
440
  module FileOperations
537
441
 
538
442
  def mkdir_p(dirname, prefix = nil)
@@ -540,7 +444,7 @@ module FileOperations
540
444
  $stderr.puts "mkdir -p #{dirname}" if verbose?
541
445
  return if no_harm?
542
446
 
543
- # Does not check '/', it's too abnormal.
447
+ # does not check '/'... it's too abnormal case
544
448
  dirs = File.expand_path(dirname).split(%r<(?=/)>)
545
449
  if /\A[a-z]:\z/i =~ dirs[0]
546
450
  disk = dirs.shift
@@ -552,73 +456,49 @@ module FileOperations
552
456
  end
553
457
  end
554
458
 
555
- def rm_f(path)
556
- $stderr.puts "rm -f #{path}" if verbose?
557
- return if no_harm?
558
- force_remove_file path
559
- end
560
-
561
- def rm_rf(path)
562
- $stderr.puts "rm -rf #{path}" if verbose?
459
+ def rm_f(fname)
460
+ $stderr.puts "rm -f #{fname}" if verbose?
563
461
  return if no_harm?
564
- remove_tree path
565
- end
566
462
 
567
- def remove_tree(path)
568
- if File.symlink?(path)
569
- remove_file path
570
- elsif File.dir?(path)
571
- remove_tree0 path
572
- else
573
- force_remove_file path
463
+ if File.exist?(fname) or File.symlink?(fname)
464
+ File.chmod 0777, fname
465
+ File.unlink fname
574
466
  end
575
467
  end
576
468
 
577
- def remove_tree0(path)
578
- Dir.foreach(path) do |ent|
579
- next if ent == '.'
580
- next if ent == '..'
581
- entpath = "#{path}/#{ent}"
582
- if File.symlink?(entpath)
583
- remove_file entpath
584
- elsif File.dir?(entpath)
585
- remove_tree0 entpath
469
+ def rm_rf(dn)
470
+ $stderr.puts "rm -rf #{dn}" if verbose?
471
+ return if no_harm?
472
+
473
+ Dir.chdir dn
474
+ Dir.foreach('.') do |fn|
475
+ next if fn == '.'
476
+ next if fn == '..'
477
+ if File.dir?(fn)
478
+ verbose_off {
479
+ rm_rf fn
480
+ }
586
481
  else
587
- force_remove_file entpath
482
+ verbose_off {
483
+ rm_f fn
484
+ }
588
485
  end
589
486
  end
590
- begin
591
- Dir.rmdir path
592
- rescue Errno::ENOTEMPTY
593
- # directory may not be empty
594
- end
487
+ Dir.chdir '..'
488
+ Dir.rmdir dn
595
489
  end
596
490
 
597
491
  def move_file(src, dest)
598
- force_remove_file dest
492
+ File.unlink dest if File.exist?(dest)
599
493
  begin
600
494
  File.rename src, dest
601
495
  rescue
602
- File.open(dest, 'wb') {|f|
603
- f.write File.binread(src)
604
- }
496
+ File.open(dest, 'wb') {|f| f.write File.binread(src) }
605
497
  File.chmod File.stat(src).mode, dest
606
498
  File.unlink src
607
499
  end
608
500
  end
609
501
 
610
- def force_remove_file(path)
611
- begin
612
- remove_file path
613
- rescue
614
- end
615
- end
616
-
617
- def remove_file(path)
618
- File.chmod 0777, path
619
- File.unlink path
620
- end
621
-
622
502
  def install(from, dest, mode, prefix = nil)
623
503
  $stderr.puts "install #{from} #{dest}" if verbose?
624
504
  return if no_harm?
@@ -650,42 +530,66 @@ module FileOperations
650
530
  new_content != File.binread(path)
651
531
  end
652
532
 
653
- def command(*args)
654
- $stderr.puts args.join(' ') if verbose?
655
- system(*args) or raise RuntimeError,
656
- "system(#{args.map{|a| a.inspect }.join(' ')}) failed"
533
+ def command(str)
534
+ $stderr.puts str if verbose?
535
+ system str or raise RuntimeError, "'system #{str}' failed"
657
536
  end
658
537
 
659
- def ruby(*args)
660
- command config('rubyprog'), *args
538
+ def ruby(str)
539
+ command config('rubyprog') + ' ' + str
661
540
  end
662
541
 
663
- def make(task = nil)
664
- command(*[config('makeprog'), task].compact)
542
+ def make(task = '')
543
+ command config('makeprog') + ' ' + task
665
544
  end
666
545
 
667
546
  def extdir?(dir)
668
- File.exist?("#{dir}/MANIFEST") or File.exist?("#{dir}/extconf.rb")
547
+ File.exist?(dir + '/MANIFEST')
669
548
  end
670
549
 
671
- def files_of(dir)
672
- Dir.open(dir) {|d|
673
- return d.select {|ent| File.file?("#{dir}/#{ent}") }
550
+ def all_files_in(dirname)
551
+ Dir.open(dirname) {|d|
552
+ return d.select {|ent| File.file?("#{dirname}/#{ent}") }
674
553
  }
675
554
  end
676
555
 
677
- DIR_REJECT = %w( . .. CVS SCCS RCS CVS.adm .svn )
556
+ REJECT_DIRS = %w(
557
+ CVS SCCS RCS CVS.adm .svn
558
+ )
678
559
 
679
- def directories_of(dir)
680
- Dir.open(dir) {|d|
681
- return d.select {|ent| File.dir?("#{dir}/#{ent}") } - DIR_REJECT
560
+ def all_dirs_in(dirname)
561
+ Dir.open(dirname) {|d|
562
+ return d.select {|n| File.dir?("#{dirname}/#{n}") } - %w(. ..) - REJECT_DIRS
682
563
  }
683
564
  end
684
565
 
685
566
  end
686
567
 
687
568
 
688
- # This module requires: #srcdir_root, #objdir_root, #relpath
569
+ #
570
+ # Main Installer
571
+ #
572
+
573
+ module HookUtils
574
+
575
+ def run_hook(name)
576
+ try_run_hook "#{curr_srcdir()}/#{name}" or
577
+ try_run_hook "#{curr_srcdir()}/#{name}.rb"
578
+ end
579
+
580
+ def try_run_hook(fname)
581
+ return false unless File.file?(fname)
582
+ begin
583
+ instance_eval File.read(fname), fname, 1
584
+ rescue
585
+ setup_rb_error "hook #{fname} failed:\n" + $!.message
586
+ end
587
+ true
588
+ end
589
+
590
+ end
591
+
592
+
689
593
  module HookScriptAPI
690
594
 
691
595
  def get_config(key)
@@ -694,7 +598,6 @@ module HookScriptAPI
694
598
 
695
599
  alias config get_config
696
600
 
697
- # obsolete: use metaconfig to change configuration
698
601
  def set_config(key, val)
699
602
  @config[key] = val
700
603
  end
@@ -703,6 +606,10 @@ module HookScriptAPI
703
606
  # srcdir/objdir (works only in the package directory)
704
607
  #
705
608
 
609
+ #abstract srcdir_root
610
+ #abstract objdir_root
611
+ #abstract relpath
612
+
706
613
  def curr_srcdir
707
614
  "#{srcdir_root()}/#{relpath()}"
708
615
  end
@@ -724,7 +631,7 @@ module HookScriptAPI
724
631
  end
725
632
 
726
633
  def srcfile?(path)
727
- File.file?(srcfile(path))
634
+ File.file? srcfile(path)
728
635
  end
729
636
 
730
637
  def srcentries(path = '.')
@@ -750,8 +657,8 @@ end
750
657
 
751
658
  class ToplevelInstaller
752
659
 
753
- Version = '3.4.1'
754
- Copyright = 'Copyright (c) 2000-2005 Minero Aoki'
660
+ Version = '3.3.1'
661
+ Copyright = 'Copyright (c) 2000-2004 Minero Aoki'
755
662
 
756
663
  TASKS = [
757
664
  [ 'all', 'do config, setup, then install' ],
@@ -759,44 +666,27 @@ class ToplevelInstaller
759
666
  [ 'show', 'shows current configuration' ],
760
667
  [ 'setup', 'compiles ruby extentions and others' ],
761
668
  [ 'install', 'installs files' ],
762
- [ 'test', 'run all tests in test/' ],
763
669
  [ 'clean', "does `make clean' for each extention" ],
764
670
  [ 'distclean',"does `make distclean' for each extention" ]
765
671
  ]
766
672
 
767
673
  def ToplevelInstaller.invoke
768
- config = ConfigTable.new(load_rbconfig())
769
- config.load_standard_entries
770
- config.load_multipackage_entries if multipackage?
771
- config.fixup
772
- klass = (multipackage?() ? ToplevelInstallerMulti : ToplevelInstaller)
773
- klass.new(File.dirname($0), config).invoke
674
+ instance().invoke
774
675
  end
775
676
 
776
- def ToplevelInstaller.multipackage?
777
- File.dir?(File.dirname($0) + '/packages')
778
- end
677
+ @singleton = nil
779
678
 
780
- def ToplevelInstaller.load_rbconfig
781
- if arg = ARGV.detect {|arg| /\A--rbconfig=/ =~ arg }
782
- ARGV.delete(arg)
783
- load File.expand_path(arg.split(/=/, 2)[1])
784
- $".push 'rbconfig.rb'
785
- else
786
- require 'rbconfig'
787
- end
788
- ::Config::CONFIG
679
+ def ToplevelInstaller.instance
680
+ @singleton ||= new(File.dirname($0))
681
+ @singleton
789
682
  end
790
683
 
791
- def initialize(ardir_root, config)
792
- @ardir = File.expand_path(ardir_root)
793
- @config = config
794
- # cache
795
- @valid_task_re = nil
796
- end
684
+ include MetaConfigAPI
797
685
 
798
- def config(key)
799
- @config[key]
686
+ def initialize(ardir_root)
687
+ @config = nil
688
+ @options = { 'verbose' => true }
689
+ @ardir = File.expand_path(ardir_root)
800
690
  end
801
691
 
802
692
  def inspect
@@ -807,20 +697,14 @@ class ToplevelInstaller
807
697
  run_metaconfigs
808
698
  case task = parsearg_global()
809
699
  when nil, 'all'
700
+ @config = load_config('config')
810
701
  parsearg_config
811
702
  init_installers
812
703
  exec_config
813
704
  exec_setup
814
705
  exec_install
815
706
  else
816
- case task
817
- when 'config', 'test'
818
- ;
819
- when 'clean', 'distclean'
820
- @config.load_savefile if File.exist?(@config.savefile)
821
- else
822
- @config.load_savefile
823
- end
707
+ @config = load_config(task)
824
708
  __send__ "parsearg_#{task}"
825
709
  init_installers
826
710
  __send__ "exec_#{task}"
@@ -828,11 +712,25 @@ class ToplevelInstaller
828
712
  end
829
713
 
830
714
  def run_metaconfigs
831
- @config.load_script "#{@ardir}/metaconfig"
715
+ eval_file_ifexist "#{@ardir}/metaconfig"
716
+ end
717
+
718
+ def load_config(task)
719
+ case task
720
+ when 'config'
721
+ ConfigTable.new
722
+ when 'clean', 'distclean'
723
+ if File.exist?(ConfigTable.savefile)
724
+ then ConfigTable.load
725
+ else ConfigTable.new
726
+ end
727
+ else
728
+ ConfigTable.load
729
+ end
832
730
  end
833
731
 
834
732
  def init_installers
835
- @installer = Installer.new(@config, @ardir, File.expand_path('.'))
733
+ @installer = Installer.new(@config, @options, @ardir, File.expand_path('.'))
836
734
  end
837
735
 
838
736
  #
@@ -856,89 +754,78 @@ class ToplevelInstaller
856
754
  #
857
755
 
858
756
  def parsearg_global
757
+ valid_task = /\A(?:#{TASKS.map {|task,desc| task }.join '|'})\z/
758
+
859
759
  while arg = ARGV.shift
860
760
  case arg
861
761
  when /\A\w+\z/
862
- setup_rb_error "invalid task: #{arg}" unless valid_task?(arg)
762
+ setup_rb_error "invalid task: #{arg}" unless valid_task =~ arg
863
763
  return arg
764
+
864
765
  when '-q', '--quiet'
865
- @config.verbose = false
866
- when '--verbose'
867
- @config.verbose = true
868
- when '--help'
766
+ @options['verbose'] = false
767
+
768
+ when '--verbose'
769
+ @options['verbose'] = true
770
+
771
+ when '-h', '--help'
869
772
  print_usage $stdout
870
773
  exit 0
871
- when '--version'
774
+
775
+ when '-v', '--version'
872
776
  puts "#{File.basename($0)} version #{Version}"
873
777
  exit 0
778
+
874
779
  when '--copyright'
875
780
  puts Copyright
876
781
  exit 0
782
+
877
783
  else
878
784
  setup_rb_error "unknown global option '#{arg}'"
879
785
  end
880
786
  end
881
- nil
882
- end
883
787
 
884
- def valid_task?(t)
885
- valid_task_re() =~ t
788
+ nil
886
789
  end
887
790
 
888
- def valid_task_re
889
- @valid_task_re ||= /\A(?:#{TASKS.map {|task,desc| task }.join('|')})\z/
890
- end
891
791
 
892
792
  def parsearg_no_options
893
793
  unless ARGV.empty?
894
- task = caller(0).first.slice(%r<`parsearg_(\w+)'>, 1)
895
- setup_rb_error "#{task}: unknown options: #{ARGV.join(' ')}"
794
+ setup_rb_error "#{task}: unknown options: #{ARGV.join ' '}"
896
795
  end
897
796
  end
898
797
 
899
798
  alias parsearg_show parsearg_no_options
900
799
  alias parsearg_setup parsearg_no_options
901
- alias parsearg_test parsearg_no_options
902
800
  alias parsearg_clean parsearg_no_options
903
801
  alias parsearg_distclean parsearg_no_options
904
802
 
905
803
  def parsearg_config
906
- evalopt = []
907
- set = []
908
- @config.config_opt = []
804
+ re = /\A--(#{ConfigTable.map {|i| i.name }.join('|')})(?:=(.*))?\z/
805
+ @options['config-opt'] = []
806
+
909
807
  while i = ARGV.shift
910
808
  if /\A--?\z/ =~ i
911
- @config.config_opt = ARGV.dup
809
+ @options['config-opt'] = ARGV.dup
912
810
  break
913
811
  end
914
- name, value = *@config.parse_opt(i)
915
- if @config.value_config?(name)
916
- @config[name] = value
917
- else
918
- evalopt.push [name, value]
919
- end
920
- set.push name
921
- end
922
- evalopt.each do |name, value|
923
- @config.lookup(name).evaluate value, @config
924
- end
925
- # Check if configuration is valid
926
- set.each do |n|
927
- @config[n] if @config.value_config?(n)
812
+ m = re.match(i) or setup_rb_error "config: unknown option #{i}"
813
+ name, value = *m.to_a[1,2]
814
+ @config[name] = value
928
815
  end
929
816
  end
930
817
 
931
818
  def parsearg_install
932
- @config.no_harm = false
933
- @config.install_prefix = ''
819
+ @options['no-harm'] = false
820
+ @options['install-prefix'] = ''
934
821
  while a = ARGV.shift
935
822
  case a
936
- when '--no-harm'
937
- @config.no_harm = true
938
- when /\A--prefix=/
939
- path = a.split(/=/, 2)[1]
823
+ when /\A--no-harm\z/
824
+ @options['no-harm'] = true
825
+ when /\A--prefix=(.*)\z/
826
+ path = $1
940
827
  path = File.expand_path(path) unless path[0,1] == '/'
941
- @config.install_prefix = path
828
+ @options['install-prefix'] = path
942
829
  else
943
830
  setup_rb_error "install: unknown option #{a}"
944
831
  end
@@ -960,8 +847,8 @@ class ToplevelInstaller
960
847
  out.puts 'Global options:'
961
848
  out.printf fmt, '-q,--quiet', 'suppress message outputs'
962
849
  out.printf fmt, ' --verbose', 'output messages verbosely'
963
- out.printf fmt, ' --help', 'print this message'
964
- out.printf fmt, ' --version', 'print version and quit'
850
+ out.printf fmt, '-h,--help', 'print this message'
851
+ out.printf fmt, '-v,--version', 'print version and quit'
965
852
  out.printf fmt, ' --copyright', 'print copyright and quit'
966
853
  out.puts
967
854
  out.puts 'Tasks:'
@@ -972,14 +859,14 @@ class ToplevelInstaller
972
859
  fmt = " %-24s %s [%s]\n"
973
860
  out.puts
974
861
  out.puts 'Options for CONFIG or ALL:'
975
- @config.each do |item|
862
+ ConfigTable.each do |item|
976
863
  out.printf fmt, item.help_opt, item.description, item.help_default
977
864
  end
978
865
  out.printf fmt, '--rbconfig=path', 'rbconfig.rb to load',"running ruby's"
979
866
  out.puts
980
867
  out.puts 'Options for INSTALL:'
981
868
  out.printf fmt, '--no-harm', 'only display what to do if given', 'off'
982
- out.printf fmt, '--prefix=path', 'install path prefix', ''
869
+ out.printf fmt, '--prefix=path', 'install path prefix', '$prefix'
983
870
  out.puts
984
871
  end
985
872
 
@@ -1000,13 +887,9 @@ class ToplevelInstaller
1000
887
  @installer.exec_install
1001
888
  end
1002
889
 
1003
- def exec_test
1004
- @installer.exec_test
1005
- end
1006
-
1007
890
  def exec_show
1008
- @config.each do |i|
1009
- printf "%-20s %s\n", i.name, i.value if i.value?
891
+ ConfigTable.each do |i|
892
+ printf "%-20s %s\n", i.name, i.value
1010
893
  end
1011
894
  end
1012
895
 
@@ -1018,45 +901,36 @@ class ToplevelInstaller
1018
901
  @installer.exec_distclean
1019
902
  end
1020
903
 
1021
- end # class ToplevelInstaller
904
+ end
1022
905
 
1023
906
 
1024
907
  class ToplevelInstallerMulti < ToplevelInstaller
1025
908
 
909
+ include HookUtils
910
+ include HookScriptAPI
1026
911
  include FileOperations
1027
912
 
1028
- def initialize(ardir_root, config)
913
+ def initialize(ardir)
1029
914
  super
1030
- @packages = directories_of("#{@ardir}/packages")
915
+ @packages = all_dirs_in("#{@ardir}/packages")
1031
916
  raise 'no package exists' if @packages.empty?
1032
- @root_installer = Installer.new(@config, @ardir, File.expand_path('.'))
1033
917
  end
1034
918
 
1035
919
  def run_metaconfigs
1036
- @config.load_script "#{@ardir}/metaconfig", self
920
+ eval_file_ifexist "#{@ardir}/metaconfig"
1037
921
  @packages.each do |name|
1038
- @config.load_script "#{@ardir}/packages/#{name}/metaconfig"
922
+ eval_file_ifexist "#{@ardir}/packages/#{name}/metaconfig"
1039
923
  end
1040
924
  end
1041
925
 
1042
- attr_reader :packages
1043
-
1044
- def packages=(list)
1045
- raise 'package list is empty' if list.empty?
1046
- list.each do |name|
1047
- raise "directory packages/#{name} does not exist"\
1048
- unless File.dir?("#{@ardir}/packages/#{name}")
1049
- end
1050
- @packages = list
1051
- end
1052
-
1053
926
  def init_installers
1054
927
  @installers = {}
1055
928
  @packages.each do |pack|
1056
- @installers[pack] = Installer.new(@config,
929
+ @installers[pack] = Installer.new(@config, @options,
1057
930
  "#{@ardir}/packages/#{pack}",
1058
931
  "packages/#{pack}")
1059
932
  end
933
+
1060
934
  with = extract_selection(config('with'))
1061
935
  without = extract_selection(config('without'))
1062
936
  @selected = @installers.keys.select {|name|
@@ -1080,6 +954,21 @@ class ToplevelInstallerMulti < ToplevelInstaller
1080
954
  f.puts
1081
955
  end
1082
956
 
957
+ #
958
+ # multi-package metaconfig API
959
+ #
960
+
961
+ attr_reader :packages
962
+
963
+ def declare_packages(list)
964
+ raise 'package list is empty' if list.empty?
965
+ list.each do |name|
966
+ raise "directory packages/#{name} does not exist"\
967
+ unless File.dir?("#{@ardir}/packages/#{name}")
968
+ end
969
+ @packages = list
970
+ end
971
+
1083
972
  #
1084
973
  # Task Handlers
1085
974
  #
@@ -1103,21 +992,15 @@ class ToplevelInstallerMulti < ToplevelInstaller
1103
992
  run_hook 'post-install'
1104
993
  end
1105
994
 
1106
- def exec_test
1107
- run_hook 'pre-test'
1108
- each_selected_installers {|inst| inst.exec_test }
1109
- run_hook 'post-test'
1110
- end
1111
-
1112
995
  def exec_clean
1113
- rm_f @config.savefile
996
+ rm_f ConfigTable.savefile
1114
997
  run_hook 'pre-clean'
1115
998
  each_selected_installers {|inst| inst.exec_clean }
1116
999
  run_hook 'post-clean'
1117
1000
  end
1118
1001
 
1119
1002
  def exec_distclean
1120
- rm_f @config.savefile
1003
+ rm_f ConfigTable.savefile
1121
1004
  run_hook 'pre-distclean'
1122
1005
  each_selected_installers {|inst| inst.exec_distclean }
1123
1006
  run_hook 'post-distclean'
@@ -1130,7 +1013,7 @@ class ToplevelInstallerMulti < ToplevelInstaller
1130
1013
  def each_selected_installers
1131
1014
  Dir.mkdir 'packages' unless File.dir?('packages')
1132
1015
  @selected.each do |pack|
1133
- $stderr.puts "Processing the package `#{pack}' ..." if verbose?
1016
+ $stderr.puts "Processing the package `#{pack}' ..." if @options['verbose']
1134
1017
  Dir.mkdir "packages/#{pack}" unless File.dir?("packages/#{pack}")
1135
1018
  Dir.chdir "packages/#{pack}"
1136
1019
  yield @installers[pack]
@@ -1138,32 +1021,28 @@ class ToplevelInstallerMulti < ToplevelInstaller
1138
1021
  end
1139
1022
  end
1140
1023
 
1141
- def run_hook(id)
1142
- @root_installer.run_hook id
1143
- end
1144
-
1145
- # module FileOperations requires this
1146
1024
  def verbose?
1147
- @config.verbose?
1025
+ @options['verbose']
1148
1026
  end
1149
1027
 
1150
- # module FileOperations requires this
1151
1028
  def no_harm?
1152
- @config.no_harm?
1029
+ @options['no-harm']
1153
1030
  end
1154
1031
 
1155
- end # class ToplevelInstallerMulti
1032
+ end
1156
1033
 
1157
1034
 
1158
1035
  class Installer
1159
1036
 
1160
- FILETYPES = %w( bin lib ext data conf man )
1037
+ FILETYPES = %w( bin lib ext data )
1161
1038
 
1162
- include FileOperations
1163
1039
  include HookScriptAPI
1040
+ include HookUtils
1041
+ include FileOperations
1164
1042
 
1165
- def initialize(config, srcroot, objroot)
1043
+ def initialize(config, opt, srcroot, objroot)
1166
1044
  @config = config
1045
+ @options = opt
1167
1046
  @srcdir = File.expand_path(srcroot)
1168
1047
  @objdir = File.expand_path(objroot)
1169
1048
  @currdir = '.'
@@ -1173,9 +1052,6 @@ class Installer
1173
1052
  "#<#{self.class} #{File.basename(@srcdir)}>"
1174
1053
  end
1175
1054
 
1176
- def noop(rel)
1177
- end
1178
-
1179
1055
  #
1180
1056
  # Hook Script API base methods
1181
1057
  #
@@ -1193,25 +1069,23 @@ class Installer
1193
1069
  end
1194
1070
 
1195
1071
  #
1196
- # Config Access
1072
+ # configs/options
1197
1073
  #
1198
1074
 
1199
- # module FileOperations requires this
1200
- def verbose?
1201
- @config.verbose?
1075
+ def no_harm?
1076
+ @options['no-harm']
1202
1077
  end
1203
1078
 
1204
- # module FileOperations requires this
1205
- def no_harm?
1206
- @config.no_harm?
1079
+ def verbose?
1080
+ @options['verbose']
1207
1081
  end
1208
1082
 
1209
1083
  def verbose_off
1210
1084
  begin
1211
- save, @config.verbose = @config.verbose?, false
1085
+ save, @options['verbose'] = @options['verbose'], false
1212
1086
  yield
1213
1087
  ensure
1214
- @config.verbose = save
1088
+ @options['verbose'] = save
1215
1089
  end
1216
1090
  end
1217
1091
 
@@ -1223,19 +1097,22 @@ class Installer
1223
1097
  exec_task_traverse 'config'
1224
1098
  end
1225
1099
 
1226
- alias config_dir_bin noop
1227
- alias config_dir_lib noop
1100
+ def config_dir_bin(rel)
1101
+ end
1102
+
1103
+ def config_dir_lib(rel)
1104
+ end
1228
1105
 
1229
1106
  def config_dir_ext(rel)
1230
1107
  extconf if extdir?(curr_srcdir())
1231
1108
  end
1232
1109
 
1233
- alias config_dir_data noop
1234
- alias config_dir_conf noop
1235
- alias config_dir_man noop
1236
-
1237
1110
  def extconf
1238
- ruby "#{curr_srcdir()}/extconf.rb", *@config.config_opt
1111
+ opt = @options['config-opt'].join(' ')
1112
+ command "#{config('rubyprog')} #{curr_srcdir()}/extconf.rb #{opt}"
1113
+ end
1114
+
1115
+ def config_dir_data(rel)
1239
1116
  end
1240
1117
 
1241
1118
  #
@@ -1247,90 +1124,39 @@ class Installer
1247
1124
  end
1248
1125
 
1249
1126
  def setup_dir_bin(rel)
1250
- files_of(curr_srcdir()).each do |fname|
1251
- update_shebang_line "#{curr_srcdir()}/#{fname}"
1127
+ all_files_in(curr_srcdir()).each do |fname|
1128
+ adjust_shebang "#{curr_srcdir()}/#{fname}"
1252
1129
  end
1253
1130
  end
1254
1131
 
1255
- alias setup_dir_lib noop
1256
-
1257
- def setup_dir_ext(rel)
1258
- make if extdir?(curr_srcdir())
1259
- end
1260
-
1261
- alias setup_dir_data noop
1262
- alias setup_dir_conf noop
1263
- alias setup_dir_man noop
1264
-
1265
- def update_shebang_line(path)
1132
+ def adjust_shebang(path)
1266
1133
  return if no_harm?
1267
- return if config('shebang') == 'never'
1268
- old = Shebang.load(path)
1269
- if old
1270
- $stderr.puts "warning: #{path}: Shebang line includes too many args. It is not portable and your program may not work." if old.args.size > 1
1271
- new = new_shebang(old)
1272
- return if new.to_s == old.to_s
1273
- else
1274
- return unless config('shebang') == 'all'
1275
- new = Shebang.new(config('rubypath'))
1276
- end
1277
- $stderr.puts "updating shebang: #{File.basename(path)}" if verbose?
1278
- open_atomic_writer(path) {|output|
1279
- File.open(path, 'rb') {|f|
1280
- f.gets if old # discard
1281
- output.puts new.to_s
1282
- output.print f.read
1283
- }
1284
- }
1285
- end
1286
-
1287
- def new_shebang(old)
1288
- if /\Aruby/ =~ File.basename(old.cmd)
1289
- Shebang.new(config('rubypath'), old.args)
1290
- elsif File.basename(old.cmd) == 'env' and old.args.first == 'ruby'
1291
- Shebang.new(config('rubypath'), old.args[1..-1])
1292
- else
1293
- return old unless config('shebang') == 'all'
1294
- Shebang.new(config('rubypath'))
1295
- end
1296
- end
1297
-
1298
- def open_atomic_writer(path, &block)
1299
1134
  tmpfile = File.basename(path) + '.tmp'
1300
1135
  begin
1301
- File.open(tmpfile, 'wb', &block)
1302
- File.rename tmpfile, File.basename(path)
1136
+ File.open(path, 'rb') {|r|
1137
+ first = r.gets
1138
+ return unless File.basename(config('rubypath')) == 'ruby'
1139
+ return unless File.basename(first.sub(/\A\#!/, '').split[0]) == 'ruby'
1140
+ $stderr.puts "adjusting shebang: #{File.basename(path)}" if verbose?
1141
+ File.open(tmpfile, 'wb') {|w|
1142
+ w.print first.sub(/\A\#!\s*\S+/, '#! ' + config('rubypath'))
1143
+ w.write r.read
1144
+ }
1145
+ move_file tmpfile, File.basename(path)
1146
+ }
1303
1147
  ensure
1304
1148
  File.unlink tmpfile if File.exist?(tmpfile)
1305
1149
  end
1306
1150
  end
1307
1151
 
1308
- class Shebang
1309
- def Shebang.load(path)
1310
- line = nil
1311
- File.open(path) {|f|
1312
- line = f.gets
1313
- }
1314
- return nil unless /\A#!/ =~ line
1315
- parse(line)
1316
- end
1317
-
1318
- def Shebang.parse(line)
1319
- cmd, *args = *line.strip.sub(/\A\#!/, '').split(' ')
1320
- new(cmd, args)
1321
- end
1322
-
1323
- def initialize(cmd, args = [])
1324
- @cmd = cmd
1325
- @args = args
1326
- end
1152
+ def setup_dir_lib(rel)
1153
+ end
1327
1154
 
1328
- attr_reader :cmd
1329
- attr_reader :args
1155
+ def setup_dir_ext(rel)
1156
+ make if extdir?(curr_srcdir())
1157
+ end
1330
1158
 
1331
- def to_s
1332
- "#! #{@cmd}" + (@args.empty? ? '' : " #{@args.join(' ')}")
1333
- end
1159
+ def setup_dir_data(rel)
1334
1160
  end
1335
1161
 
1336
1162
  #
@@ -1343,77 +1169,63 @@ class Installer
1343
1169
  end
1344
1170
 
1345
1171
  def install_dir_bin(rel)
1346
- install_files targetfiles(), "#{config('bindir')}/#{rel}", 0755
1172
+ install_files collect_filenames_auto(), "#{config('bindir')}/#{rel}", 0755
1347
1173
  end
1348
1174
 
1349
1175
  def install_dir_lib(rel)
1350
- install_files libfiles(), "#{config('rbdir')}/#{rel}", 0644
1176
+ install_files ruby_scripts(), "#{config('rbdir')}/#{rel}", 0644
1351
1177
  end
1352
1178
 
1353
1179
  def install_dir_ext(rel)
1354
1180
  return unless extdir?(curr_srcdir())
1355
- install_files rubyextentions('.'),
1181
+ install_files ruby_extentions('.'),
1356
1182
  "#{config('sodir')}/#{File.dirname(rel)}",
1357
1183
  0555
1358
1184
  end
1359
1185
 
1360
1186
  def install_dir_data(rel)
1361
- install_files targetfiles(), "#{config('datadir')}/#{rel}", 0644
1362
- end
1363
-
1364
- def install_dir_conf(rel)
1365
- # FIXME: should not remove current config files
1366
- # (rename previous file to .old/.org)
1367
- install_files targetfiles(), "#{config('sysconfdir')}/#{rel}", 0644
1368
- end
1369
-
1370
- def install_dir_man(rel)
1371
- install_files targetfiles(), "#{config('mandir')}/#{rel}", 0644
1187
+ install_files collect_filenames_auto(), "#{config('datadir')}/#{rel}", 0644
1372
1188
  end
1373
1189
 
1374
1190
  def install_files(list, dest, mode)
1375
- mkdir_p dest, @config.install_prefix
1191
+ mkdir_p dest, @options['install-prefix']
1376
1192
  list.each do |fname|
1377
- install fname, dest, mode, @config.install_prefix
1378
- end
1379
- end
1380
-
1381
- def libfiles
1382
- glob_reject(%w(*.y *.output), targetfiles())
1383
- end
1384
-
1385
- def rubyextentions(dir)
1386
- ents = glob_select("*.#{@config.dllext}", targetfiles())
1387
- if ents.empty?
1388
- setup_rb_error "no ruby extention exists: 'ruby #{$0} setup' first"
1193
+ install fname, dest, mode, @options['install-prefix']
1389
1194
  end
1390
- ents
1391
- end
1392
-
1393
- def targetfiles
1394
- mapdir(existfiles() - hookfiles())
1395
1195
  end
1396
1196
 
1397
- def mapdir(ents)
1398
- ents.map {|ent|
1399
- if File.exist?(ent)
1400
- then ent # objdir
1401
- else "#{curr_srcdir()}/#{ent}" # srcdir
1402
- end
1403
- }
1197
+ def ruby_scripts
1198
+ collect_filenames_auto().select {|n| /\.rb\z/ =~ n }
1404
1199
  end
1405
-
1200
+
1406
1201
  # picked up many entries from cvs-1.11.1/src/ignore.c
1407
- JUNK_FILES = %w(
1202
+ reject_patterns = %w(
1408
1203
  core RCSLOG tags TAGS .make.state
1409
1204
  .nse_depinfo #* .#* cvslog.* ,* .del-* *.olb
1410
1205
  *~ *.old *.bak *.BAK *.orig *.rej _$* *$
1411
1206
 
1412
1207
  *.org *.in .*
1413
1208
  )
1209
+ mapping = {
1210
+ '.' => '\.',
1211
+ '$' => '\$',
1212
+ '#' => '\#',
1213
+ '*' => '.*'
1214
+ }
1215
+ REJECT_PATTERNS = Regexp.new('\A(?:' +
1216
+ reject_patterns.map {|pat|
1217
+ pat.gsub(/[\.\$\#\*]/) {|ch| mapping[ch] }
1218
+ }.join('|') +
1219
+ ')\z')
1220
+
1221
+ def collect_filenames_auto
1222
+ mapdir((existfiles() - hookfiles()).reject {|fname|
1223
+ REJECT_PATTERNS =~ fname
1224
+ })
1225
+ end
1414
1226
 
1415
1227
  def existfiles
1416
- glob_reject(JUNK_FILES, (files_of(curr_srcdir()) | files_of('.')))
1228
+ all_files_in(curr_srcdir()) | all_files_in('.')
1417
1229
  end
1418
1230
 
1419
1231
  def hookfiles
@@ -1422,49 +1234,24 @@ class Installer
1422
1234
  }.flatten
1423
1235
  end
1424
1236
 
1425
- def glob_select(pat, ents)
1426
- re = globs2re([pat])
1427
- ents.select {|ent| re =~ ent }
1428
- end
1429
-
1430
- def glob_reject(pats, ents)
1431
- re = globs2re(pats)
1432
- ents.reject {|ent| re =~ ent }
1433
- end
1434
-
1435
- GLOB2REGEX = {
1436
- '.' => '\.',
1437
- '$' => '\$',
1438
- '#' => '\#',
1439
- '*' => '.*'
1440
- }
1441
-
1442
- def globs2re(pats)
1443
- /\A(?:#{
1444
- pats.map {|pat| pat.gsub(/[\.\$\#\*]/) {|ch| GLOB2REGEX[ch] } }.join('|')
1445
- })\z/
1237
+ def mapdir(filelist)
1238
+ filelist.map {|fname|
1239
+ if File.exist?(fname) # objdir
1240
+ fname
1241
+ else # srcdir
1242
+ File.join(curr_srcdir(), fname)
1243
+ end
1244
+ }
1446
1245
  end
1447
1246
 
1448
- #
1449
- # TASK test
1450
- #
1451
-
1452
- TESTDIR = 'test'
1453
-
1454
- def exec_test
1455
- unless File.directory?('test')
1456
- $stderr.puts 'no test in this package' if verbose?
1457
- return
1458
- end
1459
- $stderr.puts 'Running tests...' if verbose?
1460
- begin
1461
- require 'test/unit'
1462
- rescue LoadError
1463
- setup_rb_error 'test/unit cannot loaded. You need Ruby 1.8 or later to invoke this task.'
1464
- end
1465
- runner = Test::Unit::AutoRunner.new(true)
1466
- runner.to_run << TESTDIR
1467
- runner.run
1247
+ def ruby_extentions(dir)
1248
+ Dir.open(dir) {|d|
1249
+ ents = d.select {|fname| /\.#{::Config::CONFIG['DLEXT']}\z/ =~ fname }
1250
+ if ents.empty?
1251
+ setup_rb_error "no ruby extention exists: 'ruby #{$0} setup' first"
1252
+ end
1253
+ return ents
1254
+ }
1468
1255
  end
1469
1256
 
1470
1257
  #
@@ -1473,51 +1260,53 @@ class Installer
1473
1260
 
1474
1261
  def exec_clean
1475
1262
  exec_task_traverse 'clean'
1476
- rm_f @config.savefile
1263
+ rm_f ConfigTable.savefile
1477
1264
  rm_f 'InstalledFiles'
1478
1265
  end
1479
1266
 
1480
- alias clean_dir_bin noop
1481
- alias clean_dir_lib noop
1482
- alias clean_dir_data noop
1483
- alias clean_dir_conf noop
1484
- alias clean_dir_man noop
1267
+ def clean_dir_bin(rel)
1268
+ end
1269
+
1270
+ def clean_dir_lib(rel)
1271
+ end
1485
1272
 
1486
1273
  def clean_dir_ext(rel)
1487
1274
  return unless extdir?(curr_srcdir())
1488
1275
  make 'clean' if File.file?('Makefile')
1489
1276
  end
1490
1277
 
1278
+ def clean_dir_data(rel)
1279
+ end
1280
+
1491
1281
  #
1492
1282
  # TASK distclean
1493
1283
  #
1494
1284
 
1495
1285
  def exec_distclean
1496
1286
  exec_task_traverse 'distclean'
1497
- rm_f @config.savefile
1287
+ rm_f ConfigTable.savefile
1498
1288
  rm_f 'InstalledFiles'
1499
1289
  end
1500
1290
 
1501
- alias distclean_dir_bin noop
1502
- alias distclean_dir_lib noop
1291
+ def distclean_dir_bin(rel)
1292
+ end
1293
+
1294
+ def distclean_dir_lib(rel)
1295
+ end
1503
1296
 
1504
1297
  def distclean_dir_ext(rel)
1505
1298
  return unless extdir?(curr_srcdir())
1506
1299
  make 'distclean' if File.file?('Makefile')
1507
1300
  end
1508
1301
 
1509
- alias distclean_dir_data noop
1510
- alias distclean_dir_conf noop
1511
- alias distclean_dir_man noop
1512
-
1513
1302
  #
1514
- # Traversing
1303
+ # lib
1515
1304
  #
1516
1305
 
1517
1306
  def exec_task_traverse(task)
1518
1307
  run_hook "pre-#{task}"
1519
1308
  FILETYPES.each do |type|
1520
- if type == 'ext' and config('without-ext') == 'yes'
1309
+ if config('without-ext') == 'yes' and type == 'ext'
1521
1310
  $stderr.puts 'skipping ext/* by user option' if verbose?
1522
1311
  next
1523
1312
  end
@@ -1530,7 +1319,7 @@ class Installer
1530
1319
  dive_into(rel) {
1531
1320
  run_hook "pre-#{task}"
1532
1321
  __send__ mid, rel.sub(%r[\A.*?(?:/|\z)], '')
1533
- directories_of(curr_srcdir()).each do |d|
1322
+ all_dirs_in(curr_srcdir()).each do |d|
1534
1323
  traverse task, "#{rel}/#{d}", mid
1535
1324
  end
1536
1325
  run_hook "post-#{task}"
@@ -1552,30 +1341,16 @@ class Installer
1552
1341
  @currdir = File.dirname(rel)
1553
1342
  end
1554
1343
 
1555
- def run_hook(id)
1556
- path = [ "#{curr_srcdir()}/#{id}",
1557
- "#{curr_srcdir()}/#{id}.rb" ].detect {|cand| File.file?(cand) }
1558
- return unless path
1559
- begin
1560
- instance_eval File.read(path), path, 1
1561
- rescue
1562
- raise if $DEBUG
1563
- setup_rb_error "hook #{path} failed:\n" + $!.message
1564
- end
1565
- end
1566
-
1567
- end # class Installer
1568
-
1569
-
1570
- class SetupError < StandardError; end
1571
-
1572
- def setup_rb_error(msg)
1573
- raise SetupError, msg
1574
1344
  end
1575
1345
 
1346
+
1576
1347
  if $0 == __FILE__
1577
1348
  begin
1578
- ToplevelInstaller.invoke
1349
+ if multipackage_install?
1350
+ ToplevelInstallerMulti.invoke
1351
+ else
1352
+ ToplevelInstaller.invoke
1353
+ end
1579
1354
  rescue SetupError
1580
1355
  raise if $DEBUG
1581
1356
  $stderr.puts $!.message