jimweirich-rake 0.8.1.5
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/CHANGES +364 -0
- data/MIT-LICENSE +21 -0
- data/README +242 -0
- data/Rakefile +413 -0
- data/TODO +20 -0
- data/bin/rake +31 -0
- data/doc/example/Rakefile1 +38 -0
- data/doc/example/Rakefile2 +35 -0
- data/doc/example/a.c +6 -0
- data/doc/example/b.c +6 -0
- data/doc/example/main.c +11 -0
- data/doc/glossary.rdoc +51 -0
- data/doc/jamis.rb +591 -0
- data/doc/proto_rake.rdoc +127 -0
- data/doc/rake.1.gz +0 -0
- data/doc/rakefile.rdoc +411 -0
- data/doc/rational.rdoc +151 -0
- data/doc/release_notes/rake-0.4.14.rdoc +23 -0
- data/doc/release_notes/rake-0.4.15.rdoc +35 -0
- data/doc/release_notes/rake-0.5.0.rdoc +53 -0
- data/doc/release_notes/rake-0.5.3.rdoc +78 -0
- data/doc/release_notes/rake-0.5.4.rdoc +46 -0
- data/doc/release_notes/rake-0.6.0.rdoc +141 -0
- data/doc/release_notes/rake-0.7.0.rdoc +119 -0
- data/doc/release_notes/rake-0.7.1.rdoc +59 -0
- data/doc/release_notes/rake-0.7.2.rdoc +121 -0
- data/doc/release_notes/rake-0.7.3.rdoc +47 -0
- data/doc/release_notes/rake-0.8.0.rdoc +114 -0
- data/install.rb +88 -0
- data/lib/rake/classic_namespace.rb +8 -0
- data/lib/rake/clean.rb +33 -0
- data/lib/rake/contrib/compositepublisher.rb +24 -0
- data/lib/rake/contrib/ftptools.rb +153 -0
- data/lib/rake/contrib/publisher.rb +75 -0
- data/lib/rake/contrib/rubyforgepublisher.rb +18 -0
- data/lib/rake/contrib/sshpublisher.rb +47 -0
- data/lib/rake/contrib/sys.rb +209 -0
- data/lib/rake/gempackagetask.rb +103 -0
- data/lib/rake/loaders/makefile.rb +40 -0
- data/lib/rake/packagetask.rb +184 -0
- data/lib/rake/rake_test_loader.rb +5 -0
- data/lib/rake/rdoctask.rb +147 -0
- data/lib/rake/ruby182_test_unit_fix.rb +23 -0
- data/lib/rake/runtest.rb +23 -0
- data/lib/rake/tasklib.rb +18 -0
- data/lib/rake/testtask.rb +161 -0
- data/lib/rake.rb +2312 -0
- data/test/capture_stdout.rb +26 -0
- data/test/contrib/testsys.rb +47 -0
- data/test/data/chains/Rakefile +15 -0
- data/test/data/default/Rakefile +19 -0
- data/test/data/dryrun/Rakefile +22 -0
- data/test/data/file_creation_task/Rakefile +30 -0
- data/test/data/imports/Rakefile +19 -0
- data/test/data/imports/deps.mf +1 -0
- data/test/data/multidesc/Rakefile +17 -0
- data/test/data/namespace/Rakefile +57 -0
- data/test/data/rakelib/test1.rb +3 -0
- data/test/data/rbext/rakefile.rb +3 -0
- data/test/data/sample.mf +9 -0
- data/test/data/statusreturn/Rakefile +8 -0
- data/test/data/unittest/Rakefile +1 -0
- data/test/filecreation.rb +32 -0
- data/test/functional.rb +15 -0
- data/test/rake_test_setup.rb +5 -0
- data/test/reqfile.rb +3 -0
- data/test/reqfile2.rb +3 -0
- data/test/session_functional.rb +267 -0
- data/test/shellcommand.rb +3 -0
- data/test/test_application.rb +504 -0
- data/test/test_clean.rb +14 -0
- data/test/test_definitions.rb +82 -0
- data/test/test_earlytime.rb +35 -0
- data/test/test_extension.rb +63 -0
- data/test/test_file_creation_task.rb +62 -0
- data/test/test_file_task.rb +139 -0
- data/test/test_filelist.rb +618 -0
- data/test/test_fileutils.rb +239 -0
- data/test/test_ftp.rb +59 -0
- data/test/test_invocation_chain.rb +75 -0
- data/test/test_makefile_loader.rb +23 -0
- data/test/test_multitask.rb +45 -0
- data/test/test_namespace.rb +36 -0
- data/test/test_package_task.rb +116 -0
- data/test/test_pathmap.rb +209 -0
- data/test/test_rake.rb +34 -0
- data/test/test_require.rb +33 -0
- data/test/test_rules.rb +347 -0
- data/test/test_task_arguments.rb +76 -0
- data/test/test_task_manager.rb +148 -0
- data/test/test_tasks.rb +372 -0
- data/test/test_test_task.rb +75 -0
- data/test/test_top_level_functions.rb +84 -0
- metadata +173 -0
data/doc/rakefile.rdoc
ADDED
@@ -0,0 +1,411 @@
|
|
1
|
+
= Rakefile Format
|
2
|
+
|
3
|
+
First of all, there is no special format for a Rakefile. A Rakefile
|
4
|
+
contains executable Ruby code. Anything legal in a ruby script is
|
5
|
+
allowed in a Rakefile.
|
6
|
+
|
7
|
+
Now that we understand there is no special syntax in a Rakefile, there
|
8
|
+
are some conventions that are used in a Rakefile that are a little
|
9
|
+
unusual in a typical Ruby program. Since a Rakefile is tailored to
|
10
|
+
specifying tasks and actions, the idioms used in a Rakefile are
|
11
|
+
designed to support that.
|
12
|
+
|
13
|
+
So, what goes into a Rakefile?
|
14
|
+
|
15
|
+
== Tasks
|
16
|
+
|
17
|
+
Tasks are the main unit of work in a Rakefile. Tasks have a name
|
18
|
+
(usually given as a symbol or a string), a list of prerequisites (more
|
19
|
+
symbols or strings) and a list of actions (given as a block).
|
20
|
+
|
21
|
+
=== Simple Tasks
|
22
|
+
|
23
|
+
A task is declared by using the +task+ method. +task+ takes a single
|
24
|
+
parameter that is the name of the task.
|
25
|
+
|
26
|
+
task :name
|
27
|
+
|
28
|
+
=== Tasks with Prerequisites
|
29
|
+
|
30
|
+
Any prerequisites are given as a list (inclosed in square brackets)
|
31
|
+
following the name and an arrow (=>).
|
32
|
+
|
33
|
+
task :name => [:prereq1, :prereq2]
|
34
|
+
|
35
|
+
<b>NOTE:</b> Although this syntax looks a little funky, it is legal
|
36
|
+
Ruby. We are constructing a hash where the key is :name and the value
|
37
|
+
for that key is the list of prerequisites. It is equivalent to the
|
38
|
+
following ...
|
39
|
+
|
40
|
+
hash = Hash.new
|
41
|
+
hash[:name] = [:prereq1, :prereq2]
|
42
|
+
task(hash)
|
43
|
+
|
44
|
+
=== Tasks with Actions
|
45
|
+
|
46
|
+
Actions are defined by passing a block to the +task+ method. Any Ruby
|
47
|
+
code can be placed in the block. The block may reference the task
|
48
|
+
object via the block paramter..
|
49
|
+
|
50
|
+
task :name => [:prereq1, :prereq2] do |t|
|
51
|
+
# actions (may reference t)
|
52
|
+
end
|
53
|
+
|
54
|
+
=== Multiple Definitions
|
55
|
+
|
56
|
+
A task may be specified more than once. Each specification adds its
|
57
|
+
prerequisites and actions to the existing definition. This allows one
|
58
|
+
part of a rakefile to specify the actions and a different rakefile
|
59
|
+
(perhaps separately generated) to specify the dependencies.
|
60
|
+
|
61
|
+
For example, the following is equivalent to the single task
|
62
|
+
specification given above.
|
63
|
+
|
64
|
+
task :name
|
65
|
+
task :name => [:prereq1]
|
66
|
+
task :name => [:prereq2]
|
67
|
+
task :name do |t|
|
68
|
+
# actions
|
69
|
+
end
|
70
|
+
|
71
|
+
== File Tasks
|
72
|
+
|
73
|
+
Some tasks are designed to create a file from one or more other files.
|
74
|
+
Tasks that generate these files may be skipped if the file already
|
75
|
+
exists. File tasks are used to specify file creation tasks.
|
76
|
+
|
77
|
+
File tasks are declared using the +file+ method (instead of the +task+
|
78
|
+
method). In addition, file tasks are usually named with a string
|
79
|
+
rather than a symbol.
|
80
|
+
|
81
|
+
The following file task creates a executable program (named +prog+)
|
82
|
+
given two object files name <tt>a.o</tt> and <tt>b.o</tt>. The tasks
|
83
|
+
for creating <tt>a.o</tt> and <tt>b.o</tt> are not shown.
|
84
|
+
|
85
|
+
file "prog" => ["a.o", "b.o"] do |t|
|
86
|
+
sh "cc -o #{t.name} #{t.prerequisites.join(' ')}"
|
87
|
+
end
|
88
|
+
|
89
|
+
== Directory Tasks
|
90
|
+
|
91
|
+
It is common to need to create directories upon demand. The
|
92
|
+
+directory+ convenience method is a short-hand for creating a FileTask
|
93
|
+
that creates the directory. For example, the following declaration
|
94
|
+
...
|
95
|
+
|
96
|
+
directory "testdata/examples/doc"
|
97
|
+
|
98
|
+
is equivalent to ...
|
99
|
+
|
100
|
+
file "testdata" do |t| mkdir t.name end
|
101
|
+
file "testdata/examples" do |t| mkdir t.name end
|
102
|
+
file "testdata/examples/doc" do |t| mkdir t.name end
|
103
|
+
|
104
|
+
The +directory+ method does not accept prerequisites or actions, but
|
105
|
+
both prerequisites and actions can be added later. For example ...
|
106
|
+
|
107
|
+
directory "testdata"
|
108
|
+
file "testdata" => ["otherdata"]
|
109
|
+
file "testdata" do
|
110
|
+
cp Dir["standard_data/*.data"], "testdata"
|
111
|
+
end
|
112
|
+
|
113
|
+
== Tasks with Parallel Prerequisites
|
114
|
+
|
115
|
+
Rake allows parallel execution of prerequisites using the following syntax:
|
116
|
+
|
117
|
+
multitask :copy_files => [:copy_src, :copy_doc, :copy_bin] do
|
118
|
+
puts "All Copies Complete"
|
119
|
+
end
|
120
|
+
|
121
|
+
In this example, +copy_files+ is a normal rake task. Its actions are
|
122
|
+
executed whereever all of its prerequisites are done. The big
|
123
|
+
difference is that the prerequisites (+copy_src+, +copy_bin+ and
|
124
|
+
+copy_doc+) are executed in parallel. Each of the prerequisites are
|
125
|
+
run in their own Ruby thread, possibly allowing faster overall runtime.
|
126
|
+
|
127
|
+
=== Secondary Prerequisites
|
128
|
+
|
129
|
+
If any of the primary prerequites of a multitask have common secondary
|
130
|
+
prerequisites, all of the primary/parallel prerequisites will wait
|
131
|
+
until the common prerequisites have been run.
|
132
|
+
|
133
|
+
For example, if the <tt>copy_<em>xxx</em></tt> tasks have the
|
134
|
+
following prerequisites:
|
135
|
+
|
136
|
+
task :copy_src => [:prep_for_copy]
|
137
|
+
task :copy_bin => [:prep_for_copy]
|
138
|
+
task :copy_doc => [:prep_for_copy]
|
139
|
+
|
140
|
+
Then the +prep_for_copy+ task is run before starting all the copies in
|
141
|
+
parallel. Once +prep_for_copy+ is complete, +copy_src+, +copy_bin+,
|
142
|
+
and +copy_doc+ are all run in parallel. Note that +prep_for_copy+ is
|
143
|
+
run only once, even though it is referenced in multiple threads.
|
144
|
+
|
145
|
+
=== Thread Safety
|
146
|
+
|
147
|
+
The Rake internal data structures are thread-safe with respect
|
148
|
+
to the multitask parallel execution, so there is no need for the user
|
149
|
+
to do extra synchronization for Rake's benefit. However, if there are
|
150
|
+
user data structures shared between the parallel prerequisites, the
|
151
|
+
user must do whatever is necessary to prevent race conditions.
|
152
|
+
|
153
|
+
== Rules
|
154
|
+
|
155
|
+
When a file is named as a prerequisite, but does not have a file task
|
156
|
+
defined for it, Rake will attempt to synthesize a task by looking at a
|
157
|
+
list of rules supplied in the Rakefile.
|
158
|
+
|
159
|
+
Suppose we were trying to invoke task "mycode.o", but no task is
|
160
|
+
defined for it. But the rakefile has a rule that look like this ...
|
161
|
+
|
162
|
+
rule '.o' => ['.c'] do |t|
|
163
|
+
sh "cc #{t.source} -c -o #{t.name}"
|
164
|
+
end
|
165
|
+
|
166
|
+
This rule will synthesize any task that ends in ".o". It has a
|
167
|
+
prerequisite a source file with an extension of ".c" must exist. If
|
168
|
+
Rake is able to find a file named "mycode.c", it will automatically
|
169
|
+
create a task that builds "mycode.o" from "mycode.c".
|
170
|
+
|
171
|
+
If the file "mycode.c" does not exist, rake will attempt
|
172
|
+
to recursively synthesize a rule for it.
|
173
|
+
|
174
|
+
When a task is synthesized from a rule, the +source+ attribute of the
|
175
|
+
task is set to the matching source file. This allows us to write
|
176
|
+
rules with actions that reference the source file.
|
177
|
+
|
178
|
+
=== Advanced Rules
|
179
|
+
|
180
|
+
Any regular expression may be used as the rule pattern. Additionally,
|
181
|
+
a proc may be used to calculate the name of the source file. This
|
182
|
+
allows for complex patterns and sources.
|
183
|
+
|
184
|
+
The following rule is equivalent to the example above.
|
185
|
+
|
186
|
+
rule( /\.o$/ => [
|
187
|
+
proc {|task_name| task_name.sub(/\.[^.]+$/, '.c') }
|
188
|
+
]) do |t|
|
189
|
+
sh "cc #{t.source} -c -o #{t.name}"
|
190
|
+
end
|
191
|
+
|
192
|
+
<b>NOTE:</b> Because of a _quirk_ in Ruby syntax, parenthesis are
|
193
|
+
required on *rule* when the first argument is a regular expression.
|
194
|
+
|
195
|
+
The following rule might be used for Java files ...
|
196
|
+
|
197
|
+
rule '.java' => [
|
198
|
+
proc { |tn| tn.sub(/\.class$/, '.java').sub(/^classes\//, 'src/') }
|
199
|
+
] do |t|
|
200
|
+
java_compile(t.source, t.name)
|
201
|
+
end
|
202
|
+
|
203
|
+
<b>NOTE:</b> +java_compile+ is a hypothetical method that invokes the
|
204
|
+
java compiler.
|
205
|
+
|
206
|
+
== Importing Dependencies
|
207
|
+
|
208
|
+
Any ruby file (including other rakefiles) can be included with a
|
209
|
+
standard Ruby +require+ command. The rules and declarations in the
|
210
|
+
required file are just added to the definitions already accumulated.
|
211
|
+
|
212
|
+
Because the files are loaded _before_ the rake targets are evaluated,
|
213
|
+
the loaded files must be "ready to go" when the rake command is
|
214
|
+
invoked. This make generated dependency files difficult to use. By
|
215
|
+
the time rake gets around to updating the dependencies file, it is too
|
216
|
+
late to load it.
|
217
|
+
|
218
|
+
The +import+ command addresses this by specifying a file to be loaded
|
219
|
+
_after_ the main rakefile is loaded, but _before_ any targets on the
|
220
|
+
command line are specified. In addition, if the file name matches an
|
221
|
+
explicit task, that task is invoked before loading the file. This
|
222
|
+
allows dependency files to be generated and used in a single rake
|
223
|
+
command invocation.
|
224
|
+
|
225
|
+
=== Example:
|
226
|
+
|
227
|
+
require 'rake/loaders/makefile'
|
228
|
+
|
229
|
+
file ".depends.mf" => [SRC_LIST] do |t|
|
230
|
+
sh "makedepend -f- -- #{CFLAGS} -- #{t.prerequisites} > #{t.name}"
|
231
|
+
end
|
232
|
+
|
233
|
+
import ".depends.mf"
|
234
|
+
|
235
|
+
If ".depends" does not exist, or is out of date w.r.t. the source
|
236
|
+
files, a new ".depends" file is generated using +makedepend+ before
|
237
|
+
loading.
|
238
|
+
|
239
|
+
== Comments
|
240
|
+
|
241
|
+
Standard Ruby comments (beginning with "#") can be used anywhere it is
|
242
|
+
legal in Ruby source code, including comments for tasks and rules.
|
243
|
+
However, if you wish a task to be described using the "-T" switch,
|
244
|
+
then you need to use the +desc+ command to describe the task.
|
245
|
+
|
246
|
+
=== Example:
|
247
|
+
|
248
|
+
desc "Create a distribution package"
|
249
|
+
task :package => [ ... ] do ... end
|
250
|
+
|
251
|
+
The "-T" switch (or "--tasks" if you like to spell things out) will
|
252
|
+
display a list of tasks that have a defined comment. If you use
|
253
|
+
+desc+ to describe your major tasks, you have a semi-automatic way of
|
254
|
+
generating a summary of your Rake file.
|
255
|
+
|
256
|
+
traken$ rake -T
|
257
|
+
(in /home/.../rake)
|
258
|
+
rake clean # Remove any temporary products.
|
259
|
+
rake clobber # Remove any generated file.
|
260
|
+
rake clobber_rdoc # Remove rdoc products
|
261
|
+
rake contrib_test # Run tests for contrib_test
|
262
|
+
rake default # Default Task
|
263
|
+
rake install # Install the application
|
264
|
+
rake lines # Count lines in the main rake file
|
265
|
+
rake rdoc # Build the rdoc HTML Files
|
266
|
+
rake rerdoc # Force a rebuild of the RDOC files
|
267
|
+
rake test # Run tests
|
268
|
+
rake testall # Run all test targets
|
269
|
+
|
270
|
+
Only tasks with descriptions will be displayed with the "-T" switch.
|
271
|
+
Use "-P" (or "--prereqs") to get a list of all tasks and their
|
272
|
+
prerequisites.
|
273
|
+
|
274
|
+
== Namespaces
|
275
|
+
|
276
|
+
As projects grow (and along with it, the number of tasks), it is
|
277
|
+
common for task names to begin to clash. For example, if you might
|
278
|
+
have a main program and a set of sample programs built by a single
|
279
|
+
Rakefile. By placing the tasks related to the main program in one
|
280
|
+
namespace, and the tasks for building the sample programs in a
|
281
|
+
different namespace, the task names will not will not interfer with
|
282
|
+
each other.
|
283
|
+
|
284
|
+
For example:
|
285
|
+
|
286
|
+
namespace "main"
|
287
|
+
task :build do
|
288
|
+
# Build the main program
|
289
|
+
end
|
290
|
+
end
|
291
|
+
|
292
|
+
namespace "samples" do
|
293
|
+
task :build do
|
294
|
+
# Build the sample programs
|
295
|
+
end
|
296
|
+
end
|
297
|
+
|
298
|
+
task :build => ["main:build", "samples:build"]
|
299
|
+
|
300
|
+
Referencing a task in a separate namespace can be achieved by
|
301
|
+
prefixing the task name with the namespace and a colon
|
302
|
+
(e.g. "main:build" refers to the :build task in the +main+ namespace).
|
303
|
+
Nested namespaces are supported, so
|
304
|
+
|
305
|
+
Note that the name given in the +task+ command is always the unadorned
|
306
|
+
task name without any namespace prefixes. The +task+ command always
|
307
|
+
defines a task in the current namespace.
|
308
|
+
|
309
|
+
=== FileTasks
|
310
|
+
|
311
|
+
File task names are not scoped by the namespace command. Since the
|
312
|
+
name of a file task is the name of an actual file in the file system,
|
313
|
+
it makes little sense to include file task names in name space.
|
314
|
+
Directory tasks (created by the +directory+ command) are a type of
|
315
|
+
file task and are also not affected by namespaces.
|
316
|
+
|
317
|
+
=== Name Resolution
|
318
|
+
|
319
|
+
When looking up a task name, rake will start with the current
|
320
|
+
namespace and attempt to find the name there. If it fails to find a
|
321
|
+
name in the current namespace, it will search the parent namespaces
|
322
|
+
until a match is found (or an error occurs if there is no match).
|
323
|
+
|
324
|
+
The "rake" namespace is a special implicit namespace that refers to
|
325
|
+
the toplevel names.
|
326
|
+
|
327
|
+
If a task name begins with a "^" character, the name resolution will
|
328
|
+
start in the parent namespace. Multiple "^" characters are allowed.
|
329
|
+
|
330
|
+
Here is an example file with multiple :run tasks and how various names
|
331
|
+
resolve in different locations.
|
332
|
+
|
333
|
+
task :run
|
334
|
+
|
335
|
+
namespace "one" do
|
336
|
+
task :run
|
337
|
+
|
338
|
+
namespace "two" do
|
339
|
+
task :run
|
340
|
+
|
341
|
+
# :run => "one:two:run"
|
342
|
+
# "two:run" => "one:two:run"
|
343
|
+
# "one:two:run" => "one:two:run"
|
344
|
+
# "one:run" => "one:run"
|
345
|
+
# "^run" => "one:run"
|
346
|
+
# "^^run" => "rake:run" (the top level task)
|
347
|
+
# "rake:run" => "rake:run" (the top level task)
|
348
|
+
end
|
349
|
+
|
350
|
+
# :run => "one:run"
|
351
|
+
# "two:run" => "one:two:run"
|
352
|
+
# "^run" => "rake:run"
|
353
|
+
end
|
354
|
+
|
355
|
+
# :run => "rake:run"
|
356
|
+
# "one:run" => "one:run"
|
357
|
+
# "one:two:run" => "one:two:run"
|
358
|
+
|
359
|
+
== FileLists
|
360
|
+
|
361
|
+
FileLists are the way Rake manages lists of files. You can treat a
|
362
|
+
FileList as an array of strings for the most part, but FileLists
|
363
|
+
support some additional operations.
|
364
|
+
|
365
|
+
=== Creating a FileList
|
366
|
+
|
367
|
+
Creating a file list is easy. Just give it the list of file names:
|
368
|
+
|
369
|
+
fl = FileList['file1.rb', file2.rb']
|
370
|
+
|
371
|
+
Or give it a glob pattern:
|
372
|
+
|
373
|
+
fl = FileList['*.rb']
|
374
|
+
|
375
|
+
|
376
|
+
|
377
|
+
== Odds and Ends
|
378
|
+
|
379
|
+
=== do/end verses { }
|
380
|
+
|
381
|
+
Blocks may be specified with either a +do+/+end+ pair, or with curly
|
382
|
+
braces in Ruby. We _strongly_ recommend using +do+/+end+ to specify the
|
383
|
+
actions for tasks and rules. Because the rakefile idiom tends to
|
384
|
+
leave off parenthesis on the task/file/rule methods, unusual
|
385
|
+
ambiguities can arise when using curly braces.
|
386
|
+
|
387
|
+
For example, suppose that the method +object_files+ returns a list of
|
388
|
+
object files in a project. Now we use +object_files+ as the
|
389
|
+
prerequistes in a rule specified with actions in curly braces.
|
390
|
+
|
391
|
+
# DON'T DO THIS!
|
392
|
+
file "prog" => object_files {
|
393
|
+
# Actions are expected here (but it doesn't work)!
|
394
|
+
}
|
395
|
+
|
396
|
+
Because curly braces have a higher precedence than +do+/+end+, the
|
397
|
+
block is associated with the +object_files+ method rather than the
|
398
|
+
+file+ method.
|
399
|
+
|
400
|
+
This is the proper way to specify the task ...
|
401
|
+
|
402
|
+
# THIS IS FINE
|
403
|
+
file "prog" => object_files do
|
404
|
+
# Actions go here
|
405
|
+
end
|
406
|
+
|
407
|
+
----
|
408
|
+
|
409
|
+
== See
|
410
|
+
|
411
|
+
* README -- Main documentation for Rake.
|
data/doc/rational.rdoc
ADDED
@@ -0,0 +1,151 @@
|
|
1
|
+
= Why rake?
|
2
|
+
|
3
|
+
Ok, let me state from the beginning that I never intended to write this
|
4
|
+
code. I'm not convinced it is useful, and I'm not convinced anyone
|
5
|
+
would even be interested in it. All I can say is that Why's onion truck
|
6
|
+
must by been passing through the Ohio valley.
|
7
|
+
|
8
|
+
What am I talking about? ... A Ruby version of Make.
|
9
|
+
|
10
|
+
See, I can sense you cringing already, and I agree. The world certainly
|
11
|
+
doesn't need yet another reworking of the "make" program. I mean, we
|
12
|
+
already have "ant". Isn't that enough?
|
13
|
+
|
14
|
+
It started yesterday. I was helping a coworker fix a problem in one of
|
15
|
+
the Makefiles we use in our project. Not a particularly tough problem,
|
16
|
+
but during the course of the conversation I began lamenting some of the
|
17
|
+
shortcomings of make. In particular, in one of my makefiles I wanted to
|
18
|
+
determine the name of a file dynamically and had to resort to some
|
19
|
+
simple scripting (in Ruby) to make it work. "Wouldn't it be nice if you
|
20
|
+
could just use Ruby inside a Makefile" I said.
|
21
|
+
|
22
|
+
My coworker (a recent convert to Ruby) agreed, but wondered what it
|
23
|
+
would look like. So I sketched the following on the whiteboard...
|
24
|
+
|
25
|
+
"What if you could specify the make tasks in Ruby, like this ..."
|
26
|
+
|
27
|
+
task "build" do
|
28
|
+
java_compile(...args, etc ...)
|
29
|
+
end
|
30
|
+
|
31
|
+
"The task function would register "build" as a target to be made,
|
32
|
+
and the block would be the action executed whenever the build
|
33
|
+
system determined that it was time to do the build target."
|
34
|
+
|
35
|
+
We agreed that would be cool, but writing make from scratch would be WAY
|
36
|
+
too much work. And that was the end of that!
|
37
|
+
|
38
|
+
... Except I couldn't get the thought out of my head. What exactly
|
39
|
+
would be needed to make the about syntax work as a make file? Hmmm, you
|
40
|
+
would need to register the tasks, you need some way of specifying
|
41
|
+
dependencies between tasks, and some way of kicking off the process.
|
42
|
+
Hey! What if we did ... and fifteen minutes later I had a working
|
43
|
+
prototype of Ruby make, complete with dependencies and actions.
|
44
|
+
|
45
|
+
I showed the code to my coworker and we had a good laugh. It was just
|
46
|
+
about a page worth of code that reproduced an amazing amount of the
|
47
|
+
functionality of make. We were both truely stunned with the power of
|
48
|
+
Ruby.
|
49
|
+
|
50
|
+
But it didn't do everything make did. In particular, it didn't have
|
51
|
+
timestamp based file dependencies (where a file is rebuilt if any of its
|
52
|
+
prerequisite files have a later timestamp). Obviously THAT would be a
|
53
|
+
pain to add and so Ruby Make would remain an interesting experiment.
|
54
|
+
|
55
|
+
... Except as I walked back to my desk, I started thinking about what
|
56
|
+
file based dependecies would really need. Rats! I was hooked again,
|
57
|
+
and by adding a new class and two new methods, file/timestamp
|
58
|
+
dependencies were implemented.
|
59
|
+
|
60
|
+
Ok, now I was really hooked. Last night (during CSI!) I massaged the
|
61
|
+
code and cleaned it up a bit. The result is a bare-bones replacement
|
62
|
+
for make in exactly 100 lines of code.
|
63
|
+
|
64
|
+
For the curious, you can see it at ...
|
65
|
+
* doc/proto_rake.rdoc
|
66
|
+
|
67
|
+
Oh, about the name. When I wrote the example Ruby Make task on my
|
68
|
+
whiteboard, my coworker exclaimed "Oh! I have the perfect name: Rake ...
|
69
|
+
Get it? Ruby-Make. Rake!" He said he envisioned the tasks as leaves
|
70
|
+
and Rake would clean them up ... or something like that. Anyways, the
|
71
|
+
name stuck.
|
72
|
+
|
73
|
+
Some quick examples ...
|
74
|
+
|
75
|
+
A simple task to delete backup files ...
|
76
|
+
|
77
|
+
task :clean do
|
78
|
+
Dir['*~'].each {|fn| rm fn rescue nil}
|
79
|
+
end
|
80
|
+
|
81
|
+
Note that task names are symbols (they are slightly easier to type
|
82
|
+
than quoted strings ... but you may use quoted string if you would
|
83
|
+
rather). Rake makes the methods of the FileUtils module directly
|
84
|
+
available, so we take advantage of the <tt>rm</tt> command. Also note
|
85
|
+
the use of "rescue nil" to trap and ignore errors in the <tt>rm</tt>
|
86
|
+
command.
|
87
|
+
|
88
|
+
To run it, just type "rake clean". Rake will automatically find a
|
89
|
+
Rakefile in the current directory (or above!) and will invoke the
|
90
|
+
targets named on the command line. If there are no targets explicitly
|
91
|
+
named, rake will invoke the task "default".
|
92
|
+
|
93
|
+
Here's another task with dependencies ...
|
94
|
+
|
95
|
+
task :clobber => [:clean] do
|
96
|
+
rm_r "tempdir"
|
97
|
+
end
|
98
|
+
|
99
|
+
Task :clobber depends upon task :clean, so :clean will be run before
|
100
|
+
:clobber is executed.
|
101
|
+
|
102
|
+
Files are specified by using the "file" command. It is similar to the
|
103
|
+
task command, except that the task name represents a file, and the task
|
104
|
+
will be run only if the file doesn't exist, or if its modification time
|
105
|
+
is earlier than any of its prerequisites.
|
106
|
+
|
107
|
+
Here is a file based dependency that will compile "hello.cc" to
|
108
|
+
"hello.o".
|
109
|
+
|
110
|
+
file "hello.cc"
|
111
|
+
file "hello.o" => ["hello.cc"] do |t|
|
112
|
+
srcfile = t.name.sub(/\.o$/, ".cc")
|
113
|
+
sh %{g++ #{srcfile} -c -o #{t.name}}
|
114
|
+
end
|
115
|
+
|
116
|
+
I normally specify file tasks with string (rather than symbols). Some
|
117
|
+
file names can't be represented by symbols. Plus it makes the
|
118
|
+
distinction between them more clear to the casual reader.
|
119
|
+
|
120
|
+
Currently writing a task for each and every file in the project would be
|
121
|
+
tedious at best. I envision a set of libraries to make this job
|
122
|
+
easier. For instance, perhaps something like this ...
|
123
|
+
|
124
|
+
require 'rake/ctools'
|
125
|
+
Dir['*.c'].each do |fn|
|
126
|
+
c_source_file(fn)
|
127
|
+
end
|
128
|
+
|
129
|
+
where "c_source_file" will create all the tasks need to compile all the
|
130
|
+
C source files in a directory. Any number of useful libraries could be
|
131
|
+
created for rake.
|
132
|
+
|
133
|
+
That's it. There's no documentation (other than whats in this
|
134
|
+
message). Does this sound interesting to anyone? If so, I'll continue
|
135
|
+
to clean it up and write it up and publish it on RAA. Otherwise, I'll
|
136
|
+
leave it as an interesting excerise and a tribute to the power of Ruby.
|
137
|
+
|
138
|
+
Why /might/ rake be interesting to Ruby programmers. I don't know,
|
139
|
+
perhaps ...
|
140
|
+
|
141
|
+
* No weird make syntax (only weird Ruby syntax :-)
|
142
|
+
* No need to edit or read XML (a la ant)
|
143
|
+
* Platform independent build scripts.
|
144
|
+
* Will run anywhere Ruby exists, so no need to have "make" installed.
|
145
|
+
If you stay away from the "sys" command and use things like
|
146
|
+
'ftools', you can have a perfectly platform independent
|
147
|
+
build script. Also rake is only 100 lines of code, so it can
|
148
|
+
easily be packaged along with the rest of your code.
|
149
|
+
|
150
|
+
So ... Sorry for the long rambling message. Like I said, I never
|
151
|
+
intended to write this code at all.
|
@@ -0,0 +1,23 @@
|
|
1
|
+
= Rake 0.4.14 Released
|
2
|
+
|
3
|
+
== Changes
|
4
|
+
|
5
|
+
Version 0.4.14 is a compatibility fix to allow Rake's test task to
|
6
|
+
work under Ruby 1.8.2. A change in the Test::Unit autorun feature
|
7
|
+
prevented Rake from running any tests. This release fixes the
|
8
|
+
problem.
|
9
|
+
|
10
|
+
Rake 0.4.14 is the recommended release for anyone using Ruby 1.8.2.
|
11
|
+
|
12
|
+
== What is Rake
|
13
|
+
|
14
|
+
Rake is a build tool similar to the make program in many ways. But
|
15
|
+
instead of cryptic make recipes, Rake uses standard Ruby code to
|
16
|
+
declare tasks and dependencies. You have the full power of a modern
|
17
|
+
scripting language built right into your build tool.
|
18
|
+
|
19
|
+
== Availability
|
20
|
+
|
21
|
+
Home Page:: http://rake.rubyforge.org/
|
22
|
+
Download:: http://rubyforge.org/project/showfiles.php?group_id=50
|
23
|
+
|
@@ -0,0 +1,35 @@
|
|
1
|
+
= Rake 0.4.15 Released
|
2
|
+
|
3
|
+
== Changes
|
4
|
+
|
5
|
+
Version 0.4.15 is a bug fix update for the Ruby 1.8.2 compatibility
|
6
|
+
changes. This release includes:
|
7
|
+
|
8
|
+
* Fixed a bug that prevented the TESTOPTS flag from working with the
|
9
|
+
revised for 1.8.2 test task.
|
10
|
+
|
11
|
+
* Updated the docs on --trace to indicate that it also enables a full
|
12
|
+
backtrace on errors.
|
13
|
+
|
14
|
+
* Several fixes for new warnings generated.
|
15
|
+
|
16
|
+
== Mini-Roadmap
|
17
|
+
|
18
|
+
I will continue to issue Rake updates in the 0.4.xx series as new
|
19
|
+
Ruby-1.8.2 issues become manifest. Once the codebase stabilizes, I
|
20
|
+
will release a 0.5.0 version incorporating all the changes. If you
|
21
|
+
are not using Ruby-1.8.2 and wish to avoid version churn, I recommend
|
22
|
+
staying with a release prior to Rake-0.4.14.
|
23
|
+
|
24
|
+
== What is Rake
|
25
|
+
|
26
|
+
Rake is a build tool similar to the make program in many ways. But
|
27
|
+
instead of cryptic make recipes, Rake uses standard Ruby code to
|
28
|
+
declare tasks and dependencies. You have the full power of a modern
|
29
|
+
scripting language built right into your build tool.
|
30
|
+
|
31
|
+
== Availability
|
32
|
+
|
33
|
+
Home Page:: http://rake.rubyforge.org/
|
34
|
+
Download:: http://rubyforge.org/project/showfiles.php?group_id=50
|
35
|
+
|
@@ -0,0 +1,53 @@
|
|
1
|
+
= Rake 0.5.0 Released
|
2
|
+
|
3
|
+
It has been a long time in coming, but we finally have a new version
|
4
|
+
of Rake available.
|
5
|
+
|
6
|
+
== Changes
|
7
|
+
|
8
|
+
* Fixed bug where missing intermediate file dependencies could cause
|
9
|
+
an abort with --trace or --dry-run. (Brian Candler)
|
10
|
+
|
11
|
+
* Recursive rules are now supported (Tilman Sauerbeck).
|
12
|
+
|
13
|
+
* Added tar.gz and tar.bz2 support to package task (Tilman Sauerbeck).
|
14
|
+
|
15
|
+
* Added warning option for the Test Task (requested by Eric Hodel).
|
16
|
+
|
17
|
+
* The jamis rdoc template is only used if it exists.
|
18
|
+
|
19
|
+
* Added fix for Ruby 1.8.2 test/unit and rails problem.
|
20
|
+
|
21
|
+
* Added contributed rake man file. (Jani Monoses)
|
22
|
+
|
23
|
+
* Fixed documentation that was lacking the Rake module name (Tilman
|
24
|
+
Sauerbeck).
|
25
|
+
|
26
|
+
== What is Rake
|
27
|
+
|
28
|
+
Rake is a build tool similar to the make program in many ways. But
|
29
|
+
instead of cryptic make recipes, Rake uses standard Ruby code to
|
30
|
+
declare tasks and dependencies. You have the full power of a modern
|
31
|
+
scripting language built right into your build tool.
|
32
|
+
|
33
|
+
== Availability
|
34
|
+
|
35
|
+
The easiest way to get and install rake is via RubyGems ...
|
36
|
+
|
37
|
+
gem install rake (you may need root/admin privileges)
|
38
|
+
|
39
|
+
Otherwise, you can get it from the more traditional places:
|
40
|
+
|
41
|
+
Home Page:: http://rake.rubyforge.org/
|
42
|
+
Download:: http://rubyforge.org/project/showfiles.php?group_id=50
|
43
|
+
|
44
|
+
== Thanks
|
45
|
+
|
46
|
+
Lots of people provided input to this release. Thanks to Tilman
|
47
|
+
Sauerbeck for numerous patches, documentation fixes and suggestions.
|
48
|
+
And for also pushing me to get this release out. Also, thanks to
|
49
|
+
Brian Candler for the finding and fixing --trace/dry-run fix. That
|
50
|
+
was an obscure bug. Also to Eric Hodel for some good suggestions.
|
51
|
+
|
52
|
+
-- Jim Weirich
|
53
|
+
|