aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick Lehmann <Patrick.Lehmann@plc2.de>2021-06-30 20:32:07 +0200
committerGitHub <noreply@github.com>2021-06-30 20:32:07 +0200
commit6f9637713587c24789d1c89510e904754860c63d (patch)
treeebe46506d8114e19f13f09987339a3a0472e1f52
parentafae1a4ab13485d3e5d5624ca9231bc5da0ff867 (diff)
downloadghdl-6f9637713587c24789d1c89510e904754860c63d.tar.gz
ghdl-6f9637713587c24789d1c89510e904754860c63d.tar.bz2
ghdl-6f9637713587c24789d1c89510e904754860c63d.zip
pyGHDL: Added DLL search path for Python ≥3.8. (#1811)
* Added DLL search path for Python ≥3.8. Let Windows CPython 64-bit execute GHDL in msys64/mingw64. * Fix executable name of Python based on the current environment. (cherry picked from commit 618c8149df1fa53d06cb197d65b3b10a02ae52ee) * Removed debug code.
-rw-r--r--pyGHDL/libghdl/__init__.py27
-rw-r--r--testsuite/pyunit/dom/Sanity.py5
2 files changed, 22 insertions, 10 deletions
diff --git a/pyGHDL/libghdl/__init__.py b/pyGHDL/libghdl/__init__.py
index d23ffc0e7..39722f3b9 100644
--- a/pyGHDL/libghdl/__init__.py
+++ b/pyGHDL/libghdl/__init__.py
@@ -31,10 +31,9 @@
#
# SPDX-License-Identifier: GPL-2.0-or-later
# ============================================================================
-
from ctypes import c_char_p, CDLL
-import os
-import sys
+from sys import platform as sys_platform, version_info as sys_version_info
+from os import environ as os_environ
from pathlib import Path
from shutil import which
from typing import List
@@ -63,7 +62,7 @@ class LibGHDLException(GHDLBaseException):
def _get_libghdl_name() -> Path:
"""Get the name of the libghdl library (with version and extension)."""
ver = __version__.replace("-", "_").replace(".", "_")
- ext = {"win32": "dll", "cygwin": "dll", "darwin": "dylib"}.get(sys.platform, "so")
+ ext = {"win32": "dll", "cygwin": "dll", "darwin": "dylib"}.get(sys_platform, "so")
return Path("libghdl-{version}.{ext}".format(version=ver, ext=ext))
@@ -103,21 +102,21 @@ def _get_libghdl_path():
# Try GHDL_PREFIX
# GHDL_PREFIX is the prefix of the vhdl libraries, so remove the
# last path component.
- r = os.environ.get("GHDL_PREFIX")
+ r = os_environ.get("GHDL_PREFIX")
try:
return _check_libghdl_libdir(Path(r).parent, basename)
except (TypeError, FileNotFoundError):
pass
# Try VUNIT_GHDL_PATH (path of the ghdl binary when using VUnit).
- r = os.environ.get("VUNIT_GHDL_PATH")
+ r = os_environ.get("VUNIT_GHDL_PATH")
try:
return _check_libghdl_bindir(Path(r), basename)
except (TypeError, FileNotFoundError):
pass
# Try GHDL (name/path of the ghdl binary)
- r = os.environ.get("GHDL", "ghdl")
+ r = os_environ.get("GHDL", "ghdl")
r = which(r)
try:
return _check_libghdl_bindir(Path(r).parent, basename)
@@ -145,7 +144,19 @@ def _get_libghdl_path():
def _initialize():
# Load the shared library
_libghdl_path = _get_libghdl_path()
- # print("Load {}".format(_libghdl_path))
+
+ # Add DLL search path(s)
+ if (
+ sys_platform == "win32"
+ and sys_version_info.major == 3
+ and sys_version_info.minor >= 8
+ ):
+ from os import add_dll_directory as os_add_dll_directory
+
+ p1 = _libghdl_path.parent.parent / "bin"
+ os_add_dll_directory(str(p1))
+
+ # Load libghdl shared object
libghdl = CDLL(str(_libghdl_path))
# Initialize it.
diff --git a/testsuite/pyunit/dom/Sanity.py b/testsuite/pyunit/dom/Sanity.py
index dc415446b..b0177f8b3 100644
--- a/testsuite/pyunit/dom/Sanity.py
+++ b/testsuite/pyunit/dom/Sanity.py
@@ -32,10 +32,11 @@
# ============================================================================
from pathlib import Path
from subprocess import check_call, STDOUT
+from sys import executable as sys_executable
from pytest import mark
-from pyGHDL.dom.NonStandard import Design, Document
+from pyGHDL.dom.NonStandard import Design
if __name__ == "__main__":
print("ERROR: you called a testcase declaration file as an executable module.")
@@ -51,7 +52,7 @@ design = Design()
@mark.xfail
@mark.parametrize("file", [str(f.relative_to(_TESTSUITE_ROOT)) for f in _TESTSUITE_ROOT.glob("sanity/**/*.vhdl")])
def test_AllVHDLSources(file):
- check_call(["python", _GHDL_ROOT / "pyGHDL/cli/DOM.py", file], stderr=STDOUT)
+ check_call([sys_executable, _GHDL_ROOT / "pyGHDL/cli/DOM.py", file], stderr=STDOUT)
# document = Document(Path(file))
# design.Documents.append(document)