New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
building: validate binaries returned by analysis of ctypes calls #7984
Conversation
Validate binaries returned by analysis of `ctypes` calls in collected modules; the analysis might return files that are in `PATH` but are not binaries, which then cause errors during binary dependency analysis. An example of such problematic case is the `gmsh` package on Windows, where `ctypes.util.find_library('gmsh')` ends up resolving the python script called `gmsh` in the environment's Scripts directory.
This is the last-line-of-defense kind of thing. In the future, we might want to also remove the |
Doesn't that mean that there is still a |
Indeed. But it is actually called Which is why the [...]
moduledir = os.path.dirname(os.path.realpath(__file__))
parentdir1 = os.path.dirname(moduledir)
parentdir2 = os.path.dirname(parentdir1)
if platform.system() == "Windows":
libname = "gmsh-4.12.dll"
elif platform.system() == "Darwin":
libname = "libgmsh.4.12.dylib"
else:
libname = "libgmsh.so.4.12"
# Searching lib in various subfolders
libpath = None
possible_libpaths = [os.path.join(moduledir, libname),
os.path.join(moduledir, "lib", libname),
os.path.join(moduledir, "Lib", libname),
# first parent dir
os.path.join(parentdir1, libname),
os.path.join(parentdir1, "lib", libname),
os.path.join(parentdir1, "Lib", libname),
# second parent dir
os.path.join(parentdir2, libname),
os.path.join(parentdir2, "lib", libname),
os.path.join(parentdir2, "Lib", libname)
]
for libpath_to_look in possible_libpaths:
if os.path.exists(libpath_to_look):
libpath = libpath_to_look
break
# if we couldn't find it, use ctype's find_library utility...
if not libpath:
if platform.system() == "Windows":
libpath = find_library("gmsh-4.11")
if not libpath:
libpath = find_library("gmsh")
else:
libpath = find_library("gmsh")
# ... and print a warning if everything failed
if (not libpath) or (not os.path.exists(libpath)):
print("Warning: could not find Gmsh shared library " + libname)
print("Searched at these locations: " + str(possible_libpaths))
lib = CDLL(libpath)
[...] So the library is not actually discoverable by |
So for actually collecting the lib, the user would have to use |
Validate binaries returned by analysis of
ctypes
calls in collected modules; the analysis might return files that are inPATH
but are not binaries, which then cause errors during binary dependency analysis. An example of such problematic case is thegmsh
package on Windows, wherectypes.util.find_library('gmsh')
ends up resolving the python script calledgmsh
in the environment's Scripts directory (see #7982).