LLDB mainline
PythonPathSetup.h
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLDB_SOURCE_HOST_PYTHONPATHSETUP_H
10#define LLDB_SOURCE_HOST_PYTHONPATHSETUP_H
11
12#include "llvm/Support/Error.h"
13
14#ifdef LLDB_PYTHON_DLL_RELATIVE_PATH
15/// Resolve the full path of the directory defined by
16/// LLDB_PYTHON_DLL_RELATIVE_PATH. If it exists, add it to the list of DLL
17/// search directories.
18///
19/// \return `true` if the library was added to the search path.
20/// `false` otherwise.
21bool AddPythonDLLToSearchPath();
22#endif
23
24/// Attempts to setup the DLL search path for the Python runtime library.
25///
26/// In the following paragraphs, python3xx.dll refers to the Python runtime
27/// library name which is defined by LLDB_PYTHON_RUNTIME_LIBRARY_FILENAME, e.g.
28/// python311.dll for Python 3.11.
29///
30/// The setup flow depends on which macros are defined:
31///
32/// - If only LLDB_PYTHON_RUNTIME_LIBRARY_FILENAME is defined, checks whether
33/// python3xx.dll can be loaded. Returns an error if it cannot.
34///
35/// - If only LLDB_PYTHON_DLL_RELATIVE_PATH is defined, attempts to resolve the
36/// relative path and add it to the DLL search path. Returns an error if this
37/// fails. Note that this may succeed even if python3xx.dll is not present in
38/// the added search path.
39///
40/// - If both LLDB_PYTHON_RUNTIME_LIBRARY_FILENAME and
41/// LLDB_PYTHON_DLL_RELATIVE_PATH are defined, first checks if python3xx.dll
42/// can be loaded. If successful, returns immediately. Otherwise, attempts to
43/// resolve the relative path and add it to the DLL search path, then checks
44/// again if python3xx.dll can be loaded.
45///
46/// \return If LLDB_PYTHON_RUNTIME_LIBRARY_FILENAME is defined, return the
47/// absolute path of the Python shared library which was resolved or an error if
48/// it could not be found. If LLDB_PYTHON_RUNTIME_LIBRARY_FILENAME and
49/// LLDB_PYTHON_DLL_RELATIVE_PATH are not defined, return an empty string.
50llvm::Expected<std::string> SetupPythonRuntimeLibrary();
51
52#endif // LLDB_SOURCE_HOST_PYTHONPATHSETUP_H
llvm::Expected< std::string > SetupPythonRuntimeLibrary()
Attempts to setup the DLL search path for the Python runtime library.