Skip to content

Commit 485d1a6

Browse files
committed
work with b2 on posix (claude)
1 parent b5c0556 commit 485d1a6

File tree

4 files changed

+55
-32
lines changed

4 files changed

+55
-32
lines changed

test/Jamfile

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,40 +49,42 @@ for local src in [ glob compile_fail_*.cpp ]
4949
# Dynamic loading test
5050
# Requires Boost.DLL; builds three shared libraries and a test executable
5151
# that loads them at runtime.
52-
lib dl_test_registry
52+
lib boost_openmethod-dl_test_registry
5353
: dynamic_loading/registry.cpp
5454
: <link>shared
5555
<define>BOOST_DLL_FORCE_ALIAS_INSTANTIATION
5656
<visibility>global
5757
<library>/boost/dll//boost_dll
5858
;
5959

60-
lib dl_test_method
60+
lib boost_openmethod-dl_test_method
6161
: dynamic_loading/method.cpp
6262
: <link>shared
6363
<define>BOOST_DLL_FORCE_ALIAS_INSTANTIATION
6464
<visibility>global
6565
<library>/boost/dll//boost_dll
66-
<library>dl_test_registry
66+
<library>boost_openmethod-dl_test_registry
6767
;
6868

69-
lib dl_test_overrider
69+
lib boost_openmethod-dl_test_overrider
7070
: dynamic_loading/overrider.cpp
7171
: <link>shared
7272
<define>BOOST_DLL_FORCE_ALIAS_INSTANTIATION
7373
<visibility>global
7474
<library>/boost/dll//boost_dll
75-
<library>dl_test_method
75+
<library>boost_openmethod-dl_test_method
7676
;
7777

7878
run dynamic_loading/main.cpp
7979
unit_test_framework
8080
: # args
81-
: dl_test_method dl_test_overrider dl_test_registry # input-files (runtime deps)
81+
: boost_openmethod-dl_test_method boost_openmethod-dl_test_overrider boost_openmethod-dl_test_registry # input-files (runtime deps)
8282
: <link>shared
8383
<visibility>global
8484
<library>/boost/dll//boost_dll
85-
<library>dl_test_registry
85+
<library>boost_openmethod-dl_test_registry
86+
<toolset>gcc,<target-os>linux:<linkflags>-rdynamic
87+
<toolset>clang,<target-os>linux:<linkflags>-rdynamic
8688
: test_dynamic_loading
8789
;
8890

test/dynamic_loading/main.cpp

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
using namespace boost::openmethod;
2121
namespace mp11 = boost::mp11;
2222

23-
constexpr auto n_policies = mp11::mp_size<default_registry::policy_list>::value;
24-
2523
using policy_ids_fn = const void**();
2624
using method_fn = const void*();
2725

@@ -59,21 +57,47 @@ bool same_ids(const void** ids1, const void** ids2) {
5957

6058
BOOST_AUTO_TEST_CASE(test_shared_state) {
6159
namespace dll = boost::dll;
62-
auto lib_dir = dll::program_location().parent_path();
60+
namespace fs = boost::filesystem;
61+
namespace ut = boost::unit_test;
62+
63+
// b2 passes input-files as extra argv in alphabetical-path order (not
64+
// necessarily the order listed in the Jamfile). CMake puts all outputs in
65+
// one directory, found via program_location(), with no extra argv.
66+
auto& mts = ut::framework::master_test_suite();
67+
fs::path method_path, overrider_path;
68+
dll::load_mode::type load_flags;
69+
70+
// Search argv for paths containing the library names (b2 mode).
71+
for (int i = 1; i < mts.argc; ++i) {
72+
std::string arg = mts.argv[i];
73+
if (arg.find("dl_test_method") != std::string::npos) {
74+
method_path = arg;
75+
} else if (arg.find("dl_test_overrider") != std::string::npos) {
76+
overrider_path = arg;
77+
}
78+
}
79+
80+
if (!method_path.empty()) {
81+
// b2 mode: full versioned paths passed as argv (e.g. libfoo.so.1.91.0)
82+
load_flags = dll::load_mode::default_mode;
83+
} else {
84+
// CMake mode: libraries are alongside the executable, use decorations
85+
auto lib_dir = dll::program_location().parent_path();
86+
method_path = lib_dir / "boost_openmethod-dl_test_method";
87+
overrider_path = lib_dir / "boost_openmethod-dl_test_overrider";
88+
load_flags = dll::load_mode::append_decorations;
89+
}
6390

6491
// Load all three shared libraries via Boost.DLL.
6592
// Use rtld_global for registry and method so their symbols (fn, policy
6693
// statics) are visible globally and win over any locally-instantiated
6794
// copies when the overrider library is subsequently loaded.
68-
dll::shared_library method_lib(
69-
lib_dir / "boost_openmethod-dl_test_method",
70-
dll::load_mode::append_decorations);
71-
auto& method_get_ids = method_lib.get_alias<policy_ids_fn>("get_ids");
95+
dll::shared_library method_lib(method_path, load_flags);
96+
auto& method_get_ids = method_lib.get_alias<policy_ids_fn>("method_get_ids");
7297
auto& method_speak =
73-
method_lib.get_alias<const char*(virtual_ptr<Animal>)>("call_speak");
98+
method_lib.get_alias<const char*(virtual_ptr<Animal>)>("method_call_speak");
7499
auto& method_make_dog =
75-
method_lib.get_alias<unique_virtual_ptr<Animal>()>("make_dog");
76-
auto& method_get_fn = method_lib.get_alias<method_fn>("get_fn");
100+
method_lib.get_alias<unique_virtual_ptr<Animal>()>("method_make_dog");
77101

78102
BOOST_TEST(same_ids(get_ids(), method_get_ids()));
79103

@@ -88,15 +112,12 @@ BOOST_AUTO_TEST_CASE(test_shared_state) {
88112
BOOST_TEST(method_speak(main_dog) == "?");
89113
BOOST_TEST(method_speak(method_dog) == "?");
90114

91-
dll::shared_library overrider_lib(
92-
lib_dir / "boost_openmethod-dl_test_overrider",
93-
dll::load_mode::append_decorations);
94-
auto& overrider_get_ids = overrider_lib.get_alias<policy_ids_fn>("get_ids");
115+
dll::shared_library overrider_lib(overrider_path, load_flags);
116+
auto& overrider_get_ids = overrider_lib.get_alias<policy_ids_fn>("overrider_get_ids");
95117
auto& overrider_speak =
96-
overrider_lib.get_alias<const char*(virtual_ptr<Animal>)>("call_speak");
118+
overrider_lib.get_alias<const char*(virtual_ptr<Animal>)>("overrider_call_speak");
97119
auto& overrider_make_dog =
98-
overrider_lib.get_alias<unique_virtual_ptr<Animal>()>("make_dog");
99-
auto& overrider_get_fn = overrider_lib.get_alias<method_fn>("get_fn");
120+
overrider_lib.get_alias<unique_virtual_ptr<Animal>()>("overrider_make_dog");
100121

101122
BOOST_TEST(same_ids(get_ids(), overrider_get_ids()));
102123

test/dynamic_loading/method.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ DEFINE_MAKE_DOG()
3232
DEFINE_GET_FN()
3333
DEFINE_CALL_SPEAK()
3434

35-
BOOST_DLL_AUTO_ALIAS(get_ids)
36-
BOOST_DLL_AUTO_ALIAS(get_fn)
37-
BOOST_DLL_AUTO_ALIAS(make_dog)
38-
BOOST_DLL_AUTO_ALIAS(call_speak)
35+
BOOST_DLL_ALIAS(get_ids, method_get_ids)
36+
BOOST_DLL_ALIAS(get_fn, method_get_fn)
37+
BOOST_DLL_ALIAS(make_dog, method_make_dog)
38+
BOOST_DLL_ALIAS(call_speak, method_call_speak)

test/dynamic_loading/overrider.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ DEFINE_MAKE_DOG()
2222
DEFINE_GET_FN()
2323
DEFINE_CALL_SPEAK()
2424

25-
BOOST_DLL_AUTO_ALIAS(get_ids)
26-
BOOST_DLL_AUTO_ALIAS(get_fn)
27-
BOOST_DLL_AUTO_ALIAS(make_dog)
28-
BOOST_DLL_AUTO_ALIAS(call_speak)
25+
BOOST_DLL_ALIAS(get_ids, overrider_get_ids)
26+
BOOST_DLL_ALIAS(get_fn, overrider_get_fn)
27+
BOOST_DLL_ALIAS(make_dog, overrider_make_dog)
28+
BOOST_DLL_ALIAS(call_speak, overrider_call_speak)

0 commit comments

Comments
 (0)