[Scons-users] custom builder for use with wine

Patrick.Wambacq at esat.kuleuven.be Patrick.Wambacq at esat.kuleuven.be
Sun Aug 18 04:24:05 EDT 2013


Hi Dirk,

On 16 Aug 2013, at 18:39, Dirk Bächle wrote:


> On 16.08.2013 11:01, Patrick.Wambacq at esat.kuleuven.be wrote:

>> Dear all,

>>

>> I want to cross-compile unix code for windows using the mingw toolchains. In my setup, several small C programs are run by scons (using TryRun) to check compiler and system behaviour, and this requires running these Windows test executables on the host system. I use wine for this purpose on Linux, and this works well. On Linux the kernel can be made to recognize windows executables (using binfmt_misc) such that they can be run without having to specify "wine" on the command line.

>>

>> [...]

>> I get the following error:

>>

>> IndexError: list index out of range:

>> File "/Users/patrickw/my_project/SConstruct", line 331:

>> setattr(my_project,check,getattr(conf,check)());

>> File "../scons_base/lib/scons-2.2.0/SCons/SConf.py", line 640:

>> ret = self.test(context, *args, **kw)

>> File "/Users/patrickw/my_project/sysdep.py", line 55:

>> result = result[1].split();

>> File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/UserList.py", line 31:

>> def __getitem__(self, i): return self.data[i]

>>

>> [...]

>> Do you have some advice?

>

> can you please try to add your TryWine() method to the configure context instead of the environment? Note how you have the "env" as build environment, which has all the builders and stuff...and your configure context "conf" for this environment.

>

> Both support different sets of functions, and have different return values. While a builder in SCons usually returns the targets it creates (as Nodes), the configure methods return either a "0|1" (TryLink) or a tuple like (0, '') for TryRun.

>

> You should be able to get it running by using something along the lines of:

>

> conf = env.Configure(custom_tests={'TryWine' : TryWine})

> result = conf.TryWine(some_test_program,".c")

> if(not(result[0])):

> return(compiler_failure(conf))

> result = result[1].split()

>

> Please, also have a look at the MAN page of SCons. In the section "Configure Contexts" it contains a simple example for how to add your own configure checks.


It is not as simple as that. I already have attached a dictionary with custom checks to the configure context with
conf = env.Configure(custom_tests=custom_tests);
Each of these custom tests looks something like this:

def custom_test_1(conf):
result = conf.TryWine(custom_test_1.prog,".c");
if(not(result[0])):
return(compiler_failure(conf));
result = result[1].split();
... code to test the validity of the result, result in boolean variable named OK, test that fails in variable tst...
conf.Result("yes" if(OK) else "no (%s test failed)!!" %tst);
return(OK)

custom_test_1.prog = r"""
... C code for this test ...
""";

with
def compiler_failure(conf):
conf.Result("no working compiler found!!");
my_project.platform_error = True;
return(False);

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.

Thanks

Patrick


More information about the Scons-users mailing list