rant 0.4.8 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/NEWS +31 -0
- data/README +3 -1
- data/Rantfile +53 -2
- data/doc/advanced.rdoc +86 -1
- data/doc/c.rdoc +8 -0
- data/doc/homepage/index.html +2 -0
- data/doc/rant.1 +4 -0
- data/doc/rant.rdoc +38 -0
- data/doc/rant_vs_rake.rdoc +13 -0
- data/doc/rantfile.rdoc +93 -63
- data/doc/sys.rdoc +568 -0
- data/lib/rant/coregen.rb +43 -16
- data/lib/rant/import/command.rb +7 -4
- data/lib/rant/import/filelist/more.rb +57 -0
- data/lib/rant/import/metadata.rb +5 -1
- data/lib/rant/import/nodes/default.rb +3 -24
- data/lib/rant/import/signedfile.rb +1 -8
- data/lib/rant/import/sys/more.rb +2 -1
- data/lib/rant/import/var/booleans.rb +65 -0
- data/lib/rant/import/var/lists.rb +34 -0
- data/lib/rant/import/var/numbers.rb +116 -0
- data/lib/rant/import/var/strings.rb +43 -0
- data/lib/rant/import.rb +19 -3
- data/lib/rant/node.rb +39 -6
- data/lib/rant/rantlib.rb +44 -8
- data/lib/rant/rantsys.rb +22 -54
- data/lib/rant/rantvar.rb +89 -256
- data/misc/TODO +18 -0
- data/misc/devel-notes +26 -1
- data/test/action.rant +24 -0
- data/test/deprecated/test_0_5_4.rb +53 -0
- data/test/deprecated/test_0_6_0.rb +1 -1
- data/test/dryrun/Rantfile +10 -0
- data/test/dryrun/foo.c +8 -0
- data/test/dryrun/test_dryrun.rb +31 -0
- data/test/import/c/dependencies/Rantfile +1 -1
- data/test/import/command/Rantfile +1 -1
- data/test/import/sys/test_tgz.rb +22 -0
- data/test/subdirs2/root.rant +11 -1
- data/test/subdirs2/sub1/sub.rant +3 -0
- data/test/subdirs2/test_subdirs2.rb +19 -0
- data/test/test_action.rb +75 -0
- data/test/test_filelist.rb +13 -10
- data/test/test_rant_interface.rb +2 -2
- data/test/test_rule.rb +121 -3
- data/test/test_sys_methods.rb +558 -0
- data/test/test_var.rb +10 -0
- data/test/tutil.rb +81 -8
- metadata +19 -2
data/doc/rantfile.rdoc
CHANGED
@@ -42,7 +42,7 @@ task name may be a string or symbol:
|
|
42
42
|
That's it, your first task. Not very useful, because it doesn't do
|
43
43
|
anything. To associate an action with the task, add a block:
|
44
44
|
task :mytask do
|
45
|
-
|
45
|
+
puts "Hello, mytask running."
|
46
46
|
end
|
47
47
|
Put these 3 lines of code into a file called +Rantfile+ and run rant:
|
48
48
|
% rant mytask
|
@@ -53,7 +53,7 @@ the only task in the Rantfile.
|
|
53
53
|
You can add a block parameter which will be a reference to the created
|
54
54
|
task:
|
55
55
|
task :mytask do |t|
|
56
|
-
|
56
|
+
puts t.name
|
57
57
|
end
|
58
58
|
Running rant now:
|
59
59
|
% rant
|
@@ -61,13 +61,13 @@ Running rant now:
|
|
61
61
|
|
62
62
|
Add prerequisites to create relations between tasks:
|
63
63
|
task :first => [:t1, :t2] do |t|
|
64
|
-
|
64
|
+
puts t.name
|
65
65
|
end
|
66
66
|
task :t1 do |t|
|
67
|
-
|
67
|
+
puts t.name
|
68
68
|
end
|
69
69
|
task :t2 do |t|
|
70
|
-
|
70
|
+
puts t.name
|
71
71
|
end
|
72
72
|
In the definition of the "first" task we told Rant that it _depends_
|
73
73
|
on task "t1" and task "t2". "t1" and "t2" are called prerequisites for
|
@@ -94,7 +94,7 @@ In this example we use the <tt>sys.touch</tt> method to test our file
|
|
94
94
|
task. (This method works the same as the Unix touch command: Update
|
95
95
|
the modification time of a file or create an empty file):
|
96
96
|
file "testfile" do |t|
|
97
|
-
|
97
|
+
sys.touch t.name
|
98
98
|
end
|
99
99
|
Now run rant:
|
100
100
|
% rant
|
@@ -107,7 +107,7 @@ date. Of course you can add prerequisites the same way as for a normal
|
|
107
107
|
task. Additionally you can add filenames as prerequisites. Assuming
|
108
108
|
the files "a.o" and "b.o" are in the same directory as the Rantfile:
|
109
109
|
file "myprog" => %w(a.o b.o) do |t|
|
110
|
-
|
110
|
+
sys %w(cc -o), t.name, t.prerequisites
|
111
111
|
end
|
112
112
|
Running rant:
|
113
113
|
% rant
|
@@ -126,58 +126,58 @@ The +desc+ function lets you describe your tasks. A small example
|
|
126
126
|
Rantfile:
|
127
127
|
# Generate C source file ls.c with the xgen command.
|
128
128
|
file "ls.c" => %w(ls1.x ls2.x) do |t|
|
129
|
-
|
129
|
+
sys %w(xgen -o), t.name, t.prerequisites
|
130
130
|
end
|
131
131
|
|
132
132
|
desc "Build ls program."
|
133
133
|
file "ls" => "ls.c" do
|
134
|
-
|
134
|
+
sys "cc -o ls ls.c"
|
135
135
|
end
|
136
136
|
|
137
137
|
desc "Remove autogenerated files."
|
138
138
|
task :clean do
|
139
|
-
|
139
|
+
sys.rm_f %w(ls.c ls)
|
140
140
|
end
|
141
141
|
(Note that xgen is a hypothetical command ;)
|
142
142
|
The <tt>--tasks</tt> (or the short form, <tt>-T</tt>) option of rant
|
143
143
|
shows this descriptions:
|
144
144
|
% rant -T
|
145
|
-
rant ls
|
146
|
-
rant clean
|
145
|
+
rant ls # Build ls program.
|
146
|
+
rant clean # Remove autogenerated files.
|
147
147
|
Only the tasks which have a description are listed.
|
148
148
|
|
149
|
-
=== The +sys+
|
149
|
+
=== The +sys+ method
|
150
150
|
|
151
|
-
After using the +sys+
|
152
|
-
explain it a little bit.
|
151
|
+
After using the +sys+ method quite often in the examples, I should
|
152
|
+
explain it a little bit. It can be used in three ways:
|
153
153
|
|
154
154
|
1. <b>File system operations</b>
|
155
155
|
|
156
156
|
The first form is with no arguments. It returns an object on which
|
157
|
-
you can invoke
|
158
|
-
|
157
|
+
you can invoke methods for common file system operations:
|
158
|
+
|
159
159
|
Examples are:
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
FileUtils module:
|
168
|
-
sys.ruby "arg1", "arg2", ... # invoke the ruby interpreter
|
169
|
-
sys.safe_ln "src", "dest" # create a hardlink or fall back to
|
170
|
-
# copying
|
160
|
+
|
161
|
+
sys.rm ["file1", "file2"] # remove files
|
162
|
+
sys.cp "src", "dest" # copy from "src" do "dest"
|
163
|
+
sys.mkdir "dir" # create directory "dir"
|
164
|
+
|
165
|
+
For a list of all available methods read
|
166
|
+
doc/sys.rdoc[link:files/doc/sys_rdoc.html].
|
171
167
|
|
172
168
|
2. <b>Running external commands</b>
|
173
169
|
|
174
|
-
Invoke the +sys+
|
175
|
-
|
170
|
+
Invoke the +sys+ method with a string as argument to run a shell:
|
171
|
+
|
172
|
+
sys "echo *.c"
|
173
|
+
|
176
174
|
will print a list of C files to stdout.
|
177
175
|
|
178
176
|
When given multiple arguments, +sys+ invokes the program named with
|
179
177
|
the first argument giving it the remaining arguments as arguments:
|
180
|
-
|
178
|
+
|
179
|
+
sys "echo", "*.c"
|
180
|
+
|
181
181
|
will print "*.c" to stdout.
|
182
182
|
|
183
183
|
When the external program returns with an exit code other than 0,
|
@@ -206,49 +206,61 @@ explain it a little bit. The +sys+ command can be used in three ways:
|
|
206
206
|
|
207
207
|
To select files with the help of glob patterns use +sys+ with the
|
208
208
|
<tt>[]</tt> operator:
|
209
|
-
|
209
|
+
|
210
|
+
file "program" => sys["*.o"]
|
211
|
+
|
210
212
|
The task "program" depends on all files ending in ".o". Rant uses
|
211
213
|
the Dir::glob method internally to resolve patterns, so you can
|
212
214
|
read the ri docs to get an overview:
|
213
|
-
|
215
|
+
|
216
|
+
ri Dir::glob
|
214
217
|
|
215
218
|
From now on we'll call <tt>sys[...]</tt> the <em>glob
|
216
219
|
operator</em>.
|
217
220
|
|
218
221
|
You can give more patterns:
|
219
|
-
|
222
|
+
|
223
|
+
c_files = sys["**/*.h", "**/*.c"]
|
224
|
+
|
220
225
|
gives a list of all files ending in ".h" or ".c" in the current
|
221
226
|
directory and all subdirectories.
|
222
227
|
|
223
|
-
The object returned by the glob operator _behaves_ like
|
228
|
+
The object returned by the glob operator _behaves_ like an array of
|
224
229
|
strings, so it is possible to pass it to methods expecting an array.
|
225
230
|
If you're getting errors or experience strange behaviour convert
|
226
231
|
the list explicetely to an array:
|
227
|
-
|
232
|
+
|
233
|
+
# method foo_bar is hardcoded to check for an object of class
|
234
|
+
# Array
|
235
|
+
foo_bar(c_files.to_a)
|
228
236
|
|
229
237
|
=== Generators
|
230
238
|
|
231
239
|
The *gen* function takes a generator which usually creates one or more
|
232
240
|
tasks for you. The following list of generators is immediately
|
233
241
|
available:
|
234
|
-
|
235
|
-
+
|
236
|
-
+
|
237
|
-
+
|
238
|
-
|
239
|
-
|
242
|
+
|
243
|
+
+Directory+:: Create directories.
|
244
|
+
+Task+:: Define custom task.
|
245
|
+
+Rule+:: Define a rule (a rule produces tasks on the fly).
|
246
|
+
+Action+:: Run a block of code immediately.
|
247
|
+
The Action generator is discussed in
|
248
|
+
doc/advanced.rdoc[link:files/doc/advanced_rdoc.html].
|
240
249
|
|
241
250
|
=== The +Directory+ generator
|
242
251
|
|
243
252
|
An example usage of the +Directory+ generator would be the backup
|
244
253
|
example shown in the README file:
|
254
|
+
|
245
255
|
file "misc/backup/data" => %w(misc/backup data) do |t|
|
246
|
-
|
256
|
+
sys.cp "data", t.name
|
247
257
|
end
|
248
258
|
|
249
259
|
gen Directory, "misc/backup"
|
260
|
+
|
250
261
|
Now rant will create the directories "misc" and "backup" on demand.
|
251
262
|
Assuming "misc/backup" doesn't exist:
|
263
|
+
|
252
264
|
% rant
|
253
265
|
mkdir misc
|
254
266
|
mkdir misc/backup
|
@@ -258,13 +270,15 @@ Assuming "misc/backup" doesn't exist:
|
|
258
270
|
|
259
271
|
The +Task+ generator allows you to determine by hand when your task
|
260
272
|
action needs to be run:
|
273
|
+
|
261
274
|
desc "Install with setup.rb"
|
262
275
|
gen Task, :install do |t|
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
276
|
+
t.needed { !File.exist? "InstalledFiles" }
|
277
|
+
t.act do
|
278
|
+
sys.ruby "setup.rb"
|
279
|
+
end
|
267
280
|
end
|
281
|
+
|
268
282
|
The +act+ block of the "install" task will only be run if
|
269
283
|
"InstalledFiles" doesn't exist. Of course you can add prerequisites
|
270
284
|
like with any other task.
|
@@ -274,29 +288,37 @@ like with any other task.
|
|
274
288
|
A Rule allows you to tell Rant how it should build files matching a
|
275
289
|
common pattern, e.g. how to build files ending in ".o". A standard
|
276
290
|
rule usage is to create C object files:
|
291
|
+
|
277
292
|
gen Rule, '.o' => '.c' do |t|
|
278
|
-
|
293
|
+
sys "cc -c -o #{t.name} #{t.source}"
|
279
294
|
end
|
295
|
+
|
280
296
|
Assuming that we have the C source file util.c in the current
|
281
297
|
directory:
|
298
|
+
|
282
299
|
% rant util.o
|
283
300
|
cc -c -o util.o util.c
|
301
|
+
|
284
302
|
Because Rant didn't find a task for util.o, it looked for a matching
|
285
303
|
rule and created a task for util.o.
|
286
304
|
|
287
305
|
The first line above could also be written as:
|
306
|
+
|
288
307
|
gen Rule, :o => :c do |t|
|
289
308
|
|
290
309
|
The +source+ method of the task object gives us the first dependency.
|
291
310
|
So the following line has the same effect:
|
292
|
-
|
311
|
+
|
312
|
+
sys "cc -c -o #{t.name} #{t.prerequisites.first}"
|
293
313
|
|
294
314
|
You can also refine the rule pattern by using a regular expression. To
|
295
315
|
refine dependency selection give a block as source argument:
|
316
|
+
|
296
317
|
src = lambda { |target| [target.sub_ext("c"), target.sub_ext("h")] }
|
297
318
|
gen Rule, /^my_[^.]+\.o$/ => src do |t|
|
298
|
-
|
319
|
+
sys "cc -c -o #{t.name} #{t.source}"
|
299
320
|
end
|
321
|
+
|
300
322
|
This rule generates a task for files beginning with "my_" and ending
|
301
323
|
in ".o" (like "my_program.o"). The task has a file ending in ".c" and
|
302
324
|
one ending in ".h" as dependencies (like "my_program.c" and
|
@@ -311,6 +333,7 @@ last dot with the given string.
|
|
311
333
|
|
312
334
|
The +import+ function lets you import additional generators.
|
313
335
|
Currently the following come with Rant:
|
336
|
+
|
314
337
|
Clean:: Remove selected files.
|
315
338
|
AutoClean:: Remove all files generated by any file task (including
|
316
339
|
those generated by rules).
|
@@ -318,10 +341,17 @@ DirectedRule:: A Rule which takes sources from one or more
|
|
318
341
|
directories and puts generated files into a specified
|
319
342
|
directory.
|
320
343
|
SubFile:: Create file task and necessary directory tasks.
|
344
|
+
Command:: Tasks with command change recognition.
|
321
345
|
RubyTest:: Run Test::Unit tests for your Ruby code.
|
322
346
|
RubyDoc:: Run RDoc.
|
323
347
|
RubyPackage:: Generate tar, zip and gem packages of your Ruby
|
324
348
|
application/library.
|
349
|
+
Archive::Tgz:: Create gzipped tar archives.
|
350
|
+
Archive::Zip:: Create zip archives.
|
351
|
+
Package::Tgz:: Create gzipped tar packages.
|
352
|
+
Package::Zip:: Create zip packages.
|
353
|
+
C::Dependencies:: Determine dependencies between C/C++ source/header
|
354
|
+
files caused by #include statements.
|
325
355
|
Win32::RubyCmdWrapper:: Create .cmd wrapper scripts for installation
|
326
356
|
of Ruby scripts on Windows.
|
327
357
|
|
@@ -338,22 +368,22 @@ from your main Rantfile and vice versa.
|
|
338
368
|
|
339
369
|
A small example: We are assuming the following files:
|
340
370
|
myprog/
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
371
|
+
Rantfile # the main Rantfile
|
372
|
+
README
|
373
|
+
src/
|
374
|
+
Rantfile
|
375
|
+
main.c
|
376
|
+
lib.c
|
377
|
+
lib.h
|
348
378
|
Then the main Rantfile could look like:
|
349
379
|
desc "Build myprog."
|
350
380
|
file "myprog" => "src/myprog" do
|
351
|
-
|
381
|
+
sys.cp "src/myprog", "myprog"
|
352
382
|
end
|
353
383
|
|
354
384
|
desc "Remove compiler products."
|
355
385
|
task :clean => "src/clean" do
|
356
|
-
|
386
|
+
sys.rm_f "myprog"
|
357
387
|
end
|
358
388
|
|
359
389
|
# Tell Rant to look in src for an Rantfile,
|
@@ -361,19 +391,19 @@ Then the main Rantfile could look like:
|
|
361
391
|
subdirs "src"
|
362
392
|
And src/Rantfile:
|
363
393
|
file "lib.o" => %w(lib.c lib.h) do
|
364
|
-
|
394
|
+
sys "cc -c -o lib.o lib.c"
|
365
395
|
end
|
366
396
|
|
367
397
|
file "main.o" => "main.c" do
|
368
|
-
|
398
|
+
sys "cc -c -o main.o main.c"
|
369
399
|
end
|
370
400
|
|
371
401
|
file "myprog" => %w(lib.o main.o) do
|
372
|
-
|
402
|
+
sys "cc -o myprog main.o lib.o"
|
373
403
|
end
|
374
404
|
|
375
405
|
task :clean do
|
376
|
-
|
406
|
+
sys.rm_f Dir["*.o"] + %w(myprog)
|
377
407
|
end
|
378
408
|
Note that we refer to the task in subdirectory simply by prepending
|
379
409
|
the directory name and a slash to the task name.
|