rant 0.3.2 → 0.3.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/install.rb ADDED
@@ -0,0 +1,6 @@
1
+
2
+ # Install Rant with Rant :)
3
+ $:.unshift File.expand_path(File.join(File.dirname(__FILE__), "lib"))
4
+ require 'rant/rantlib'
5
+
6
+ exit Rant.run("install")
data/lib/rant.rb CHANGED
@@ -2,7 +2,11 @@
2
2
 
3
3
  require 'rant/rantlib'
4
4
 
5
- include Rant
5
+ def rac
6
+ Rant.rac
7
+ end
8
+
9
+ include RantContext
6
10
 
7
11
  if $0 == __FILE__
8
12
  exit Rant.run
data/lib/rant/import.rb CHANGED
@@ -29,6 +29,8 @@ module Rant
29
29
  "Print this help and exit." ],
30
30
  [ "--version", "-v", GetoptLong::NO_ARGUMENT,
31
31
  "Print version of rant-import and exit." ],
32
+ [ "--quiet", "-q", GetoptLong::NO_ARGUMENT,
33
+ "Operate quiet." ],
32
34
  [ "--plugins", "-p", GetoptLong::REQUIRED_ARGUMENT,
33
35
  "Include PLUGINS (comma separated list)." ],
34
36
  [ "--imports", "-i", GetoptLong::REQUIRED_ARGUMENT,
@@ -86,16 +88,17 @@ module Rant
86
88
  @reduce_whitespace = false
87
89
  @auto = false
88
90
  @arg_rantfiles = []
91
+ @quiet = false
89
92
  end
90
93
 
91
94
  def run
92
95
  process_args
93
96
 
94
97
  if @auto
95
- @rantapp = RantApp.new(
96
- %w(-v --stop-after-load) +
98
+ rac_args = %w(--stop-after-load) +
97
99
  @arg_rantfiles.collect { |rf| "-f#{rf}" }
98
- )
100
+ rac_args << "-v" unless @quiet
101
+ @rantapp = RantApp.new(rac_args)
99
102
  unless @rantapp.run == 0
100
103
  abort("Auto-determination of required code failed.")
101
104
  end
@@ -111,7 +114,7 @@ module Rant
111
114
  mf << <<EOH
112
115
  #!/usr/bin/env ruby
113
116
 
114
- # #@mono_fn - Monolithic rant script, autogenerated by rant-import.
117
+ # #@mono_fn - Monolithic rant script, autogenerated by rant-import #{Rant::VERSION}.
115
118
  #
116
119
  # Copyright (C) 2005 Stefan Lang <langstefan@gmx.at>
117
120
  #
@@ -171,6 +174,7 @@ EOF
171
174
  puts "rant-import #{Rant::VERSION}"
172
175
  done
173
176
  when "--help": help
177
+ when "--quiet": @quiet = true
174
178
  when "--force": @force = true
175
179
  when "--with-comments": @skip_comments = false
176
180
  when "--reduce-whitespace": @reduce_whitespace = true
@@ -211,6 +215,10 @@ EOF
211
215
  done
212
216
  end
213
217
 
218
+ def msg *args
219
+ super unless @quiet
220
+ end
221
+
214
222
  def abort(*text)
215
223
  err_msg(*text) unless text.empty?
216
224
  raise RantImportAbortException
@@ -47,7 +47,7 @@ module Rant
47
47
  @verbose = false
48
48
 
49
49
  yield self if block_given?
50
- app.var["gen-rubydoc-rdoc_opts"] = self.rdoc_opts.dup
50
+ app.var[:rubydoc_opts] = self.rdoc_opts.dup
51
51
 
52
52
  @pre ||= []
53
53
  @pre.concat(self.rdoc_source_deps)
@@ -1,7 +1,7 @@
1
1
 
2
2
  require 'rant/rantlib'
3
3
 
4
- class Rant::RubyPackage
4
+ class Rant::Generators::RubyPackage
5
5
 
6
6
  class << self
7
7
  def rant_generate(app, ch, args, &block)
@@ -266,7 +266,7 @@ class Rant::RubyPackage
266
266
  end
267
267
  Gem.manage_gems
268
268
  # map rdoc options from application vars
269
- @data["rdoc_options"] ||= @app.var["gen-rubydoc-rdoc_opts"]
269
+ @data["rdoc_options"] ||= @app.var[:rubydoc_opts]
270
270
  if @data["rdoc_options"]
271
271
  # remove the --op option, otherwise rubygems will
272
272
  # install the rdoc in the wrong directory (at least as
@@ -31,6 +31,7 @@ module Rant
31
31
  attr_accessor :test_dir
32
32
 
33
33
  def initialize(app, cinf, name = :test, prerequisites = [], &block)
34
+ @rac = app
34
35
  @name = name
35
36
  @pre = prerequisites
36
37
  @block = block
@@ -77,10 +78,10 @@ module Rant
77
78
  def optlist
78
79
  options = (@options.is_a? Array) ?
79
80
  @options.arglist : @options
80
- ENV["TESTOPTS"] || options || ""
81
+ @rac.cx.var["TESTOPTS"] || options || ""
81
82
  end
82
83
  def filelist
83
- return Dir[ENV['TEST']] if ENV['TEST']
84
+ return Dir[@rac.cx.var['TEST']] if @rac.cx.var['TEST']
84
85
  filelist = @test_files || []
85
86
  if filelist.empty?
86
87
  if @test_dirs && !@test_dirs.empty?
@@ -145,27 +145,23 @@ module Rant
145
145
  end # class Generators::Assembly
146
146
 
147
147
  class AssemblyTask < FileTask
148
+
148
149
  def initialize(app, assembly)
149
150
  @assembly = assembly
150
151
  super(app, @assembly.out) { |t|
151
152
  app.context.sys assembly.send("cmd_" + assembly.target)
152
153
  }
153
154
  end
154
- =begin
155
- def resolve_prerequisites
156
- @assembly.init
157
- @pre.concat(@assembly.sources)
158
- @pre.concat(@assembly.resources) if @assembly.resources
159
- super
160
- end
161
- =end
155
+
162
156
  def invoke(force = false)
157
+ goto_task_home
163
158
  @assembly.init
164
159
  @pre.concat(@assembly.sources)
165
160
  @pre.concat(@assembly.resources) if @assembly.resources
166
161
  super
167
162
  end
168
- end
163
+
164
+ end # class AssemblyTask
169
165
  end # module Rant
170
166
 
171
167
  module Rant::Plugin
data/lib/rant/rantenv.rb CHANGED
@@ -41,6 +41,7 @@ end
41
41
  module Rant::Env
42
42
  OS = ::Config::CONFIG['target']
43
43
  RUBY = ::Config::CONFIG['ruby_install_name']
44
+ RUBY_BINDIR = ::Config::CONFIG['bindir']
44
45
 
45
46
  @@zip_bin = false
46
47
  @@tar_bin = false
data/lib/rant/rantfile.rb CHANGED
@@ -49,11 +49,12 @@ module Rant
49
49
  @description = nil
50
50
  @rantfile = nil
51
51
  @line_number = nil
52
+ @run = false
52
53
  end
53
54
 
54
- # Returns the +name+ attribute.
55
+ # Returns the full name of this task.
55
56
  def to_s
56
- name
57
+ full_name
57
58
  end
58
59
 
59
60
  def project_subdir
@@ -77,6 +78,11 @@ module Rant
77
78
  !done?
78
79
  end
79
80
 
81
+ # True during invoke. Used to encounter circular dependencies.
82
+ def run?
83
+ @run
84
+ end
85
+
80
86
  # +opt+ is a Hash and shouldn't be modified.
81
87
  # All objects implementing the Rant::Worker protocol should
82
88
  # know about the following +opt+ values:
@@ -85,10 +91,16 @@ module Rant
85
91
  # as calling Worker#needed?
86
92
  # <tt>:force</tt>::
87
93
  # Run task action even if needed? is false.
94
+ # Returns true if task action was run.
88
95
  def invoke(opt = INVOKE_OPT)
89
- goto_task_home
90
- return needed? if opt[:needed?]
91
- self.run if opt[:force] || self.needed?
96
+ return circular_dep if run?
97
+ @run = true
98
+ begin
99
+ return needed? if opt[:needed?]
100
+ self.run if opt[:force] || self.needed?
101
+ ensure
102
+ @run = false
103
+ end
92
104
  end
93
105
 
94
106
  def fail msg = nil
@@ -102,14 +114,20 @@ module Rant
102
114
  end
103
115
  private :run
104
116
 
117
+ def circular_dep
118
+ app.warn_msg "Circular dependency on task `#{full_name}'."
119
+ false
120
+ end
121
+ private :circular_dep
122
+
105
123
  def hash
106
124
  name.hash
107
125
  end
108
126
 
109
127
  def eql? other
110
- Worker === other and name.eql? other.name
128
+ Worker === other and full_name.eql? other.full_name
111
129
  end
112
- end
130
+ end # module Worker
113
131
 
114
132
  # A list of tasks with an equal name.
115
133
  class MetaTask < Array
@@ -238,33 +256,36 @@ module Rant
238
256
  return false if done?
239
257
  return true if @needed.nil?
240
258
  goto_task_home
241
- if @needed.arity == 0
242
- @needed.call
243
- else
244
- @needed[self]
245
- end
259
+ @needed.arity == 0 ? @needed.call : @needed[self]
246
260
  end
247
261
 
248
262
  def invoke(opt = INVOKE_OPT)
249
- return needed? if opt[:needed?]
250
- goto_task_home
251
- if opt[:force] && !@done
252
- self.run
253
- @done = true
254
- else
255
- if needed?
256
- run
263
+ return circular_dep if @run
264
+ @run = true
265
+ begin
266
+ return needed? if opt[:needed?]
267
+ # +run+ already calls +goto_task_home+
268
+ #goto_task_home
269
+ if opt[:force] && !@done
270
+ self.run
257
271
  @done = true
258
272
  else
259
- false
273
+ if needed?
274
+ run
275
+ @done = true
276
+ else
277
+ false
278
+ end
260
279
  end
280
+ rescue CommandError => e
281
+ err_msg e.message if app[:err_commands]
282
+ self.fail
283
+ rescue SystemCallError => e
284
+ err_msg e.message
285
+ self.fail
286
+ ensure
287
+ @run = false
261
288
  end
262
- rescue CommandError => e
263
- err_msg e.message if app[:err_commands]
264
- self.fail
265
- rescue SystemCallError => e
266
- err_msg e.message
267
- self.fail
268
289
  end
269
290
  end # LightTask
270
291
 
@@ -287,13 +308,17 @@ module Rant
287
308
 
288
309
  def initialize(app, name, prerequisites = [], &block)
289
310
  super()
290
- @app = app || Rant.rantapp
311
+ @app = app || Rant.rac
291
312
  @name = name or raise ArgumentError, "name not given"
292
313
  @pre = prerequisites || []
293
314
  @pre_resolved = false
294
315
  @block = block
295
316
  @run = false
296
- @fail = false
317
+ # success has one of three values:
318
+ # nil no invoke
319
+ # false invoked, but fail
320
+ # true invoked and run successfully
321
+ @success = nil
297
322
  end
298
323
 
299
324
  # Get a list of the *names* of all prerequisites. The
@@ -303,6 +328,11 @@ module Rant
303
328
  @pre.collect { |pre| pre.to_s }
304
329
  end
305
330
 
331
+ # First prerequisite.
332
+ def source
333
+ @pre.first.to_s
334
+ end
335
+
306
336
  # True if this task has at least one action (block to be
307
337
  # executed) associated.
308
338
  def has_actions?
@@ -315,20 +345,20 @@ module Rant
315
345
  @pre << pre
316
346
  end
317
347
 
318
- # Was this task ever run? If this is true, it doesn't
348
+ # Was this task ever invoked? If this is true, it doesn't
319
349
  # necessarily mean that the run was successfull!
320
- def run?
321
- @run
350
+ def invoked?
351
+ !@success.nil?
322
352
  end
323
353
 
324
354
  # True if last task run fail.
325
355
  def fail?
326
- @fail
356
+ @success == false
327
357
  end
328
358
 
329
359
  # Task was run and didn't fail.
330
360
  def done?
331
- run? && !fail?
361
+ @success
332
362
  end
333
363
 
334
364
  # Enhance this task with the given dependencies and blk.
@@ -357,8 +387,14 @@ module Rant
357
387
  # Returns a true value if task was acutally run.
358
388
  # Raises Rant::TaskFail to signal task (or prerequiste) failure.
359
389
  def invoke(opt = INVOKE_OPT)
360
- return if done?
361
- internal_invoke opt
390
+ return circular_dep if @run
391
+ @run = true
392
+ begin
393
+ return if done?
394
+ internal_invoke opt
395
+ ensure
396
+ @run = false
397
+ end
362
398
  end
363
399
 
364
400
  def internal_invoke opt, ud_init = true
@@ -379,13 +415,12 @@ module Rant
379
415
  }
380
416
  # Never run a task block for a "needed?" query.
381
417
  return update if opt[:needed?]
382
- if update
383
- @run = true
384
- run
385
- end
386
- @run
418
+ run if update
419
+ @success = true
420
+ # IMPORTANT: return update flag
421
+ update
387
422
  rescue StandardError => e
388
- @fail = true
423
+ @success = false
389
424
  case e
390
425
  when TaskFail: raise
391
426
  when CommandError
@@ -446,6 +481,7 @@ module Rant
446
481
  return @pre.each { |t| yield(t) }
447
482
  end
448
483
  my_full_name = full_name
484
+ my_project_subdir = project_subdir
449
485
  @pre.map! { |t|
450
486
  if Worker === t
451
487
  # Remove references to self from prerequisites!
@@ -461,8 +497,8 @@ module Rant
461
497
  nil
462
498
  else
463
499
  #STDERR.puts "selecting `#{t}'"
464
- selection = @app.select_tasks_by_name t,
465
- project_subdir
500
+ selection = @app.resolve t,
501
+ my_project_subdir
466
502
  #STDERR.puts selection.size
467
503
  if selection.empty?
468
504
  # use return value of yield
@@ -519,8 +555,14 @@ module Rant
519
555
  # the +ud_init+ flag according to the result of a call to the
520
556
  # +needed+ block.
521
557
  def invoke(opt = INVOKE_OPT)
522
- return if done?
523
- internal_invoke(opt, ud_init_by_needed)
558
+ return circular_dep if @run
559
+ @run = true
560
+ begin
561
+ return if done?
562
+ internal_invoke(opt, ud_init_by_needed)
563
+ ensure
564
+ @run = false
565
+ end
524
566
  end
525
567
 
526
568
  private
@@ -528,6 +570,7 @@ module Rant
528
570
  if @needed
529
571
  goto_task_home
530
572
  @needed.arity == 0 ? @needed.call : @needed[self]
573
+ #else: true #??
531
574
  end
532
575
  end
533
576
  end # class UserTask
@@ -555,14 +598,20 @@ module Rant
555
598
  end
556
599
 
557
600
  def invoke(opt = INVOKE_OPT)
558
- return if done?
559
- goto_task_home
560
- if @path.exist?
561
- @ts = @path.mtime
562
- internal_invoke opt, false
563
- else
564
- @ts = T0
565
- internal_invoke opt, true
601
+ return circular_dep if @run
602
+ @run = true
603
+ begin
604
+ return if done?
605
+ goto_task_home
606
+ if @path.exist?
607
+ @ts = @path.mtime
608
+ internal_invoke opt, false
609
+ else
610
+ @ts = T0
611
+ internal_invoke opt, true
612
+ end
613
+ ensure
614
+ @run = false
566
615
  end
567
616
  end
568
617
 
@@ -590,8 +639,6 @@ module Rant
590
639
  # directory.
591
640
  class DirTask < Task
592
641
 
593
- # TODO: subdir support
594
-
595
642
  class << self
596
643
 
597
644
  # Generate a task for making a directory path.
@@ -650,19 +697,26 @@ module Rant
650
697
  @isdir = nil
651
698
  end
652
699
 
653
- def needed?
654
- invoke(:needed? => true)
655
- end
700
+ #def needed?
701
+ # invoke(:needed? => true)
702
+ #end
656
703
 
657
704
  def invoke(opt = INVOKE_OPT)
658
- return if done?
659
- @isdir = test(?d, @name)
660
- if @isdir
661
- @ts = @block ? test(?M, @name) : Time.now
662
- internal_invoke opt, false
663
- else
664
- @ts = T0
665
- internal_invoke opt, true
705
+ return circular_dep if @run
706
+ @run = true
707
+ begin
708
+ return if done?
709
+ goto_task_home
710
+ @isdir = test(?d, @name)
711
+ if @isdir
712
+ @ts = @block ? test(?M, @name) : Time.now
713
+ internal_invoke opt, false
714
+ else
715
+ @ts = T0
716
+ internal_invoke opt, true
717
+ end
718
+ ensure
719
+ @run = false
666
720
  end
667
721
  end
668
722
 
@@ -692,6 +746,68 @@ module Rant
692
746
  end
693
747
  end # class DirTask
694
748
  module Generators
749
+ Task = ::Rant::Task
750
+ LightTask = ::Rant::LightTask
695
751
  Directory = ::Rant::DirTask
696
- end
752
+
753
+ class Rule
754
+ # TODO
755
+ def self.rant_generate(rac, ch, args, &block)
756
+ unless args.size == 1
757
+ rac.abort_at(ch, "Rule takes only one argument.")
758
+ end
759
+ arg = args.first
760
+ target = nil
761
+ src_arg = nil
762
+ if Symbol === arg
763
+ target = ".#{arg}"
764
+ elsif arg.respond_to? :to_str
765
+ target = arg.to_str
766
+ elsif Regexp === arg
767
+ target = arg
768
+ elsif Hash === arg && arg.size == 1
769
+ arg.each_pair { |target, src_arg| }
770
+ src_arg = src_arg.to_str if src_arg.respond_to? :to_str
771
+ target = target.to_str if target.respond_to? :to_str
772
+ src_arg = ".#{src_arg}" if Symbol === src_arg
773
+ target = ".#{target}" if Symbol === target
774
+ else
775
+ rac.abort_at(ch, "Rule argument " +
776
+ "has to be a hash with one key-value pair.")
777
+ end
778
+ esc_target = nil
779
+ target_rx = case target
780
+ when String
781
+ esc_target = Regexp.escape(target)
782
+ /#{esc_target}$/
783
+ when Regexp
784
+ target
785
+ else
786
+ rac.abort_at(ch, "rule target has " +
787
+ "to be a string or regular expression")
788
+ end
789
+ src_proc = case src_arg
790
+ when String
791
+ unless String === target
792
+ rac.abort(ch, "rule target has to be a string " +
793
+ "if source is a string")
794
+ end
795
+ lambda { |name| name.sub(/#{esc_target}$/, src_arg) }
796
+ when Proc: src_arg
797
+ when nil: lambda { |name| [] }
798
+ else
799
+ rac.abort_at(ch, "rule source has to be " +
800
+ "String or Proc")
801
+ end
802
+ rac.at_resolve { |task_name|
803
+ if target_rx =~ task_name
804
+ [rac.file(:__caller__ => ch,
805
+ task_name => src_proc[task_name], &block)]
806
+ else
807
+ nil
808
+ end
809
+ }
810
+ end
811
+ end # class Rule
812
+ end # module Generators
697
813
  end # module Rant