Skip to content

Commit 8c4dbfc

Browse files
bindings: Change module header and library loading order
1 parent 1753c5f commit 8c4dbfc

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

bindings/python/ns__init__.py

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@
88

99
DEFAULT_INCLUDE_DIR = sysconfig.get_config_var("INCLUDEDIR")
1010
DEFAULT_LIB_DIR = sysconfig.get_config_var("LIBDIR")
11+
BUILD_TYPES = (
12+
"debug",
13+
"default",
14+
"optimized",
15+
"release",
16+
"relwithdebinfo",
17+
"minsizerel",
18+
)
1119

1220

1321
def find_ns3_lock() -> str:
@@ -313,14 +321,7 @@ def filter_module_name(library: str) -> str:
313321
components.pop(0)
314322

315323
# Drop build profile suffix and test libraries
316-
if components[-1] in [
317-
"debug",
318-
"default",
319-
"optimized",
320-
"release",
321-
"relwithdebinfo",
322-
"minsizerel",
323-
]:
324+
if components[-1] in BUILD_TYPES:
324325
components.pop(-1)
325326
return "-".join(components)
326327

@@ -521,12 +522,22 @@ def dependency_order(
521522
if os.path.isdir(linked_lib_include_dir):
522523
cppyy.add_include_path(linked_lib_include_dir)
523524

524-
for module in modules:
525-
cppyy.include(f"ns3/{module}-module.h")
525+
# Get build type
526+
build_type = "" # release
527+
for type in BUILD_TYPES:
528+
if type in libraries_to_load[-1]:
529+
build_type = type
526530

527-
# After including all headers, we finally load the modules
531+
# Load a module, then its module header
528532
for library in libraries_to_load:
529533
cppyy.load_library(library)
534+
for module in modules:
535+
library_name_from_module = (
536+
f"{version}-{module}{'-' if len(build_type)>0 else ''}{build_type}"
537+
)
538+
if library_name_from_module in library:
539+
cppyy.include(f"ns3/{module}-module.h")
540+
break
530541

531542
# We expose cppyy to consumers of this module as ns.cppyy
532543
setattr(cppyy.gbl.ns3, "cppyy", cppyy)

0 commit comments

Comments
 (0)