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

Merged
merged 13 commits into from
Feb 15, 2025
Merged
125 changes: 5 additions & 120 deletions test/Configure/CheckLibWithHeader_extra_libs.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,138 +38,23 @@
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 <stdio.h>
#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')
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you should just be able to do this once as
test.dir_fixture(['fixture', 'checklib_extra'])

Copy link
Collaborator

Choose a reason for hiding this comment

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

I suppose. If you think it's worth doing yet another iteration...


# 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 <stdio.h>
#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:
Expand Down
30 changes: 30 additions & 0 deletions test/Configure/fixture/checklib_extra/SConstruct
Original file line number Diff line number Diff line change
@@ -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")

Empty file.
6 changes: 6 additions & 0 deletions test/Configure/fixture/checklib_extra/libA/SConstruct
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# SPDX-License-Identifier: MIT
#
# Copyright The SCons Foundation

SharedLibrary(target='A', source=['libA.c'], CPPDEFINES='BUILDINGSHAREDLIB')

10 changes: 10 additions & 0 deletions test/Configure/fixture/checklib_extra/libA/libA.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: MIT
//
// Copyright The SCons Foundation

#include <stdio.h>
#include "libA.h"

LIBA_DECL void libA(void) {
printf("libA\\n");
}
22 changes: 22 additions & 0 deletions test/Configure/fixture/checklib_extra/libA/libA.h
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions test/Configure/fixture/checklib_extra/libB/SConstruct
Original file line number Diff line number Diff line change
@@ -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',
)
12 changes: 12 additions & 0 deletions test/Configure/fixture/checklib_extra/libB/libB.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// SPDX-License-Identifier: MIT
//
// Copyright The SCons Foundation

#include <stdio.h>
#include "libA.h"
#include "libB.h"

LIBB_DECL void libB (void) {
printf("libB\\n");
libA();
}
22 changes: 22 additions & 0 deletions test/Configure/fixture/checklib_extra/libB/libB.h
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions test/Configure/fixture/checklib_extra/src/test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "libB/libB.h"

int main()
{
libB();
}
Loading