diff --git a/buildhelp/cyclone_search.py b/buildhelp/cyclone_search.py index 6ee34a0d..9ff8e92b 100644 --- a/buildhelp/cyclone_search.py +++ b/buildhelp/cyclone_search.py @@ -45,18 +45,22 @@ def good_directory(directory: Path): if not include_path.exists() or not bindir.exists(): return + # Define the libraries directory based on where the CycloneDDS library + # has been installed. That is required because CMake overrides the libraries + # directory definition 'lib' with 'lib64' depending on the operating system. libdir = dir / 'lib' - if not libdir.exists(): - libdir = dir / 'lib64' - if not libdir.exists(): - return None - if platform.system() == 'Windows': ddsc_library = bindir / "ddsc.dll" elif platform.system() == 'Darwin': ddsc_library = libdir / "libddsc.dylib" else: ddsc_library = libdir / "libddsc.so" + if not ddsc_library.exists(): + libdir = dir / 'lib64' + ddsc_library = libdir / "libddsc.so" + + if not libdir.exists(): + return None if not ddsc_library.exists(): return None diff --git a/cyclonedds/internal.py b/cyclonedds/internal.py index 1cad8424..f943a4af 100644 --- a/cyclonedds/internal.py +++ b/cyclonedds/internal.py @@ -53,10 +53,11 @@ def _loader_cyclonedds_home_gen(name): If CYCLONEDDS_HOME is set it is required to be valid and must be used to load. """ def _loader_cyclonedds_home(): - if "CYCLONEDDS_HOME" not in os.environ: - return None - - return _load(os.path.join(os.environ["CYCLONEDDS_HOME"], name)) + if "CYCLONEDDS_HOME" in os.environ: + path = os.path.join(os.environ["CYCLONEDDS_HOME"], name) + if os.path.exists(path): + return _load(path) + return None return _loader_cyclonedds_home @@ -93,6 +94,7 @@ def _loader_install_path(): _loaders_per_system = { "Linux": [ _loader_wheel_gen(["..", "cyclonedds.libs"], ".so"), + _loader_cyclonedds_home_gen(f"lib64{os.sep}libddsc.so"), _loader_cyclonedds_home_gen(f"lib{os.sep}libddsc.so"), _loader_on_path_gen("libddsc.so"), _loader_install_path diff --git a/tests/test_loader.py b/tests/test_loader.py index 3ddfa723..7b61ec46 100644 --- a/tests/test_loader.py +++ b/tests/test_loader.py @@ -28,6 +28,7 @@ def common_mocks(mocker: MockerFixture, platform: str, ext: str): mocker.patch("cyclonedds.internal._load", new=gen_test_loader(loadlist)) mocker.patch("platform.system", new=lambda: platform) mocker.patch("os.environ", new={"CYCLONEDDS_HOME": "env_canary", "PATH": ""}) + mocker.patch("os.path.exists", new_callable=mocker.PropertyMock, return_value=True) return loadlist @@ -39,6 +40,7 @@ def test_loading_linux(mocker: MockerFixture): pass assert paths == [ + f"env_canary{os.sep}lib64{os.sep}libddsc.so", f"env_canary{os.sep}lib{os.sep}libddsc.so", "libddsc.so", library_path