1 import SCons.Environment
2 import SCons.Util, SCons.Script
4 # Fix for SCons 0.97 compatibility
6 try: SCons.SConf.SConfBase.Define
9 def Define(self, name, value = None, comment = None):
12 comment_str = "/* %s */" % comment
13 lines.append(comment_str)
15 define_str = "#define %s %s" % (name, value)
17 define_str = "#define %s" % name
18 lines.append(define_str)
20 self.config_h_text = self.config_h_text + string.join(lines, '\n')
21 SCons.SConf.SConfBase.Define = Define
23 class ConfTest(object):
24 """Configuration test decorator.
26 This class is used as a decorator to define SCons Configure
27 tests. There are three ways to use this facility:
30 DIRECT WITH EXTERNAL REGISTRY
32 In this scenario, you pass the test registry, a map, as argument to
33 the decorator. This usage is primarily interesting for tool writers:
35 from CustomTests import ConfTest
40 def CheckMyFoo(context):
44 env.Append(CUSTOM_TESTS = MY_TESTS)
46 This will place CheckMyFoo into the MY_TESTS dictionary which you can
47 later add to the CUSTOM_TESTS environment variable.
50 USING A REGISTRY ALIAS
52 In this scenario, you define a local alias for the decorator which
53 serves as the registry. This usage is again primarily interesting for
54 tool and extension writers:
58 MyConfTest = CustomTests.ConfTest()
61 def CheckMyFoo(context):
65 env.Append(CUSTOM_TESTS = MyConfTest.tests)
67 Logically this is like the previous method.
70 USING THE ENVIRONMENT MEMBER
72 This usage is interesting for SConstruct and SConscript writers:
75 env.Tool('CustomTests')
78 def CheckMyFoo(context):
81 conf = env.Configure()
85 The new configuration test is automatically added to
86 env['CUSTOM_TESTS'] and is thus automatically available to all
87 configuration contexts created from the environment.
90 def __init__(self, registry=None):
93 elif isinstance(registry, SCons.Environment.SubstitutionEnvironment):
94 self.tests =registry['CUSTOM_TESTS']
98 def __call__(self, func):
99 self.tests[func.__name__] = func
102 def Configure(self, *args, **kw):
103 try: kw['custom_tests'].update(self['CUSTOM_TESTS'])
104 except KeyError: kw['custom_tests'] = dict(self['CUSTOM_TESTS'])
105 return self._CustomTests_orig_Configure(*args, **kw)
107 def Fail(context, message, condition=True):
109 SCons.Util.display("scons: *** %s" % message)
112 DefaultTest = ConfTest()
114 # Hmm .. no default tests for now ...
117 env.Append( CUSTOM_TESTS = DefaultTest.tests )
118 env._CustomTests_orig_Configure = env.Configure
119 env.AddMethod(Configure)
120 env.AddMethod(ConfTest)