From 66a7ba729c149bf2e746b7f52f58f2361b817a01 Mon Sep 17 00:00:00 2001 From: stevenknight Date: Wed, 11 Jun 2003 01:28:19 +0000 Subject: [PATCH] SConf CheckFunc and CheckType functionality, plus fixes. (David Snopek) git-svn-id: http://scons.tigris.org/svn/scons/trunk@707 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- doc/man/scons.1 | 19 +++++++++++++ src/CHANGES.txt | 39 +++++++++++++++++++++++++ src/engine/SCons/SConf.py | 52 +++++++++++++++++++++++++++++++--- src/engine/SCons/SConfTests.py | 52 ++++++++++++++++++++++++++++++++++ 4 files changed, 158 insertions(+), 4 deletions(-) diff --git a/doc/man/scons.1 b/doc/man/scons.1 index e52903e9..eb7594b4 100644 --- a/doc/man/scons.1 +++ b/doc/man/scons.1 @@ -3202,6 +3202,13 @@ quote and the second character denotes the closing quote (both default to \N'34') Returns 1 on success and 0 on failure. +.TP +.RI Configure.CheckFunc( self ", " function_name ) +Checks if the specified +C or C+++ function is available. +.I function_name +is the name of the function to check for. + .TP .RI Configure.CheckLib( self ", [" library ", " symbol ", " autoadd ]) Checks if @@ -3249,6 +3256,18 @@ can be any valid expression (with a trailing ';'). The default is 'main();'. specifies whether to add the library to the environment (only if the check succeeds). This method returns 1 on success and 0 on error. +.TP +.RI Configure.CheckType( self ", " type_name ", [" includes ]) +Checks for the existence of a type defined by +.BR typedef . +.I type_name +specifies the typedef name to check for. +.I includes +is a string containing one or more +.B #include +lines that will be inserted into the program +that will be run to test for the existence of the type. + .EE Example of a typical Configure usage: diff --git a/src/CHANGES.txt b/src/CHANGES.txt index b86c2dea..0971f96b 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -10,6 +10,20 @@ RELEASE 0.15 - XXX + From Matt Balvin: + + - Fix handling of library prefixes when the subdirectory matches + the prefix. + + From Timothee Bessett: + + - Add an M4 Builder. + + From Charles Crain: + + - Use '.lnk' as the suffix on the temporary file for linking long + command lines (necessary for the Phar Lap linkloc linker). + From Steven Knight: - SCons now enforces (with an error) that construction variables @@ -21,10 +35,35 @@ RELEASE 0.15 - XXX - Eliminate a dependency on the distutils.fancy_getopt module by copying and pasting its wrap_text() function directly. + - Make the Script.Options() subclass match the underlying base class + implementation. + + From Steve Leblanc: + + - Don't update the .sconsign files when run with -n. + + From David Snopek + + - Fix use of SConf in paths with white space in them. + + - Add CheckFunc and CheckType functionality to SConf. + + - Fix use of SConf with Builders that return a list of nodes. + From David Snopek and Christoph Wiedemann - Fix use of the SConf subsystem with SConscriptChdir(). + From Greg Spencer + + - Check for the existence of MS Visual Studio on disk before using it, + to avoid getting fooled by leftover junk in the registry. + + - Add support for MSVC++ .NET. + + - Add support for MS Visual Studio project files (DSP, DSW, + SLN and VCPROJ files). + RELEASE 0.14 - Wed, 21 May 2003 05:16:32 -0500 diff --git a/src/engine/SCons/SConf.py b/src/engine/SCons/SConf.py index d01ce7ec..7336cdec 100644 --- a/src/engine/SCons/SConf.py +++ b/src/engine/SCons/SConf.py @@ -104,6 +104,8 @@ class SConf: # add default tests default_tests = { + 'CheckFunc' : CheckFunc, + 'CheckType' : CheckType, 'CheckCHeader' : CheckCHeader, 'CheckCXXHeader' : CheckCXXHeader, 'CheckLib' : CheckLib, @@ -224,15 +226,17 @@ class SConf: else: source = None - node = builder(target = target, source = source) - nodesToBeBuilt.append(node) + nodes = builder(target = target, source = source) + if not SCons.Util.is_List(nodes): + nodes = [nodes] + nodesToBeBuilt.extend(nodes) ret = self.BuildNodes(nodesToBeBuilt) del self.env['SCONF_TEXT'] _ac_build_counter = _ac_build_counter + 1 if ret: - self.lastTarget = node + self.lastTarget = nodes[0] else: self.lastTarget = None @@ -279,7 +283,7 @@ class SConf: if( ok ): prog = self.lastTarget output = SConfFS.File(prog.get_path()+'.out') - node = self.env.Command(output, prog, "%s > $TARGET" % (prog.get_path())) + node = self.env.Command(output, prog, [ [ prog.get_path(), ">", "${TARGET}"] ]) ok = self.BuildNodes([node]) if ok: outputStr = output.get_contents() @@ -531,6 +535,46 @@ def _header_prog( header, include_quotes ): header, include_quotes[1]) +def CheckFunc(context, function_name): + context.Message("Checking for %s... " % function_name) + + ret = context.TryBuild(context.env.Program, """ + #include + + #ifdef __cplusplus + extern "C" + #endif + char %(name)s(); + + int main() { + #if defined (__stub_%(name)s) || defined (__stub___%(name)s) + fail fail fail + #else + %(name)s(); + #endif + + return 0; + }\n\n""" % { 'name': function_name }, ".cpp") + context.Result(ret) + + return ret + +def CheckType(context, type_name, includes = ""): + context.Message("Checking for %s..." % type_name) + + ret = context.TryBuild(context.env.Program, """ + %(includes)s + + int main() { + if ((%(name)s *) 0) + return 0; + if (sizeof (%(name)s)) + return 0; + }\n\n""" % { 'name': type_name, 'includes': includes }, ".cpp") + context.Result(ret) + + return ret + def CheckCHeader(test, header, include_quotes='""'): """ A test for a c header file. diff --git a/src/engine/SCons/SConfTests.py b/src/engine/SCons/SConfTests.py index cd4a31f9..bf003b4d 100644 --- a/src/engine/SCons/SConfTests.py +++ b/src/engine/SCons/SConfTests.py @@ -146,6 +146,44 @@ class SConfTestCase(unittest.TestCase): finally: sconf.Finish() + def test_TryBuild(self): + """Test SConf.TryBuild + """ + # 1 test that we can try a builder that returns a list of nodes + self._resetSConfState() + sconf = self.SConf.SConf(self.scons_env, + conf_dir=self.test.workpath('config.tests'), + log_file=self.test.workpath('config.log')) + class MyBuilder: + def __init__(self): + self.prefix = '' + self.suffix = '' + def __call__(self, env, target, source): + class MyNode: + def __init__(self, name): + self.name = name + self.state = None + self.side_effects = [] + def has_builder(self): + return 1 + def add_pre_action(self, *actions): + pass + def add_post_action(self, *actions): + pass + def children(self): + return [] + def get_state(self): + return self.state + def set_state(self, state): + self.state = state + def alter_targets(self): + return [], None + def depends_on(self, nodes): + return None + return [MyNode('n1'), MyNode('n2')] + self.scons_env.Append(BUILDERS = {'SConfActionBuilder' : MyBuilder()}) + sconf.TryBuild(self.scons_env.SConfActionBuilder) + def test_TryCompile(self): """Test SConf.TryCompile """ @@ -277,6 +315,16 @@ int main() { sconf.env = env.Copy() return ((res1, libs1), (res2, libs2)) + def FuncChecks(sconf): + res1 = sconf.CheckFunc('strcpy') + res2 = sconf.CheckFunc('hopefullynofunction') + return (res1, res2) + + def TypeChecks(sconf): + res1 = sconf.CheckType('u_int', '#include \n') + res2 = sconf.CheckType('hopefullynotypedef_not') + return (res1, res2) + self._resetSConfState() sconf = self.SConf.SConf(self.scons_env, conf_dir=self.test.workpath('config.tests'), @@ -298,6 +346,10 @@ int main() { assert res1 and res2 assert len(libs1[1]) - 1 == len(libs1[0]) and libs1[1][-1] == existing_lib assert len(libs2[1]) == len(libs2[0]) + (res1, res2) = FuncChecks(sconf) + assert res1 and not res2 + (res1, res2) = TypeChecks(sconf) + assert res1 and not res2 finally: sconf.Finish() -- 2.26.2