[Scons-users] Getting the result of an action?
Brian Fitzgerald
bfitz at blizzard.com
Thu Sep 25 13:18:47 EDT 2014
The comment from Gary is how we do it in our build – we need to know the exact version of GCC, so we run this as part of the build setup:
def GccVersion(env, gcc_path):
# Get its version
output, error = subprocess.Popen(
args="%s --version" % gcc_path, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True).communicate()
if len(output) == 0:
raise Exception("No GCC at %s" % gcc_path)
env['BNET_GCC_VERSION_FULL'] = (output.splitlines())[0]
match = re.search('^\S+\s+\(GCC\)\s+(\S\S\S).+$', env['BNET_GCC_VERSION_FULL'])
if not match:
raise Exception("Could not parse GCC version from %s" % output)
env['BNET_GCC_VERSION'] = match.group(1)
Ignore all the parts custom to us. We have some parts of the build conditional on GCC version, so we need to be able to feed it to the rest of the system, not just the C++ compile. It’s a little gross, but it’s wrapped in a function so the rest of the code just sees something clean ☺
From: Scons-users [mailto:scons-users-bounces at scons.org] On Behalf Of Gary Oberbrunner
Sent: Thursday, September 25, 2014 9:24 AM
To: SCons users mailing list
Subject: Re: [Scons-users] Getting the result of an action?
On Thu, Sep 25, 2014 at 11:21 AM, Russell E. Owen <rowen at uw.edu<mailto:rowen at uw.edu>> wrote:
As part of configuring some environment variables in an SConstruct file
I want to run the command
$CC --version
and parse the output (or raise an exception if it fails). Is there
something like SCons.Script.Action(action) that I can use? That
particular command seems to only return the exit code, which isn't what
I need in this case.
Alternatively, is it safe to use the subprocess module for this?
Yes, and yes. :-) You can use a Configure context to do this, analogous to how GNU Autoconf would work. That's the fancy way. But for simple things it's often simpler just to use subprocess and parse the output. A SConstruct is just a python script.
--
Gary
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pairlist4.pair.net/pipermail/scons-users/attachments/20140925/63ad44e3/attachment-0001.html>
More information about the Scons-users
mailing list