diff --git a/src/richchk/mpq/stormlib/dlls/linux/libstorm.so.9.22.0 b/src/richchk/mpq/stormlib/dlls/linux/libstorm.so.9.22.0 new file mode 100755 index 0000000..7323de8 Binary files /dev/null and b/src/richchk/mpq/stormlib/dlls/linux/libstorm.so.9.22.0 differ diff --git a/src/richchk/mpq/stormlib/stormlib_finder.py b/src/richchk/mpq/stormlib/stormlib_finder.py index 46528b2..4c0c847 100644 --- a/src/richchk/mpq/stormlib/stormlib_finder.py +++ b/src/richchk/mpq/stormlib/stormlib_finder.py @@ -18,6 +18,7 @@ class StormLibFinder: _MAC_STORM_INTEL = os.path.join(_SCRIPT_PATH, "dlls/macos/libStorm.dylib") _MAC_STORM_M1 = os.path.join(_SCRIPT_PATH, "dlls/macos/libstorm.9.22.0.dylib") _WINDOWS_STORM = os.path.join(_SCRIPT_PATH, "dlls/windows/Storm.dll") + _LINUX_STORM_X86_64 = os.path.join(_SCRIPT_PATH, "dlls/linux/libstorm.so.9.22.0") @classmethod def find_stormlib( @@ -29,7 +30,7 @@ def find_stormlib( else: cls._LOG.warning( "No path to a StormLib DLL was provided, " - "attempting to use precompiled DLL for Windows and macOS. " + "attempting to use precompiled DLL for Windows, macOS and Linux. " "Future compatibility is not guaranteed; " "please provide a path to StormLib DLL compiled for your platform." ) @@ -42,6 +43,11 @@ def find_stormlib( return StormLibFilePath(_path_to_stormlib_dll=cls._MAC_STORM_M1) elif platform.system().lower() == "darwin": return StormLibFilePath(_path_to_stormlib_dll=cls._MAC_STORM_INTEL) + elif ( + platform.system().lower() == "linux" + and platform.machine().lower() == "x86_64" + ): + return StormLibFilePath(_path_to_stormlib_dll=cls._LINUX_STORM_X86_64) else: msg = ( f"Unsupported platform for precompiled StormLib DLL. " diff --git a/src/setup.py b/src/setup.py index 8ad2513..5ea4a1c 100644 --- a/src/setup.py +++ b/src/setup.py @@ -4,6 +4,7 @@ _PACKAGE_DATA["richchk"] = [ "mpq/stormlib/dlls/macos/*.*", "mpq/stormlib/dlls/windows/*.*", + "mpq/stormlib/dlls/linux/*.*", ] setup( diff --git a/test/chk_resources.py b/test/chk_resources.py index d022af9..47a67ba 100644 --- a/test/chk_resources.py +++ b/test/chk_resources.py @@ -67,6 +67,10 @@ def _extract_chk_section_name_from_file_path(file_path: str) -> str: Path.joinpath(_RESOURCES_DIR_PATH, "stormlib/macos/libstorm.9.22.0.dylib") ).absolute() +LINUX_STORMLIB_X86_64 = Path( + Path.joinpath(_RESOURCES_DIR_PATH, "stormlib/linux/libstorm.so.9.22.0") +).absolute() + EXAMPLE_STARCRAFT_SCX_MAP = Path( Path.joinpath(_RESOURCES_DIR_PATH, "stormlib/example-stacraft-map.scx") ).absolute() diff --git a/test/helpers/stormlib_helper.py b/test/helpers/stormlib_helper.py index 7e68d46..965ca00 100644 --- a/test/helpers/stormlib_helper.py +++ b/test/helpers/stormlib_helper.py @@ -5,3 +5,9 @@ def run_test_if_mac_m1() -> bool: return ( platform.system().lower() == "darwin" and platform.machine().lower() == "arm64" ) + + +def run_test_if_linux_x86_64() -> bool: + return ( + platform.system().lower() == "linux" and platform.machine().lower() == "x86_64" + ) diff --git a/test/mpq/stormlib/search/stormlib_file_searcher_test.py b/test/mpq/stormlib/search/stormlib_file_searcher_test.py index 5a73892..58473c9 100644 --- a/test/mpq/stormlib/search/stormlib_file_searcher_test.py +++ b/test/mpq/stormlib/search/stormlib_file_searcher_test.py @@ -9,8 +9,12 @@ from richchk.mpq.stormlib.stormlib_loader import StormLibLoader from richchk.mpq.stormlib.stormlib_wrapper import StormLibWrapper -from ....chk_resources import COMPLEX_STARCRAFT_SCX_MAP, MACOS_STORMLIB_M1 -from ....helpers.stormlib_helper import run_test_if_mac_m1 +from ....chk_resources import ( + COMPLEX_STARCRAFT_SCX_MAP, + LINUX_STORMLIB_X86_64, + MACOS_STORMLIB_M1, +) +from ....helpers.stormlib_helper import run_test_if_linux_x86_64, run_test_if_mac_m1 # the canonical place the CHK is stored in a SCX/SCM map file _CHK_MPQ_PATH = "staredit\\scenario.chk" @@ -36,6 +40,14 @@ def stormlib_wrapper(): ) ) ) + elif run_test_if_linux_x86_64(): + return StormLibWrapper( + StormLibLoader.load_stormlib( + path_to_stormlib=StormLibFilePath( + _path_to_stormlib_dll=LINUX_STORMLIB_X86_64 + ) + ) + ) def _read_file_as_bytes(infile: str) -> bytes: diff --git a/test/mpq/stormlib/stormlib_finder_test.py b/test/mpq/stormlib/stormlib_finder_test.py index 05eced3..ec88452 100644 --- a/test/mpq/stormlib/stormlib_finder_test.py +++ b/test/mpq/stormlib/stormlib_finder_test.py @@ -59,8 +59,20 @@ def test_it_finds_precompiled_macos_intel_dll_if_no_path_provided(): assert path_to_stormlib.path_to_stormlib_dll.endswith("libStorm.dylib") +def test_it_finds_precompiled_linux_dll_if_no_path_provided(): + with ( + patch("platform.system") as mock_platform_system, + patch("platform.machine") as mock_cpu, + ): + mock_platform_system.return_value = "Linux" + mock_cpu.return_value = "x86_64" + path_to_stormlib = StormLibFinder.find_stormlib() + assert os.path.join(path_to_stormlib.path_to_stormlib_dll) + assert path_to_stormlib.path_to_stormlib_dll.endswith("libstorm.so.9.22.0") + + def test_it_throws_if_unrecognized_operating_system(): with patch("platform.system") as mock_platform_system: - mock_platform_system.return_value = "Linux" + mock_platform_system.return_value = "iOS" with pytest.raises(OSError): StormLibFinder.find_stormlib() diff --git a/test/mpq/stormlib/stormlib_wrapper_test.py b/test/mpq/stormlib/stormlib_wrapper_test.py index 85d5bde..409ef4e 100644 --- a/test/mpq/stormlib/stormlib_wrapper_test.py +++ b/test/mpq/stormlib/stormlib_wrapper_test.py @@ -12,8 +12,12 @@ from richchk.mpq.stormlib.stormlib_loader import StormLibLoader from richchk.mpq.stormlib.stormlib_wrapper import StormLibWrapper -from ...chk_resources import EXAMPLE_STARCRAFT_SCX_MAP, MACOS_STORMLIB_M1 -from ...helpers.stormlib_helper import run_test_if_mac_m1 +from ...chk_resources import ( + EXAMPLE_STARCRAFT_SCX_MAP, + LINUX_STORMLIB_X86_64, + MACOS_STORMLIB_M1, +) +from ...helpers.stormlib_helper import run_test_if_linux_x86_64, run_test_if_mac_m1 # the canonical place the CHK is stored in a SCX/SCM map file _CHK_MPQ_PATH = "staredit\\scenario.chk" @@ -29,6 +33,14 @@ def stormlib_wrapper(): ) ) ) + elif run_test_if_linux_x86_64(): + return StormLibWrapper( + StormLibLoader.load_stormlib( + path_to_stormlib=StormLibFilePath( + _path_to_stormlib_dll=LINUX_STORMLIB_X86_64 + ) + ) + ) def _read_file_as_bytes(infile: str) -> bytes: diff --git a/test/resources/stormlib/linux/libstorm.so.9.22.0 b/test/resources/stormlib/linux/libstorm.so.9.22.0 new file mode 100755 index 0000000..7323de8 Binary files /dev/null and b/test/resources/stormlib/linux/libstorm.so.9.22.0 differ