[Cook] Enumerating leaf directories

Reuben Thomas rrt at sc3d.org
Sun Mar 4 04:00:10 EST 2007


On Fri, 2 Mar 2007, Pendergraft, Jerry wrote:

> Normally within a cook file you have some kind of list of "project" files - a manifest as it were.

Right, this is the sort of philosophical correction I wanted. I was starting 
from the products, whereas with cook I should start, it seems, from the 
ingredients.

> project_files = [collect find . -type f -name [quote '*.html'] -print | sed -e [quote 's:^\./'::']];

This is a good start, but what about spaces in file names? Surely I should 
be using "-print0"? Also, the sed bit at the end is better done by find:

project_files = [collect find . -type f -name [quote '*.html'] -printf \"%P\\0\"'];

But this leaves me with a couple of problems:

1. This doesn't yet deal properly with spaces or other odd characters in 
filenames. I can't find anything in the Cook documentation about using 
NUL-terminated strings, so the best I can do for now is:

project_files = [collect_lines find . -type f -name [quote '*.html'] -printf \"%P\\n\"'];

i.e. get find to print newline-separated filenames, which works provided 
none of the names contains a newline. That's a fairly safe bet, I just don't 
like that it's not the standard NUL-based way of dealing with this problem.

2. I use subversion, so I have to prune the subversion directories from the 
find. I can do this by prefixing the find predicate with "-wholename .svn 
-prune -o", but then what if I switch to CVS? darcs? monotone? svk? 
mercurial? I see that for aegis there is an aegis-specific collection 
command, so I'm guessing I should write something similar for subversion and 
use that? I can't see anything about aelpf in the cook manual, so is this 
something put in a cookfile generated by aegis? I can't do quite the same 
thing with most version-control systems, as they don't also do configuration 
management as aegis seems to. Maybe a cook include file that simply sets a 
variable find_prefix that I can stick on the front of any find to avoid 
getting CVS metadata would be the right way to solve this?

One final thing: the whole point of my using cook was to use it to build 
HTML files from non-HTML files, so I should remove the "-name" predicate 
above, leaving:

project_files = [collect_lines find . -type f -printf \"%P\\n\"'];

(plus whatever fiddle I use to make it avoid subversion meta-data).

> So now the leaf directories you seek are given by:
> leaf_directories = [stringset [dirname [project_files]]];

I'm not convinced by this: it looks as though it'll simply give me a list of 
directories in the project (i.e. a list of every directory containing 
files), which is not the same as a list of leaf directories. I'm pretty sure 
I need a list of leaf directories, because they determine what I build 
(there's one web page in the output per leaf directory in the source).

Thanks for your patience, Jerry; as you can see, I'm in culture 
shock...anyway, it looks like once I've sorted out these two things (list of 
files, list of targets) I'll be good to try sorting out the dependencies.

-- 
http://rrt.sc3d.org/ | Brevity is the soul



More information about the Cook-users mailing list