[Scons-users] custom builder for use with wine

Patrick.Wambacq at esat.kuleuven.be Patrick.Wambacq at esat.kuleuven.be
Mon Aug 19 07:22:53 EDT 2013


Hi Dirk,

On 19 Aug 2013, at 09:10, Dirk Bächle wrote:


> Hi Patrick,

>

> On 18.08.2013 10:24, Patrick.Wambacq at esat.kuleuven.be wrote:

>> [...]

>>

>> As you can see, my own TryWine method is not a custom test itself but rather it is a method that I want to use in most of my custom tests in the code above, as a replacement for TryRun, such that wine is called to run the compiled executable. I fail to correctly declare and use this custom builder TryWIne.

>

> this is Python, where functions are first-class objects. So you should be able to say something like

>

> conf.TryWine = MyTryWine

>

> where you have defined MyTryWine as your own replacement for TryRun.

>

> Does this help?


This also does not work.
I made a minimal test SConstruct file, as follows:

---
def my_test(conf):
conf.Message("Checking hello world: ");
result=conf.TryWine(my_test.prog,".c")
#result=conf.TryRun(my_test.prog,".c")
if(not(result[0])):
return(False);
print result[1];
conf.Result("yes, it works!");
return(True);

my_test.prog = r"""
#include <stdio.h>
int main(void)
{
printf("Hello World\n");
return 0;
}
"""

def TryWine(self, text, extension):
ok = self.TryLink(text, extension);
if( ok ):
prog = self.lastTarget;
pname = prog.path;
#pname = "/path_to_wine/wine " + prog.path;
output = self.confdir.File(os.path.basename(pname)+'.out');
node = self.env.Command(output, prog, [ [ pname, ">", "${TARGET}"] ]);
ok = self.BuildNodes(node);
if ok:
outputStr = output.get_contents();
return( 1, outputStr);
return (0, "");

env = Environment();
conf = Configure(env, custom_tests = {'my_test' : my_test});
conf.TryWine = TryWine;
print conf.my_test();
env = conf.Finish();
---

This works when TryRun is used instead of TryWine (lines 2 and 3 in the code above). When my own TryWine (plain copy of the TryRun source with wine suppressed for now) is used, I get the following error:

scons: Reading SConscript files ...
AttributeError: CheckContext instance has no attribute 'TryWine':
File "/Users/patrickw/scons_test/SConstruct", line 37:
print conf.my_test();
File "../scons_base/lib/scons-2.2.0/SCons/SConf.py", line 640:
ret = self.test(context, *args, **kw)
File "/Users/patrickw/scons_test/SConstruct", line 3:
result=conf.TryWine(my_test.prog,".c")
File "../scons_base/lib/scons-2.2.0/SCons/SConf.py", line 819:
raise AttributeError("CheckContext instance has no attribute '%s'" % attr)
Checking hello world:

I don't even understand why TryRun works because when I check the attributes of conf with the python debugger, TryRun is not even there, while TryWine is, as you can see below:

(Pdb) p conf.__dict__
{'sconf': <SCons.SConf.SConfBase object at 0x1047b50>, 'havedict': {}, 'vardict': {}, 'config_h': '', 'headerfilename': None, 'did_show_result': 0}
(Pdb) p conf.sconf.__dict__
{'CheckCC': <SCons.SConf.TestWrapper object at 0x11101f0>, 'CheckCXXHeader': <SCons.SConf.TestWrapper object at 0x1110270>, 'config_h_text': '', 'logfile': <SCons.Node.FS.File object at 0x10690d0>, 'CheckLib': <SCons.SConf.TestWrapper object at 0x1110430>, 'lastEnvFs': <SCons.Node.FS.FS object at 0x1047630>, 'CheckType': <SCons.SConf.TestWrapper object at 0x1110450>, 'CheckSHCC': <SCons.SConf.TestWrapper object at 0x11104b0>, 'CheckSHCXX': <SCons.SConf.TestWrapper object at 0x1110470>, 'CheckDeclaration': <SCons.SConf.TestWrapper object at 0x11104d0>, 'env': <SCons.Script.SConscript.SConsEnvironment object at 0x1047a50>, 'CheckHeader': <SCons.SConf.TestWrapper object at 0x11104f0>, 'CheckCHeader': <SCons.SConf.TestWrapper object at 0x11103f0>, 'CheckFunc': <SCons.SConf.TestWrapper object at 0x1110310>, 'CheckTypeSize': <SCons.SConf.TestWrapper object at 0x1110390>, 'active': 1, 'CheckCXX': <SCons.SConf.TestWrapper object at 0x1110410>, 'logstream': <SCons.Util.Unbuffered object at 0x11105d0>, 'cached': 0, 'lastTarget': None, 'CheckLibWithHeader': <SCons.SConf.TestWrapper object at 0x1110490>, 'confdir': <SCons.Node.FS.Dir object at 0x1110330>, 'depth': 2, 'config_h': None, 'TryWine': <function TryWine at 0x10652f0>, 'my_test': <SCons.SConf.TestWrapper object at 0x1110510>}

When looking at the scons source code in SConf.py, I believe that what I need is a way to add the TryWine method to the SconfBase and/or CheckContext classes (or my instance thereof) but I don't know how to do that. I tried with SconfBase.TryWine = TryWine and variations thereof but that does not work because SconfBase is not defined and I don't know what I should import from scons (tried import SCons.almost_anything) to make it known.

Thanks

Patrick


More information about the Scons-users mailing list