# Rake: Looking for shortcut to file targets list from within

**URL:** <https://www.ruby-forum.com/t/rake-looking-for-shortcut-to-file-targets-list-from-within/68049>\
**Category:** Ruby\
**Created:** [September 8, 2006, 7:16pm UTC](https://www.ruby-forum.com/t/rake-looking-for-shortcut-to-file-targets-list-from-within/68049 "2006-09-08T19:16:41Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mikshir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/45deac/32.png) [@mikshir](https://www.ruby-forum.com/u/mikshir)\
**Post date:** [September 8, 2006, 7:16pm UTC](https://www.ruby-forum.com/t/rake-looking-for-shortcut-to-file-targets-list-from-within/68049/1 "2006-09-08T19:16:41Z")

</div>

I have several projects that are growing and I’m using rake to manage  
the builds. These are NOT C builds and I cannot use patterns or globs  
or suffixes to reliably collect all of the built files and  
intermediates. So right now, for every file target that I specify I  
have to manually add it to the CLOBBER list if I hope to completely  
clean out the build to pristine condition.

I’m looking for a shortcut to all file targets from within a rakefile.  
It has to be in there somewhere but looking through the rdoc, it  
doesn’t seem to be exposed.

I guess it’s akin to using the results of “rake -T” but from within the  
rakefile and keeping only targets of type “file”. That way I can  
simply do a “CLOBBER.include(ALL\_FILE\_TARGETS\_ARY\_OR\_METHOD)” at the  
end of the rakefile and be done with it and not have to remember to  
push every file target on the clobber list.

Secondary hope: Sometimes I don’t want to do a complete clean/clobber  
and I’d like to prune all file targets that are in the dependency  
“ancestor” tree of a specific target.

short example:

# rakefile

file f1 =\> [f\_source1]do … end  
file f2 =\> [f1,f\_source2] do … end  
file f3 =\> [f2] do … end  
file g1 do … end  
file g2 =\> [g1,g\_source1] do … end  
file g3 =\> [g2] do … end

CLOBBER.include(meth\_that\_returns\_file\_task\_ancestors(g3))

# will clobber g3, g2, g1 but not any of the f’s and not g\_source1

since it’s a dependency but not a file target

task :clean\_f\_also  
CLOBBER.include(meth\_that\_returns\_file\_task\_ancestors(f3))

# adds f3, f2, f1 only

end

# end rakefile

then from shell

#removes only g items

> rake clobber

# removes both f and g items

> rake clean\_f\_also clobber

I know this example hardly motivates the desire but for a large growing  
build where I can’t rely on globs or suffixes, such a shortcut would be  
a godsend.

SCons has some functionality like this but I wish to use Rake.
