[PATCH] D52806: [python] Support overriding library path via environment

Michał Górny via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 2 15:25:52 PDT 2018


mgorny created this revision.
mgorny added reviewers: jbcoe, arphaman, frutiger.

Support a new CLANG_LIBRARY_PATH environment variable within the Python
bindings.  This variable can be used to force the bindings to load
libclang.* from a specific directory without having to explicitly
read the path in the code using the library.

I plan to use this when integrating Python binding tests with the CMake
build system.  Currently, those tests load libclang.so from default
search paths, so I would have to rely on platform-specific mechanics
such as LD_LIBRARY_PATH.  Instead of copying the whole logic necessary
to handle platform differences into yet another place, it's easier to
just add a dedicated variable for this purpose.


Repository:
  rC Clang

https://reviews.llvm.org/D52806

Files:
  bindings/python/clang/cindex.py


Index: bindings/python/clang/cindex.py
===================================================================
--- bindings/python/clang/cindex.py
+++ bindings/python/clang/cindex.py
@@ -67,6 +67,7 @@
 
 import clang.enumerations
 
+import os
 import sys
 if sys.version_info[0] == 3:
     # Python 3 strings are unicode, translate them to/from utf8 for C-interop.
@@ -4148,6 +4149,8 @@
 
         if Config.library_path:
             file = Config.library_path + '/' + file
+        elif 'CLANG_LIBRARY_PATH' in os.environ:
+            file = os.environ['CLANG_LIBRARY_PATH'] + '/' + file
 
         return file
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52806.168041.patch
Type: text/x-patch
Size: 612 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181002/ee02d8f6/attachment.bin>


More information about the cfe-commits mailing list