libxml-ruby 0.5.4 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (139) hide show
  1. data/LICENSE +23 -23
  2. data/README +144 -144
  3. data/ext/libxml/extconf.rb +26 -27
  4. data/ext/libxml/libxml.c +7 -37
  5. data/ext/libxml/{libxml.h → ruby_libxml.h} +93 -98
  6. data/ext/libxml/ruby_xml_attr.c +405 -387
  7. data/ext/libxml/ruby_xml_attr.h +19 -18
  8. data/ext/libxml/ruby_xml_document.c +1111 -1115
  9. data/ext/libxml/ruby_xml_document.h +27 -24
  10. data/ext/libxml/ruby_xml_dtd.c +168 -168
  11. data/ext/libxml/ruby_xml_html_parser.c +449 -450
  12. data/ext/libxml/ruby_xml_html_parser.h +1 -1
  13. data/ext/libxml/ruby_xml_input_cbg.c +158 -158
  14. data/ext/libxml/ruby_xml_node.c +2410 -2395
  15. data/ext/libxml/ruby_xml_node.h +1 -1
  16. data/ext/libxml/ruby_xml_node_set.c +170 -170
  17. data/ext/libxml/ruby_xml_node_set.h +1 -1
  18. data/ext/libxml/ruby_xml_ns.c +153 -153
  19. data/ext/libxml/ruby_xml_ns.h +1 -1
  20. data/ext/libxml/ruby_xml_parser.c +1425 -1422
  21. data/ext/libxml/ruby_xml_parser.h +1 -1
  22. data/ext/libxml/ruby_xml_parser_context.c +750 -716
  23. data/ext/libxml/ruby_xml_parser_context.h +1 -1
  24. data/ext/libxml/ruby_xml_reader.c +900 -896
  25. data/ext/libxml/ruby_xml_sax_parser.c +485 -485
  26. data/ext/libxml/ruby_xml_sax_parser.h +1 -1
  27. data/ext/libxml/ruby_xml_schema.c +146 -142
  28. data/ext/libxml/ruby_xml_state.c +5 -6
  29. data/ext/libxml/ruby_xml_state.h +1 -0
  30. data/ext/libxml/ruby_xml_tree.c +43 -43
  31. data/ext/libxml/ruby_xml_tree.h +1 -1
  32. data/ext/libxml/ruby_xml_xinclude.c +20 -20
  33. data/ext/libxml/ruby_xml_xinclude.h +1 -1
  34. data/ext/libxml/ruby_xml_xpath.c +243 -252
  35. data/ext/libxml/ruby_xml_xpath.h +1 -1
  36. data/ext/libxml/ruby_xml_xpath_context.c +118 -118
  37. data/ext/libxml/ruby_xml_xpath_context.h +1 -1
  38. data/ext/libxml/ruby_xml_xpath_object.c +43 -29
  39. data/ext/libxml/ruby_xml_xpath_object.h +0 -1
  40. data/ext/libxml/ruby_xml_xpointer.c +100 -100
  41. data/ext/libxml/ruby_xml_xpointer.h +1 -1
  42. data/ext/libxml/ruby_xml_xpointer_context.c +21 -21
  43. data/ext/libxml/ruby_xml_xpointer_context.h +1 -1
  44. data/ext/libxml/sax_parser_callbacks.inc +213 -213
  45. data/ext/libxml/version.h +9 -9
  46. data/lib/libxml.rb +24 -3
  47. data/mingw/libiconv-2.dll +0 -0
  48. data/mingw/libxml2-2.dll +0 -0
  49. data/mingw/libxml_ruby.so +0 -0
  50. data/mingw/mingw.rake +36 -0
  51. data/test/dtd-test.rb +24 -24
  52. data/test/etc_doc_to_s.rb +1 -3
  53. data/test/ets_copy_bug.rb +21 -21
  54. data/test/ets_copy_bug2.rb +32 -32
  55. data/test/ets_copy_bug3.rb +38 -0
  56. data/test/ets_doc_file.rb +1 -0
  57. data/test/{model/default_validation_bug.rb → gc.log} +0 -0
  58. data/test/merge_bug.rb +55 -55
  59. data/test/schema-test.rb +74 -74
  60. data/test/tc_well_formed.rb +11 -0
  61. data/test/tc_xml_document.rb +52 -52
  62. data/test/tc_xml_document_write.rb +24 -24
  63. data/test/tc_xml_document_write2.rb +54 -54
  64. data/test/tc_xml_document_write3.rb +96 -96
  65. data/test/tc_xml_html_parser.rb +63 -63
  66. data/test/tc_xml_node.rb +59 -59
  67. data/test/tc_xml_node2.rb +25 -25
  68. data/test/tc_xml_node3.rb +27 -27
  69. data/test/tc_xml_node4.rb +86 -86
  70. data/test/tc_xml_node5.rb +52 -52
  71. data/test/tc_xml_node6.rb +27 -27
  72. data/test/tc_xml_node7.rb +35 -35
  73. data/test/tc_xml_node8.rb +32 -32
  74. data/test/tc_xml_node9.rb +32 -32
  75. data/test/tc_xml_node_set.rb +24 -24
  76. data/test/tc_xml_node_set2.rb +37 -37
  77. data/test/tc_xml_node_xlink.rb +28 -28
  78. data/test/tc_xml_parser.rb +190 -178
  79. data/test/tc_xml_parser2.rb +16 -17
  80. data/test/tc_xml_parser3.rb +23 -23
  81. data/test/tc_xml_parser4.rb +33 -33
  82. data/test/tc_xml_parser5.rb +27 -27
  83. data/test/tc_xml_parser6.rb +23 -23
  84. data/test/tc_xml_parser7.rb +28 -28
  85. data/test/tc_xml_parser8.rb +32 -32
  86. data/test/tc_xml_parser9.rb +11 -0
  87. data/test/tc_xml_parser_context.rb +88 -88
  88. data/test/tc_xml_reader.rb +112 -109
  89. data/test/tc_xml_sax_parser.rb +104 -94
  90. data/test/tc_xml_sax_parser2.rb +51 -0
  91. data/test/tc_xml_xinclude.rb +30 -30
  92. data/test/tc_xml_xpath.rb +38 -38
  93. data/test/tc_xml_xpath2.rb +14 -0
  94. data/test/tc_xml_xpointer.rb +78 -78
  95. data/vc/libxml.sln +20 -0
  96. data/vc/libxml.vcproj +389 -0
  97. data/work/Rakefile +247 -0
  98. data/work/task/make +26 -0
  99. data/work/task/memory +37 -0
  100. data/work/task/rdoc +39 -0
  101. data/work/task/setup +1616 -0
  102. data/work/task/test +29 -0
  103. data/work/test/ets_runner.rb +33 -0
  104. data/work/test/libxml_test.rb +3 -0
  105. data/work/test/runner.rb +0 -0
  106. data/work/test/runner_ets.rb +33 -0
  107. data/work/vc/debug/libxml.exp +0 -0
  108. data/work/vc/debug/libxml.ilk +0 -0
  109. data/work/vc/debug/libxml.lib +0 -0
  110. data/work/vc/debug/libxml.pdb +0 -0
  111. data/work/vc/debug/libxml.so +0 -0
  112. metadata +158 -189
  113. data/MANIFEST +0 -138
  114. data/NOTES +0 -9
  115. data/Rakefile +0 -38
  116. data/TODO +0 -75
  117. data/VERSION +0 -1
  118. data/log/Changelog-0.txt +0 -426
  119. data/log/Changelog.txt +0 -435
  120. data/meta/project.yaml +0 -27
  121. data/meta/unixname +0 -1
  122. data/setup.rb +0 -1472
  123. data/site/css/normal.css +0 -182
  124. data/site/img/raze-tiny.png +0 -0
  125. data/site/img/red-cube.jpg +0 -0
  126. data/site/img/xml-ruby.png +0 -0
  127. data/site/index.xml +0 -43
  128. data/site/install.xml +0 -77
  129. data/site/layout.rhtml +0 -38
  130. data/site/layout.xsl +0 -67
  131. data/site/license.xml +0 -32
  132. data/site/log/changelog.xml +0 -1324
  133. data/site/log/changelog.xsl +0 -42
  134. data/test/model/merge_bug_data.xml +0 -58
  135. data/test/model/rubynet.xml +0 -78
  136. data/test/model/rubynet_project +0 -13
  137. data/test/model/saxtest.xml +0 -5
  138. data/test/model/simple.xml +0 -7
  139. data/test/model/xinclude.xml +0 -5
data/setup.rb DELETED
@@ -1,1472 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # Setup.rb v3.5.0
3
- # Copyright (c) 2008 Minero Aoki, Trans
4
- #
5
- # This program is free software.
6
- # You can distribute/modify this program under the terms of
7
- # the GNU LGPL, Lesser General Public License version 2.1.
8
-
9
- # Need the package name, and whether to generate documentation.
10
- PACKAGE = File.read(Dir.glob('{.,meta/}unixname{,.txt}', File::FNM_CASEFOLD).first).strip
11
- GENERATE_RDOCS = true # package developer may need to deactivate
12
-
13
- require 'optparse'
14
- require 'rbconfig'
15
-
16
- class SetupError < StandardError; end
17
-
18
- # Typical installation procedure:
19
- #
20
- # $ ./setup.rb
21
- #
22
- # -- or --
23
- #
24
- # $ ./setup.rb config
25
- # $ ./setup.rb setup
26
- # $ ./setup.rb install
27
- #
28
- # @all@ and @install@ may require root privileges.
29
- #
30
- # This update only works with Ruby 1.6.3 and above.
31
- #
32
- # TODO: Update shebangs on install of binaries.
33
- # TODO: Make cleaning more comprehensive (?)
34
-
35
- module Setup
36
- Version = "3.5.0"
37
-
38
- Copyright = "Copyright (c) 2000,2008 Minero Aoki, Trans"
39
-
40
- # ConfigTable stores platform information.
41
-
42
- class ConfigTable
43
-
44
- RBCONFIG = ::Config::CONFIG
45
-
46
- CONFIGFILE = '.config'
47
-
48
- DESCRIPTIONS = [
49
- [:prefix , :path, 'path prefix of target environment'],
50
- [:bindir , :path, 'directory for commands'],
51
- [:libdir , :path, 'directory for libraries'],
52
- [:datadir , :path, 'directory for shared data'],
53
- [:mandir , :path, 'directory for man pages'],
54
- [:docdir , :path, 'Directory for documentation'],
55
- [:sysconfdir , :path, 'directory for system configuration files'],
56
- [:localstatedir , :path, 'directory for local state data'],
57
- [:libruby , :path, 'directory for ruby libraries'],
58
- [:librubyver , :path, 'directory for standard ruby libraries'],
59
- [:librubyverarch , :path, 'directory for standard ruby extensions'],
60
- [:siteruby , :path, 'directory for version-independent aux ruby libraries'],
61
- [:siterubyver , :path, 'directory for aux ruby libraries'],
62
- [:siterubyverarch , :path, 'directory for aux ruby binaries'],
63
- [:rbdir , :path, 'directory for ruby scripts'],
64
- [:sodir , :path, 'directory for ruby extentions'],
65
- [:rubypath , :prog, 'path to set to #! line'],
66
- [:rubyprog , :prog, 'ruby program using for installation'],
67
- [:makeprog , :prog, 'make program to compile ruby extentions'],
68
- [:extconfopt , :name, 'options to pass-thru to extconf.rb'],
69
- [:without_ext , :bool, 'do not compile/install ruby extentions'],
70
- [:without_doc , :bool, 'do not generate html documentation'],
71
- [:shebang , :pick, 'shebang line (#!) editing mode (all,ruby,never)'],
72
- [:doctemplate , :pick, 'document template to use (html|xml)'],
73
- [:testrunner , :pick, 'Runner to use for testing (auto|console|tk|gtk|gtk2)'],
74
- [:installdirs , :pick, 'install location mode (std,site,home :: libruby,site_ruby,$HOME)']
75
- ]
76
-
77
- # List of configurable options.
78
- OPTIONS = DESCRIPTIONS.collect{ |(k,t,v)| k.to_s }
79
-
80
- # Pathname attribute. Pathnames are automatically expanded
81
- # unless they start with '$', a path variable.
82
- def self.attr_pathname(name)
83
- class_eval %{
84
- def #{name}
85
- @#{name}.gsub(%r<\\$([^/]+)>){ self[$1] }
86
- end
87
- def #{name}=(path)
88
- raise SetupError, "bad config: #{name.to_s.upcase} requires argument" unless path
89
- @#{name} = (path[0,1] == '$' ? path : File.expand_path(path))
90
- end
91
- }
92
- end
93
-
94
- # List of pathnames. These are not expanded though.
95
- def self.attr_pathlist(name)
96
- class_eval %{
97
- def #{name}
98
- @#{name}
99
- end
100
- def #{name}=(pathlist)
101
- case pathlist
102
- when Array
103
- @#{name} = pathlist
104
- else
105
- @#{name} = pathlist.to_s.split(/[:;,]/)
106
- end
107
- end
108
- }
109
- end
110
-
111
- # Adds boolean support.
112
- def self.attr_accessor(*names)
113
- bools, attrs = names.partition{ |name| name.to_s =~ /\?$/ }
114
- attr_boolean *bools
115
- super *attrs
116
- end
117
-
118
- # Boolean attribute. Can be assigned true, false, nil, or
119
- # a string matching yes|true|y|t or no|false|n|f.
120
- def self.attr_boolean(*names)
121
- names.each do |name|
122
- name = name.to_s.chomp('?')
123
- attr_reader name # MAYBE: Deprecate
124
- code = %{
125
- def #{name}?; @#{name}; end
126
- def #{name}=(val)
127
- case val
128
- when true, false, nil
129
- @#{name} = val
130
- else
131
- case val.to_s.downcase
132
- when 'y', 'yes', 't', 'true'
133
- @#{name} = true
134
- when 'n', 'no', 'f', 'false'
135
- @#{name} = false
136
- else
137
- raise SetupError, "bad config: use #{name.upcase}=(yes|no) [\#{val}]"
138
- end
139
- end
140
- end
141
- }
142
- class_eval code
143
- end
144
- end
145
-
146
- DESCRIPTIONS.each do |k,t,d|
147
- case t
148
- when :path
149
- attr_pathname k
150
- when :bool
151
- attr_boolean k
152
- else
153
- attr_accessor k
154
- end
155
- end
156
-
157
- # # provide verbosity (default is true)
158
- # attr_accessor :verbose?
159
-
160
- # # don't actually write files to system
161
- # attr_accessor :no_harm?
162
-
163
- # shebang has only three options.
164
- def shebang=(val)
165
- if %w(all ruby never).include?(val)
166
- @shebang = val
167
- else
168
- raise SetupError, "bad config: use SHEBANG=(all|ruby|never) [#{val}]"
169
- end
170
- end
171
-
172
- # installdirs has only three options; and it has side-effects.
173
- def installdirs=(val)
174
- @installdirs = val
175
- case val.to_s
176
- when 'std'
177
- self.rbdir = '$librubyver'
178
- self.sodir = '$librubyverarch'
179
- when 'site'
180
- self.rbdir = '$siterubyver'
181
- self.sodir = '$siterubyverarch'
182
- when 'home'
183
- raise SetupError, 'HOME is not set.' unless ENV['HOME']
184
- self.prefix = ENV['HOME']
185
- self.rbdir = '$libdir/ruby'
186
- self.sodir = '$libdir/ruby'
187
- else
188
- raise SetupError, "bad config: use INSTALLDIRS=(std|site|home|local) [#{val}]"
189
- end
190
- end
191
-
192
- # New ConfigTable
193
- def initialize(values=nil)
194
- initialize_defaults
195
- if values
196
- values.each{ |k,v| __send__("#{k}=", v) }
197
- end
198
- yeild(self) if block_given?
199
- load_config if File.file?(CONFIGFILE)
200
- end
201
-
202
- # Assign CONFIG defaults
203
- #
204
- # TODO: Does this handle 'nmake' on windows?
205
- def initialize_defaults
206
- prefix = RBCONFIG['prefix']
207
-
208
- rubypath = File.join(RBCONFIG['bindir'], RBCONFIG['ruby_install_name'] + RBCONFIG['EXEEXT'])
209
-
210
- major = RBCONFIG['MAJOR'].to_i
211
- minor = RBCONFIG['MINOR'].to_i
212
- teeny = RBCONFIG['TEENY'].to_i
213
- version = "#{major}.#{minor}"
214
-
215
- # ruby ver. >= 1.4.4?
216
- newpath_p = ((major >= 2) or
217
- ((major == 1) and
218
- ((minor >= 5) or
219
- ((minor == 4) and (teeny >= 4)))))
220
-
221
- if RBCONFIG['rubylibdir']
222
- # V > 1.6.3
223
- libruby = "#{prefix}/lib/ruby"
224
- librubyver = RBCONFIG['rubylibdir']
225
- librubyverarch = RBCONFIG['archdir']
226
- siteruby = RBCONFIG['sitedir']
227
- siterubyver = RBCONFIG['sitelibdir']
228
- siterubyverarch = RBCONFIG['sitearchdir']
229
- elsif newpath_p
230
- # 1.4.4 <= V <= 1.6.3
231
- libruby = "#{prefix}/lib/ruby"
232
- librubyver = "#{prefix}/lib/ruby/#{version}"
233
- librubyverarch = "#{prefix}/lib/ruby/#{version}/#{c['arch']}"
234
- siteruby = RBCONFIG['sitedir']
235
- siterubyver = "$siteruby/#{version}"
236
- siterubyverarch = "$siterubyver/#{RBCONFIG['arch']}"
237
- else
238
- # V < 1.4.4
239
- libruby = "#{prefix}/lib/ruby"
240
- librubyver = "#{prefix}/lib/ruby/#{version}"
241
- librubyverarch = "#{prefix}/lib/ruby/#{version}/#{c['arch']}"
242
- siteruby = "#{prefix}/lib/ruby/#{version}/site_ruby"
243
- siterubyver = siteruby
244
- siterubyverarch = "$siterubyver/#{RBCONFIG['arch']}"
245
- end
246
-
247
- if arg = RBCONFIG['configure_args'].split.detect {|arg| /--with-make-prog=/ =~ arg }
248
- makeprog = arg.sub(/'/, '').split(/=/, 2)[1]
249
- else
250
- makeprog = 'make'
251
- end
252
-
253
- parameterize = lambda do |path|
254
- val = RBCONFIG[path]
255
- val.sub(/\A#{Regexp.quote(prefix)}/, '$prefix')
256
- end
257
-
258
- self.prefix = prefix
259
- self.bindir = parameterize['bindir']
260
- self.libdir = parameterize['libdir']
261
- self.datadir = parameterize['datadir']
262
- self.mandir = parameterize['mandir']
263
- self.docdir = File.dirname(parameterize['docdir']) # b/c of trailing $(PACKAGE)
264
- self.sysconfdir = parameterize['sysconfdir']
265
- self.localstatedir = parameterize['localstatedir']
266
- self.libruby = libruby
267
- self.librubyver = librubyver
268
- self.librubyverarch = librubyverarch
269
- self.siteruby = siteruby
270
- self.siterubyver = siterubyver
271
- self.siterubyverarch = siterubyverarch
272
- self.rbdir = '$siterubyver'
273
- self.sodir = '$siterubyverarch'
274
- self.rubypath = rubypath
275
- self.rubyprog = rubypath
276
- self.makeprog = makeprog
277
- self.extconfopt = ''
278
- self.shebang = 'ruby'
279
- self.without_ext = 'no'
280
- self.without_doc = 'yes'
281
- self.doctemplate = 'html'
282
- self.testrunner = 'auto'
283
- self.installdirs = 'site'
284
- end
285
-
286
- # Get configuration from environment.
287
- def env_config
288
- OPTIONS.each do |name|
289
- if value = ENV[name]
290
- __send__("#{name}=",value)
291
- end
292
- end
293
- end
294
-
295
- # Load configuration.
296
- def load_config
297
- #if File.file?(CONFIGFILE)
298
- begin
299
- File.foreach(CONFIGFILE) do |line|
300
- k, v = *line.split(/=/, 2)
301
- __send__("#{k}=",v.strip) #self[k] = v.strip
302
- end
303
- rescue Errno::ENOENT
304
- raise SetupError, $!.message + "\n#{File.basename($0)} config first"
305
- end
306
- #end
307
- end
308
-
309
- # Save configuration.
310
- def save_config
311
- File.open(CONFIGFILE, 'w') do |f|
312
- OPTIONS.each do |name|
313
- val = self[name]
314
- f << "#{name}=#{val}\n"
315
- end
316
- end
317
- end
318
-
319
- def show
320
- fmt = "%-20s %s\n"
321
- OPTIONS.each do |name|
322
- value = self[name]
323
- reslv = __send__(name)
324
- reslv = "(none)" if String===reslv && reslv.empty?
325
- printf fmt, name, reslv if value
326
- end
327
- end
328
-
329
- #
330
-
331
- def extconfs
332
- @extconfs ||= Dir['ext/**/extconf.rb']
333
- end
334
-
335
- def extensions
336
- @extensions ||= extconfs.collect{ |f| File.dirname(f) }
337
- end
338
-
339
- def compiles?
340
- !extensions.empty?
341
- end
342
-
343
- private
344
-
345
- # Get unresloved attribute.
346
- def [](name)
347
- instance_variable_get("@#{name}")
348
- end
349
-
350
- # Set attribute.
351
- def []=(name, value)
352
- instance_variable_set("@#{name}", value)
353
- end
354
-
355
- # Resolved attribute. (for paths)
356
- #def resolve(name)
357
- # self[name].gsub(%r<\\$([^/]+)>){ self[$1] }
358
- #end
359
-
360
- end
361
-
362
- # Installer class handles the actual install procedure,
363
- # as well as the other tasks, such as testing.
364
-
365
- class Installer
366
-
367
- MANIFEST = '.installedfiles'
368
-
369
- FILETYPES = %w( bin lib ext data conf man doc )
370
-
371
- TASK_DESCRIPTIONS = [
372
- [ 'all', 'do config, setup, then install' ],
373
- [ 'config', 'saves your configurations' ],
374
- [ 'show', 'shows current configuration' ],
375
- [ 'setup', 'compiles ruby extentions and others' ],
376
- [ 'doc', 'generate html documentation' ],
377
- [ 'index', 'generate index documentation' ],
378
- [ 'install', 'installs files' ],
379
- [ 'test', 'run all tests in test/' ],
380
- [ 'clean', "does `make clean' for each extention" ],
381
- [ 'distclean',"does `make distclean' for each extention" ]
382
- ]
383
-
384
- TASKS = %w(all config show setup test install uninstall doc index clean distclean)
385
-
386
- # Configuration
387
- attr :config
388
-
389
- attr_writer :no_harm
390
- attr_writer :verbose
391
- attr_writer :quiet
392
-
393
- attr_accessor :install_prefix
394
-
395
- # New Installer.
396
- def initialize #:yield:
397
- srcroot = '.'
398
- objroot = '.'
399
-
400
- @config = ConfigTable.new
401
-
402
- @srcdir = File.expand_path(srcroot)
403
- @objdir = File.expand_path(objroot)
404
- @currdir = '.'
405
-
406
- self.quiet = ENV['quiet'] if ENV['quiet']
407
- self.verbose = ENV['verbose'] if ENV['verbose']
408
- self.no_harm = ENV['nowrite'] if ENV['nowrite']
409
-
410
- yield(self) if block_given?
411
- end
412
-
413
- def inspect
414
- "#<#{self.class} #{File.basename(@srcdir)}>"
415
- end
416
-
417
- # Are we running an installation?
418
- def installation?; @installation; end
419
- def installation!; @installation = true; end
420
-
421
- def no_harm?; @no_harm; end
422
- def verbose?; @verbose; end
423
- def quiet?; @quiet; end
424
-
425
- def verbose_off #:yield:
426
- begin
427
- save, @verbose = verbose?, false
428
- yield
429
- ensure
430
- @verbose = save
431
- end
432
- end
433
-
434
- # Rake task handlers
435
- def rake_define
436
- require 'rake/clean'
437
-
438
- desc 'Config, setup and then install'
439
- task :all => [:config, :setup, :install]
440
-
441
- desc 'Saves your configurations'
442
- task :config do exec_config end
443
-
444
- desc 'Compiles ruby extentions'
445
- task :setup do exec_setup end
446
-
447
- desc 'Runs unit tests'
448
- task :test do exec_test end
449
-
450
- desc 'Generate html api docs'
451
- task :doc do exec_doc end
452
-
453
- desc 'Generate api index docs'
454
- task :index do exec_index end
455
-
456
- desc 'Installs files'
457
- task :install do exec_install end
458
-
459
- desc 'Uninstalls files'
460
- task :uninstall do exec_uninstall end
461
-
462
- #desc "Does `make clean' for each extention"
463
- task :makeclean do exec_clean end
464
-
465
- task :clean => [:makeclean]
466
-
467
- #desc "Does `make distclean' for each extention"
468
- task :distclean do exec_distclean end
469
-
470
- task :clobber => [:distclean]
471
-
472
- desc 'Shows current configuration'
473
- task :show do exec_show end
474
- end
475
-
476
- # Added these for future use in simplificaiton of design.
477
-
478
- def extensions
479
- @extensions ||= Dir['ext/**/extconf.rb']
480
- end
481
-
482
- def compiles?
483
- !extensions.empty?
484
- end
485
-
486
- #
487
- def noop(rel); end
488
-
489
- #
490
- # Hook Script API bases
491
- #
492
-
493
- def srcdir_root
494
- @srcdir
495
- end
496
-
497
- def objdir_root
498
- @objdir
499
- end
500
-
501
- def relpath
502
- @currdir
503
- end
504
-
505
- #
506
- # Task all
507
- #
508
-
509
- def exec_all
510
- exec_config
511
- exec_setup
512
- exec_test # TODO: we need to stop here if tests fail (how?)
513
- exec_doc if GENERATE_RDOCS && !config.without_doc?
514
- exec_install
515
- end
516
-
517
- #
518
- # TASK config
519
- #
520
-
521
- def exec_config
522
- config.env_config
523
- config.save_config
524
- config.show unless quiet?
525
- puts("Configuration saved.") unless quiet?
526
- exec_task_traverse 'config'
527
- end
528
-
529
- alias config_dir_bin noop
530
- alias config_dir_lib noop
531
-
532
- def config_dir_ext(rel)
533
- extconf if extdir?(curr_srcdir())
534
- end
535
-
536
- alias config_dir_data noop
537
- alias config_dir_conf noop
538
- alias config_dir_man noop
539
- alias config_dir_doc noop
540
-
541
- def extconf
542
- ruby "#{curr_srcdir()}/extconf.rb", config.extconfopt
543
- end
544
-
545
- #
546
- # TASK show
547
- #
548
-
549
- def exec_show
550
- config.show
551
- end
552
-
553
- #
554
- # TASK setup
555
- #
556
- # FIXME: Update shebang at time of install not before.
557
- # for now I've commented it out the shebang.
558
-
559
- def exec_setup
560
- exec_task_traverse 'setup'
561
- end
562
-
563
- def setup_dir_bin(rel)
564
- files_of(curr_srcdir()).each do |fname|
565
- #update_shebang_line "#{curr_srcdir()}/#{fname}"
566
- end
567
- end
568
-
569
- alias setup_dir_lib noop
570
-
571
- def setup_dir_ext(rel)
572
- make if extdir?(curr_srcdir())
573
- end
574
-
575
- alias setup_dir_data noop
576
- alias setup_dir_conf noop
577
- alias setup_dir_man noop
578
- alias setup_dir_doc noop
579
-
580
- def update_shebang_line(path)
581
- return if no_harm?
582
- return if config.shebang == 'never'
583
- old = Shebang.load(path)
584
- if old
585
- if old.args.size > 1
586
- $stderr.puts "warning: #{path}"
587
- $stderr.puts "Shebang line has too many args."
588
- $stderr.puts "It is not portable and your program may not work."
589
- end
590
- new = new_shebang(old)
591
- return if new.to_s == old.to_s
592
- else
593
- return unless config.shebang == 'all'
594
- new = Shebang.new(config.rubypath)
595
- end
596
- $stderr.puts "updating shebang: #{File.basename(path)}" if verbose?
597
- open_atomic_writer(path) {|output|
598
- File.open(path, 'rb') {|f|
599
- f.gets if old # discard
600
- output.puts new.to_s
601
- output.print f.read
602
- }
603
- }
604
- end
605
-
606
- def new_shebang(old)
607
- if /\Aruby/ =~ File.basename(old.cmd)
608
- Shebang.new(config.rubypath, old.args)
609
- elsif File.basename(old.cmd) == 'env' and old.args.first == 'ruby'
610
- Shebang.new(config.rubypath, old.args[1..-1])
611
- else
612
- return old unless config.shebang == 'all'
613
- Shebang.new(config.rubypath)
614
- end
615
- end
616
-
617
- def open_atomic_writer(path, &block)
618
- tmpfile = File.basename(path) + '.tmp'
619
- begin
620
- File.open(tmpfile, 'wb', &block)
621
- File.rename tmpfile, File.basename(path)
622
- ensure
623
- File.unlink tmpfile if File.exist?(tmpfile)
624
- end
625
- end
626
-
627
- class Shebang
628
- def Shebang.load(path)
629
- line = nil
630
- File.open(path) {|f|
631
- line = f.gets
632
- }
633
- return nil unless /\A#!/ =~ line
634
- parse(line)
635
- end
636
-
637
- def Shebang.parse(line)
638
- cmd, *args = *line.strip.sub(/\A\#!/, '').split(' ')
639
- new(cmd, args)
640
- end
641
-
642
- def initialize(cmd, args = [])
643
- @cmd = cmd
644
- @args = args
645
- end
646
-
647
- attr_reader :cmd
648
- attr_reader :args
649
-
650
- def to_s
651
- "#! #{@cmd}" + (@args.empty? ? '' : " #{@args.join(' ')}")
652
- end
653
- end
654
-
655
- #
656
- # TASK test
657
- #
658
- # TODO: Add spec support.
659
-
660
- def exec_test
661
- $stderr.puts 'Running tests...' if verbose?
662
-
663
- runner = config.testrunner
664
-
665
- case runner
666
- when 'auto'
667
- unless File.directory?('test')
668
- $stderr.puts 'no test in this package' if verbose?
669
- return
670
- end
671
- begin
672
- require 'test/unit'
673
- rescue LoadError
674
- setup_rb_error 'test/unit cannot loaded. You need Ruby 1.8 or later to invoke this task.'
675
- end
676
- autorunner = Test::Unit::AutoRunner.new(true)
677
- autorunner.to_run << 'test'
678
- autorunner.run
679
- else # use testrb
680
- opt = []
681
- opt << " -v" if verbose?
682
- opt << " --runner #{runner}"
683
- if File.file?('test/suite.rb')
684
- notests = false
685
- opt << "test/suite.rb"
686
- else
687
- notests = Dir["test/**/*.rb"].empty?
688
- lib = ["lib"] + config.extensions.collect{ |d| File.dirname(d) }
689
- opt << "-I" + lib.join(':')
690
- opt << Dir["test/**/{test,tc}*.rb"]
691
- end
692
- opt = opt.flatten.join(' ').strip
693
- # run tests
694
- if notests
695
- $stderr.puts 'no test in this package' if verbose?
696
- else
697
- cmd = "testrb #{opt}"
698
- $stderr.puts cmd if verbose?
699
- system cmd #config.ruby "-S tesrb", opt
700
- end
701
- end
702
- end
703
-
704
- # MAYBE: We could traverse and run each test independently (?)
705
- #def test_dir_test
706
- #end
707
-
708
- #
709
- # TASK doc
710
- #
711
-
712
- def exec_doc
713
- output = File.join('doc', PACKAGE, 'rdoc')
714
- title = (PACKAGE.capitalize + " API").strip
715
- main = Dir.glob("README{,.txt}", File::FNM_CASEFOLD).first
716
- template = config.doctemplate || 'html'
717
-
718
- opt = []
719
- opt << "-U"
720
- opt << "-S"
721
- opt << "--op=#{output}"
722
- opt << "--template=#{template}"
723
- opt << "--title=#{title}"
724
- opt << "--main=#{main}" if main
725
-
726
- if File.exist?('.document')
727
- files = File.read('.document').split("\n")
728
- files.reject!{ |l| l =~ /^\s*[#]/ || l !~ /\S/ }
729
- files.collect!{ |f| f.strip }
730
- opt << files
731
- else
732
- opt << main if main
733
- opt << ["lib", "ext"]
734
- end
735
-
736
- opt = opt.flatten
737
-
738
- if no_harm?
739
- puts "rdoc " + opt.join(' ').strip
740
- else
741
- #sh "rdoc {opt.join(' ').strip}"
742
- require 'rdoc/rdoc'
743
- ::RDoc::RDoc.new.document(opt)
744
- end
745
- end
746
-
747
- #
748
- # TASK index
749
- #
750
- # TODO: Totally deprecate stadard ri support in favor of fastri.
751
-
752
- def exec_index
753
- begin
754
- require 'fastri/version'
755
- fastri = true
756
- rescue LoadError
757
- fastri = false
758
- end
759
- if fastri
760
- if no_harm?
761
- $stderr.puts "fastri-server -b"
762
- else
763
- system "fastri-server -b"
764
- end
765
- else
766
- case config.installdirs
767
- when 'std'
768
- output = "--ri-system"
769
- when 'site'
770
- output = "--ri-site"
771
- when 'home'
772
- output = "--ri"
773
- else
774
- abort "bad config: sould not be possible -- installdirs = #{config.installdirs}"
775
- end
776
-
777
- if File.exist?('.document')
778
- files = File.read('.document').split("\n")
779
- files.reject!{ |l| l =~ /^\s*[#]/ || l !~ /\S/ }
780
- files.collect!{ |f| f.strip }
781
- else
782
- files = ["lib", "ext"]
783
- end
784
-
785
- opt = []
786
- opt << "-U"
787
- opt << output
788
- opt << files
789
- opt = opt.flatten
790
-
791
- if no_harm?
792
- puts "rdoc #{opt.join(' ').strip}"
793
- else
794
- #sh "rdoc #{opt.join(' ').strip}"
795
- require 'rdoc/rdoc'
796
- ::RDoc::RDoc.new.document(opt)
797
- end
798
- end
799
- end
800
-
801
- #
802
- # TASK install
803
- #
804
-
805
- def exec_install
806
- installation! # were are installing
807
- #rm_f MANIFEST # we'll append rather then delete!
808
- exec_task_traverse 'install'
809
- end
810
-
811
- def install_dir_bin(rel)
812
- install_files targetfiles(), "#{config.bindir}/#{rel}", 0755
813
- end
814
-
815
- def install_dir_lib(rel)
816
- install_files libfiles(), "#{config.rbdir}/#{rel}", 0644
817
- end
818
-
819
- def install_dir_ext(rel)
820
- return unless extdir?(curr_srcdir())
821
- install_files rubyextentions('.'),
822
- "#{config.sodir}/#{File.dirname(rel)}", 0555
823
- end
824
-
825
- def install_dir_data(rel)
826
- install_files targetfiles(), "#{config.datadir}/#{rel}", 0644
827
- end
828
-
829
- def install_dir_conf(rel)
830
- # FIXME: should not remove current config files
831
- # (rename previous file to .old/.org)
832
- install_files targetfiles(), "#{config.sysconfdir}/#{rel}", 0644
833
- end
834
-
835
- def install_dir_man(rel)
836
- install_files targetfiles(), "#{config.mandir}/#{rel}", 0644
837
- end
838
-
839
- def install_dir_doc(rel)
840
- return if config.without_doc?
841
- install_files targetfiles(), "#{config.docdir}/#{rel}", 0644
842
- end
843
-
844
- def install_files(list, dest, mode)
845
- mkdir_p dest, install_prefix
846
- list.each do |fname|
847
- install fname, dest, mode, install_prefix
848
- end
849
- end
850
-
851
- def libfiles
852
- glob_reject(%w(*.y *.output), targetfiles())
853
- end
854
-
855
- def rubyextentions(dir)
856
- ents = glob_select("*.#{dllext}", targetfiles())
857
- if ents.empty?
858
- setup_rb_error "no ruby extention exists: 'ruby #{$0} setup' first"
859
- end
860
- ents
861
- end
862
-
863
- def dllext
864
- RBCONFIG['DLEXT']
865
- end
866
-
867
- def targetfiles
868
- mapdir(existfiles() - hookfiles())
869
- end
870
-
871
- def mapdir(ents)
872
- ents.map {|ent|
873
- if File.exist?(ent)
874
- then ent # objdir
875
- else "#{curr_srcdir()}/#{ent}" # srcdir
876
- end
877
- }
878
- end
879
-
880
- # picked up many entries from cvs-1.11.1/src/ignore.c
881
- JUNK_FILES = %w(
882
- core RCSLOG tags TAGS .make.state
883
- .nse_depinfo #* .#* cvslog.* ,* .del-* *.olb
884
- *~ *.old *.bak *.BAK *.orig *.rej _$* *$
885
-
886
- *.org *.in .*
887
- )
888
-
889
- def existfiles
890
- glob_reject(JUNK_FILES, (files_of(curr_srcdir()) | files_of('.')))
891
- end
892
-
893
- def hookfiles
894
- %w( pre-%s post-%s pre-%s.rb post-%s.rb ).map {|fmt|
895
- %w( config setup install clean ).map {|t| sprintf(fmt, t) }
896
- }.flatten
897
- end
898
-
899
- def glob_select(pat, ents)
900
- re = globs2re([pat])
901
- ents.select {|ent| re =~ ent }
902
- end
903
-
904
- def glob_reject(pats, ents)
905
- re = globs2re(pats)
906
- ents.reject {|ent| re =~ ent }
907
- end
908
-
909
- GLOB2REGEX = {
910
- '.' => '\.',
911
- '$' => '\$',
912
- '#' => '\#',
913
- '*' => '.*'
914
- }
915
-
916
- def globs2re(pats)
917
- /\A(?:#{
918
- pats.map {|pat| pat.gsub(/[\.\$\#\*]/) {|ch| GLOB2REGEX[ch] } }.join('|')
919
- })\z/
920
- end
921
-
922
- #
923
- # TASK uninstall
924
- #
925
-
926
- def exec_uninstall
927
- paths = File.read(MANIFEST).split("\n")
928
- dirs, files = paths.partition{ |f| File.dir?(f) }
929
-
930
- files.each do |file|
931
- next if /^\#/ =~ file # skip comments
932
- rm_f(file) if File.exist?(file)
933
- end
934
-
935
- dirs.each do |dir|
936
- # okay this is over kill, but playing it safe...
937
- empty = Dir[File.join(dir,'*')].empty?
938
- begin
939
- if no_harm?
940
- $stderr.puts "rmdir #{dir}"
941
- else
942
- rmdir(dir) if empty
943
- end
944
- rescue Errno::ENOTEMPTY
945
- $stderr.puts "may not be empty -- #{dir}" if verbose?
946
- end
947
- end
948
-
949
- rm_f(MANIFEST)
950
- end
951
-
952
- #
953
- # TASK clean
954
- #
955
-
956
- def exec_clean
957
- exec_task_traverse 'clean'
958
- rm_f ConfigTable::CONFIGFILE
959
- #rm_f MANIFEST # only on clobber!
960
- end
961
-
962
- alias clean_dir_bin noop
963
- alias clean_dir_lib noop
964
- alias clean_dir_data noop
965
- alias clean_dir_conf noop
966
- alias clean_dir_man noop
967
- alias clean_dir_doc noop
968
-
969
- def clean_dir_ext(rel)
970
- return unless extdir?(curr_srcdir())
971
- make 'clean' if File.file?('Makefile')
972
- end
973
-
974
- #
975
- # TASK distclean
976
- #
977
-
978
- def exec_distclean
979
- exec_task_traverse 'distclean'
980
- rm_f ConfigTable::CONFIGFILE
981
- rm_f MANIFEST
982
- end
983
-
984
- alias distclean_dir_bin noop
985
- alias distclean_dir_lib noop
986
-
987
- def distclean_dir_ext(rel)
988
- return unless extdir?(curr_srcdir())
989
- make 'distclean' if File.file?('Makefile')
990
- end
991
-
992
- alias distclean_dir_data noop
993
- alias distclean_dir_conf noop
994
- alias distclean_dir_man noop
995
-
996
- def distclean_dir_doc(rel)
997
- if GENERATE_RDOCS
998
- rm_rf('rdoc') if File.directory?('rdoc')
999
- end
1000
- end
1001
-
1002
- #
1003
- # Traversing
1004
- #
1005
-
1006
- def exec_task_traverse(task)
1007
- run_hook "pre-#{task}"
1008
- FILETYPES.each do |type|
1009
- if type == 'ext' and config.without_ext == 'yes'
1010
- $stderr.puts 'skipping ext/* by user option' if verbose?
1011
- next
1012
- end
1013
- traverse task, type, "#{task}_dir_#{type}"
1014
- end
1015
- run_hook "post-#{task}"
1016
- end
1017
-
1018
- def traverse(task, rel, mid)
1019
- dive_into(rel) {
1020
- run_hook "pre-#{task}"
1021
- __send__ mid, rel.sub(%r[\A.*?(?:/|\z)], '')
1022
- directories_of(curr_srcdir()).each do |d|
1023
- traverse task, "#{rel}/#{d}", mid
1024
- end
1025
- run_hook "post-#{task}"
1026
- }
1027
- end
1028
-
1029
- def dive_into(rel)
1030
- return unless File.dir?("#{@srcdir}/#{rel}")
1031
-
1032
- dir = File.basename(rel)
1033
- Dir.mkdir dir unless File.dir?(dir)
1034
- prevdir = Dir.pwd
1035
- Dir.chdir dir
1036
- $stderr.puts '---> ' + rel if verbose?
1037
- @currdir = rel
1038
- yield
1039
- Dir.chdir prevdir
1040
- $stderr.puts '<--- ' + rel if verbose?
1041
- @currdir = File.dirname(rel)
1042
- end
1043
-
1044
- def run_hook(id)
1045
- path = [ "#{curr_srcdir()}/#{id}",
1046
- "#{curr_srcdir()}/#{id}.rb" ].detect {|cand| File.file?(cand) }
1047
- return unless path
1048
- begin
1049
- instance_eval File.read(path), path, 1
1050
- rescue
1051
- raise if $DEBUG
1052
- setup_rb_error "hook #{path} failed:\n" + $!.message
1053
- end
1054
- end
1055
-
1056
- # File Operations
1057
- #
1058
- # This module requires: #verbose?, #no_harm?
1059
-
1060
- def binread(fname)
1061
- File.open(fname, 'rb'){ |f|
1062
- return f.read
1063
- }
1064
- end
1065
-
1066
- def mkdir_p(dirname, prefix = nil)
1067
- dirname = prefix + File.expand_path(dirname) if prefix
1068
- $stderr.puts "mkdir -p #{dirname}" if verbose?
1069
- return if no_harm?
1070
-
1071
- # Does not check '/', it's too abnormal.
1072
- dirs = File.expand_path(dirname).split(%r<(?=/)>)
1073
- if /\A[a-z]:\z/i =~ dirs[0]
1074
- disk = dirs.shift
1075
- dirs[0] = disk + dirs[0]
1076
- end
1077
- dirs.each_index do |idx|
1078
- path = dirs[0..idx].join('')
1079
- Dir.mkdir path unless File.dir?(path)
1080
- record_installation(path) # also record directories made
1081
- end
1082
- end
1083
-
1084
- def rm_f(path)
1085
- $stderr.puts "rm -f #{path}" if verbose?
1086
- return if no_harm?
1087
- force_remove_file path
1088
- end
1089
-
1090
- def rm_rf(path)
1091
- $stderr.puts "rm -rf #{path}" if verbose?
1092
- return if no_harm?
1093
- remove_tree path
1094
- end
1095
-
1096
- def rmdir(path)
1097
- $stderr.puts "rmdir #{path}" if verbose?
1098
- return if no_harm?
1099
- Dir.rmdir path
1100
- end
1101
-
1102
- def remove_tree(path)
1103
- if File.symlink?(path)
1104
- remove_file path
1105
- elsif File.dir?(path)
1106
- remove_tree0 path
1107
- else
1108
- force_remove_file path
1109
- end
1110
- end
1111
-
1112
- def remove_tree0(path)
1113
- Dir.foreach(path) do |ent|
1114
- next if ent == '.'
1115
- next if ent == '..'
1116
- entpath = "#{path}/#{ent}"
1117
- if File.symlink?(entpath)
1118
- remove_file entpath
1119
- elsif File.dir?(entpath)
1120
- remove_tree0 entpath
1121
- else
1122
- force_remove_file entpath
1123
- end
1124
- end
1125
- begin
1126
- Dir.rmdir path
1127
- rescue Errno::ENOTEMPTY
1128
- # directory may not be empty
1129
- end
1130
- end
1131
-
1132
- def move_file(src, dest)
1133
- force_remove_file dest
1134
- begin
1135
- File.rename src, dest
1136
- rescue
1137
- File.open(dest, 'wb') {|f|
1138
- f.write binread(src)
1139
- }
1140
- File.chmod File.stat(src).mode, dest
1141
- File.unlink src
1142
- end
1143
- end
1144
-
1145
- def force_remove_file(path)
1146
- begin
1147
- remove_file path
1148
- rescue
1149
- end
1150
- end
1151
-
1152
- def remove_file(path)
1153
- File.chmod 0777, path
1154
- File.unlink path
1155
- end
1156
-
1157
- def install(from, dest, mode, prefix = nil)
1158
- $stderr.puts "install #{from} #{dest}" if verbose?
1159
- return if no_harm?
1160
-
1161
- realdest = prefix ? prefix + File.expand_path(dest) : dest
1162
- realdest = File.join(realdest, File.basename(from)) if File.dir?(realdest)
1163
- str = binread(from)
1164
- if diff?(str, realdest)
1165
- verbose_off {
1166
- rm_f realdest if File.exist?(realdest)
1167
- }
1168
- File.open(realdest, 'wb') {|f|
1169
- f.write str
1170
- }
1171
- File.chmod mode, realdest
1172
-
1173
- if prefix
1174
- path = realdest.sub(prefix, '')
1175
- else
1176
- path = realdest
1177
- end
1178
-
1179
- record_installation(path)
1180
- end
1181
- end
1182
-
1183
- def record_installation(path)
1184
- File.open("#{objdir_root()}/#{MANIFEST}", 'a') do |f|
1185
- f.puts(path)
1186
- end
1187
- end
1188
-
1189
- def diff?(new_content, path)
1190
- return true unless File.exist?(path)
1191
- new_content != binread(path)
1192
- end
1193
-
1194
- def command(*args)
1195
- $stderr.puts args.join(' ') if verbose?
1196
- system(*args) or raise RuntimeError,
1197
- "system(#{args.map{|a| a.inspect }.join(' ')}) failed"
1198
- end
1199
-
1200
- def ruby(*args)
1201
- command config.rubyprog, *args
1202
- end
1203
-
1204
- def make(task = nil)
1205
- command(*[config.makeprog, task].compact)
1206
- end
1207
-
1208
- def extdir?(dir)
1209
- File.exist?("#{dir}/MANIFEST") or File.exist?("#{dir}/extconf.rb")
1210
- end
1211
-
1212
- def files_of(dir)
1213
- Dir.open(dir) {|d|
1214
- return d.select {|ent| File.file?("#{dir}/#{ent}") }
1215
- }
1216
- end
1217
-
1218
- DIR_REJECT = %w( . .. CVS SCCS RCS CVS.adm .svn )
1219
-
1220
- def directories_of(dir)
1221
- Dir.open(dir) {|d|
1222
- return d.select {|ent| File.dir?("#{dir}/#{ent}") } - DIR_REJECT
1223
- }
1224
- end
1225
-
1226
- #
1227
- # Hook Script API
1228
- #
1229
- # These require: #srcdir_root, #objdir_root, #relpath
1230
- #
1231
-
1232
- #
1233
- def get_config(key)
1234
- config.__send__(key)
1235
- end
1236
-
1237
- # obsolete: use metaconfig to change configuration
1238
- # TODO: what to do with?
1239
- def set_config(key, val)
1240
- config[key] = val
1241
- end
1242
-
1243
- #
1244
- # srcdir/objdir (works only in the package directory)
1245
- #
1246
-
1247
- def curr_srcdir
1248
- "#{srcdir_root()}/#{relpath()}"
1249
- end
1250
-
1251
- def curr_objdir
1252
- "#{objdir_root()}/#{relpath()}"
1253
- end
1254
-
1255
- def srcfile(path)
1256
- "#{curr_srcdir()}/#{path}"
1257
- end
1258
-
1259
- def srcexist?(path)
1260
- File.exist?(srcfile(path))
1261
- end
1262
-
1263
- def srcdirectory?(path)
1264
- File.dir?(srcfile(path))
1265
- end
1266
-
1267
- def srcfile?(path)
1268
- File.file?(srcfile(path))
1269
- end
1270
-
1271
- def srcentries(path = '.')
1272
- Dir.open("#{curr_srcdir()}/#{path}") {|d|
1273
- return d.to_a - %w(. ..)
1274
- }
1275
- end
1276
-
1277
- def srcfiles(path = '.')
1278
- srcentries(path).select {|fname|
1279
- File.file?(File.join(curr_srcdir(), path, fname))
1280
- }
1281
- end
1282
-
1283
- def srcdirectories(path = '.')
1284
- srcentries(path).select {|fname|
1285
- File.dir?(File.join(curr_srcdir(), path, fname))
1286
- }
1287
- end
1288
-
1289
- end
1290
-
1291
- # CLI runner.
1292
- def self.run_cli
1293
- installer = Setup::Installer.new
1294
-
1295
- task = ARGV.find{ |a| a !~ /^[-]/ }
1296
- task = 'all' unless task
1297
-
1298
- unless Setup::Installer::TASKS.include?(task)
1299
- $stderr.puts "Not a valid task -- #{task}"
1300
- exit 1
1301
- end
1302
-
1303
- opts = OptionParser.new
1304
-
1305
- opts.banner = "Usage: #{File.basename($0)} [task] [options]"
1306
-
1307
- if task == 'config' or task == 'all'
1308
- opts.separator ""
1309
- opts.separator "Config options:"
1310
- Setup::ConfigTable::DESCRIPTIONS.each do |name, type, desc|
1311
- opts.on("--#{name} #{type.to_s.upcase}", desc) do |val|
1312
- ENV[name.to_s] = val.to_s
1313
- end
1314
- end
1315
- end
1316
-
1317
- if task == 'install'
1318
- opts.separator ""
1319
- opts.separator "Install options:"
1320
-
1321
- opts.on("--prefix PATH", "Installation prefix") do |val|
1322
- installer.install_prefix = val
1323
- end
1324
- end
1325
-
1326
- if task == 'test'
1327
- opts.separator ""
1328
- opts.separator "Install options:"
1329
-
1330
- opts.on("--runner TYPE", "Test runner (auto|console|gtk|gtk2|tk)") do |val|
1331
- installer.config.testrunner = val
1332
- end
1333
- end
1334
-
1335
- # common options
1336
- opts.separator ""
1337
- opts.separator "General options:"
1338
-
1339
- opts.on("-q", "--quiet", "Silence output") do |val|
1340
- installer.quiet = val
1341
- end
1342
-
1343
- opts.on("--verbose", "Provide verbose output") do |val|
1344
- installer.verbose = val
1345
- end
1346
-
1347
- opts.on("-n", "--no-write", "Do not write to disk") do |val|
1348
- installer.no_harm = !val
1349
- end
1350
-
1351
- opts.on("--dryrun", "Same as --no-write") do |val|
1352
- installer.no_harm = val
1353
- end
1354
-
1355
- # common options
1356
- opts.separator ""
1357
- opts.separator "Inform options:"
1358
-
1359
- # Tail options (eg. commands in option form)
1360
- opts.on_tail("-h", "--help", "display this help information") do
1361
- puts Setup.help
1362
- exit
1363
- end
1364
-
1365
- opts.on_tail("--version", "Show version") do
1366
- puts File.basename($0) + ' v' + Setup::Version.join('.')
1367
- exit
1368
- end
1369
-
1370
- opts.on_tail("--copyright", "Show copyright") do
1371
- puts Setup::Copyright
1372
- exit
1373
- end
1374
-
1375
- begin
1376
- opts.parse!(ARGV)
1377
- rescue OptionParser::InvalidOption
1378
- $stderr.puts $!.to_s.capitalize
1379
- exit 1
1380
- end
1381
-
1382
- begin
1383
- installer.__send__("exec_#{task}")
1384
- rescue SetupError
1385
- raise if $DEBUG
1386
- $stderr.puts $!.message
1387
- $stderr.puts "Try 'ruby #{$0} --help' for detailed usage."
1388
- exit 1
1389
- end
1390
- end
1391
-
1392
- # Generate help text.
1393
- def self.help
1394
- fmt = " " * 10 + "%-10s %s"
1395
- commands = Installer::TASK_DESCRIPTIONS.collect do |k,d|
1396
- (fmt % ["#{k}", d])
1397
- end.join("\n").strip
1398
-
1399
- fmt = " " * 13 + "%-20s %s"
1400
- configs = ConfigTable::DESCRIPTIONS.collect do |k,t,d|
1401
- (fmt % ["--#{k}", d])
1402
- end.join("\n").strip
1403
-
1404
- text = <<-END
1405
- USAGE: #{File.basename($0)} [command] [options]
1406
-
1407
- Commands:
1408
- #{commands}
1409
-
1410
- Options for CONFIG:
1411
- #{configs}
1412
-
1413
- Options for INSTALL:
1414
- --prefix Set the install prefix
1415
-
1416
- Options in common:
1417
- -q --quiet Silence output
1418
- --verbose Provide verbose output
1419
- -n --no-write Do not write to disk
1420
-
1421
- END
1422
-
1423
- text.gsub(/^ \ \ \ \ \ /, '')
1424
- end
1425
-
1426
- #
1427
- def self.run_rake
1428
- installer = Setup::Installer.new
1429
- installer.rake_define
1430
- end
1431
-
1432
- end
1433
-
1434
- #
1435
- # Ruby Extensions
1436
- #
1437
-
1438
- unless File.respond_to?(:read) # Ruby 1.6 and less
1439
- def File.read(fname)
1440
- open(fname) {|f|
1441
- return f.read
1442
- }
1443
- end
1444
- end
1445
-
1446
- unless Errno.const_defined?(:ENOTEMPTY) # Windows?
1447
- module Errno
1448
- class ENOTEMPTY
1449
- # We do not raise this exception, implementation is not needed.
1450
- end
1451
- end
1452
- end
1453
-
1454
- # for corrupted Windows' stat(2)
1455
- def File.dir?(path)
1456
- File.directory?((path[-1,1] == '/') ? path : path + '/')
1457
- end
1458
-
1459
- #
1460
- # Runners
1461
- #
1462
-
1463
- if $0 == __FILE__
1464
-
1465
- Setup.run_cli
1466
-
1467
- elsif defined?(Rake)
1468
-
1469
- Setup.run_rake
1470
-
1471
- end
1472
-