From 75754213c78031cecb668e1c93a382cb1366da55 Mon Sep 17 00:00:00 2001 From: Ruben Di Battista Date: Sun, 26 Jan 2025 19:30:02 +0100 Subject: :bug: Allow passing `extra_libs` to `CheckLibWithHeader` --- SCons/SConf.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/SCons/SConf.py b/SCons/SConf.py index c223556..7d3d484 100644 --- a/SCons/SConf.py +++ b/SCons/SConf.py @@ -1126,7 +1126,7 @@ def CheckLib(context, library = None, symbol: str = "main", # Bram: Can only include one header and can't use #ifdef HAVE_HEADER_H. def CheckLibWithHeader(context, libs, header, language, - call = None, autoadd: bool=True, append: bool=True, unique: bool=False) -> bool: + extra_libs = None, call = None, autoadd: bool=True, append: bool=True, unique: bool=False) -> bool: # ToDo: accept path for library. Support system header files. """ Another (more sophisticated) test for a library. @@ -1143,8 +1143,8 @@ def CheckLibWithHeader(context, libs, header, language, libs = [libs] res = SCons.Conftest.CheckLib(context, libs, None, prog_prefix, - call = call, language = language, autoadd=autoadd, - append=append, unique=unique) + extra_libs = extra_libs, call = call, language = language, + autoadd=autoadd, append=append, unique=unique) context.did_show_result = 1 return not res -- cgit v0.12 From dae3e49cd61da02e927a0ed4bda2f2c6cb5d27cf Mon Sep 17 00:00:00 2001 From: Ruben Di Battista Date: Mon, 27 Jan 2025 00:23:35 +0100 Subject: :white_check_mark: Add test --- test/Configure/CheckLibWithHeader_extra_libs.py | 94 +++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 test/Configure/CheckLibWithHeader_extra_libs.py diff --git a/test/Configure/CheckLibWithHeader_extra_libs.py b/test/Configure/CheckLibWithHeader_extra_libs.py new file mode 100644 index 0000000..9d5f300 --- /dev/null +++ b/test/Configure/CheckLibWithHeader_extra_libs.py @@ -0,0 +1,94 @@ +""" +Verify that a program which depends on library which in turns depend on another library +can be built correctly using CheckLibWithHeader +""" + +from pathlib import Path + +from TestSCons import TestSCons + +test = TestSCons(match=TestSCons.match_re_dotall) + + +libA_dir = Path(test.workdir) / "libA" +libA_dir.mkdir() +test.write( + str(libA_dir / "libA.h"), + """\ +void libA(); +""", +) +test.write( + str(libA_dir / "libA.c"), + """\ +#include +#include "libA.h" + +void libA() { + printf("libA\\n"); +} +""", +) +test.write( + str(libA_dir / "SConstruct"), + """\ +SharedLibrary('libA', source=['libA.c']) +""", +) +test.run(chdir=libA_dir) + + +libB_dir = Path(test.workdir) / "libB" +libB_dir.mkdir() +test.write( + str(libB_dir / "libB.h"), + """\ +void libB(); +""", +) +test.write( + str(libB_dir / "libB.c"), + """\ +#include +#include "libA.h" +#include "libB.h" + +void libB () { + libA(); +} +""", +) +test.write( + str(libB_dir / "SConstruct"), + """\ +SharedLibrary( + 'libB', + source=['libB.c'], + LIBS=['A'], + LIBPATH='../libA', + CPPPATH='../libA', +) +""", +) +test.run(chdir=libB_dir) + +test.write( + "SConstruct", + """\ +import os +env = Environment(ENV=os.environ, CPPPATH=['libB', 'libA'], LIBPATH=['libB', 'libA']) +conf = Configure(env) + +ret = conf.CheckLibWithHeader( + ['B'], + header="libB.h", + language='C', + extra_libs=['A'], + call='libB();', + autoadd=False, +) +assert ret +""", +) +test.run() +test.pass_test() -- cgit v0.12 From 5c1ee17e4341a7b702e241b0619d106919e63b17 Mon Sep 17 00:00:00 2001 From: Ruben Di Battista Date: Mon, 27 Jan 2025 00:29:24 +0100 Subject: :memo: Add change summary --- CHANGES.txt | 4 ++++ RELEASE.txt | 1 + doc/man/scons.xml | 1 + 3 files changed, 6 insertions(+) diff --git a/CHANGES.txt b/CHANGES.txt index 97f7be2..7903724 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -12,6 +12,10 @@ NOTE: Python 3.6 support is deprecated and will be dropped in a future release. RELEASE VERSION/DATE TO BE FILLED IN LATER + From Ruben Di Battista: + - Expose `extra_libs` kwarg in the `CheckLibWithHeader` and forward it downstream + to `CheckLib` + From Joseph Brill: - Added error handling when creating MSVC detection debug log file specified by SCONS_MSCOMMON_DEBUG. diff --git a/RELEASE.txt b/RELEASE.txt index 1b823b9..c4f9fe5 100644 --- a/RELEASE.txt +++ b/RELEASE.txt @@ -25,6 +25,7 @@ DEPRECATED FUNCTIONALITY CHANGED/ENHANCED EXISTING FUNCTIONALITY --------------------------------------- +- Expose the `extra_libs` keyword argument in `CheckLibWithHeader` - List modifications to existing features, where the previous behavior wouldn't actually be considered a bug diff --git a/doc/man/scons.xml b/doc/man/scons.xml index 979f67d..4119a45 100644 --- a/doc/man/scons.xml +++ b/doc/man/scons.xml @@ -4244,6 +4244,7 @@ to serve as the test can be supplied in if not supplied, the default checks the ability to link against the specified library. +extra_libs can be used to add additional libraries to link against. If autoadd is true (the default), the first library that passes the check is added to the &cv-link-LIBS; &consvar; in the context -- cgit v0.12 From 2bb3cd381c0df6d8a7170692c692f47efa648e08 Mon Sep 17 00:00:00 2001 From: Mats Wichmann Date: Fri, 7 Feb 2025 12:13:01 -0700 Subject: Also enable extra_libs for CheckLib Manpage entries and docstrings updated with version-added specifiers. Signed-off-by: Mats Wichmann --- CHANGES.txt | 6 +-- RELEASE.txt | 2 +- SCons/SConf.py | 29 ++++++++---- doc/man/scons.xml | 59 ++++++++++++++++++------- test/Configure/CheckLibWithHeader_extra_libs.py | 6 +-- 5 files changed, 70 insertions(+), 32 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 7903724..fb35ffb 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -12,9 +12,9 @@ NOTE: Python 3.6 support is deprecated and will be dropped in a future release. RELEASE VERSION/DATE TO BE FILLED IN LATER - From Ruben Di Battista: - - Expose `extra_libs` kwarg in the `CheckLibWithHeader` and forward it downstream - to `CheckLib` + From Ruben Di Battista: + - Expose `extra_libs` kwarg in Configure checks `CheckLibWithHeader` + and 'CheckLib' and forward it downstream to `CheckLib` From Joseph Brill: - Added error handling when creating MSVC detection debug log file specified by diff --git a/RELEASE.txt b/RELEASE.txt index c4f9fe5..38e4a1f 100644 --- a/RELEASE.txt +++ b/RELEASE.txt @@ -25,7 +25,7 @@ DEPRECATED FUNCTIONALITY CHANGED/ENHANCED EXISTING FUNCTIONALITY --------------------------------------- -- Expose the `extra_libs` keyword argument in `CheckLibWithHeader` +- Expose the `extra_libs` keyword argument in `CheckLibWithHeader` and 'CheckLib' - List modifications to existing features, where the previous behavior wouldn't actually be considered a bug diff --git a/SCons/SConf.py b/SCons/SConf.py index 7d3d484..36bb914 100644 --- a/SCons/SConf.py +++ b/SCons/SConf.py @@ -1101,12 +1101,17 @@ def CheckCXXHeader(context, header, include_quotes: str = '""'): def CheckLib(context, library = None, symbol: str = "main", - header = None, language = None, autoadd: bool=True, - append: bool=True, unique: bool=False) -> bool: + header = None, language = None, extra_libs = None, + autoadd: bool=True, append: bool=True, unique: bool=False) -> bool: """ - A test for a library. See also CheckLibWithHeader. + A test for a library. See also :func:`CheckLibWithHeader`. Note that library may also be None to test whether the given symbol compiles without flags. + + .. versionchanged:: NEXT_RELEASE + Added the *extra_libs* keyword parameter. The actual implementation + is in :func:`SCons.Conftest.CheckLib` which already accepted this + parameter, so this is only exposing existing functionality. """ if not library: @@ -1116,9 +1121,9 @@ def CheckLib(context, library = None, symbol: str = "main", library = [library] # ToDo: accept path for the library - res = SCons.Conftest.CheckLib(context, library, symbol, header = header, - language = language, autoadd = autoadd, - append=append, unique=unique) + res = SCons.Conftest.CheckLib(context, library, symbol, header=header, + language=language, extra_libs=extra_libs, + autoadd=autoadd, append=append, unique=unique) context.did_show_result = True return not res @@ -1126,15 +1131,21 @@ def CheckLib(context, library = None, symbol: str = "main", # Bram: Can only include one header and can't use #ifdef HAVE_HEADER_H. def CheckLibWithHeader(context, libs, header, language, - extra_libs = None, call = None, autoadd: bool=True, append: bool=True, unique: bool=False) -> bool: - # ToDo: accept path for library. Support system header files. + extra_libs = None, call = None, autoadd: bool=True, + append: bool=True, unique: bool=False) -> bool: """ Another (more sophisticated) test for a library. Checks, if library and header is available for language (may be 'C' or 'CXX'). Call maybe be a valid expression _with_ a trailing ';'. - As in CheckLib, we support library=None, to test if the call compiles + As in :func:`CheckLib`, we support library=None, to test if the call compiles without extra link flags. + + .. versionchanged:: NEXT_RELEASE + Added the *extra_libs* keyword parameter. The actual implementation + is in :func:`SCons.Conftest.CheckLib` which already accepted this + parameter, so this is only exposing existing functionality. """ + # ToDo: accept path for library. Support system header files. prog_prefix, dummy = createIncludesFromHeaders(header, 0) if not libs: libs = [None] diff --git a/doc/man/scons.xml b/doc/man/scons.xml index 4119a45..5a05466 100644 --- a/doc/man/scons.xml +++ b/doc/man/scons.xml @@ -4163,7 +4163,7 @@ function calls whose arguments are not type compatible with the prototype. - context.CheckLib([library, symbol, header, language, autoadd=True, append=True, unique=False]) + context.CheckLib([library, symbol, header, language, extra_libs=None, autoadd=True, append=True, unique=False]) Checks if library @@ -4173,12 +4173,19 @@ with the compiler selected by language, and optionally adds that library to the context. If supplied, the text of header is included at the top of the stub. + + +The remaining arguments should be specified in keyword style. +If extra_libs is specified, +it is a list off additional libraries to include when +linking the stub program (usually, dependencies of +the library being checked). If autoadd is true (the default), and the library provides the specified -symbol (as defined by successfully -linking the stub program), +symbol, +as defined by successfully linking the stub program, it is added to the &cv-link-LIBS; &consvar; in the context. -if append is true (the default), +If append is true (the default), the library is appended, otherwise it is prepended. If unique is true, and the library would otherwise be added but is @@ -4213,23 +4220,29 @@ at least one should be supplied. append and unique parameters. + +Changed in version NEXT_RELEASE: added the +extra_libs parameter. + - context.CheckLibWithHeader(library, header, [language, call, autoadd=True, append=True, unique=False]) + context.CheckLibWithHeader([library, header, language, extra_libs=None, call=None, autoadd=True, append=True, unique=False]) Provides an alternative to the CheckLib method -for checking for libraries usable in a build. +for checking whether libraries are usable in a build. +The first three arguments can be given as +positional or keyword style arguments. library -specifies a library or list of libraries to check. +specifies a library or list of libraries to check +(the default is None), header -specifies a header to include in the test program, -and language indicates the compiler to use. +specifies header text to include in the test program. header -may be a list, +may also be a list, in which case the last item in the list is the header file to be checked, and the previous list items are @@ -4237,14 +4250,22 @@ header files whose #include lines should precede the header line being checked for. -A code fragment -(must be a valid expression, including a trailing semicolon) -to serve as the test can be supplied in -call; -if not supplied, +The default is to include no header text. +language indicates the compiler to use +(default "C"). + + + +The remaining parameters should be specified in keyword style. +If provided, call +is a code fragment to compile as the stub test, +replacing the auto-generated stub. +The fragment must be a valid expression in language. +If not supplied, the default checks the ability to link against the specified library. -extra_libs can be used to add additional libraries to link against. +extra_libs can be used to add additional libraries +to link against (usually, dependencies of the library under test). If autoadd is true (the default), the first library that passes the check is added to the &cv-link-LIBS; &consvar; in the context @@ -4256,12 +4277,18 @@ and the library would otherwise be added but is already present in &cv-link-LIBS; in the configure context, it will not be added again. The default is False. + Returns a boolean indicating success or failure. + Changed in version 4.5.0: added the append and unique parameters. + +Changed in version NEXT_RELEASE: added the +extra_libs parameter. + diff --git a/test/Configure/CheckLibWithHeader_extra_libs.py b/test/Configure/CheckLibWithHeader_extra_libs.py index 9d5f300..0be8999 100644 --- a/test/Configure/CheckLibWithHeader_extra_libs.py +++ b/test/Configure/CheckLibWithHeader_extra_libs.py @@ -62,9 +62,9 @@ test.write( str(libB_dir / "SConstruct"), """\ SharedLibrary( - 'libB', - source=['libB.c'], - LIBS=['A'], + 'libB', + source=['libB.c'], + LIBS=['A'], LIBPATH='../libA', CPPPATH='../libA', ) -- cgit v0.12 From 07e63ae27ecdd710fef08b6e9344faa71ce4885d Mon Sep 17 00:00:00 2001 From: Mats Wichmann Date: Fri, 7 Feb 2025 17:12:39 -0700 Subject: Minor fixes to CheckLibWithHeader test Add boilderplate header/footer, fix one place where the wrong (non-portable) name for a library was used. Still does not build on Windows, due to mismatch between .dll/.lib construction. Signed-off-by: Mats Wichmann --- test/Configure/CheckLibWithHeader_extra_libs.py | 51 +++++++++++++++++++++---- 1 file changed, 43 insertions(+), 8 deletions(-) diff --git a/test/Configure/CheckLibWithHeader_extra_libs.py b/test/Configure/CheckLibWithHeader_extra_libs.py index 0be8999..0b7a560 100644 --- a/test/Configure/CheckLibWithHeader_extra_libs.py +++ b/test/Configure/CheckLibWithHeader_extra_libs.py @@ -1,6 +1,31 @@ +#!/usr/bin/env python +# +# MIT License +# +# Copyright The SCons Foundation +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE + """ -Verify that a program which depends on library which in turns depend on another library -can be built correctly using CheckLibWithHeader +Verify that a program which depends on library which in turn depends +on another library can be built correctly using CheckLibWithHeader """ from pathlib import Path @@ -9,7 +34,7 @@ from TestSCons import TestSCons test = TestSCons(match=TestSCons.match_re_dotall) - +# This is the first library project libA_dir = Path(test.workdir) / "libA" libA_dir.mkdir() test.write( @@ -32,12 +57,13 @@ void libA() { test.write( str(libA_dir / "SConstruct"), """\ -SharedLibrary('libA', source=['libA.c']) +DefaultEnvironment(tools=[]) +SharedLibrary('A', source=['libA.c']) """, ) -test.run(chdir=libA_dir) - +test.run(arguments='-C libA') +# This is the second library project, depending on the first libB_dir = Path(test.workdir) / "libB" libB_dir.mkdir() test.write( @@ -61,8 +87,9 @@ void libB () { test.write( str(libB_dir / "SConstruct"), """\ +DefaultEnvironment(tools=[]) SharedLibrary( - 'libB', + 'B', source=['libB.c'], LIBS=['A'], LIBPATH='../libA', @@ -70,12 +97,14 @@ SharedLibrary( ) """, ) -test.run(chdir=libB_dir) +test.run(arguments='-C libB') +# With the two projects built, we can now run the Configure check test.write( "SConstruct", """\ import os + env = Environment(ENV=os.environ, CPPPATH=['libB', 'libA'], LIBPATH=['libB', 'libA']) conf = Configure(env) @@ -92,3 +121,9 @@ assert ret ) test.run() test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: -- cgit v0.12 From b1d71e674eb2feb2c0520390ed65c73cfda35bfb Mon Sep 17 00:00:00 2001 From: Mats Wichmann Date: Sat, 8 Feb 2025 07:04:54 -0700 Subject: Fix CheckLibWithHeader test - undo mistake "Muscle memory" had me add calls to skip tools for DefaultEnvironment, but the two library builds use it, so that was just plain wrong. Restored prior state. Signed-off-by: Mats Wichmann --- test/Configure/CheckLibWithHeader_extra_libs.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/Configure/CheckLibWithHeader_extra_libs.py b/test/Configure/CheckLibWithHeader_extra_libs.py index 0b7a560..7b5c05d 100644 --- a/test/Configure/CheckLibWithHeader_extra_libs.py +++ b/test/Configure/CheckLibWithHeader_extra_libs.py @@ -57,7 +57,6 @@ void libA() { test.write( str(libA_dir / "SConstruct"), """\ -DefaultEnvironment(tools=[]) SharedLibrary('A', source=['libA.c']) """, ) @@ -87,7 +86,6 @@ void libB () { test.write( str(libB_dir / "SConstruct"), """\ -DefaultEnvironment(tools=[]) SharedLibrary( 'B', source=['libB.c'], -- cgit v0.12 From 5f8a725efa44296654a24676618549ec3633a88b Mon Sep 17 00:00:00 2001 From: Mats Wichmann Date: Sun, 9 Feb 2025 11:25:45 -0700 Subject: Windows-ify the new CheckLibWithHeader test Signed-off-by: Mats Wichmann --- test/Configure/CheckLibWithHeader_extra_libs.py | 82 ++++++++++++++++++++----- 1 file changed, 67 insertions(+), 15 deletions(-) diff --git a/test/Configure/CheckLibWithHeader_extra_libs.py b/test/Configure/CheckLibWithHeader_extra_libs.py index 7b5c05d..e98b894 100644 --- a/test/Configure/CheckLibWithHeader_extra_libs.py +++ b/test/Configure/CheckLibWithHeader_extra_libs.py @@ -30,17 +30,36 @@ on another library can be built correctly using CheckLibWithHeader from pathlib import Path -from TestSCons import TestSCons +from TestSCons import TestSCons, dll_, _dll test = TestSCons(match=TestSCons.match_re_dotall) # This is the first library project libA_dir = Path(test.workdir) / "libA" libA_dir.mkdir() +libA = str(libA_dir / (dll_ + 'A' + _dll)) # for existence check + test.write( str(libA_dir / "libA.h"), """\ -void libA(); +#ifndef _LIBA_H +#define _LIBA_H + +// define BUILDINGSHAREDLIB when building libA as shared lib +#ifdef _MSC_VER +# ifdef BUILDINGSHAREDLIB +# define LIBA_DECL __declspec(dllexport) +# else +# define LIBA_DECL __declspec(dllimport) +# endif +#endif // WIN32 + +#ifndef LIBA_DECL +# define LIBA_DECL +#endif + +LIBA_DECL void libA(void); +#endif // _LIBA_H """, ) test.write( @@ -49,7 +68,7 @@ test.write( #include #include "libA.h" -void libA() { +LIBA_DECL void libA(void) { printf("libA\\n"); } """, @@ -57,18 +76,35 @@ void libA() { test.write( str(libA_dir / "SConstruct"), """\ -SharedLibrary('A', source=['libA.c']) +SharedLibrary(target='A', source=['libA.c'], CPPDEFINES='BUILDINGSHAREDLIB') """, ) -test.run(arguments='-C libA') # This is the second library project, depending on the first libB_dir = Path(test.workdir) / "libB" libB_dir.mkdir() +libB = str(libB_dir / (dll_ + 'B' + _dll)) # for existence check test.write( str(libB_dir / "libB.h"), """\ -void libB(); +#ifndef _LIBB_H +#define _LIBB_H + +// define BUILDINGSHAREDLIB when building libB as shared lib +#ifdef _MSC_VER +# ifdef BUILDINGSHAREDLIB +# define LIBB_DECL __declspec(dllexport) +# else +# define LIBB_DECL __declspec(dllimport) +# endif +#endif // WIN32 + +#ifndef LIBB_DECL +# define LIBB_DECL +#endif + +LIBB_DECL void libB(void); +#endif // _LIBB_H """, ) test.write( @@ -78,7 +114,8 @@ test.write( #include "libA.h" #include "libB.h" -void libB () { +LIBB_DECL void libB (void) { + printf("libB\\n"); libA(); } """, @@ -87,34 +124,49 @@ test.write( str(libB_dir / "SConstruct"), """\ SharedLibrary( - 'B', + target='B', source=['libB.c'], LIBS=['A'], LIBPATH='../libA', CPPPATH='../libA', + CPPDEFINES='BUILDINGSHAREDLIB', ) """, ) + +test.run(arguments='-C libA') +test.must_exist(libA) test.run(arguments='-C libB') +test.must_exist(libB) # With the two projects built, we can now run the Configure check test.write( "SConstruct", """\ -import os +env = Environment( + CPPPATH=['#'], + LIBPATH=['libB', 'libA'], + LIBS=['A', 'B'], + RPATH=['libA', 'libB'], +) -env = Environment(ENV=os.environ, CPPPATH=['libB', 'libA'], LIBPATH=['libB', 'libA']) conf = Configure(env) - -ret = conf.CheckLibWithHeader( +if not conf.CheckLibWithHeader( ['B'], - header="libB.h", + header="libB/libB.h", language='C', extra_libs=['A'], call='libB();', autoadd=False, -) -assert ret +): + print("Cannot build against 'B' library, exiting.") + Exit(1) +env = conf.Finish() + +# TODO: we should be able to build and run a test program now, +# to make sure Configure() didn't lie to us about usability. +# Disabled for now, because that's trickier in Windows (no rpath) +# env.Program(target="testlibs", source="src/test.c") """, ) test.run() -- cgit v0.12 From 9bcbf7b45fc8ebd7e791e1ae58fe4444f3240d96 Mon Sep 17 00:00:00 2001 From: Mats Wichmann Date: Thu, 13 Feb 2025 12:57:14 -0700 Subject: Per request, "fixture-ize" CheckLibWithHeader_extra_libs test Signed-off-by: Mats Wichmann --- test/Configure/CheckLibWithHeader_extra_libs.py | 125 +-------------------- test/Configure/fixture/checklib_extra/SConstruct | 30 +++++ .../Configure/fixture/checklib_extra/conftest.skip | 0 .../fixture/checklib_extra/libA/SConstruct | 6 + test/Configure/fixture/checklib_extra/libA/libA.c | 10 ++ test/Configure/fixture/checklib_extra/libA/libA.h | 22 ++++ .../fixture/checklib_extra/libB/SConstruct | 12 ++ test/Configure/fixture/checklib_extra/libB/libB.c | 12 ++ test/Configure/fixture/checklib_extra/libB/libB.h | 22 ++++ test/Configure/fixture/checklib_extra/src/test.c | 6 + 10 files changed, 125 insertions(+), 120 deletions(-) create mode 100644 test/Configure/fixture/checklib_extra/SConstruct create mode 100644 test/Configure/fixture/checklib_extra/conftest.skip create mode 100644 test/Configure/fixture/checklib_extra/libA/SConstruct create mode 100644 test/Configure/fixture/checklib_extra/libA/libA.c create mode 100644 test/Configure/fixture/checklib_extra/libA/libA.h create mode 100644 test/Configure/fixture/checklib_extra/libB/SConstruct create mode 100644 test/Configure/fixture/checklib_extra/libB/libB.c create mode 100644 test/Configure/fixture/checklib_extra/libB/libB.h create mode 100644 test/Configure/fixture/checklib_extra/src/test.c diff --git a/test/Configure/CheckLibWithHeader_extra_libs.py b/test/Configure/CheckLibWithHeader_extra_libs.py index e98b894..eef5c0e 100644 --- a/test/Configure/CheckLibWithHeader_extra_libs.py +++ b/test/Configure/CheckLibWithHeader_extra_libs.py @@ -38,138 +38,23 @@ test = TestSCons(match=TestSCons.match_re_dotall) libA_dir = Path(test.workdir) / "libA" libA_dir.mkdir() libA = str(libA_dir / (dll_ + 'A' + _dll)) # for existence check - -test.write( - str(libA_dir / "libA.h"), - """\ -#ifndef _LIBA_H -#define _LIBA_H - -// define BUILDINGSHAREDLIB when building libA as shared lib -#ifdef _MSC_VER -# ifdef BUILDINGSHAREDLIB -# define LIBA_DECL __declspec(dllexport) -# else -# define LIBA_DECL __declspec(dllimport) -# endif -#endif // WIN32 - -#ifndef LIBA_DECL -# define LIBA_DECL -#endif - -LIBA_DECL void libA(void); -#endif // _LIBA_H -""", -) -test.write( - str(libA_dir / "libA.c"), - """\ -#include -#include "libA.h" - -LIBA_DECL void libA(void) { - printf("libA\\n"); -} -""", -) -test.write( - str(libA_dir / "SConstruct"), - """\ -SharedLibrary(target='A', source=['libA.c'], CPPDEFINES='BUILDINGSHAREDLIB') -""", -) +test.dir_fixture(['fixture', 'checklib_extra', 'libA'], 'libA') # This is the second library project, depending on the first libB_dir = Path(test.workdir) / "libB" libB_dir.mkdir() libB = str(libB_dir / (dll_ + 'B' + _dll)) # for existence check -test.write( - str(libB_dir / "libB.h"), - """\ -#ifndef _LIBB_H -#define _LIBB_H - -// define BUILDINGSHAREDLIB when building libB as shared lib -#ifdef _MSC_VER -# ifdef BUILDINGSHAREDLIB -# define LIBB_DECL __declspec(dllexport) -# else -# define LIBB_DECL __declspec(dllimport) -# endif -#endif // WIN32 - -#ifndef LIBB_DECL -# define LIBB_DECL -#endif - -LIBB_DECL void libB(void); -#endif // _LIBB_H -""", -) -test.write( - str(libB_dir / "libB.c"), - """\ -#include -#include "libA.h" -#include "libB.h" - -LIBB_DECL void libB (void) { - printf("libB\\n"); - libA(); -} -""", -) -test.write( - str(libB_dir / "SConstruct"), - """\ -SharedLibrary( - target='B', - source=['libB.c'], - LIBS=['A'], - LIBPATH='../libA', - CPPPATH='../libA', - CPPDEFINES='BUILDINGSHAREDLIB', -) -""", -) +test.dir_fixture(['fixture', 'checklib_extra', 'libB'], 'libB') test.run(arguments='-C libA') test.must_exist(libA) test.run(arguments='-C libB') test.must_exist(libB) -# With the two projects built, we can now run the Configure check -test.write( - "SConstruct", - """\ -env = Environment( - CPPPATH=['#'], - LIBPATH=['libB', 'libA'], - LIBS=['A', 'B'], - RPATH=['libA', 'libB'], -) - -conf = Configure(env) -if not conf.CheckLibWithHeader( - ['B'], - header="libB/libB.h", - language='C', - extra_libs=['A'], - call='libB();', - autoadd=False, -): - print("Cannot build against 'B' library, exiting.") - Exit(1) -env = conf.Finish() - -# TODO: we should be able to build and run a test program now, -# to make sure Configure() didn't lie to us about usability. -# Disabled for now, because that's trickier in Windows (no rpath) -# env.Program(target="testlibs", source="src/test.c") -""", -) +test.file_fixture(['fixture', 'checklib_extra', 'SConstruct']) +test.dir_fixture(['fixture', 'checklib_extra', 'src'], 'src') test.run() + test.pass_test() # Local Variables: diff --git a/test/Configure/fixture/checklib_extra/SConstruct b/test/Configure/fixture/checklib_extra/SConstruct new file mode 100644 index 0000000..177dc16 --- /dev/null +++ b/test/Configure/fixture/checklib_extra/SConstruct @@ -0,0 +1,30 @@ +# SPDX-License-Identifier: MIT +# +# Copyright The SCons Foundation + +env = Environment( + CPPPATH=['#'], + LIBPATH=['libB', 'libA'], + LIBS=['A', 'B'], + RPATH=['libA', 'libB'], +) + +conf = Configure(env) +if not conf.CheckLibWithHeader( + ['B'], + header="libB/libB.h", + language='C', + extra_libs=['A'], + call='libB();', + autoadd=False, +): + print("Cannot build against 'B' library, exiting.") + Exit(1) +env = conf.Finish() + +# TODO: we should be able to build and run a test program now, +# to make sure Configure() didn't lie to us about usability. +# Disabled for now, because that's trickier in Windows (the rpath +# only works for Linux) +# env.Program(target="testlibs", source="src/test.c") + diff --git a/test/Configure/fixture/checklib_extra/conftest.skip b/test/Configure/fixture/checklib_extra/conftest.skip new file mode 100644 index 0000000..e69de29 diff --git a/test/Configure/fixture/checklib_extra/libA/SConstruct b/test/Configure/fixture/checklib_extra/libA/SConstruct new file mode 100644 index 0000000..e75e1e1 --- /dev/null +++ b/test/Configure/fixture/checklib_extra/libA/SConstruct @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: MIT +# +# Copyright The SCons Foundation + +SharedLibrary(target='A', source=['libA.c'], CPPDEFINES='BUILDINGSHAREDLIB') + diff --git a/test/Configure/fixture/checklib_extra/libA/libA.c b/test/Configure/fixture/checklib_extra/libA/libA.c new file mode 100644 index 0000000..01f727c --- /dev/null +++ b/test/Configure/fixture/checklib_extra/libA/libA.c @@ -0,0 +1,10 @@ +// SPDX-License-Identifier: MIT +// +// Copyright The SCons Foundation + +#include +#include "libA.h" + +LIBA_DECL void libA(void) { + printf("libA\\n"); +} diff --git a/test/Configure/fixture/checklib_extra/libA/libA.h b/test/Configure/fixture/checklib_extra/libA/libA.h new file mode 100644 index 0000000..9c531a3 --- /dev/null +++ b/test/Configure/fixture/checklib_extra/libA/libA.h @@ -0,0 +1,22 @@ +// SPDX-License-Identifier: MIT +// +// Copyright The SCons Foundation + +#ifndef _LIBA_H +#define _LIBA_H + +// define BUILDINGSHAREDLIB when building libA as shared lib +#ifdef _MSC_VER +# ifdef BUILDINGSHAREDLIB +# define LIBA_DECL __declspec(dllexport) +# else +# define LIBA_DECL __declspec(dllimport) +# endif +#endif // WIN32 + +#ifndef LIBA_DECL +# define LIBA_DECL +#endif + +LIBA_DECL void libA(void); +#endif // _LIBA_H diff --git a/test/Configure/fixture/checklib_extra/libB/SConstruct b/test/Configure/fixture/checklib_extra/libB/SConstruct new file mode 100644 index 0000000..4e9cfe0 --- /dev/null +++ b/test/Configure/fixture/checklib_extra/libB/SConstruct @@ -0,0 +1,12 @@ +# SPDX-License-Identifier: MIT +# +# Copyright The SCons Foundation + +SharedLibrary( + target='B', + source=['libB.c'], + LIBS=['A'], + LIBPATH='../libA', + CPPPATH='../libA', + CPPDEFINES='BUILDINGSHAREDLIB', +) diff --git a/test/Configure/fixture/checklib_extra/libB/libB.c b/test/Configure/fixture/checklib_extra/libB/libB.c new file mode 100644 index 0000000..c861b14 --- /dev/null +++ b/test/Configure/fixture/checklib_extra/libB/libB.c @@ -0,0 +1,12 @@ +// SPDX-License-Identifier: MIT +// +// Copyright The SCons Foundation + +#include +#include "libA.h" +#include "libB.h" + +LIBB_DECL void libB (void) { + printf("libB\\n"); + libA(); +} diff --git a/test/Configure/fixture/checklib_extra/libB/libB.h b/test/Configure/fixture/checklib_extra/libB/libB.h new file mode 100644 index 0000000..9872bb3 --- /dev/null +++ b/test/Configure/fixture/checklib_extra/libB/libB.h @@ -0,0 +1,22 @@ +// SPDX-License-Identifier: MIT +// +// Copyright The SCons Foundation + +#ifndef _LIBB_H +#define _LIBB_H + +// define BUILDINGSHAREDLIB when building libB as shared lib +#ifdef _MSC_VER +# ifdef BUILDINGSHAREDLIB +# define LIBB_DECL __declspec(dllexport) +# else +# define LIBB_DECL __declspec(dllimport) +# endif +#endif // WIN32 + +#ifndef LIBB_DECL +# define LIBB_DECL +#endif + +LIBB_DECL void libB(void); +#endif // _LIBB_H diff --git a/test/Configure/fixture/checklib_extra/src/test.c b/test/Configure/fixture/checklib_extra/src/test.c new file mode 100644 index 0000000..dedf40a --- /dev/null +++ b/test/Configure/fixture/checklib_extra/src/test.c @@ -0,0 +1,6 @@ +#include "libB/libB.h" + +int main() +{ + libB(); +} -- cgit v0.12 From 663165b149f013a10590a4e3b97ee340770fe228 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Sat, 15 Feb 2025 13:21:12 -0800 Subject: Simplify use of dir_fixture and some test logic. Added DefaultEnvironment(tools=[]) to speed up on windows --- test/Configure/CheckLibWithHeader_extra_libs.py | 14 +++----------- test/Configure/fixture/checklib_extra/SConstruct | 1 + 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/test/Configure/CheckLibWithHeader_extra_libs.py b/test/Configure/CheckLibWithHeader_extra_libs.py index eef5c0e..5e7d450 100644 --- a/test/Configure/CheckLibWithHeader_extra_libs.py +++ b/test/Configure/CheckLibWithHeader_extra_libs.py @@ -33,18 +33,10 @@ from pathlib import Path from TestSCons import TestSCons, dll_, _dll test = TestSCons(match=TestSCons.match_re_dotall) +test.dir_fixture(['fixture', 'checklib_extra'],) -# This is the first library project -libA_dir = Path(test.workdir) / "libA" -libA_dir.mkdir() -libA = str(libA_dir / (dll_ + 'A' + _dll)) # for existence check -test.dir_fixture(['fixture', 'checklib_extra', 'libA'], 'libA') - -# This is the second library project, depending on the first -libB_dir = Path(test.workdir) / "libB" -libB_dir.mkdir() -libB = str(libB_dir / (dll_ + 'B' + _dll)) # for existence check -test.dir_fixture(['fixture', 'checklib_extra', 'libB'], 'libB') +libA = f"libA/{dll_}A{_dll}" +libB = f"libB/{dll_}B{_dll}" test.run(arguments='-C libA') test.must_exist(libA) diff --git a/test/Configure/fixture/checklib_extra/SConstruct b/test/Configure/fixture/checklib_extra/SConstruct index 177dc16..82bf5aa 100644 --- a/test/Configure/fixture/checklib_extra/SConstruct +++ b/test/Configure/fixture/checklib_extra/SConstruct @@ -1,6 +1,7 @@ # SPDX-License-Identifier: MIT # # Copyright The SCons Foundation +DefaultEnvironment(tools=[]) env = Environment( CPPPATH=['#'], -- cgit v0.12 From 2a9d19ac69c29b8cb5aeecd2657d4c4cdf4f2989 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Sat, 15 Feb 2025 13:25:09 -0800 Subject: Simplify use of dir_fixture --- test/Configure/CheckLibWithHeader_extra_libs.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/Configure/CheckLibWithHeader_extra_libs.py b/test/Configure/CheckLibWithHeader_extra_libs.py index 5e7d450..037bd86 100644 --- a/test/Configure/CheckLibWithHeader_extra_libs.py +++ b/test/Configure/CheckLibWithHeader_extra_libs.py @@ -43,8 +43,6 @@ test.must_exist(libA) test.run(arguments='-C libB') test.must_exist(libB) -test.file_fixture(['fixture', 'checklib_extra', 'SConstruct']) -test.dir_fixture(['fixture', 'checklib_extra', 'src'], 'src') test.run() test.pass_test() -- cgit v0.12 From a5fcde6a9f37e7879551f4abf2f882ddaeb29835 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Sat, 15 Feb 2025 13:25:29 -0800 Subject: Simplify use of dir_fixture --- test/Configure/CheckLibWithHeader_extra_libs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Configure/CheckLibWithHeader_extra_libs.py b/test/Configure/CheckLibWithHeader_extra_libs.py index 037bd86..9e95fe8 100644 --- a/test/Configure/CheckLibWithHeader_extra_libs.py +++ b/test/Configure/CheckLibWithHeader_extra_libs.py @@ -33,7 +33,7 @@ from pathlib import Path from TestSCons import TestSCons, dll_, _dll test = TestSCons(match=TestSCons.match_re_dotall) -test.dir_fixture(['fixture', 'checklib_extra'],) +test.dir_fixture(['fixture', 'checklib_extra']) libA = f"libA/{dll_}A{_dll}" libB = f"libB/{dll_}B{_dll}" -- cgit v0.12 From e3c23de67eeeb577b4a24b6597c298939acb52a1 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Sat, 15 Feb 2025 13:26:06 -0800 Subject: Simplify --- test/Configure/CheckLibWithHeader_extra_libs.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/Configure/CheckLibWithHeader_extra_libs.py b/test/Configure/CheckLibWithHeader_extra_libs.py index 9e95fe8..d9b699a 100644 --- a/test/Configure/CheckLibWithHeader_extra_libs.py +++ b/test/Configure/CheckLibWithHeader_extra_libs.py @@ -28,8 +28,6 @@ Verify that a program which depends on library which in turn depends on another library can be built correctly using CheckLibWithHeader """ -from pathlib import Path - from TestSCons import TestSCons, dll_, _dll test = TestSCons(match=TestSCons.match_re_dotall) -- cgit v0.12 From 769eff9d7d7c2c778bcad81c07f294dca0691b70 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Sat, 15 Feb 2025 13:32:05 -0800 Subject: Add note to docstring that this is a live test per mwichmann --- test/Configure/CheckLibWithHeader_extra_libs.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/Configure/CheckLibWithHeader_extra_libs.py b/test/Configure/CheckLibWithHeader_extra_libs.py index d9b699a..b9c920c 100644 --- a/test/Configure/CheckLibWithHeader_extra_libs.py +++ b/test/Configure/CheckLibWithHeader_extra_libs.py @@ -26,6 +26,8 @@ """ Verify that a program which depends on library which in turn depends on another library can be built correctly using CheckLibWithHeader + +This is a "live" test - requires a configured C compiler/toolchain to run. """ from TestSCons import TestSCons, dll_, _dll -- cgit v0.12