[python] [tests] Support overriding library path via environment
authorMichal Gorny <mgorny@gentoo.org>
Thu, 11 Oct 2018 11:58:07 +0000 (11:58 +0000)
committerMichal Gorny <mgorny@gentoo.org>
Thu, 11 Oct 2018 11:58:07 +0000 (11:58 +0000)
Support a new CLANG_LIBRARY_PATH environment variable for the Python
binding tests.  This variable can be used to force the bindings to load
libclang.* from a specific directory.

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.

Differential Revision: https://reviews.llvm.org/D52806

llvm-svn: 344240

18 files changed:
clang/bindings/python/README.txt
clang/bindings/python/tests/cindex/test_access_specifiers.py
clang/bindings/python/tests/cindex/test_cdb.py
clang/bindings/python/tests/cindex/test_code_completion.py
clang/bindings/python/tests/cindex/test_comment.py
clang/bindings/python/tests/cindex/test_cursor.py
clang/bindings/python/tests/cindex/test_cursor_kind.py
clang/bindings/python/tests/cindex/test_diagnostics.py
clang/bindings/python/tests/cindex/test_exception_specification_kind.py
clang/bindings/python/tests/cindex/test_file.py
clang/bindings/python/tests/cindex/test_index.py
clang/bindings/python/tests/cindex/test_linkage.py
clang/bindings/python/tests/cindex/test_location.py
clang/bindings/python/tests/cindex/test_tls_kind.py
clang/bindings/python/tests/cindex/test_token_kind.py
clang/bindings/python/tests/cindex/test_tokens.py
clang/bindings/python/tests/cindex/test_translation_unit.py
clang/bindings/python/tests/cindex/test_type.py

index 8a0bf99..b0f0142 100644 (file)
@@ -4,12 +4,12 @@
 
 This directory implements Python bindings for Clang.
 
-You may need to alter LD_LIBRARY_PATH so that the Clang library can be
+You may need to set CLANG_LIBRARY_PATH so that the Clang library can be
 found. The unit tests are designed to be run with any standard test
 runner. For example:
 --
 $ env PYTHONPATH=$(echo ~/llvm/tools/clang/bindings/python/) \
-      LD_LIBRARY_PATH=$(llvm-config --libdir) \
+      CLANG_LIBRARY_PATH=$(llvm-config --libdir) \
   python -m unittest discover -v
 tests.cindex.test_index.test_create ... ok
 ...
index 2f6144b..e36424f 100644 (file)
@@ -1,3 +1,7 @@
+import os
+from clang.cindex import Config
+if 'CLANG_LIBRARY_PATH' in os.environ:
+    Config.set_library_path(os.environ['CLANG_LIBRARY_PATH'])
 
 from clang.cindex import AccessSpecifier
 from clang.cindex import Cursor
index 64651af..25ee6d3 100644 (file)
@@ -1,3 +1,8 @@
+import os
+from clang.cindex import Config
+if 'CLANG_LIBRARY_PATH' in os.environ:
+    Config.set_library_path(os.environ['CLANG_LIBRARY_PATH'])
+
 from clang.cindex import CompilationDatabase
 from clang.cindex import CompilationDatabaseError
 from clang.cindex import CompileCommands
index efc7912..9cd5a5f 100644 (file)
@@ -1,3 +1,8 @@
+import os
+from clang.cindex import Config
+if 'CLANG_LIBRARY_PATH' in os.environ:
+    Config.set_library_path(os.environ['CLANG_LIBRARY_PATH'])
+
 from clang.cindex import TranslationUnit
 
 import unittest
index d6c6d8e..73fb617 100644 (file)
@@ -1,3 +1,8 @@
+import os
+from clang.cindex import Config
+if 'CLANG_LIBRARY_PATH' in os.environ:
+    Config.set_library_path(os.environ['CLANG_LIBRARY_PATH'])
+
 from clang.cindex import TranslationUnit
 from tests.cindex.util import get_cursor
 
index f5733fd..ef875e9 100644 (file)
@@ -1,3 +1,8 @@
+import os
+from clang.cindex import Config
+if 'CLANG_LIBRARY_PATH' in os.environ:
+    Config.set_library_path(os.environ['CLANG_LIBRARY_PATH'])
+
 import ctypes
 import gc
 import unittest
index f1ee753..e6b9558 100644 (file)
@@ -1,3 +1,8 @@
+import os
+from clang.cindex import Config
+if 'CLANG_LIBRARY_PATH' in os.environ:
+    Config.set_library_path(os.environ['CLANG_LIBRARY_PATH'])
+
 from clang.cindex import CursorKind
 
 import unittest
index 78b327d..79d7a5f 100644 (file)
@@ -1,3 +1,8 @@
+import os
+from clang.cindex import Config
+if 'CLANG_LIBRARY_PATH' in os.environ:
+    Config.set_library_path(os.environ['CLANG_LIBRARY_PATH'])
+
 from clang.cindex import *
 from .util import get_tu
 
index 80b3639..6c13f70 100644 (file)
@@ -1,3 +1,8 @@
+import os
+from clang.cindex import Config
+if 'CLANG_LIBRARY_PATH' in os.environ:
+    Config.set_library_path(os.environ['CLANG_LIBRARY_PATH'])
+
 import clang.cindex
 from clang.cindex import ExceptionSpecificationKind
 from .util import get_tu
index 98f6575..a146fe5 100644 (file)
@@ -1,3 +1,8 @@
+import os
+from clang.cindex import Config
+if 'CLANG_LIBRARY_PATH' in os.environ:
+    Config.set_library_path(os.environ['CLANG_LIBRARY_PATH'])
+
 from clang.cindex import Index, File
 
 import unittest
index cfdf98e..46aafcf 100644 (file)
@@ -1,3 +1,8 @@
+import os
+from clang.cindex import Config
+if 'CLANG_LIBRARY_PATH' in os.environ:
+    Config.set_library_path(os.environ['CLANG_LIBRARY_PATH'])
+
 from clang.cindex import *
 import os
 import unittest
index 6b482f8..cdd97fc 100644 (file)
@@ -1,3 +1,8 @@
+import os
+from clang.cindex import Config
+if 'CLANG_LIBRARY_PATH' in os.environ:
+    Config.set_library_path(os.environ['CLANG_LIBRARY_PATH'])
+
 from clang.cindex import LinkageKind
 from clang.cindex import Cursor
 from clang.cindex import TranslationUnit
index cbc32de..fbe9770 100644 (file)
@@ -1,3 +1,8 @@
+import os
+from clang.cindex import Config
+if 'CLANG_LIBRARY_PATH' in os.environ:
+    Config.set_library_path(os.environ['CLANG_LIBRARY_PATH'])
+
 from clang.cindex import Cursor
 from clang.cindex import File
 from clang.cindex import SourceLocation
index fbc3418..c828ac8 100644 (file)
@@ -1,3 +1,8 @@
+import os
+from clang.cindex import Config
+if 'CLANG_LIBRARY_PATH' in os.environ:
+    Config.set_library_path(os.environ['CLANG_LIBRARY_PATH'])
+
 from clang.cindex import TLSKind
 from clang.cindex import Cursor
 from clang.cindex import TranslationUnit
index 700f95a..904e007 100644 (file)
@@ -1,3 +1,8 @@
+import os
+from clang.cindex import Config
+if 'CLANG_LIBRARY_PATH' in os.environ:
+    Config.set_library_path(os.environ['CLANG_LIBRARY_PATH'])
+
 from clang.cindex import TokenKind
 
 import unittest
index c93353d..dd6d3a3 100644 (file)
@@ -1,3 +1,8 @@
+import os
+from clang.cindex import Config
+if 'CLANG_LIBRARY_PATH' in os.environ:
+    Config.set_library_path(os.environ['CLANG_LIBRARY_PATH'])
+
 from clang.cindex import CursorKind
 from clang.cindex import Index
 from clang.cindex import SourceLocation
index d3ee535..0abfda8 100644 (file)
@@ -1,3 +1,8 @@
+import os
+from clang.cindex import Config
+if 'CLANG_LIBRARY_PATH' in os.environ:
+    Config.set_library_path(os.environ['CLANG_LIBRARY_PATH'])
+
 from contextlib import contextmanager
 import gc
 import os
index 12db996..bcdbeff 100644 (file)
@@ -1,3 +1,8 @@
+import os
+from clang.cindex import Config
+if 'CLANG_LIBRARY_PATH' in os.environ:
+    Config.set_library_path(os.environ['CLANG_LIBRARY_PATH'])
+
 import gc
 import unittest