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

Gary Oberbrunner garyo at oberbrunner.com
Thu Dec 4 09:09:25 EST 2014


Tool initialization is not ideal right now; you're right that sometimes
exists() isn't called, and sometimes its value is ignored.  We're working
on replacing the low-level guts of the Tool subsystem in ways that will
support exactly your use case, but in the meantime you might be better off
building your list of tools by querying directly in python, then passing
that tool list to your Environment constructors.

tools=['default']
if tool_x_exists():
  tools.append('tool_x')

env = Environment(tools=tools)


On Thu, Dec 4, 2014 at 8:29 AM, Brian Cody <brian.j.cody at gmail.com> wrote:

> 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
>
> _______________________________________________
> Scons-users mailing list
> Scons-users at scons.org
> https://pairlist4.pair.net/mailman/listinfo/scons-users
>
>


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


More information about the Scons-users mailing list