Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Allow passing extra_libs to CheckLibWithHeader #4676

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions RELEASE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions SCons/SConf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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

Expand Down
1 change: 1 addition & 0 deletions doc/man/scons.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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
<parameter>library</parameter>.
<parameter>extra_libs</parameter> can be used to add additional libraries to link against.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mwichmann - what's the blurb to indicate this is added in NEXT_RELEASE?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the xml files are not processed by Sphinx, it needs the hand-crafted version:

<para>
<emphasis>Changed in version NEXT_RELEASE:</emphasis>
Added the <parameter>extra_libs</parameter> parameter.
</para>

It's a little unclear whether an existing method getting a new parameter is considered "added" or "changed". I'm tending to follow what CPython does, which is to consider that "changed" (though I admit that's not been consistent).

The corresponding markup in source code (aka the docstring) is:

.. versionchanged:: NEXT_RELEASE
    Added the  *extra_libs* parameter.

If <parameter>autoadd</parameter> is true (the default),
the first library that passes the check
is added to the &cv-link-LIBS; &consvar; in the context
Expand Down
94 changes: 94 additions & 0 deletions test/Configure/CheckLibWithHeader_extra_libs.py
Original file line number Diff line number Diff line change
@@ -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 <stdio.h>
#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 <stdio.h>
#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()
Loading