rant 0.3.0 → 0.3.2

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 (51) hide show
  1. data/NEWS +21 -0
  2. data/README +8 -0
  3. data/Rantfile +30 -16
  4. data/TODO +3 -4
  5. data/devel-notes +16 -0
  6. data/doc/csharp.rdoc +2 -3
  7. data/doc/examples/myprog/README +2 -0
  8. data/doc/examples/myprog/Rantfile +13 -0
  9. data/doc/examples/myprog/src/Rantfile +15 -0
  10. data/doc/examples/myprog/src/lib.c +6 -0
  11. data/doc/examples/myprog/src/lib.h +4 -0
  12. data/doc/examples/myprog/src/main.c +7 -0
  13. data/doc/rantfile.rdoc +108 -3
  14. data/lib/rant/cs_compiler.rb +6 -4
  15. data/lib/rant/import.rb +13 -0
  16. data/lib/rant/import/rubypackage.rb +43 -20
  17. data/lib/rant/plugin/configure.rb +21 -7
  18. data/lib/rant/plugin/csharp.rb +8 -9
  19. data/lib/rant/rantenv.rb +3 -0
  20. data/lib/rant/rantfile.rb +66 -33
  21. data/lib/rant/rantlib.rb +133 -27
  22. data/lib/rant/rantsys.rb +197 -42
  23. data/rantmethods.rb +46 -0
  24. data/setup.rb +18 -4
  25. data/test/plugin/configure/Rantfile +0 -6
  26. data/test/plugin/configure/test_configure.rb +2 -2
  27. data/test/plugin/csharp/test_csharp.rb +7 -2
  28. data/test/plugin/rantfile +45 -0
  29. data/test/plugin/test_conf_csharp.rb +53 -0
  30. data/test/project1/Rantfile +4 -0
  31. data/test/project1/test_project.rb +33 -8
  32. data/test/project2/buildfile +3 -3
  33. data/test/project2/sub1/Rantfile +3 -3
  34. data/test/project2/test_project.rb +6 -4
  35. data/test/project_rb1/test_project_rb1.rb +2 -2
  36. data/test/standalone.rf +10 -0
  37. data/test/subdirs/Rantfile +26 -0
  38. data/test/subdirs/sub1/Rantfile +15 -0
  39. data/test/subdirs/sub2/rantfile.rb +14 -0
  40. data/test/subdirs/sub2/sub/rantfile +15 -0
  41. data/test/subdirs/test_subdirs.rb +96 -0
  42. data/test/test_env.rb +3 -3
  43. data/test/test_filelist.rb +143 -0
  44. data/test/test_lighttask.rb +21 -0
  45. data/test/test_metatask.rb +1 -1
  46. data/test/test_rant_interface.rb +5 -5
  47. data/test/test_sys.rb +7 -1
  48. data/test/test_task.rb +25 -0
  49. data/test/toplevel.rf +0 -1
  50. data/test/tutil.rb +26 -1
  51. metadata +39 -14
@@ -77,3 +77,49 @@ file "bench-depsearch" do |t|
77
77
  EOT
78
78
  }
79
79
  end
80
+
81
+ =begin
82
+ class TraceObject < Object
83
+ ml = public_instance_methods + protected_instance_methods + private_instance_methods
84
+ ml.each { |m|
85
+ eval <<-EOM
86
+ def #{m}(*args)
87
+ print "TraceObject##{m}("
88
+ print args.join(", ")
89
+ print ")"
90
+ puts(block_given? ? " block_given" : "")
91
+ super
92
+ end
93
+ EOM
94
+ }
95
+ end
96
+ =end
97
+
98
+ class TraceArray < Array
99
+ ml = public_instance_methods + protected_instance_methods + private_instance_methods
100
+ ml.delete "print"
101
+ ml.delete "block_given?"
102
+ ml.delete "puts"
103
+ ml.each { |m|
104
+ eval <<-EOM
105
+ def #{m}(*args)
106
+ print "TraceArray##{m}("
107
+ print args.join(", ")
108
+ print ")"
109
+ puts(block_given? ? " block_given" : "")
110
+ super
111
+ end
112
+ EOM
113
+ }
114
+ end
115
+
116
+ # list the methods that are sent to an object that is in an array
117
+ # which is flattened.
118
+ #task :flatten do
119
+ # to = TraceObject.new
120
+ #[to].flatten
121
+ #end
122
+
123
+ task :flatten_ary do
124
+ [TraceArray.new].flatten
125
+ end
data/setup.rb CHANGED
@@ -7,6 +7,9 @@
7
7
  # You can distribute/modify this program under the terms of
8
8
  # the GNU LGPL, Lesser General Public License version 2.1.
9
9
  #
10
+ # Modifications made by Stefan Lang are marked with a line
11
+ ### stefan ###
12
+ #
10
13
 
11
14
  unless Enumerable.method_defined?(:map) # Ruby 1.4.6
12
15
  module Enumerable
@@ -1124,9 +1127,14 @@ class Installer
1124
1127
  end
1125
1128
 
1126
1129
  def setup_dir_bin(rel)
1127
- all_files_in(curr_srcdir()).each do |fname|
1128
- adjust_shebang "#{curr_srcdir()}/#{fname}"
1129
- end
1130
+ ### stefan ###
1131
+ # Do not adjust shebang on Windows as it is useless and setup.rb
1132
+ # is failing for me (Note: already fixed in adjust_shebang).
1133
+ #unless PLATFORM =~ /mswin/i
1134
+ all_files_in(curr_srcdir()).each do |fname|
1135
+ adjust_shebang "#{curr_srcdir()}/#{fname}"
1136
+ end
1137
+ #end
1130
1138
  end
1131
1139
 
1132
1140
  def adjust_shebang(path)
@@ -1136,14 +1144,20 @@ class Installer
1136
1144
  File.open(path, 'rb') {|r|
1137
1145
  first = r.gets
1138
1146
  return unless File.basename(config('rubypath')) == 'ruby'
1147
+ ### stefan ###
1148
+ # Add <tt>|| ""</tt> which avoids an ArgumentError if first
1149
+ # line doesn't match the regexp.
1139
1150
  return unless File.basename(first.sub(/\A\#!/, '').split[0] || "") == 'ruby'
1140
1151
  $stderr.puts "adjusting shebang: #{File.basename(path)}" if verbose?
1141
1152
  File.open(tmpfile, 'wb') {|w|
1142
1153
  w.print first.sub(/\A\#!\s*\S+/, '#! ' + config('rubypath'))
1143
1154
  w.write r.read
1144
1155
  }
1145
- move_file tmpfile, File.basename(path)
1146
1156
  }
1157
+ ### stefan ###
1158
+ # Move +move_file+ out of File.open block to close tmpfile
1159
+ # before unlinking (which didn't work on Windows).
1160
+ move_file tmpfile, File.basename(path)
1147
1161
  ensure
1148
1162
  File.unlink tmpfile if File.exist?(tmpfile)
1149
1163
  end
@@ -3,8 +3,6 @@
3
3
  rd = File.expand_path("../../../lib")
4
4
  $:.unshift rd unless $:.include? rd
5
5
 
6
- require 'rant'
7
-
8
6
  task :hello do |t|
9
7
  sys.touch t.name
10
8
  end
@@ -41,7 +39,3 @@ end
41
39
  task :clean do
42
40
  sys.rm_f %w(config hello value_a value_a_guess)
43
41
  end
44
-
45
- if $0 == __FILE__
46
- Rant.run
47
- end
@@ -1,6 +1,6 @@
1
1
 
2
2
  require 'test/unit'
3
- require 'rant'
3
+ require 'rant/rantlib'
4
4
  require 'tutil'
5
5
 
6
6
  $testPluginConfigureDir = File.expand_path(File.dirname(__FILE__))
@@ -30,7 +30,7 @@ class TestPluginConfigure < Test::Unit::TestCase
30
30
  end
31
31
  def test_configure
32
32
  capture_std do
33
- assert_equal(Rant.run("configure"), 0)
33
+ assert_equal(0, Rant.run("configure"))
34
34
  end
35
35
  assert(File.exist?("config"),
36
36
  "config should have been created by `configure'")
@@ -1,13 +1,16 @@
1
1
 
2
2
  require 'test/unit'
3
- require 'rant'
3
+ require 'rant/rantlib'
4
4
  require 'rant/plugin/csharp'
5
5
  require 'tutil'
6
6
 
7
7
  $testPluginCsDir = File.expand_path(File.dirname(__FILE__))
8
- $have_csc = Env.find_bin("csc") || Env.find_bin("cscc") || Env.find_bin("mcs")
8
+ $have_csc ||= Rant::Env.find_bin("csc") ||
9
+ Rant::Env.find_bin("cscc") || Rant::Env.find_bin("mcs")
9
10
 
10
11
  class TestPluginCsharp < Test::Unit::TestCase
12
+ include Rant
13
+
11
14
  def setup
12
15
  # Ensure we run in test directory.
13
16
  Dir.chdir($testPluginCsDir) unless Dir.pwd == $testPluginCsDir
@@ -16,6 +19,8 @@ class TestPluginCsharp < Test::Unit::TestCase
16
19
  capture_std do
17
20
  assert(Rant.run("clean"), 0)
18
21
  end
22
+ assert(Dir["*.{exe,dll,obj}"].empty?,
23
+ "task :clean should remove exe, dll and obj files")
19
24
  end
20
25
  if $have_csc
21
26
  # Try to compile the "hello world" program. Requires cscc, csc
@@ -0,0 +1,45 @@
1
+
2
+ conf = plugin :Configure do |conf|
3
+ conf.init_modes = [:explicit]
4
+ conf.override_modes = [:env]
5
+ conf.task # define a task named :configure
6
+ conf.check "target" do |c|
7
+ c.default "conf_csharp.exe"
8
+ c.interact {
9
+ c.prompt "Name for executable: "
10
+ }
11
+ end
12
+ # define more checks
13
+ end
14
+
15
+ plugin :Csharp do |cs|
16
+ cs.config = conf
17
+ end
18
+
19
+ conf.init
20
+
21
+ task :default => ["conf_csharp.cs", conf["target"]]
22
+
23
+ # from our example above
24
+ gen Assembly, conf["target"] do |t|
25
+ t.libs = %w(System.Xml.dll)
26
+ t.sources = Dir["*.cs"]
27
+ end
28
+
29
+ file "conf_csharp.cs" do |t|
30
+ File.open(t.name, "w") { |f|
31
+ f << <<-EOF
32
+ class ConfCSharp
33
+ {
34
+ public static void Main(string[] args)
35
+ {
36
+ System.Console.WriteLine("ConfCSharp");
37
+ }
38
+ }
39
+ EOF
40
+ }
41
+ end
42
+
43
+ task :clean do
44
+ sys.rm_f Dir["*.{exe,cs}"] + %w(config)
45
+ end
@@ -0,0 +1,53 @@
1
+
2
+ require 'test/unit'
3
+ require 'rant/rantlib'
4
+ require 'tutil'
5
+
6
+ $testPluginConfCsDir = File.expand_path(File.dirname(__FILE__))
7
+ $have_csc ||= Rant::Env.find_bin("csc") ||
8
+ Rant::Env.find_bin("cscc") || Rant::Env.find_bin("mcs")
9
+
10
+ class TestConfCsharp < Test::Unit::TestCase
11
+ def setup
12
+ # Ensure we run in test directory.
13
+ Dir.chdir($testPluginConfCsDir) unless Dir.pwd == $testPluginConfCsDir
14
+ end
15
+ def teardown
16
+ capture_std do
17
+ assert_equal(0, Rant.run("clean"))
18
+ end
19
+ end
20
+ if $have_csc
21
+ def test_defaults
22
+ capture_std do
23
+ assert_equal(0, Rant.run([]))
24
+ end
25
+ assert(test(?f, "conf_csharp.cs"),
26
+ "conf_csharp.cs should be created by default task")
27
+ assert(test(?f, "conf_csharp.exe"),
28
+ "conf_csharp.exe should be compiled by default task")
29
+ assert(test(?f, "config"),
30
+ "config should habe been created by Configure plugin")
31
+ end
32
+ def test_with_explicit_target
33
+ capture_std do
34
+ assert_equal(0, Rant.run(%w(target=myprog.exe)))
35
+ end
36
+ assert(test(?f, "conf_csharp.cs"))
37
+ assert(test(?f, "myprog.exe"),
38
+ "myprog.exe was given as target name on commandline")
39
+ assert(test(?f, "config"))
40
+ File.delete "myprog.exe"
41
+ capture_std do
42
+ assert_equal(0, Rant.run([]))
43
+ end
44
+ assert(test(?f, "myprog.exe"),
45
+ "target should be set to myprog.exe from config")
46
+ end
47
+ else
48
+ # required to fool test/unit
49
+ def test_dummy
50
+ assert(true)
51
+ end
52
+ end
53
+ end
@@ -62,6 +62,10 @@ gen Directory, "dir/sub2" do |t|
62
62
  sys.touch "#{t.name}/postprocess"
63
63
  end
64
64
 
65
+ gen Directory, "dir/sub3" => "dep1" do |t|
66
+ sys.touch "#{t.name}/postprocess"
67
+ end
68
+
65
69
  file "tbe" => :dep1 do |t|
66
70
  sys.touch t.name
67
71
  sleep 2
@@ -1,6 +1,6 @@
1
1
 
2
2
  require 'test/unit'
3
- require 'rant'
3
+ require 'rant/rantlib'
4
4
  require 'tutil'
5
5
 
6
6
  # Ensure we run in testproject directory.
@@ -37,24 +37,24 @@ class TestProject1 < Test::Unit::TestCase
37
37
  end
38
38
  assert(File.exist?("target"))
39
39
  Rant.reset
40
- sleep 2
40
+ timeout
41
41
  capture_std do
42
42
  assert_equal(Rant.run("create_dep"), 0)
43
43
  end
44
44
  assert(File.exist?("dep"))
45
- assert(sys.uptodate?("dep", "target"),
45
+ assert(Rant::Sys.uptodate?("dep", "target"),
46
46
  "`create_target' was run before `create_dep'")
47
- sleep 2
47
+ timeout
48
48
  capture_std do
49
49
  assert_equal(Rant.run("target"), 0)
50
50
  end
51
51
  assert(File.exist?("target"))
52
52
  assert(File.exist?("dep"))
53
- assert(sys.uptodate?("target", "dep"),
53
+ assert(Rant::Sys.uptodate?("target", "dep"),
54
54
  "`target' should be newer than `dep'")
55
55
  t1 = File.mtime "target"
56
56
  Rant.reset
57
- sleep 2
57
+ timeout
58
58
  capture_std do
59
59
  assert_equal(Rant.run("target"), 0)
60
60
  end
@@ -123,6 +123,31 @@ class TestProject1 < Test::Unit::TestCase
123
123
  assert(test(?f, "dir/sub2/postprocess"),
124
124
  "dir/sub2/postprocess should have been created by block supplied to directory task")
125
125
  end
126
+ def test_directory_pre_postprocess
127
+ capture_std do
128
+ assert_equal(0, Rant.run("dir/sub3"))
129
+ end
130
+ assert(test(?d, "dir/sub3"))
131
+ assert(test(?e, "dep1"), "dep1 is a prerequisite")
132
+ assert(test(?e, "dir/sub3/postprocess"))
133
+ old_mtime = File.mtime "dir/sub3"
134
+ assert_equal(old_mtime, File.mtime("dep1"))
135
+ timeout
136
+ capture_std do
137
+ assert_equal(0, Rant.run("dir/sub3"))
138
+ end
139
+ assert_equal(old_mtime, File.mtime("dir/sub3"),
140
+ "no prerequisite requires update")
141
+ assert_equal(old_mtime, File.mtime("dir/sub3/postprocess"))
142
+ capture_std do
143
+ assert_equal(0, Rant.run(%w(-a dep1)))
144
+ assert(File.mtime("dep1") > old_mtime)
145
+ timeout
146
+ assert_equal(0, Rant.run("dir/sub3"))
147
+ assert(File.mtime("dir/sub3") > old_mtime)
148
+ assert(File.mtime("dir/sub3/postprocess") > old_mtime)
149
+ end
150
+ end
126
151
  def test_order
127
152
  capture_std do
128
153
  assert_equal(Rant.run("order"), 0)
@@ -158,7 +183,7 @@ class TestProject1 < Test::Unit::TestCase
158
183
  assert(test(?f, "inc"))
159
184
  assert(test(?f, "incdep"))
160
185
  old_mtime = test(?M, "incdep")
161
- sleep 2
186
+ timeout
162
187
  capture_std do
163
188
  assert_equal(Rant.run(%w(--force-run incdep)), 0,
164
189
  "--force-run should unconditionally run `incdep'")
@@ -185,7 +210,7 @@ class TestProject1 < Test::Unit::TestCase
185
210
  assert(test(?e, "one_target"),
186
211
  "one_target should get `touched' by task_one")
187
212
  old_mtime = test(?M, "one_target")
188
- sleep 2
213
+ timeout
189
214
  capture_std do
190
215
  assert_equal(Rant.run("task_one"), 0)
191
216
  end
@@ -1,14 +1,14 @@
1
1
 
2
2
  file "b_f1" => ["r_f4", "b_f2"] do |t|
3
- touch t.name
3
+ sys.touch t.name
4
4
  end
5
5
 
6
6
  file "b_f2" do |t|
7
- touch t.name
7
+ sys.touch t.name
8
8
  end
9
9
 
10
10
  task :clean do |t|
11
- rm_f Dir["b_f*"]
11
+ sys.rm_f Dir["b_f*"]
12
12
  end
13
13
 
14
14
  subdirs %w(sub1 sub2)
@@ -1,12 +1,12 @@
1
1
 
2
2
  task :create_s1f1 do
3
- touch "sub1/s1f1"
3
+ sys.touch "s1f1"
4
4
  end
5
5
 
6
6
  task :insub1_s1f1 do
7
- touch "s1f1"
7
+ sys.touch "s1f1"
8
8
  end
9
9
 
10
10
  task :clean do
11
- rm_f %w(sub1/s1f1 s1f1)
11
+ sys.rm_f %w(s1f1)
12
12
  end
@@ -6,13 +6,14 @@ require 'tutil'
6
6
  # which would cause the rant.rb (which is ment as a Rantfile)
7
7
  # to be loaded!
8
8
  require 'rant/rantlib'
9
- include Rant
10
- include ::Rant::Sys
11
9
 
12
10
  # Ensure we run in testproject directory.
13
11
  $testProject2Dir = File.expand_path(File.dirname(__FILE__))
14
12
 
15
13
  class TestProject2 < Test::Unit::TestCase
14
+ include Rant
15
+ include ::Rant::Sys
16
+
16
17
  def app *args
17
18
  @app = ::Rant::RantApp.new(*args)
18
19
  end
@@ -21,7 +22,7 @@ class TestProject2 < Test::Unit::TestCase
21
22
  end
22
23
  def teardown
23
24
  capture_std do
24
- assert_equal(app(%w(-f rantfile.rb -f buildfile clean)).run, 0)
25
+ assert_equal(app(%w(-f rantfile.rb -f buildfile clean sub1/clean)).run, 0)
25
26
  end
26
27
  assert(Dir["r_f*"].empty?,
27
28
  "r_f* files should have been removed by `clean'")
@@ -49,6 +50,7 @@ class TestProject2 < Test::Unit::TestCase
49
50
  def test_load_rantfile
50
51
  capture_std do
51
52
  app("b_f2")
53
+ @app.rootdir = $testProject2Dir
52
54
  assert(@app.source("buildfile"),
53
55
  "source should return a true value on success")
54
56
  assert_equal(@app.run, 0)
@@ -57,7 +59,7 @@ class TestProject2 < Test::Unit::TestCase
57
59
  end
58
60
  def test_subdirs
59
61
  capture_std do
60
- assert_equal(app(%w(-f buildfile create_s1f1)).run, 0)
62
+ assert_equal(0, app(%w(-f buildfile sub1/create_s1f1)).run)
61
63
  end
62
64
  assert(File.exist?("sub1/s1f1"))
63
65
  end
@@ -46,12 +46,12 @@ class TestProjectRb1 < Test::Unit::TestCase
46
46
  end
47
47
  def test_test
48
48
  capture_std do
49
- assert_equal(Rant.run(%w(test)), 0)
49
+ assert_equal(0, Rant.run(%w(test)))
50
50
  end
51
51
  end
52
52
  def test_package
53
53
  capture_std do
54
- assert_equal(Rant.run(%w(pkg)), 0)
54
+ assert_equal(0, Rant.run(%w(pkg)))
55
55
  end
56
56
  assert(test(?d, "packages"),
57
57
  "task `pkg' should create dir `packages'")