[Scons-users] Using the exists() function in a tool definition

Brian Cody brian.j.cody at gmail.com
Thu Dec 4 08:29:21 EST 2014


We have a build where a single top level SConstruct manages dependencies
between many sub-projects with varying target processors. A few of the
projects have additional tool requirements which most of our developers
don't have. There are licensing issues with providing the tools to
everyone, and while it would be convenient they aren't actually needed by
most of the developers. Our goal statement in this case would be that we
want 'scons' with no arguments to build as much as possible on a given
machine, and supply a note when something isn't build-able.

We've created a Tool that gets added to the environment(s) for building
these projects. We've implemented the exists() function to return true if
the tool is actually installed. In the case that the tool isn't installed,
we would like a brief message printed to let the user know that part of the
build is being skipped, and so their overall build will be incomplete,
however the other parts of the build will proceed (without the need for
-k). This works, but it was a little bit annoying to make it work. The
problem was figuring out how to actually invoke the exists() function.
Here's what we came up with:

def does_tool_exist(env, tool):
    return SCons.Tool.Tool(tool, [str(SCons.Script.Dir(path)) for path in
env['toolpath']]).exists(env)

The comprehension with str(Dir()) is required because the Tool constructor
does not perform any substitutions on the tool path passed in, while
env['toolpath'] still contains tokens such as '#/path'.

Is there any more SConsy way to get a handle to the tool or to query an
environment to determine if a tool exists?


Also, it struck me as odd is that without our check added, the return value
of exists() appears to not matter. If the tool really does exist and the
function is coded to always return False, the tool is still used. We dug
into the SCons source a bit and we saw where the tool exists() is used, but
it's apparently not within our use case (ToolInitializer.apply_tools).

Thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pairlist4.pair.net/pipermail/scons-users/attachments/20141204/fe921095/attachment.html>


More information about the Scons-users mailing list