SCons

Saturday 19 March 2005This is over 19 years old. Be careful.

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:

Program('hello.c')

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?

Comments

[gravatar]
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.
[gravatar]
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!
[gravatar]
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.

Thanks,

--SK

Add a comment:

Ignore this:
Leave this empty:
Name is required. Either email or web are required. Email won't be displayed and I won't spam you. Your web site won't be indexed by search engines.
Don't put anything here:
Leave this empty:
Comment text is Markdown.