summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2019-03-05 23:40:03 +0000
committerGerrit Code Review <review@openstack.org>2019-03-05 23:40:03 +0000
commitbec3387a1893a79e93103f0c2b660ba8c7728d0c (patch)
treea7ced6f4ef17df23633447783b62e00f414589b1
parentdf28f6521c66f00450b13e4bfa903c1b920e37b6 (diff)
parent931c4e4559afeeaf1ea5867b1d44132626f2b575 (diff)
downloadpyeclib-bec3387a1893a79e93103f0c2b660ba8c7728d0c.tar.gz
Merge "Use liberasurecode_get_version()"
-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 = \