latex_curriculum_vitae 0.1.3 → 0.1.4

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