Saturday 19 March 2005

A Cog email correspondent asked a question about using Cog with SCons, so I read up on it. It's very interesting: A "make" replacement for building software, but uses full Python scripts instead of declarative Makefiles. But don't worry: most build tasks are handled in declarative style. For example, building hello.exe from hello.c is simply:


Another interesting feature is that SCons determines the need for building using an MD5 checksum of the file, so the need to build is determined more accurately. For example, a C file may change, but if the .o file it produces hasn't (because the C file only changed a comment), then there's no need to execute the link step.

BTW: the Cog question had to do with using Cog in an SCons environment, where the same file is both the input and output for Cog, and how to get SCons to do the right thing. Anyone know?


Michael Twomey 3:21 PM on 20 Mar 2005

Unfortunately modifying files in place goes against scons's design.

I usually deal with this by running commands in a non-inplace mode (piping from stdout to a file works fine in scons), or do a fudgey command like this:

env.Command("out.file", "in.file",
"cp $SOURCE $TARGET && cog $TARGET")

(unix only unfortunately)

This copies the file from the source to the dest then runs the command. I think there might be cleaner ways of dealing with this, but I haven't written new scons stuff in a while so I mightn't know about them.

Generally life is easier in scons if your commands support an alternative to inplace operations, I've had some entertaining episodes chaining multiple copies and inplace commands in a sconstruct.

Larry Hastings 5:15 PM on 20 Mar 2005

I'm the original email correspondent. And, while I see your point, running cog with -r is half the fun!

I think it's a bit short-sighted that SCons won't take into consideration files that get modified as part of the build process. I imagine it wouldn't be hard to extend SCons to support rescanning the file, which is all it'd take; perhaps it would be a worthy expendature of a Saturday afternoon someday.

Thanks for your suggestion!

Steven Knight 5:32 PM on 31 Mar 2005

Hi Larry (and Michael)--

I just foundthis thread. You should be able to modify files in-place with SCons by using the Precious() function to suppress the default behavior of removing targets before they're built. That's what it's intended for, anyway.

SCons already re-scans files after they're built, which is necessary to handle things like generated source files.

If I'm overlooking some more subtle functionality that you're looking for, let me know.



Add a comment:

Ignore this:
not displayed and no spam.
Leave this empty:
not searched.
Name and either email or www are required.
Don't put anything here:
Leave this empty:
URLs auto-link and some tags are allowed: <a><b><i><p><br><pre>.