From 931c4e4559afeeaf1ea5867b1d44132626f2b575 Mon Sep 17 00:00:00 2001 From: Tim Burke Date: Wed, 13 Feb 2019 11:56:24 -0800 Subject: Use liberasurecode_get_version() ... to determine whether we have a supported version. If not available, fall back to file name parsing to check the version, keeping in mind that we haven't yet released a v2. Change-Id: I5f81ddd6df1970bef3a2614126bce0eb78f44473 Closes-Bug: 1780320 --- setup.py | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index bd6c644..46a336d 100644 --- a/setup.py +++ b/setup.py @@ -28,6 +28,7 @@ import os import platform import sys +import ctypes from ctypes.util import find_library from distutils.command.build import build as _build from distutils.command.clean import clean as _clean @@ -84,10 +85,29 @@ class build(_build): found_path = _find_library("erasurecode") if found_path: - if found_path.endswith(library_version) or \ - found_path.find(library_version + ".") > -1: - # call 1.x.x the only compatible version for now - return + libec = ctypes.CDLL(found_path) + try: + packed_version = libec.liberasurecode_get_version() + except AttributeError: + # If we don't have the version getter, we're probably + # pre-1.4.0; fall back to some heuristics based on name + version_parts = [x for x in found_path.split('.') + if x.isdigit()] + if not version_parts: + # A bare .so? Well, we haven't released a 2.x yet... but + # if we ever do, hopefully it'd still provide a + # liberasurecode_get_version() + return + if version_parts[0] == library_version: + return + # else, seems to be an unknown version -- assume it won't work + else: + version = ( + packed_version >> 16, + (packed_version >> 8) & 0xff, + packed_version & 0xff) + if (1, 0, 0) <= version < (2, 0, 0): + return if platform_str.find("Darwin") > -1: liberasure_file = \ -- cgit v1.2.1