summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Burke <tim.burke@gmail.com>2019-02-13 11:56:24 -0800
committerTim Burke <tim.burke@gmail.com>2019-02-13 14:38:30 -0800
commit931c4e4559afeeaf1ea5867b1d44132626f2b575 (patch)
tree5497e07e224f3b57935d90b5c669cd7d86d0d2c8
parent0e3afd3b946d8bf0fa8353c1ac18fed391cb20dc (diff)
downloadpyeclib-931c4e4559afeeaf1ea5867b1d44132626f2b575.tar.gz
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
-rw-r--r--setup.py28
1 files 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 = \