rio 0.3.8 → 0.3.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (223) hide show
  1. data/README +18 -12
  2. data/Rakefile +57 -87
  3. data/build_doc.rb +19 -17
  4. data/doc/ANNOUNCE +3 -32
  5. data/doc/RELEASE_NOTES +4 -5
  6. data/doc/RIOIS +215 -0
  7. data/doc/generators/template/html/rio.css +428 -0
  8. data/doc/generators/template/html/rio.rb +18 -389
  9. data/doc/generators/template/html/ugly.rb +130 -0
  10. data/doc/pkg_def.rb +66 -0
  11. data/ex/catcsv.rb +64 -0
  12. data/ex/colx.rb +8 -0
  13. data/ex/findinruby +15 -0
  14. data/ex/findruby +14 -0
  15. data/ex/passwd_report.rb +8 -0
  16. data/ex/prompt.rb +25 -0
  17. data/ex/rgb.txt.gz +0 -0
  18. data/ex/riocat +42 -0
  19. data/ex/riogunzip +31 -0
  20. data/ex/riogzip +24 -0
  21. data/ex/rioprompt.rb +10 -0
  22. data/ex/targz2zip +17 -0
  23. data/ex/tonl +10 -0
  24. data/lib/rio.rb +16 -10
  25. data/lib/rio/abstract_method.rb +3 -4
  26. data/lib/rio/argv.rb +3 -4
  27. data/lib/rio/arycopy.rb +3 -4
  28. data/lib/rio/assert.rb +3 -4
  29. data/lib/rio/base.rb +3 -4
  30. data/lib/rio/callstr.rb +3 -4
  31. data/lib/rio/const.rb +3 -4
  32. data/lib/rio/construct.rb +3 -4
  33. data/lib/rio/constructor.rb +12 -8
  34. data/lib/rio/context.rb +15 -30
  35. data/lib/rio/context/autoclose.rb +3 -4
  36. data/lib/rio/context/copying.rb +3 -4
  37. data/lib/rio/context/cxx.rb +3 -4
  38. data/lib/rio/context/dir.rb +3 -4
  39. data/lib/rio/context/gzip.rb +3 -4
  40. data/lib/rio/context/methods.rb +16 -5
  41. data/lib/rio/context/skip.rb +3 -4
  42. data/lib/rio/context/stream.rb +42 -5
  43. data/lib/rio/cp.rb +7 -7
  44. data/lib/rio/def.rb +3 -4
  45. data/lib/rio/dir.rb +3 -4
  46. data/lib/rio/doc.rb +4 -5
  47. data/lib/rio/doc/EXAMPLES.rb +299 -0
  48. data/lib/rio/doc/HOWTO.rb +3 -4
  49. data/lib/rio/doc/INTRO.rb +86 -105
  50. data/lib/rio/doc/OPTIONAL.rb +4 -5
  51. data/lib/rio/doc/SYNOPSIS.rb +7 -6
  52. data/lib/rio/entrysel.rb +21 -23
  53. data/lib/rio/exception.rb +3 -4
  54. data/lib/rio/exception/copy.rb +3 -4
  55. data/lib/rio/exception/notimplemented.rb +57 -0
  56. data/lib/rio/exception/notsupported.rb +3 -4
  57. data/lib/rio/exception/open.rb +3 -4
  58. data/lib/rio/exception/state.rb +3 -4
  59. data/lib/rio/ext.rb +47 -13
  60. data/lib/rio/ext/csv.rb +4 -5
  61. data/lib/rio/ext/if.rb +45 -0
  62. data/lib/rio/ext/mp3info.rb +80 -0
  63. data/lib/rio/ext/splitlines.rb +253 -0
  64. data/lib/rio/ext/yaml.rb +9 -5
  65. data/lib/rio/ext/yaml/doc.rb +133 -0
  66. data/lib/rio/ext/yaml/tie.rb +149 -0
  67. data/lib/rio/ext/zipfile.rb +23 -4
  68. data/lib/rio/ext/zipfile/fs.rb +116 -0
  69. data/lib/rio/ext/zipfile/rl.rb +251 -0
  70. data/lib/rio/ext/zipfile/rootdir.rb +117 -0
  71. data/lib/rio/ext/zipfile/state.rb +161 -0
  72. data/lib/rio/ext/zipfile/wrap.rb +204 -0
  73. data/lib/rio/factory.rb +235 -27
  74. data/lib/rio/file.rb +4 -4
  75. data/lib/rio/filter.rb +3 -4
  76. data/lib/rio/filter/closeoneof.rb +3 -4
  77. data/lib/rio/filter/gzip.rb +9 -4
  78. data/lib/rio/fs/base.rb +3 -4
  79. data/lib/rio/fs/impl.rb +4 -5
  80. data/lib/rio/fs/native.rb +3 -4
  81. data/lib/rio/fs/stream.rb +3 -4
  82. data/lib/rio/fs/url.rb +3 -4
  83. data/lib/rio/ftp/conncache.rb +19 -5
  84. data/lib/rio/ftp/dir.rb +3 -4
  85. data/lib/rio/ftp/fs.rb +30 -24
  86. data/lib/rio/grande.rb +27 -7
  87. data/lib/rio/handle.rb +3 -4
  88. data/lib/rio/if.rb +19 -15
  89. data/lib/rio/if/basic.rb +7 -7
  90. data/lib/rio/if/csv.rb +5 -6
  91. data/lib/rio/if/dir.rb +120 -114
  92. data/lib/rio/if/file.rb +52 -44
  93. data/lib/rio/if/fileordir.rb +217 -211
  94. data/lib/rio/if/grande.rb +674 -644
  95. data/lib/rio/if/grande_entry.rb +321 -313
  96. data/lib/rio/if/grande_stream.rb +653 -553
  97. data/lib/rio/if/internal.rb +3 -4
  98. data/lib/rio/if/path.rb +425 -426
  99. data/lib/rio/if/rubyio.rb +681 -0
  100. data/lib/rio/if/string.rb +42 -5
  101. data/lib/rio/if/temp.rb +3 -4
  102. data/lib/rio/if/test.rb +245 -238
  103. data/lib/rio/if/yaml.rb +15 -41
  104. data/lib/rio/ioh.rb +7 -5
  105. data/lib/rio/iomode.rb +19 -7
  106. data/lib/rio/ios/fail.rb +4 -5
  107. data/lib/rio/ios/generic.rb +4 -5
  108. data/lib/rio/ios/mode.rb +4 -5
  109. data/lib/rio/ios/null.rb +6 -7
  110. data/lib/rio/iowrap.rb +3 -4
  111. data/lib/rio/kernel.rb +3 -5
  112. data/lib/rio/local.rb +3 -4
  113. data/lib/rio/match.rb +3 -4
  114. data/lib/rio/matchrecord.rb +3 -4
  115. data/lib/rio/no_warn.rb +3 -4
  116. data/lib/rio/nullio.rb +3 -4
  117. data/lib/rio/open3.rb +4 -5
  118. data/lib/rio/ops/construct.rb +3 -4
  119. data/lib/rio/ops/create.rb +11 -6
  120. data/lib/rio/ops/dir.rb +19 -8
  121. data/lib/rio/ops/either.rb +6 -5
  122. data/lib/rio/ops/file.rb +3 -4
  123. data/lib/rio/ops/path.rb +14 -35
  124. data/lib/rio/ops/stream.rb +3 -4
  125. data/lib/rio/ops/stream/input.rb +4 -7
  126. data/lib/rio/ops/stream/output.rb +3 -4
  127. data/lib/rio/ops/stream/read.rb +6 -5
  128. data/lib/rio/ops/stream/write.rb +3 -4
  129. data/lib/rio/ops/symlink.rb +3 -4
  130. data/lib/rio/path.rb +22 -18
  131. data/lib/rio/path/reset.rb +4 -5
  132. data/lib/rio/piper.rb +3 -4
  133. data/lib/rio/piper/cp.rb +3 -4
  134. data/lib/rio/prompt.rb +10 -5
  135. data/lib/rio/rectype.rb +5 -5
  136. data/lib/rio/rl/base.rb +17 -71
  137. data/lib/rio/rl/builder.rb +14 -38
  138. data/lib/rio/rl/chmap.rb +66 -0
  139. data/lib/rio/rl/fs2url.rb +82 -0
  140. data/lib/rio/rl/ioi.rb +4 -4
  141. data/lib/rio/rl/path.rb +44 -122
  142. data/lib/rio/rl/pathmethods.rb +19 -8
  143. data/lib/rio/rl/uri.rb +137 -60
  144. data/lib/rio/rl/withpath.rb +295 -0
  145. data/lib/rio/scheme/aryio.rb +3 -4
  146. data/lib/rio/scheme/cmdio.rb +3 -4
  147. data/lib/rio/scheme/cmdpipe.rb +4 -4
  148. data/lib/rio/scheme/fd.rb +3 -4
  149. data/lib/rio/scheme/ftp.rb +7 -7
  150. data/lib/rio/scheme/http.rb +4 -5
  151. data/lib/rio/scheme/null.rb +3 -4
  152. data/lib/rio/scheme/path.rb +3 -4
  153. data/lib/rio/scheme/stderr.rb +3 -4
  154. data/lib/rio/scheme/stdio.rb +3 -4
  155. data/lib/rio/scheme/strio.rb +3 -4
  156. data/lib/rio/scheme/sysio.rb +3 -4
  157. data/lib/rio/scheme/tcp.rb +3 -4
  158. data/lib/rio/scheme/temp.rb +6 -6
  159. data/lib/rio/state.rb +18 -46
  160. data/lib/rio/state/error.rb +3 -4
  161. data/lib/rio/stream.rb +4 -4
  162. data/lib/rio/stream/base.rb +3 -4
  163. data/lib/rio/stream/duplex.rb +3 -4
  164. data/lib/rio/stream/open.rb +3 -8
  165. data/lib/rio/symantics.rb +3 -4
  166. data/lib/rio/tempdir.rb +2 -2
  167. data/lib/rio/to_rio.rb +3 -4
  168. data/lib/rio/to_rio/all.rb +3 -4
  169. data/lib/rio/to_rio/array.rb +4 -5
  170. data/lib/rio/to_rio/io.rb +4 -5
  171. data/lib/rio/to_rio/object.rb +4 -5
  172. data/lib/rio/to_rio/string.rb +4 -5
  173. data/lib/rio/uri/file.rb +41 -5
  174. data/lib/rio/util.rb +3 -4
  175. data/lib/rio/version.rb +4 -5
  176. data/setup.rb +368 -339
  177. data/test/bin/list_dir.rb +1 -1
  178. data/test/ftp/anon_misc.rb +13 -1
  179. data/test/ftp/anon_special.rb +6 -6
  180. data/test/ftp/anon_write.rb +10 -3
  181. data/test/ftp/ftp2ftp.rb +2 -2
  182. data/test/ftp/testdef.rb +9 -6
  183. data/test/http/all.rb +3 -0
  184. data/test/http/copy-from-http.rb +140 -0
  185. data/test/lib/temp_server.rb +44 -0
  186. data/test/runalltests.rb +3 -1
  187. data/test/runhttp.rb +12 -0
  188. data/test/runhttptests.rb +1 -1
  189. data/test/runtests.rb +41 -3
  190. data/test/tc/abs.rb +9 -5
  191. data/test/tc/all.rb +9 -4
  192. data/test/tc/base.rb +1 -1
  193. data/test/tc/base2.rb +87 -0
  194. data/test/tc/{methods.rb → clone.rb} +72 -50
  195. data/test/tc/closeoncopy.rb +13 -2
  196. data/test/tc/copy-dir-samevar.rb +91 -0
  197. data/test/tc/dir_iter.rb +0 -1
  198. data/test/tc/empty.rb +6 -2
  199. data/test/tc/expand_path.rb +36 -54
  200. data/test/tc/ext.rb +42 -18
  201. data/test/tc/gzip.rb +30 -3
  202. data/test/tc/likeio.rb +5 -1
  203. data/test/tc/line_record_row.rb +51 -0
  204. data/test/tc/noqae.rb +71 -70
  205. data/test/tc/path_parts.rb +175 -0
  206. data/test/tc/programs_util.rb +3 -3
  207. data/test/tc/rename.rb +4 -5
  208. data/test/tc/riorl.rb +9 -7
  209. data/test/tc/skip.rb +35 -6
  210. data/test/tc/skiplines.rb +34 -5
  211. data/test/tc/split.rb +8 -50
  212. data/test/tc/splitlines.rb +65 -0
  213. data/test/tc/splitpath.rb +83 -0
  214. data/test/tc/testcase.rb +1 -1
  215. data/test/tc/truncate.rb +39 -0
  216. data/test/tc/yaml.rb +9 -8
  217. metadata +261 -207
  218. data/ChangeLog +0 -1418
  219. data/VERSION +0 -1
  220. data/lib/rio/doc/MISC.rb +0 -259
  221. data/lib/rio/if/stream.rb +0 -680
  222. data/lib/rio/impl/path.rb +0 -87
  223. data/test/tc/copy-from-http.rb +0 -89
@@ -1,6 +1,6 @@
1
1
  #--
2
2
  # ===============================================================================
3
- # Copyright (c) 2005, 2006 Christopher Kleckner
3
+ # Copyright (c) 2005,2006,2007 Christopher Kleckner
4
4
  # All rights reserved
5
5
  #
6
6
  # This file is part of the Rio library for ruby.
@@ -23,16 +23,15 @@
23
23
  #
24
24
  # To create the documentation for Rio run the command
25
25
  # ruby build_doc.rb
26
- # from the distribution directory. Then point your browser at the 'doc/rdoc' directory.
26
+ # from the distribution directory.
27
27
  #
28
28
  # Suggested Reading
29
29
  # * RIO::Doc::SYNOPSIS
30
30
  # * RIO::Doc::INTRO
31
31
  # * RIO::Doc::HOWTO
32
+ # * RIO::Doc::EXAMPLES
32
33
  # * RIO::Rio
33
34
  #
34
- # <b>Rio is pre-alpha software.
35
- # The documented interface and behavior is subject to change without notice.</b>
36
35
 
37
36
 
38
37
  module RIO
@@ -1,6 +1,6 @@
1
1
  #--
2
2
  # ===============================================================================
3
- # Copyright (c) 2005, 2006 Christopher Kleckner
3
+ # Copyright (c) 2005,2006,2007 Christopher Kleckner
4
4
  # All rights reserved
5
5
  #
6
6
  # This file is part of the Rio library for ruby.
@@ -23,23 +23,22 @@
23
23
  #
24
24
  # To create the documentation for Rio run the command
25
25
  # ruby build_doc.rb
26
- # from the distribution directory. Then point your browser at the 'doc/rdoc' directory.
26
+ # from the distribution directory.
27
27
  #
28
28
  # Suggested Reading
29
29
  # * RIO::Doc::SYNOPSIS
30
30
  # * RIO::Doc::INTRO
31
31
  # * RIO::Doc::HOWTO
32
+ # * RIO::Doc::EXAMPLES
32
33
  # * RIO::Rio
33
34
  #
34
- # <b>Rio is pre-alpha software.
35
- # The documented interface and behavior is subject to change without notice.</b>
36
35
 
37
36
  #
38
37
 
39
38
  module RIO
40
39
  # :stopdoc:
41
40
  module Version #:nodoc: all
42
- VERSION = '0.3.8'
41
+ VERSION = '0.3.9'
43
42
 
44
43
  N = VERSION.split('.').freeze
45
44
  MAJOR = N[0].freeze
data/setup.rb CHANGED
@@ -5,66 +5,16 @@
5
5
  #
6
6
  # This program is free software.
7
7
  # You can distribute/modify this program under the terms of
8
- # the GNU Lesser General Public License version 2.1.
8
+ # the GNU LGPL, Lesser General Public License version 2.1.
9
9
  #
10
10
 
11
- #
12
- # For backward compatibility
13
- #
14
-
15
- unless Enumerable.method_defined?(:map)
11
+ unless Enumerable.method_defined?(:map) # Ruby 1.4.6
16
12
  module Enumerable
17
13
  alias map collect
18
14
  end
19
15
  end
20
16
 
21
- unless Enumerable.method_defined?(:detect)
22
- module Enumerable
23
- alias detect find
24
- end
25
- end
26
-
27
- unless Enumerable.method_defined?(:select)
28
- module Enumerable
29
- alias select find_all
30
- end
31
- end
32
-
33
- unless Enumerable.method_defined?(:reject)
34
- module Enumerable
35
- def reject
36
- result = []
37
- each do |i|
38
- result.push i unless yield(i)
39
- end
40
- result
41
- end
42
- end
43
- end
44
-
45
- unless Enumerable.method_defined?(:inject)
46
- module Enumerable
47
- def inject(result)
48
- each do |i|
49
- result = yield(result, i)
50
- end
51
- result
52
- end
53
- end
54
- end
55
-
56
- unless Enumerable.method_defined?(:any?)
57
- module Enumerable
58
- def any?
59
- each do |i|
60
- return true if yield(i)
61
- end
62
- false
63
- end
64
- end
65
- end
66
-
67
- unless File.respond_to?(:read)
17
+ unless File.respond_to?(:read) # Ruby 1.6
68
18
  def File.read(fname)
69
19
  open(fname) {|f|
70
20
  return f.read
@@ -72,10 +22,6 @@ unless File.respond_to?(:read)
72
22
  end
73
23
  end
74
24
 
75
- #
76
- # Application independent utilities
77
- #
78
-
79
25
  def File.binread(fname)
80
26
  open(fname, 'rb') {|f|
81
27
  return f.read
@@ -87,11 +33,18 @@ def File.dir?(path)
87
33
  File.directory?((path[-1,1] == '/') ? path : path + '/')
88
34
  end
89
35
 
36
+
37
+ class SetupError < StandardError; end
38
+
39
+ def setup_rb_error(msg)
40
+ raise SetupError, msg
41
+ end
42
+
90
43
  #
91
44
  # Config
92
45
  #
93
46
 
94
- if arg = ARGV.detect{|arg| /\A--rbconfig=/ =~ arg }
47
+ if arg = ARGV.detect {|arg| /\A--rbconfig=/ =~ arg }
95
48
  ARGV.delete(arg)
96
49
  require arg.split(/=/, 2)[1]
97
50
  $".push 'rbconfig.rb'
@@ -104,219 +57,325 @@ def multipackage_install?
104
57
  end
105
58
 
106
59
 
107
- class ConfigTable
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
67
+ end
108
68
 
109
- c = ::Config::CONFIG
69
+ attr_reader :name
70
+ attr_reader :description
110
71
 
111
- rubypath = c['bindir'] + '/' + c['ruby_install_name']
72
+ attr_accessor :default
73
+ alias help_default default
112
74
 
113
- major = c['MAJOR'].to_i
114
- minor = c['MINOR'].to_i
115
- teeny = c['TEENY'].to_i
116
- version = "#{major}.#{minor}"
75
+ def help_opt
76
+ "--#{@name}=#{@template}"
77
+ end
117
78
 
118
- # ruby ver. >= 1.4.4?
119
- newpath_p = ((major >= 2) or
120
- ((major == 1) and
121
- ((minor >= 5) or
122
- ((minor == 4) and (teeny >= 4)))))
123
-
124
- subprefix = lambda {|path|
125
- path.sub(/\A#{Regexp.quote(c['prefix'])}/o, '$prefix')
126
- }
79
+ def value
80
+ @value
81
+ end
127
82
 
128
- if c['rubylibdir']
129
- # V < 1.6.3
130
- stdruby = subprefix.call(c['rubylibdir'])
131
- siteruby = subprefix.call(c['sitedir'])
132
- versite = subprefix.call(c['sitelibdir'])
133
- sodir = subprefix.call(c['sitearchdir'])
134
- elsif newpath_p
135
- # 1.4.4 <= V <= 1.6.3
136
- stdruby = "$prefix/lib/ruby/#{version}"
137
- siteruby = subprefix.call(c['sitedir'])
138
- versite = siteruby + '/' + version
139
- sodir = "$site-ruby/#{c['arch']}"
140
- else
141
- # V < 1.4.4
142
- stdruby = "$prefix/lib/ruby/#{version}"
143
- siteruby = "$prefix/lib/ruby/#{version}/site_ruby"
144
- versite = siteruby
145
- sodir = "$site-ruby/#{c['arch']}"
146
- end
147
-
148
- if arg = c['configure_args'].split.detect {|arg| /--with-make-prog=/ =~ arg }
149
- makeprog = arg.sub(/'/, '').split(/=/, 2)[1]
150
- else
151
- makeprog = 'make'
152
- end
153
-
154
- common_descripters = [
155
- [ 'prefix', [ c['prefix'],
156
- 'path',
157
- 'path prefix of target environment' ] ],
158
- [ 'std-ruby', [ stdruby,
159
- 'path',
160
- 'the directory for standard ruby libraries' ] ],
161
- [ 'site-ruby-common', [ siteruby,
162
- 'path',
163
- 'the directory for version-independent non-standard ruby libraries' ] ],
164
- [ 'site-ruby', [ versite,
165
- 'path',
166
- 'the directory for non-standard ruby libraries' ] ],
167
- [ 'bin-dir', [ '$prefix/bin',
168
- 'path',
169
- 'the directory for commands' ] ],
170
- [ 'rb-dir', [ '$site-ruby',
171
- 'path',
172
- 'the directory for ruby scripts' ] ],
173
- [ 'so-dir', [ sodir,
174
- 'path',
175
- 'the directory for ruby extentions' ] ],
176
- [ 'data-dir', [ '$prefix/share',
177
- 'path',
178
- 'the directory for shared data' ] ],
179
- [ 'ruby-path', [ rubypath,
180
- 'path',
181
- 'path to set to #! line' ] ],
182
- [ 'ruby-prog', [ rubypath,
183
- 'name',
184
- 'the ruby program using for installation' ] ],
185
- [ 'make-prog', [ makeprog,
186
- 'name',
187
- 'the make program to compile ruby extentions' ] ],
188
- [ 'without-ext', [ 'no',
189
- 'yes/no',
190
- 'does not compile/install ruby extentions' ] ]
191
- ]
192
- multipackage_descripters = [
193
- [ 'with', [ '',
194
- 'name,name...',
195
- 'package names that you want to install',
196
- 'ALL' ] ],
197
- [ 'without', [ '',
198
- 'name,name...',
199
- 'package names that you do not want to install',
200
- 'NONE' ] ]
201
- ]
202
- if multipackage_install?
203
- DESCRIPTER = common_descripters + multipackage_descripters
204
- else
205
- DESCRIPTER = common_descripters
83
+ def eval(table)
84
+ @value.gsub(%r<\$([^/]+)>) { table[$1] }
85
+ end
86
+
87
+ def set(val)
88
+ @value = check(val)
206
89
  end
207
90
 
208
- SAVE_FILE = 'config.save'
91
+ private
209
92
 
210
- def ConfigTable.each_name(&block)
211
- keys().each(&block)
93
+ def check(val)
94
+ setup_rb_error "config: --#{name} requires argument" unless val
95
+ val
212
96
  end
97
+ end
213
98
 
214
- def ConfigTable.keys
215
- DESCRIPTER.map {|name, *dummy| name }
99
+ class BoolItem < ConfigItem
100
+ def config_type
101
+ 'bool'
216
102
  end
217
103
 
218
- def ConfigTable.each_definition(&block)
219
- DESCRIPTER.each(&block)
104
+ def help_opt
105
+ "--#{@name}"
220
106
  end
221
107
 
222
- def ConfigTable.get_entry(name)
223
- name, ent = DESCRIPTER.assoc(name)
224
- ent
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'
225
116
  end
117
+ end
226
118
 
227
- def ConfigTable.get_entry!(name)
228
- get_entry(name) or raise ArgumentError, "no such config: #{name}"
119
+ class PathItem < ConfigItem
120
+ def config_type
121
+ 'path'
229
122
  end
230
123
 
231
- def ConfigTable.add_entry(name, vals)
232
- ConfigTable::DESCRIPTER.push [name,vals]
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)
233
129
  end
130
+ end
234
131
 
235
- def ConfigTable.remove_entry(name)
236
- get_entry(name) or raise ArgumentError, "no such config: #{name}"
237
- DESCRIPTER.delete_if {|n, arr| n == name }
132
+ class ProgramItem < ConfigItem
133
+ def config_type
134
+ 'program'
238
135
  end
136
+ end
239
137
 
240
- def ConfigTable.config_key?(name)
241
- get_entry(name) ? true : false
138
+ class SelectItem < ConfigItem
139
+ def initialize(name, template, default, desc)
140
+ super
141
+ @ok = template.split('/')
242
142
  end
243
143
 
244
- def ConfigTable.bool_config?(name)
245
- ent = get_entry(name) or return false
246
- ent[1] == 'yes/no'
144
+ def config_type
145
+ 'select'
247
146
  end
248
147
 
249
- def ConfigTable.value_config?(name)
250
- ent = get_entry(name) or return false
251
- ent[1] != 'yes/no'
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
252
155
  end
156
+ end
253
157
 
254
- def ConfigTable.path_config?(name)
255
- ent = get_entry(name) or return false
256
- ent[1] == 'path'
158
+ class PackageSelectionItem < ConfigItem
159
+ def initialize(name, template, default, help_default, desc)
160
+ super name, template, default, desc
161
+ @help_default = help_default
257
162
  end
258
163
 
164
+ attr_reader :help_default
259
165
 
260
- class << self
261
- alias newobj new
166
+ def config_type
167
+ 'package'
262
168
  end
263
169
 
264
- def ConfigTable.new
265
- c = newobj()
266
- c.initialize_from_table
267
- c
268
- end
170
+ private
269
171
 
270
- def ConfigTable.load
271
- c = newobj()
272
- c.initialize_from_file
273
- c
172
+ def check(val)
173
+ unless File.dir?("packages/#{val}")
174
+ setup_rb_error "config: no such package: #{val}"
175
+ end
176
+ val
274
177
  end
178
+ end
179
+
180
+ class ConfigTable_class
275
181
 
276
- def initialize_from_table
182
+ def initialize(items)
183
+ @items = items
277
184
  @table = {}
278
- DESCRIPTER.each do |k, (default, vname, desc, default2)|
279
- @table[k] = default
185
+ items.each do |i|
186
+ @table[i.name] = i
187
+ end
188
+ ALIASES.each do |ali, name|
189
+ @table[ali] = @table[name]
280
190
  end
281
191
  end
282
192
 
283
- def initialize_from_file
284
- raise InstallError, "#{File.basename $0} config first"\
285
- unless File.file?(SAVE_FILE)
286
- @table = {}
287
- File.foreach(SAVE_FILE) do |line|
288
- k, v = line.split(/=/, 2)
289
- @table[k] = v.strip
193
+ include Enumerable
194
+
195
+ def each(&block)
196
+ @items.each(&block)
197
+ end
198
+
199
+ def key?(name)
200
+ @table.key?(name)
201
+ end
202
+
203
+ def lookup(name)
204
+ @table[name] or raise ArgumentError, "no such config item: #{name}"
205
+ end
206
+
207
+ def add(item)
208
+ @items.push item
209
+ @table[item.name] = item
210
+ end
211
+
212
+ def remove(name)
213
+ item = lookup(name)
214
+ @items.delete_if {|i| i.name == name }
215
+ @table.delete_if {|name, i| i.name == name }
216
+ item
217
+ end
218
+
219
+ def new
220
+ dup()
221
+ end
222
+
223
+ def savefile
224
+ '.config'
225
+ end
226
+
227
+ def load
228
+ begin
229
+ t = dup()
230
+ File.foreach(savefile()) do |line|
231
+ k, v = *line.split(/=/, 2)
232
+ t[k] = v.strip
233
+ end
234
+ t
235
+ rescue Errno::ENOENT
236
+ setup_rb_error $!.message + "#{File.basename($0)} config first"
290
237
  end
291
238
  end
292
239
 
293
240
  def save
294
- File.open(SAVE_FILE, 'w') {|f|
295
- @table.each do |k, v|
296
- f.printf "%s=%s\n", k, v if v
241
+ @items.each {|i| i.value }
242
+ File.open(savefile(), 'w') {|f|
243
+ @items.each do |i|
244
+ f.printf "%s=%s\n", i.name, i.value if i.value
297
245
  end
298
246
  }
299
247
  end
300
248
 
301
- def []=(k, v)
302
- raise InstallError, "unknown config option #{k}"\
303
- unless ConfigTable.config_key?(k)
304
- @table[k] = v
305
- end
306
-
307
249
  def [](key)
308
- return nil unless @table[key]
309
- @table[key].gsub(%r<\$([^/]+)>) { self[$1] }
250
+ lookup(key).eval(self)
310
251
  end
311
252
 
312
- def set_raw(key, val)
313
- @table[key] = val
253
+ def []=(key, val)
254
+ lookup(key).set val
314
255
  end
315
256
 
316
- def get_raw(key)
317
- @table[key]
318
- end
257
+ end
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
319
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
353
+ ALIASES = {
354
+ 'std-ruby' => 'stdruby',
355
+ 'site-ruby-common' => 'siteruby', # For backward compatibility
356
+ 'site-ruby' => 'siterubyver', # For backward compatibility
357
+ 'bin-dir' => 'bindir',
358
+ 'bin-dir' => 'bindir',
359
+ 'rb-dir' => 'rbdir',
360
+ 'so-dir' => 'sodir',
361
+ 'data-dir' => 'datadir',
362
+ 'ruby-path' => 'rubypath',
363
+ 'ruby-prog' => 'rubyprog',
364
+ 'ruby' => 'rubyprog',
365
+ 'make-prog' => 'makeprog',
366
+ 'make' => 'makeprog'
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)
320
379
  end
321
380
 
322
381
 
@@ -327,53 +386,53 @@ module MetaConfigAPI
327
386
  end
328
387
 
329
388
  def config_names
330
- ConfigTable.keys
389
+ ConfigTable.map {|i| i.name }
331
390
  end
332
391
 
333
392
  def config?(name)
334
- ConfigTable.config_key?(name)
393
+ ConfigTable.key?(name)
335
394
  end
336
395
 
337
396
  def bool_config?(name)
338
- ConfigTable.bool_config?(name)
339
- end
340
-
341
- def value_config?(name)
342
- ConfigTable.value_config?(name)
397
+ ConfigTable.lookup(name).config_type == 'bool'
343
398
  end
344
399
 
345
400
  def path_config?(name)
346
- ConfigTable.path_config?(name)
401
+ ConfigTable.lookup(name).config_type == 'path'
347
402
  end
348
403
 
349
- def add_config(name, argname, default, desc)
350
- ConfigTable.add_entry name,[default,argname,desc]
404
+ def value_config?(name)
405
+ case ConfigTable.lookup(name).config_type
406
+ when 'bool', 'path'
407
+ true
408
+ else
409
+ false
410
+ end
351
411
  end
352
412
 
353
- def add_path_config(name, default, desc)
354
- add_config name, 'path', default, desc
413
+ def add_config(item)
414
+ ConfigTable.add item
355
415
  end
356
416
 
357
417
  def add_bool_config(name, default, desc)
358
- add_config name, 'yes/no', default ? 'yes' : 'no', desc
418
+ ConfigTable.add BoolItem.new(name, 'yes/no', default ? 'yes' : 'no', desc)
419
+ end
420
+
421
+ def add_path_config(name, default, desc)
422
+ ConfigTable.add PathItem.new(name, 'path', default, desc)
359
423
  end
360
424
 
361
425
  def set_config_default(name, default)
362
- if bool_config?(name)
363
- ConfigTable.get_entry!(name)[0] = (default ? 'yes' : 'no')
364
- else
365
- ConfigTable.get_entry!(name)[0] = default
366
- end
426
+ ConfigTable.lookup(name).default = default
367
427
  end
368
428
 
369
429
  def remove_config(name)
370
- ent = ConfigTable.get_entry(name)
371
- ConfigTable.remove_entry name
372
- ent
430
+ ConfigTable.remove(name)
373
431
  end
374
432
 
375
433
  end
376
434
 
435
+
377
436
  #
378
437
  # File Operations
379
438
  #
@@ -381,12 +440,12 @@ end
381
440
  module FileOperations
382
441
 
383
442
  def mkdir_p(dirname, prefix = nil)
384
- dirname = prefix + dirname if prefix
443
+ dirname = prefix + File.expand_path(dirname) if prefix
385
444
  $stderr.puts "mkdir -p #{dirname}" if verbose?
386
445
  return if no_harm?
387
446
 
388
447
  # does not check '/'... it's too abnormal case
389
- dirs = dirname.split(%r<(?=/)>)
448
+ dirs = File.expand_path(dirname).split(%r<(?=/)>)
390
449
  if /\A[a-z]:\z/i =~ dirs[0]
391
450
  disk = dirs.shift
392
451
  dirs[0] = disk + dirs[0]
@@ -444,7 +503,7 @@ module FileOperations
444
503
  $stderr.puts "install #{from} #{dest}" if verbose?
445
504
  return if no_harm?
446
505
 
447
- realdest = prefix + dest if prefix
506
+ realdest = prefix ? prefix + File.expand_path(dest) : dest
448
507
  realdest = File.join(realdest, File.basename(from)) if File.dir?(realdest)
449
508
  str = File.binread(from)
450
509
  if diff?(str, realdest)
@@ -477,11 +536,11 @@ module FileOperations
477
536
  end
478
537
 
479
538
  def ruby(str)
480
- command config('ruby-prog') + ' ' + str
539
+ command config('rubyprog') + ' ' + str
481
540
  end
482
541
 
483
542
  def make(task = '')
484
- command config('make-prog') + ' ' + task
543
+ command config('makeprog') + ' ' + task
485
544
  end
486
545
 
487
546
  def extdir?(dir)
@@ -495,7 +554,7 @@ module FileOperations
495
554
  end
496
555
 
497
556
  REJECT_DIRS = %w(
498
- CVS SCCS RCS CVS.adm
557
+ CVS SCCS RCS CVS.adm .svn
499
558
  )
500
559
 
501
560
  def all_dirs_in(dirname)
@@ -506,13 +565,11 @@ module FileOperations
506
565
 
507
566
  end
508
567
 
568
+
509
569
  #
510
570
  # Main Installer
511
571
  #
512
572
 
513
- class InstallError < StandardError; end
514
-
515
-
516
573
  module HookUtils
517
574
 
518
575
  def run_hook(name)
@@ -525,7 +582,7 @@ module HookUtils
525
582
  begin
526
583
  instance_eval File.read(fname), fname, 1
527
584
  rescue
528
- raise InstallError, "hook #{fname} failed:\n" + $!.message
585
+ setup_rb_error "hook #{fname} failed:\n" + $!.message
529
586
  end
530
587
  true
531
588
  end
@@ -600,10 +657,11 @@ end
600
657
 
601
658
  class ToplevelInstaller
602
659
 
603
- Version = '3.2.4'
660
+ Version = '3.3.1'
604
661
  Copyright = 'Copyright (c) 2000-2004 Minero Aoki'
605
662
 
606
663
  TASKS = [
664
+ [ 'all', 'do config, setup, then install' ],
607
665
  [ 'config', 'saves your configurations' ],
608
666
  [ 'show', 'shows current configuration' ],
609
667
  [ 'setup', 'compiles ruby extentions and others' ],
@@ -637,13 +695,22 @@ class ToplevelInstaller
637
695
 
638
696
  def invoke
639
697
  run_metaconfigs
640
- task = parsearg_global()
641
- @config = load_config(task)
642
- __send__ "parsearg_#{task}"
643
- init_installers
644
- __send__ "exec_#{task}"
698
+ case task = parsearg_global()
699
+ when nil, 'all'
700
+ @config = load_config('config')
701
+ parsearg_config
702
+ init_installers
703
+ exec_config
704
+ exec_setup
705
+ exec_install
706
+ else
707
+ @config = load_config(task)
708
+ __send__ "parsearg_#{task}"
709
+ init_installers
710
+ __send__ "exec_#{task}"
711
+ end
645
712
  end
646
-
713
+
647
714
  def run_metaconfigs
648
715
  eval_file_ifexist "#{@ardir}/metaconfig"
649
716
  end
@@ -653,7 +720,7 @@ class ToplevelInstaller
653
720
  when 'config'
654
721
  ConfigTable.new
655
722
  when 'clean', 'distclean'
656
- if File.exist?('config.save')
723
+ if File.exist?(ConfigTable.savefile)
657
724
  then ConfigTable.load
658
725
  else ConfigTable.new
659
726
  end
@@ -692,7 +759,7 @@ class ToplevelInstaller
692
759
  while arg = ARGV.shift
693
760
  case arg
694
761
  when /\A\w+\z/
695
- raise InstallError, "invalid task: #{arg}" unless valid_task =~ arg
762
+ setup_rb_error "invalid task: #{arg}" unless valid_task =~ arg
696
763
  return arg
697
764
 
698
765
  when '-q', '--quiet'
@@ -714,23 +781,18 @@ class ToplevelInstaller
714
781
  exit 0
715
782
 
716
783
  else
717
- raise InstallError, "unknown global option '#{arg}'"
784
+ setup_rb_error "unknown global option '#{arg}'"
718
785
  end
719
786
  end
720
787
 
721
- raise InstallError, <<EOS
722
- No task or global option given.
723
- Typical installation procedure is:
724
- $ ruby #{File.basename($0)} config
725
- $ ruby #{File.basename($0)} setup
726
- # ruby #{File.basename($0)} install (may require root privilege)
727
- EOS
788
+ nil
728
789
  end
729
790
 
730
791
 
731
792
  def parsearg_no_options
732
- raise InstallError, "#{task}: unknown options: #{ARGV.join ' '}"\
733
- unless ARGV.empty?
793
+ unless ARGV.empty?
794
+ setup_rb_error "#{task}: unknown options: #{ARGV.join ' '}"
795
+ end
734
796
  end
735
797
 
736
798
  alias parsearg_show parsearg_no_options
@@ -739,7 +801,7 @@ EOS
739
801
  alias parsearg_distclean parsearg_no_options
740
802
 
741
803
  def parsearg_config
742
- re = /\A--(#{ConfigTable.keys.join '|'})(?:=(.*))?\z/
804
+ re = /\A--(#{ConfigTable.map {|i| i.name }.join('|')})(?:=(.*))?\z/
743
805
  @options['config-opt'] = []
744
806
 
745
807
  while i = ARGV.shift
@@ -747,19 +809,8 @@ EOS
747
809
  @options['config-opt'] = ARGV.dup
748
810
  break
749
811
  end
750
- m = re.match(i) or raise InstallError, "config: unknown option #{i}"
751
- name, value = m.to_a[1,2]
752
- if value
753
- if ConfigTable.bool_config?(name)
754
- raise InstallError, "config: --#{name} allows only yes/no for argument"\
755
- unless /\A(y(es)?|n(o)?|t(rue)?|f(alse))\z/i =~ value
756
- value = (/\Ay(es)?|\At(rue)/i =~ value) ? 'yes' : 'no'
757
- end
758
- else
759
- raise InstallError, "config: --#{name} requires argument"\
760
- unless ConfigTable.bool_config?(name)
761
- value = 'yes'
762
- end
812
+ m = re.match(i) or setup_rb_error "config: unknown option #{i}"
813
+ name, value = *m.to_a[1,2]
763
814
  @config[name] = value
764
815
  end
765
816
  end
@@ -776,7 +827,7 @@ EOS
776
827
  path = File.expand_path(path) unless path[0,1] == '/'
777
828
  @options['install-prefix'] = path
778
829
  else
779
- raise InstallError, "install: unknown option #{a}"
830
+ setup_rb_error "install: unknown option #{a}"
780
831
  end
781
832
  end
782
833
  end
@@ -791,7 +842,7 @@ EOS
791
842
  out.puts " ruby #{File.basename $0} <global option>"
792
843
  out.puts " ruby #{File.basename $0} [<global options>] <task> [<task options>]"
793
844
 
794
- fmt = " %-20s %s\n"
845
+ fmt = " %-24s %s\n"
795
846
  out.puts
796
847
  out.puts 'Global options:'
797
848
  out.printf fmt, '-q,--quiet', 'suppress message outputs'
@@ -799,31 +850,23 @@ EOS
799
850
  out.printf fmt, '-h,--help', 'print this message'
800
851
  out.printf fmt, '-v,--version', 'print version and quit'
801
852
  out.printf fmt, ' --copyright', 'print copyright and quit'
802
-
803
853
  out.puts
804
854
  out.puts 'Tasks:'
805
855
  TASKS.each do |name, desc|
806
- out.printf " %-10s %s\n", name, desc
856
+ out.printf fmt, name, desc
807
857
  end
808
858
 
859
+ fmt = " %-24s %s [%s]\n"
809
860
  out.puts
810
- out.puts 'Options for config:'
811
- ConfigTable.each_definition do |name, (default, arg, desc, default2)|
812
- out.printf " %-20s %s [%s]\n",
813
- '--'+ name + (ConfigTable.bool_config?(name) ? '' : '='+arg),
814
- desc,
815
- default2 || default
861
+ out.puts 'Options for CONFIG or ALL:'
862
+ ConfigTable.each do |item|
863
+ out.printf fmt, item.help_opt, item.description, item.help_default
816
864
  end
817
- out.printf " %-20s %s [%s]\n",
818
- '--rbconfig=path', 'your rbconfig.rb to load', "running ruby's"
819
-
865
+ out.printf fmt, '--rbconfig=path', 'rbconfig.rb to load',"running ruby's"
820
866
  out.puts
821
- out.puts 'Options for install:'
822
- out.printf " %-20s %s [%s]\n",
823
- '--no-harm', 'only display what to do if given', 'off'
824
- out.printf " %-20s %s [%s]\n",
825
- '--prefix', 'install path prefix', '$prefix'
826
-
867
+ out.puts 'Options for INSTALL:'
868
+ out.printf fmt, '--no-harm', 'only display what to do if given', 'off'
869
+ out.printf fmt, '--prefix=path', 'install path prefix', '$prefix'
827
870
  out.puts
828
871
  end
829
872
 
@@ -845,12 +888,8 @@ EOS
845
888
  end
846
889
 
847
890
  def exec_show
848
- ConfigTable.each_name do |k|
849
- v = @config.get_raw(k)
850
- if not v or v.empty?
851
- v = '(not specified)'
852
- end
853
- printf "%-10s %s\n", k, v
891
+ ConfigTable.each do |i|
892
+ printf "%-20s %s\n", i.name, i.value
854
893
  end
855
894
  end
856
895
 
@@ -903,8 +942,7 @@ class ToplevelInstallerMulti < ToplevelInstaller
903
942
  def extract_selection(list)
904
943
  a = list.split(/,/)
905
944
  a.each do |name|
906
- raise InstallError, "no such package: #{name}" \
907
- unless @installers.key?(name)
945
+ setup_rb_error "no such package: #{name}" unless @installers.key?(name)
908
946
  end
909
947
  a
910
948
  end
@@ -955,14 +993,14 @@ class ToplevelInstallerMulti < ToplevelInstaller
955
993
  end
956
994
 
957
995
  def exec_clean
958
- rm_f 'config.save'
996
+ rm_f ConfigTable.savefile
959
997
  run_hook 'pre-clean'
960
998
  each_selected_installers {|inst| inst.exec_clean }
961
999
  run_hook 'post-clean'
962
1000
  end
963
1001
 
964
1002
  def exec_distclean
965
- rm_f 'config.save'
1003
+ rm_f ConfigTable.savefile
966
1004
  run_hook 'pre-distclean'
967
1005
  each_selected_installers {|inst| inst.exec_distclean }
968
1006
  run_hook 'post-distclean'
@@ -1015,7 +1053,7 @@ class Installer
1015
1053
  end
1016
1054
 
1017
1055
  #
1018
- # Hook Script API bases
1056
+ # Hook Script API base methods
1019
1057
  #
1020
1058
 
1021
1059
  def srcdir_root
@@ -1071,7 +1109,7 @@ class Installer
1071
1109
 
1072
1110
  def extconf
1073
1111
  opt = @options['config-opt'].join(' ')
1074
- command "#{config('ruby-prog')} #{curr_srcdir()}/extconf.rb #{opt}"
1112
+ command "#{config('rubyprog')} #{curr_srcdir()}/extconf.rb #{opt}"
1075
1113
  end
1076
1114
 
1077
1115
  def config_dir_data(rel)
@@ -1091,24 +1129,17 @@ class Installer
1091
1129
  end
1092
1130
  end
1093
1131
 
1094
- # modify: #!/usr/bin/ruby
1095
- # modify: #! /usr/bin/ruby
1096
- # modify: #!ruby
1097
- # not modify: #!/usr/bin/env ruby
1098
- SHEBANG_RE = /\A\#!\s*\S*ruby\S*/
1099
-
1100
1132
  def adjust_shebang(path)
1101
1133
  return if no_harm?
1102
-
1103
1134
  tmpfile = File.basename(path) + '.tmp'
1104
1135
  begin
1105
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?
1106
1141
  File.open(tmpfile, 'wb') {|w|
1107
- first = r.gets
1108
- return unless SHEBANG_RE =~ first
1109
-
1110
- $stderr.puts "adjusting shebang: #{File.basename path}" if verbose?
1111
- w.print first.sub(SHEBANG_RE, '#!' + config('ruby-path'))
1142
+ w.print first.sub(/\A\#!\s*\S+/, '#! ' + config('rubypath'))
1112
1143
  w.write r.read
1113
1144
  }
1114
1145
  }
@@ -1133,26 +1164,27 @@ class Installer
1133
1164
  #
1134
1165
 
1135
1166
  def exec_install
1167
+ rm_f 'InstalledFiles'
1136
1168
  exec_task_traverse 'install'
1137
1169
  end
1138
1170
 
1139
1171
  def install_dir_bin(rel)
1140
- install_files collect_filenames_auto(), "#{config('bin-dir')}/#{rel}", 0755
1172
+ install_files collect_filenames_auto(), "#{config('bindir')}/#{rel}", 0755
1141
1173
  end
1142
1174
 
1143
1175
  def install_dir_lib(rel)
1144
- install_files ruby_scripts(), "#{config('rb-dir')}/#{rel}", 0644
1176
+ install_files ruby_scripts(), "#{config('rbdir')}/#{rel}", 0644
1145
1177
  end
1146
1178
 
1147
1179
  def install_dir_ext(rel)
1148
1180
  return unless extdir?(curr_srcdir())
1149
1181
  install_files ruby_extentions('.'),
1150
- "#{config('so-dir')}/#{File.dirname(rel)}",
1182
+ "#{config('sodir')}/#{File.dirname(rel)}",
1151
1183
  0555
1152
1184
  end
1153
1185
 
1154
1186
  def install_dir_data(rel)
1155
- install_files collect_filenames_auto(), "#{config('data-dir')}/#{rel}", 0644
1187
+ install_files collect_filenames_auto(), "#{config('datadir')}/#{rel}", 0644
1156
1188
  end
1157
1189
 
1158
1190
  def install_files(list, dest, mode)
@@ -1213,15 +1245,12 @@ class Installer
1213
1245
  end
1214
1246
 
1215
1247
  def ruby_extentions(dir)
1216
- _ruby_extentions(dir) or
1217
- raise InstallError, "no ruby extention exists: 'ruby #{$0} setup' first"
1218
- end
1219
-
1220
- DLEXT = /\.#{ ::Config::CONFIG['DLEXT'] }\z/
1221
-
1222
- def _ruby_extentions(dir)
1223
1248
  Dir.open(dir) {|d|
1224
- return d.select {|fname| DLEXT =~ fname }
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
1225
1254
  }
1226
1255
  end
1227
1256
 
@@ -1231,7 +1260,7 @@ class Installer
1231
1260
 
1232
1261
  def exec_clean
1233
1262
  exec_task_traverse 'clean'
1234
- rm_f 'config.save'
1263
+ rm_f ConfigTable.savefile
1235
1264
  rm_f 'InstalledFiles'
1236
1265
  end
1237
1266
 
@@ -1255,7 +1284,7 @@ class Installer
1255
1284
 
1256
1285
  def exec_distclean
1257
1286
  exec_task_traverse 'distclean'
1258
- rm_f 'config.save'
1287
+ rm_f ConfigTable.savefile
1259
1288
  rm_f 'InstalledFiles'
1260
1289
  end
1261
1290
 
@@ -1322,7 +1351,7 @@ if $0 == __FILE__
1322
1351
  else
1323
1352
  ToplevelInstaller.invoke
1324
1353
  end
1325
- rescue
1354
+ rescue SetupError
1326
1355
  raise if $DEBUG
1327
1356
  $stderr.puts $!.message
1328
1357
  $stderr.puts "Try 'ruby #{$0} --help' for detailed usage."