rant 0.4.4 → 0.4.6

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.
Files changed (89) hide show
  1. data/NEWS +38 -0
  2. data/README +4 -2
  3. data/Rantfile +50 -12
  4. data/doc/examples/c_cpp/c++/problem_1_1/another_test.cpp +6 -0
  5. data/doc/examples/c_cpp/c++/problem_1_1/another_test.h +5 -0
  6. data/doc/examples/c_cpp/c++/problem_1_1/main.cpp +12 -0
  7. data/doc/examples/c_cpp/c++/problem_1_1/test.cpp +6 -0
  8. data/doc/examples/c_cpp/c++/problem_1_1/test.h +5 -0
  9. data/doc/examples/c_cpp/c++/template.rf +15 -0
  10. data/doc/examples/c_cpp/c/problem_1_1/another_test.c +6 -0
  11. data/doc/examples/c_cpp/c/problem_1_1/another_test.h +7 -0
  12. data/doc/examples/c_cpp/c/problem_1_1/main.c +12 -0
  13. data/doc/examples/c_cpp/c/problem_1_1/test.c +6 -0
  14. data/doc/examples/c_cpp/c/problem_1_1/test.h +7 -0
  15. data/doc/examples/c_cpp/c/template.rf +15 -0
  16. data/doc/examples/c_cpp/root.rant +46 -0
  17. data/doc/homepage/index.html +115 -0
  18. data/doc/homepage/rant_home.css +98 -0
  19. data/doc/rant.1 +129 -0
  20. data/doc/rant.rdoc +5 -6
  21. data/doc/rantfile.rdoc +55 -32
  22. data/doc/subdirs.rdoc +147 -0
  23. data/lib/rant.rb +47 -49
  24. data/lib/rant/coregen.rb +20 -20
  25. data/lib/rant/import.rb +63 -11
  26. data/lib/rant/import/archive.rb +47 -15
  27. data/lib/rant/import/archive/tgz.rb +1 -1
  28. data/lib/rant/import/autoclean.rb +28 -26
  29. data/lib/rant/import/c/dependencies.rb +1 -1
  30. data/lib/rant/import/directedrule.rb +1 -4
  31. data/lib/rant/import/metadata.rb +30 -7
  32. data/lib/rant/import/nodes/default.rb +67 -13
  33. data/lib/rant/import/rubypackage.rb +1 -1
  34. data/lib/rant/import/rubytest.rb +25 -19
  35. data/lib/rant/import/signedfile.rb +14 -8
  36. data/lib/rant/import/sys/more.rb +22 -0
  37. data/lib/rant/import/sys/tgz.rb +43 -0
  38. data/lib/rant/import/sys/zip.rb +42 -0
  39. data/lib/rant/node.rb +19 -13
  40. data/lib/rant/plugin/configure.rb +1 -1
  41. data/lib/rant/progress.rb +33 -0
  42. data/lib/rant/rantenv.rb +7 -7
  43. data/lib/rant/rantlib.rb +246 -256
  44. data/lib/rant/rantsys.rb +61 -22
  45. data/lib/rant/rantvar.rb +7 -9
  46. data/misc/TODO +18 -0
  47. data/misc/devel-notes +4 -1
  48. data/test/Rantfile +17 -3
  49. data/test/deprecated/README +6 -0
  50. data/test/deprecated/test_0_4_8.rb +41 -0
  51. data/test/deprecated/test_0_5_2.rb +33 -0
  52. data/test/import/md5/root.rant +9 -0
  53. data/test/import/md5/test_md5.rb +45 -0
  54. data/test/import/metadata/Rantfile +2 -2
  55. data/test/import/metadata/test_metadata.rb +2 -2
  56. data/test/import/package/test_package.rb +40 -1
  57. data/test/import/signedfile/sub1/Rantfile +1 -1
  58. data/test/import/sys/data/pkg.tgz +0 -0
  59. data/test/import/sys/data/pkg.zip +0 -0
  60. data/test/import/sys/data/pkg/bin/test +0 -0
  61. data/test/import/sys/data/pkg/bin/test.o +0 -0
  62. data/test/import/sys/data/pkg/test.c +6 -0
  63. data/test/import/sys/data/pkg/test.h +7 -0
  64. data/test/import/sys/data/pkg2.zip +0 -0
  65. data/test/import/sys/test_tgz.rb +38 -0
  66. data/test/import/sys/test_zip.rb +68 -0
  67. data/test/import/sys/tgz.rf +6 -0
  68. data/test/import/sys/zip.rf +15 -0
  69. data/test/project2/{rantfile.rb → root.rant} +0 -0
  70. data/test/project2/test_project.rb +3 -8
  71. data/test/project_rb1/{rantfile.rb → rantfile} +1 -1
  72. data/test/project_rb1/test_project_rb1.rb +3 -5
  73. data/test/rant-import/test_rant-import.rb +22 -10
  74. data/test/subdirs/sub1/Rantfile +1 -1
  75. data/test/subdirs/sub2/{rantfile.rb → rantfile} +0 -0
  76. data/test/subdirs/sub2/sub/rantfile +1 -1
  77. data/test/subdirs2/root.rant +36 -0
  78. data/test/subdirs2/sub00/sub.rant +8 -0
  79. data/test/subdirs2/sub1/sub.rant +13 -0
  80. data/test/subdirs2/test_subdirs2.rb +239 -0
  81. data/test/test_examples.rb +91 -0
  82. data/test/test_filetask.rb +51 -11
  83. data/test/test_rant_interface.rb +24 -0
  84. data/test/test_rantfile_api.rb +54 -2
  85. data/test/test_sourcenode.rb +30 -0
  86. data/test/test_sys.rb +143 -15
  87. data/test/test_task.rb +16 -22
  88. data/test/tutil.rb +22 -38
  89. metadata +67 -9
data/lib/rant.rb CHANGED
@@ -5,66 +5,64 @@ require 'rant/rantlib'
5
5
  module RantContext
6
6
  # Needed for irb, which defines its own +source+ method.
7
7
  def source_rf(*args, &block)
8
- rac.source(*args, &block)
8
+ rac.source(*args, &block)
9
9
  end
10
10
  end
11
11
  module Rant
12
12
  class FileList
13
- def inspect
14
- # what's the right encoding for object_id ?
15
- s = "#<#{self.class}:0x#{"%x" % object_id} "
16
- s << "#{@actions.size} actions, #{@files.size} files"
17
- if @ignore_rx
18
- is = @ignore_rx.inspect.gsub(/\n|\t/, ' ')
19
- s << ", ignore#{is.squeeze ' '}"
20
- end
21
- if @glob_flags != 0
22
- s << ", flags:#@glob_flags"
23
- end
24
- s << ">"
25
- end
13
+ def inspect
14
+ # what's the right encoding for object_id ?
15
+ s = "#<#{self.class}:0x#{"%x" % object_id} "
16
+ s << "#{@actions.size} actions, #{@files.size} files"
17
+ if @ignore_rx
18
+ is = @ignore_rx.inspect.gsub(/\n|\t/, ' ')
19
+ s << ", ignore#{is.squeeze ' '}"
20
+ end
21
+ if @glob_flags != 0
22
+ s << ", flags:#@glob_flags"
23
+ end
24
+ s << ">"
25
+ end
26
26
  end
27
27
  module Node
28
- def inspect
29
- s = "#<#{self.class}:0x#{"%x" % object_id} "
30
- s << "task_id:#{full_name}, action:#{inspect_action}"
31
- s << ", deps:#{inspect_deps}"
32
- s << ">"
33
- end
34
- private
35
- def inspect_action
36
- (defined? @block) ? @block.inspect : "nil"
37
- end
38
- def inspect_deps
39
- if respond_to? :deps
40
- dl = deps
41
- s = dl.size.to_s
42
- dls = dl.join(",")
43
- dls[12..dls.length] = "..." if dls.length > 12
44
- s << "[#{dls}]"
45
- else
46
- "0"
47
- end
48
- end
28
+ def inspect
29
+ s = "#<#{self.class}:0x#{"%x" % object_id} "
30
+ s << "task_id:#{full_name}, action:#{inspect_action}"
31
+ s << ", deps:#{inspect_deps}"
32
+ s << ">"
33
+ end
34
+ private
35
+ def inspect_action
36
+ (defined? @block) ? @block.inspect : "nil"
37
+ end
38
+ def inspect_deps
39
+ if respond_to? :deps
40
+ dl = deps
41
+ s = dl.size.to_s
42
+ dls = dl.join(",")
43
+ dls[12..dls.length] = "..." if dls.length > 12
44
+ s << "[#{dls}]"
45
+ else
46
+ "0"
47
+ end
48
+ end
49
49
  end
50
50
  class RantApp
51
- def inspect
52
- s = "#<#{self.class}:0x#{"%x" % object_id} "
53
- if current_subdir && !current_subdir.empty?
54
- s << "subdir:#{current_subdir}, "
55
- end
56
- s << "tasks:#{tasks.size}"
57
- s << ">"
58
- end
51
+ def inspect
52
+ s = "#<#{self.class}:0x#{"%x" % object_id} "
53
+ if current_subdir && !current_subdir.empty?
54
+ s << "subdir:#{current_subdir}, "
55
+ end
56
+ s << "tasks:#{tasks.size}"
57
+ s << ">"
58
+ end
59
59
  end
60
60
  end
61
61
 
62
- def rac
63
- Rant.rac
62
+ def rant
63
+ @__rant__
64
64
  end
65
65
 
66
- include RantContext
66
+ @__rant__ = Rant::RantApp.new
67
67
 
68
- if $0 == __FILE__
69
- exit Rant.run
70
- end
68
+ include RantContext
data/lib/rant/coregen.rb CHANGED
@@ -51,7 +51,7 @@ module Rant
51
51
  # element (and has all other necessary directories as
52
52
  # prerequisites).
53
53
  def self.task(rac, ch, name, prerequisites=[], basedir=nil, &block)
54
- dirs = ::Rant::Sys.split_path(name)
54
+ dirs = ::Rant::Sys.split_all(name)
55
55
  if dirs.empty?
56
56
  rac.abort_at(ch,
57
57
  "Not a valid directory name: `#{name}'")
@@ -126,29 +126,29 @@ module Rant
126
126
  end
127
127
  esc_target = nil
128
128
  target_rx = case target
129
- when String
130
- esc_target = Regexp.escape(target)
131
- /#{esc_target}$/
132
- when Regexp
133
- target
134
- else
129
+ when String
130
+ esc_target = Regexp.escape(target)
131
+ /#{esc_target}$/
132
+ when Regexp
133
+ target
134
+ else
135
135
  rac.abort_at(ch, "rule target has " +
136
136
  "to be a string or regular expression")
137
137
  end
138
138
  src_proc = case src_arg
139
- when String
140
- unless String === target
141
- rac.abort(ch, "rule target has to be a string " +
142
- "if source is a string")
143
- end
144
- lambda { |name| name.sub(/#{esc_target}$/, src_arg) }
145
- when Proc: src_arg
146
- when nil: lambda { |name| [] }
147
- else
148
- rac.abort_at(ch, "rule source has to be " +
149
- "String or Proc")
150
- end
151
- blk = self.new { |task_name|
139
+ when String
140
+ unless String === target
141
+ rac.abort(ch, "rule target has to be " +
142
+ "a string if source is a string")
143
+ end
144
+ lambda { |name| name.sub(/#{esc_target}$/, src_arg) }
145
+ when Proc: src_arg
146
+ when nil: lambda { |name| [] }
147
+ else
148
+ rac.abort_at(ch, "rule source has to be " +
149
+ "String or Proc")
150
+ end
151
+ blk = self.new { |task_name, rel_project_dir|
152
152
  if target_rx =~ task_name
153
153
  have_src = true
154
154
  src = src_proc[task_name]
data/lib/rant/import.rb CHANGED
@@ -104,16 +104,11 @@ module Rant
104
104
  @plugins.concat(@rantapp.plugins.map { |p| p.name })
105
105
  end
106
106
 
107
- #unless @imports.include? "nodes/default"
108
- #@imports.unshift "nodes/default"
109
- #end
110
-
111
107
  if File.exist?(@mono_fn) && !@force
112
108
  abort("#{@mono_fn} exists. Rant won't overwrite this file.",
113
109
  "Add --force to override this restriction.")
114
110
  end
115
- File.open(@mono_fn, "w") { |mf|
116
- mf << <<EOH
111
+ script = <<EOH
117
112
  #!/usr/bin/env ruby
118
113
 
119
114
  # #@mono_fn - Monolithic rant script, autogenerated by rant-import #{Rant::VERSION}.
@@ -124,10 +119,10 @@ module Rant
124
119
  # You can distribute/modify this program under the terms of
125
120
  # the GNU LGPL, Lesser General Public License version 2.1.
126
121
  EOH
127
- mf << mono_rant_core
128
- mf << mono_imports
129
- mf << mono_plugins
130
- mf << <<EOF
122
+ script << mono_rant_core
123
+ script << mono_imports
124
+ script << mono_plugins
125
+ script << <<EOF
131
126
 
132
127
  $".concat([#{@included_files.map{ |f| "'" + f + ".rb'" }.join(", ")}])
133
128
  Rant::CODE_IMPORTS.concat %w(#{@included_imports.join(' ')}
@@ -149,7 +144,11 @@ end
149
144
 
150
145
  exit Rant.run
151
146
  EOF
152
- }
147
+ msg "Postprocessing..."
148
+ script = filter_reopen_module(script)
149
+ File.open @mono_fn, "w" do |mf|
150
+ mf.write script
151
+ end
153
152
  msg "Done.",
154
153
  "Included imports: " + @included_imports.join(', '),
155
154
  "Included plugins: " + @included_plugins.join(', '),
@@ -366,5 +365,58 @@ EOF
366
365
  nil
367
366
  end
368
367
 
368
+ # Takes a script text as argument and returns the same script
369
+ # but without unnecessary `end module XY' statements.
370
+ #
371
+ # Example input:
372
+ #
373
+ # 1 module Rant
374
+ # 2 # more code
375
+ # 3 end # module Rant
376
+ # 4
377
+ # 5
378
+ # 6 module Rant
379
+ # 7 # more code
380
+ #
381
+ # gives:
382
+ #
383
+ # 1 module Rant
384
+ # 2 # more code
385
+ # 5
386
+ # 7 # more code
387
+ #
388
+ # Note:: The comment with the module name in line 3 of the
389
+ # input is very important.
390
+ def filter_reopen_module(script)
391
+ lines = []
392
+ buffer = []
393
+ identifier = nil # class/module name
394
+ keyword = nil # class or module
395
+ script.split(/\n/).each { |line|
396
+ if identifier
397
+ if line.strip.empty?
398
+ buffer << line
399
+ elsif line =~ /^\s*#{keyword}\s+#{identifier}\s*$/
400
+ # replace buffer with one empty line
401
+ lines << ""
402
+ buffer.clear
403
+ identifier = keyword = nil
404
+ else
405
+ lines.concat buffer
406
+ buffer.clear
407
+ identifier = keyword = nil
408
+ redo
409
+ end
410
+ elsif line =~ /\s*end\s*#\s*(module|class)\s+(\w+)\s*$/
411
+ keyword = $1
412
+ identifier = $2
413
+ buffer << line
414
+ else
415
+ lines << line
416
+ end
417
+ }
418
+ lines.join("\n") << "\n"
419
+ end
420
+
369
421
  end # class RantImport
370
422
  end # module Rant
@@ -9,6 +9,7 @@
9
9
 
10
10
  require 'rant/rantlib'
11
11
  require 'rant/import/subfile'
12
+ #require 'rant/progress' #rant-import:uncomment
12
13
  #require 'rant/tempfile' #rant-import:uncomment
13
14
 
14
15
  module Rant::Generators::Archive
@@ -82,7 +83,9 @@ module Rant::Generators::Archive
82
83
  end
83
84
  }
84
85
  desc = pkg.rac.pop_desc
85
- pkg.define_manifest_task if opts[:files] && opts[:manifest]
86
+ if opts[:files] and opts[:manifest] || flags.include?(:manifest)
87
+ pkg.define_manifest_task
88
+ end
86
89
  pkg.rac.cx.desc desc
87
90
  pkg.define_task
88
91
  pkg
@@ -195,11 +198,9 @@ module Rant::Generators::Archive
195
198
  def define_manifest_task
196
199
  return @manifest_task if @manifest_task
197
200
  @manifest_task =
198
- @rac.gen ::Rant::Generators::Task, @manifest do |t|
199
- def t.each_target
200
- goto_task_home
201
- yield name
202
- end
201
+ ::Rant::Generators::Task.rant_gen(
202
+ @rac, @ch, [@manifest]) do |t|
203
+ t.file_target
203
204
  t.needed {
204
205
  # fl refers to @res_files
205
206
  fl = get_files
@@ -308,16 +309,47 @@ module Rant::Generators::Archive
308
309
  dirs << dir unless dir == "." || dirs.include?(dir)
309
310
  end
310
311
  }
312
+ require 'rant/progress' #rant-import:remove
311
313
  # create directory structure
312
- dirs.each { |dir|
313
- dest = File.join(@dist_path, dir)
314
- cx.sys.mkpath(dest) unless test(?d, dest)
315
- }
316
- # link or copy files
317
- fl.each { |f|
318
- dest = File.join(@dist_path, f)
319
- cx.sys.safe_ln(f, dest)
320
- }
314
+ progress = Rant::ProgressCountdown.new(dirs.size, @rac)
315
+ dir_msg = "Creating directories under #@dist_path: "
316
+ msg_len = dir_msg.length
317
+ unless dirs.empty?
318
+ @rac.cmd_print dir_msg
319
+ dirs.each { |dir|
320
+ FileUtils.mkpath(File.join(@dist_path, dir))
321
+ progress.inc
322
+ }
323
+ @rac.cmd_msg "done"
324
+ end
325
+ # link/copy files to package directory
326
+ f = fl.first
327
+ if f
328
+ progress = Rant::ProgressCountdown.new(fl.size, @rac)
329
+ dest = File.join(@dist_path, f)
330
+ ln_supported = true
331
+ begin
332
+ FileUtils.ln(f, dest)
333
+ fl.shift
334
+ @rac.cmd_print "Linking "
335
+ rescue Exception #Errno::EOPNOTSUPP
336
+ ln_supported = false
337
+ @rac.cmd_print "Copying "
338
+ end
339
+ @rac.cmd_print \
340
+ "#{progress.total} files to #@dist_path: ".ljust(msg_len - 8)
341
+ progress.inc if ln_supported
342
+ fl.each { |f|
343
+ dest = File.join(@dist_path, f)
344
+ if ln_supported
345
+ FileUtils.ln(f, dest)
346
+ else
347
+ FileUtils.cp(f, dest)
348
+ end
349
+ progress.inc
350
+ }
351
+ @rac.cmd_msg "done"
352
+ end
321
353
  }
322
354
  end
323
355
  end # class Base
@@ -37,7 +37,7 @@ module Rant::Generators::Archive
37
37
  end
38
38
  def minitar_tgz fn, files, opts = {:recurse => false}
39
39
  require 'zlib'
40
- require 'rant/archive/minitar'
40
+ require 'rant/archive/minitar' #rant-import:remove
41
41
  @rac.cmd_msg "minitar #{fn}"
42
42
  files = files.to_ary if files.respond_to? :to_ary
43
43
  tgz = Zlib::GzipWriter.new(File.open(fn, 'wb'))
@@ -5,6 +5,7 @@
5
5
 
6
6
  require 'rant/rantlib'
7
7
  require 'rant/import/clean'
8
+ require 'rant/import/sys/more'
8
9
 
9
10
  class Rant::Generators::AutoClean
10
11
  def self.rant_gen(rac, ch, args, &block)
@@ -21,24 +22,29 @@ class Rant::Generators::AutoClean
21
22
 
22
23
  # create task
23
24
  rac.task :__caller__ => ch, tname => [] do |t|
24
- rac.tasks.each { |n, worker|
25
- if Array === worker
26
- worker.each { |subw|
27
- subw.each_target { |entry| clean rac, entry }
25
+ add_common_dirs = {}
26
+ rac.tasks.each { |name, node|
27
+ if Array === node
28
+ f = node.first
29
+ if f.file_target?
30
+ add_common_dirs[File.dirname(f.full_name)] = true
31
+ end
32
+ node.each { |subw|
33
+ subw.each_target { |entry| rac.sys.clean entry }
28
34
  }
29
35
  else
30
- worker.each_target { |entry| clean rac, entry }
36
+ if node.file_target?
37
+ add_common_dirs[File.dirname(node.full_name)] = true
38
+ end
39
+ node.each_target { |entry| rac.sys.clean entry }
31
40
  end
32
41
  }
33
42
  target_rx = nil
34
43
  rac.resolve_hooks.each { |hook|
35
44
  if hook.respond_to? :each_target
36
45
  hook.each_target { |entry|
37
- if test ?f, entry
38
- rac.cx.sys.rm_f entry
39
- else
40
- rac.cx.sys.rm_rf entry
41
- end
46
+ add_common_dirs[File.expand_path(File.dirname(entry))] = true
47
+ rac.sys.clean entry
42
48
  }
43
49
  elsif hook.respond_to? :target_rx
44
50
  next(rx) unless (t_rx = hook.target_rx)
@@ -46,15 +52,13 @@ class Rant::Generators::AutoClean
46
52
  Regexp.union(target_rx, t_rx)
47
53
  end
48
54
  }
55
+ t.goto_task_home
49
56
  if target_rx
50
- rac.msg 1, "searching for rule products"
51
- rac.cx.sys["**/*"].each { |entry|
57
+ rac.vmsg 1, "searching for rule products"
58
+ rac.sys["**/*"].each { |entry|
52
59
  if entry =~ target_rx
53
- if test ?f, entry
54
- rac.cx.sys.rm_f entry
55
- else
56
- rac.cx.sys.rm_rf entry
57
- end
60
+ add_common_dirs[File.dirname(entry)] = true
61
+ rac.sys.clean entry
58
62
  end
59
63
  }
60
64
  end
@@ -64,18 +68,16 @@ class Rant::Generators::AutoClean
64
68
  sd = rf.project_subdir
65
69
  common.each { |fn|
66
70
  path = sd.empty? ? fn : File.join(sd, fn)
67
- clean rac, path
71
+ rac.sys.clean path
72
+ }
73
+ }
74
+ #STDERR.puts add_common_dirs.inspect
75
+ add_common_dirs.each { |dir, _|
76
+ common.each { |fn|
77
+ rac.sys.clean File.join(dir, fn)
68
78
  }
69
79
  }
70
80
  end
71
- t.goto_task_home
72
81
  end
73
82
  end
74
- def self.clean(rac, entry)
75
- if test ?f, entry
76
- rac.cx.sys.rm_f entry
77
- elsif test ?e, entry
78
- rac.cx.sys.rm_rf entry
79
- end
80
- end
81
83
  end