[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

rake rules with multiple prerequisites

Joel VanderWerf

3/19/2006 10:48:00 PM


Is it possible to have a rule which has a prerequisite specified by a
proc and also a FileList? I can use several procs, as a workaround:

generic_files = [proc {"foo"}, proc {"bar"}, proc {"baz"}]
rule /^site_\w+/ => [
proc {|fn| site_cfg_file(fn)},
*generic_files
] do ... end


But it would be nice to use a FileList. However, when I try

generic_files = FileList["foo", "bar", "baz"]

rake says it doesn't know how to build the task.

Is there a better way of doing this?

--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407


9 Answers

Jim Weirich

3/20/2006 12:16:00 PM

0

Joel VanderWerf wrote:
> Is it possible to have a rule which has a prerequisite specified by a
> proc and also a FileList? I can use several procs, as a workaround:
>
> generic_files = [proc {"foo"}, proc {"bar"}, proc {"baz"}]
> rule /^site_\w+/ => [
> proc {|fn| site_cfg_file(fn)},
> *generic_files
> ] do ... end
>
>
> But it would be nice to use a FileList. However, when I try
>
> generic_files = FileList["foo", "bar", "baz"]
>
> rake says it doesn't know how to build the task.
>
> Is there a better way of doing this?

Actually that should work. If rake is reporting that it cannot build
your task, then probably one of the prerequisites cannot be built.
Remember, your rule says that you can build a site_XXX file if the
following file (or rules to build the following files) exist:
site_cfg_file(fn), "foo", "bar" and "baz". I would check to see if
"foo", "bar" and "baz" all exist.

--
-- Jim Weirich



--
Posted via http://www.ruby-....


Joel VanderWerf

3/20/2006 6:05:00 PM

0

Jim Weirich wrote:
> Joel VanderWerf wrote:
>> Is it possible to have a rule which has a prerequisite specified by a
>> proc and also a FileList? I can use several procs, as a workaround:
>>
>> generic_files = [proc {"foo"}, proc {"bar"}, proc {"baz"}]
>> rule /^site_\w+/ => [
>> proc {|fn| site_cfg_file(fn)},
>> *generic_files
>> ] do ... end
>>
>>
>> But it would be nice to use a FileList. However, when I try
>>
>> generic_files = FileList["foo", "bar", "baz"]
>>
>> rake says it doesn't know how to build the task.
>>
>> Is there a better way of doing this?
>
> Actually that should work. If rake is reporting that it cannot build
> your task, then probably one of the prerequisites cannot be built.
> Remember, your rule says that you can build a site_XXX file if the
> following file (or rules to build the following files) exist:
> site_cfg_file(fn), "foo", "bar" and "baz". I would check to see if
> "foo", "bar" and "baz" all exist.

Here's what happens in this example:

---------
generic_files = [proc {"foo"}, proc {"bar"}, proc {"baz"}]
#generic_files = FileList["foo", "bar", "baz"]

rule /^site_\w+/ => [
proc {|fn| "__#{fn}"},
*generic_files
] do |t|
p t.name
end

task :__site_stuff

file "foo" do touch "foo"; end
file "bar" do touch "bar"; end
file "baz" do touch "baz"; end
---------

As it is, it works:

$ rake site_stuff
(in /home/vjoel/ruby/misc/rake)
touch foo
touch bar
touch baz
"site_stuff"

But when I flip comments on the first two lines, I get:

$ rake site_stuff --trace
(in /home/vjoel/ruby/misc/rake)
rake aborted!
Don't know how to build task 'site_stuff'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.7.0/lib/rake.rb:1287:in `[]'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.7.0/lib/rake.rb:300:in `[]'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.7.0/lib/rake.rb:1719:in `run'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.7.0/lib/rake.rb:1719:in `run'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.7.0/bin/rake:7
/usr/local/bin/rake:18

Furthermore, if I comment out the proc:

# proc {|fn| "__#{fn}"},

(still using the FileList) then rake goes into a tailspin:

$ rake site_stuff --trace
(in /home/vjoel/ruby/misc/rake)
rake aborted!
Rule Recursion Too Deep: [site_stuff => site_stuff => site_stuff =>
site_stuff =.......


--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407


Jim Weirich

3/20/2006 6:46:00 PM

0

Joel VanderWerf wrote:
> Jim Weirich wrote:
>>>
>> Remember, your rule says that you can build a site_XXX file if the
>> following file (or rules to build the following files) exist:
>> site_cfg_file(fn), "foo", "bar" and "baz". I would check to see if
>> "foo", "bar" and "baz" all exist.
>
> Here's what happens in this example:

Oops. Sorry, I misread your example. I thought you were saying the
first example with the [proc{"foo"} ... ] wasn't working.

As I understand, what you would like is:

FileList["foo", ... ]

to work as well.

The problem is that a plain string in the *rule* dependency list already
has a meaning: it is the file extension to be used in the name of the
source file for the target.

> Furthermore, if I comment out the proc:
>
> # proc {|fn| "__#{fn}"},
>
> (still using the FileList) then rake goes into a tailspin:
>
> $ rake site_stuff --trace
> (in /home/vjoel/ruby/misc/rake)
> rake aborted!
> Rule Recursion Too Deep: [site_stuff => site_stuff => site_stuff =>
> site_stuff =.......

The reason for the tail spin is that plain strings in the depedency list
for rules specifies file extensions. Since "site_stuff" has no
extension, it comes out unchanged in the dependency list. So it looks
like "site_stuff" depends on "site_stuff", which is an circular
dependency.

You can do this:

generic_files = FileList["foo", "bar", "baz"].collect { |fn| lambda { fn
} }

--
-- Jim Weirich

--
Posted via http://www.ruby-....


Joel VanderWerf

3/20/2006 7:08:00 PM

0

Jim Weirich wrote:
> The problem is that a plain string in the *rule* dependency list already
> has a meaning: it is the file extension to be used in the name of the
> source file for the target.

That's what I was guessing. I'll stick with procs, as you suggest below:

> You can do this:
>
> generic_files = FileList["foo", "bar", "baz"].collect { |fn| lambda { fn
> } }

Thanks!

--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407


Joel VanderWerf

3/20/2006 7:14:00 PM

0

Joel VanderWerf wrote:
> Jim Weirich wrote:
>> The problem is that a plain string in the *rule* dependency list already
>> has a meaning: it is the file extension to be used in the name of the
>> source file for the target.
>
> That's what I was guessing. I'll stick with procs, as you suggest below:
>
>> You can do this:
>>
>> generic_files = FileList["foo", "bar", "baz"].collect { |fn| lambda { fn
>> } }
>
> Thanks!
>

On second thought... would it be possible for the proc to *return* a
FileList? It doesn't seem to work now, but it would be a nice feature,
wouldn't it?

$ cat rakefile
generic_files = proc {FileList["foo", "bar", "baz"]}

rule /^site_\w+/ => [
proc {|fn| "__#{fn}"},
generic_files
] do |t|
p t.name
end

task :__site_stuff

file "foo" do touch "foo"; end
file "bar" do touch "bar"; end
file "baz" do touch "baz"; end

$ rake site_stuff
(in /home/vjoel/ruby/misc/rake)
rake aborted!
can't convert Rake::FileList into String

(See full trace by running task with --trace)
$

--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407


Joel VanderWerf

3/21/2006 6:04:00 AM

0

Joel VanderWerf wrote:
> Joel VanderWerf wrote:
>> Jim Weirich wrote:
>>> The problem is that a plain string in the *rule* dependency list already
>>> has a meaning: it is the file extension to be used in the name of the
>>> source file for the target.
>> That's what I was guessing. I'll stick with procs, as you suggest below:
>>
>>> You can do this:
>>>
>>> generic_files = FileList["foo", "bar", "baz"].collect { |fn| lambda { fn
>>> } }
>> Thanks!
>>
>
> On second thought... would it be possible for the proc to *return* a
> FileList? It doesn't seem to work now, but it would be a nice feature,
> wouldn't it?
>
> $ cat rakefile
> generic_files = proc {FileList["foo", "bar", "baz"]}
>
> rule /^site_\w+/ => [
> proc {|fn| "__#{fn}"},
> generic_files
> ] do |t|
> p t.name
> end
>
> task :__site_stuff
>
> file "foo" do touch "foo"; end
> file "bar" do touch "bar"; end
> file "baz" do touch "baz"; end
>
> $ rake site_stuff
> (in /home/vjoel/ruby/misc/rake)
> rake aborted!
> can't convert Rake::FileList into String
>
> (See full trace by running task with --trace)
> $
>

I found a small patch to make this example work, but of course it could
break something else. It seems like a natural thing to do: just flatten
the result of Rake::TaskManager#make_sources. Normally, the result would
be an array of strings, but this patch allows the translation procs to
return an array of filenames (or a FileList), rather than just one.

--- rake.rb.bck 2006-03-20 22:00:12.000000000 -0800
+++ rake.rb 2006-03-20 22:00:12.000000000 -0800
@@ -1427,7 +1427,7 @@
else
fail "Don't know how to handle rule dependent: #{ext.inspect}"
end
- }
+ }.flatten
end

end




--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407


Jim Weirich

3/21/2006 6:53:00 AM

0

Joel VanderWerf wrote:
> I found a small patch to make this example work,

Patch commited, test case added. The CVS head now has the change. You
can pick it up there or with:

gem install rake -s http://onestepback.or...

The beta version is 0.7.0.1.

-- Jim Weirich

--
Posted via http://www.ruby-....


Joel VanderWerf

3/21/2006 8:09:00 AM

0

Jim Weirich wrote:
> Joel VanderWerf wrote:
>> I found a small patch to make this example work,
>
> Patch commited, test case added. The CVS head now has the change. You
> can pick it up there or with:
>
> gem install rake -s http://onestepback.or...
>
> The beta version is 0.7.0.1.
>
> -- Jim Weirich
>

Great! Just installed it and it works nicely. Thanks!

--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407


Mark Kleinhaut

3/17/2011 5:02:00 PM

0

On Mar 17, 12:01 pm, sheetsofsound <jackzuc...@gmail.com> wrote:
> On Mar 17, 11:25 am, Mark Kleinhaut <markkleinh...@hotmail.com> wrote:
>
> > On Mar 17, 6:53 am, sheetsofsound <jackzuc...@gmail.com> wrote:
>
> > > Selling a relic'd nash tele with a butterscotch finish, boat maple
> > > neck with 12" radius and 6105 frets, a '70s mini humbucker in the neck
> > > and a dimarzio virtual T bridge.
>
> > > I need $1300 shipped for it.
>
> > >http://www.jackzucker.com/forsale/nashtelefront.jpghttp://w.......
>
> > Is that the axe you played at Nighttown a coupl of months ago?
>
> >www.markkleinhaut.com
>
> yes

Really!!? I'm surprised you'd sell that. Besides having a great tone
for us in the audience, I recall you saying that night just how great
it felt to play that instrument, comfort and responsiveness. Some
lucky bastid will get one hell of a guitar. I'd grab it myself if I
was into solid bods.

www.markkleinhaut.com