[Scons-users] Using Command with TryBuild
    Dirk Bächle 
    tshortik at gmx.de
       
    Fri Feb 15 11:53:51 EST 2013
    
    
  
Carnë,
On 15.02.2013 08:37, Carnë Draug wrote:
> Hi
>
> I'm unable to use the Command builder with TryBuild. I get the following error:
>
> AttributeError: 'NodeList' object has no attribute 'builder':
>    <snip>
>    File "/usr/lib/scons/SCons/SConf.py", line 799:
>      return self.sconf.TryBuild(*args, **kw)
>    File "/usr/lib/scons/SCons/SConf.py", line 546:
>      pref = self.env.subst( builder.builder.prefix )
>
> I'm using this has to check for the availability of a perl module
>
> context.TryBuild (context.env.Command(target = [], source = [], action
> = "perl -M%s -e 1" % module))
please don't use TryBuild or TryAction for these kind of checks. They 
are highly specialised methods, usually working together with the 
Object() or Program() Builders. In your case it makes sense to do the 
check completely on your own. Please, find a first simple version 
attached, based on subprocess. I hope you can put it to good use...
Regards,
Dirk
-------------- next part --------------
import SCons.Builder
import subprocess
def PerlHasModule(context, module):
    res = True
    context.Message('Checking for Perl module %s... ' % module)
    process = subprocess.Popen(['perl','-M%s' % module,'-e','1'], shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    stdout, stderr = process.communicate()
    status = process.wait()
    
    if status:
        res = False
    context.Result(res)
    return res
env = Environment()
c = env.Configure(custom_tests = {'PerlHasModule' : PerlHasModule})
if c.PerlHasModule('balla'):
    print "Adding defines for Perl module."
else:
    print "Not adding anything for Perl module!"
    
    
More information about the Scons-users
mailing list