Hello community,

here is the log from the commit of package llvm4 for openSUSE:Factory checked 
in at 2017-12-10 18:12:58
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/llvm4 (Old)
 and      /work/SRC/openSUSE:Factory/.llvm4.new (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Package is "llvm4"

Sun Dec 10 18:12:58 2017 rev:10 rq:554941 version:4.0.1

Changes:
--------
--- /work/SRC/openSUSE:Factory/llvm4/llvm4.changes      2017-10-19 
19:31:32.154563247 +0200
+++ /work/SRC/openSUSE:Factory/.llvm4.new/llvm4.changes 2017-12-10 
18:13:09.987422038 +0100
@@ -1,0 +2,38 @@
+Mon Dec  4 15:39:30 UTC 2017 - m...@suse.com
+
+- Fix %check tests when used with python3.
+  * llvm-lit-Make-util.executeCommand-python3-friendly.patch
+  * llvm-lit-Re-apply-Fix-some-convoluted-logic-around-Unicod.patch
+  * libcxx-fix-python3-syntax-error.patch
+  * Define LANG=C.UTF-8 when running the tests.
+- Add explicit Provides/Conflicts to llvm4-devel,
+  clang4-devel-static and lldb4-devel.
+  * These are required to be validated by obs repo-checker.
+
+-------------------------------------------------------------------
+Fri Dec  1 12:37:33 UTC 2017 - m...@suse.com
+
+- Switch to python3.
+  * clang-add-python-3-support-to-clang-cindex.patch
+  * clang-bindings-allow-null-strings-in-python-3.patch
+
+-------------------------------------------------------------------
+Tue Nov 21 14:50:26 UTC 2017 - m...@suse.com
+
+- Use LLVM_OPTIMIZED_TABLEGEN to speed up build. (bnc#1064786)
+- Fix files of lldb4 to work correctly with update-alternatives.
+- Remove Conflicts clang(LLDB) from lldb4-devel - it does not
+  exist. It would be provided automatically, but no such cmake file
+  is installed.
+
+-------------------------------------------------------------------
+Fri Oct 27 07:09:07 UTC 2017 - m...@suse.com
+
+- llvm-do-not-install-static-libraries.patch
+  * Do not install static libraries instead of installing them and
+    deleting after.
+  * Reduces disk usage during build. (bnc#1064786)
+- Do not build unnecessary parts during stage1.
+  * Speeds up build a bit. (bnc#1064786)
+
+-------------------------------------------------------------------

New:
----
  clang-add-python-3-support-to-clang-cindex.patch
  clang-bindings-allow-null-strings-in-python-3.patch
  libcxx-fix-python3-syntax-error.patch
  llvm-do-not-install-static-libraries.patch
  llvm-lit-Make-util.executeCommand-python3-friendly.patch
  llvm-lit-Re-apply-Fix-some-convoluted-logic-around-Unicod.patch

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Other differences:
------------------
++++++ llvm4.spec ++++++
--- /var/tmp/diff_new_pack.6iQ3gi/_old  2017-12-10 18:13:12.451304682 +0100
+++ /var/tmp/diff_new_pack.6iQ3gi/_new  2017-12-10 18:13:12.455304491 +0100
@@ -42,6 +42,7 @@
 %bcond_with oprofile
 %bcond_with valgrind
 %bcond_without pyclang
+
 Name:           llvm4
 Version:        4.0.1
 Release:        0
@@ -88,6 +89,12 @@
 Patch16:        lldb-add-pthread-dl-libs.patch
 Patch17:        lldb-gcc7.patch
 Patch18:        llvm-normally-versioned-libllvm.patch
+Patch19:        llvm-do-not-install-static-libraries.patch
+Patch20:        clang-add-python-3-support-to-clang-cindex.patch
+Patch21:        clang-bindings-allow-null-strings-in-python-3.patch
+Patch22:        llvm-lit-Make-util.executeCommand-python3-friendly.patch
+Patch23:        llvm-lit-Re-apply-Fix-some-convoluted-logic-around-Unicod.patch
+Patch24:        libcxx-fix-python3-syntax-error.patch
 BuildRequires:  binutils-devel >= 2.21.90
 BuildRequires:  binutils-gold
 BuildRequires:  cmake
@@ -99,8 +106,7 @@
 BuildRequires:  ninja
 BuildRequires:  pkgconfig
 BuildRequires:  procps
-BuildRequires:  python-base
-BuildRequires:  python-xml
+BuildRequires:  python3
 BuildRequires:  pkgconfig(libedit)
 BuildRequires:  pkgconfig(zlib)
 # Avoid multiple provider errors
@@ -157,6 +163,8 @@
 Requires:       ncurses-devel
 Requires:       pkgconfig
 Requires:       pkgconfig(libedit)
+Provides:       llvm-devel-provider
+Conflicts:      llvm-devel-provider
 Conflicts:      cmake(LLVM)
 %if %{with ffi}
 Requires:       pkgconfig(libffi)
@@ -256,6 +264,8 @@
 Summary:        Static libraries for CLANG
 Group:          Development/Languages/Other
 Requires:       clang%{_sonum}-devel = %{version}
+Provides:       clang-devel-static-provider
+Conflicts:      clang-devel-static-provider
 
 %description -n clang%{_sonum}-devel-static
 This package contains static libraries for clang  (C language)
@@ -374,14 +384,14 @@
 This package contains Emacs plugins for LLVM like syntax highlighting.
 
 %package -n python-clang
-Summary:        Python 2 bindings for libclang
+Summary:        Python bindings for libclang
 Group:          Development/Languages/Python
 Requires:       clang%{_sonum}-devel = %{version}
-Requires:       python
+Requires:       python3
 BuildArch:      noarch
 
 %description -n python-clang
-This package contains the Python 2.x bindings to clang (C language)
+This package contains the Python bindings to clang (C language)
 frontend for LLVM.
 
 %if !0%{?sle_version}
@@ -416,12 +426,12 @@
 BuildRequires:  pkgconfig(libedit)
 BuildRequires:  pkgconfig(libffi)
 BuildRequires:  pkgconfig(libxml-2.0)
-BuildRequires:  pkgconfig(python2)
+BuildRequires:  pkgconfig(python3)
 BuildRequires:  pkgconfig(zlib)
 # Avoid multiple provider errors
 Requires:       liblldb%{_sonum} = %{version}
-Requires:       python
-Requires:       python-six
+Requires:       python3
+Requires:       python3-six
 ExclusiveArch:  x86_64
 Requires(post): update-alternatives
 Requires(postun): update-alternatives
@@ -456,7 +466,8 @@
 Requires:       pkgconfig(libffi)
 Requires:       pkgconfig(libxml-2.0)
 Requires:       pkgconfig(zlib)
-Conflicts:      cmake(LLDB)
+Provides:       lldb-devel-provider
+Conflicts:      lldb-devel-provider
 
 %description -n lldb%{_sonum}-devel
 This package contains the development files for LLDB.
@@ -466,9 +477,9 @@
 # Avoid multiple provider errors
 Group:          Development/Languages/Python
 Requires:       liblldb%{_sonum} = %{version}
-Requires:       python
-Provides:       %{python_sitearch}/lldb/
-Conflicts:      %{python_sitearch}/lldb/
+Requires:       python3
+Provides:       %{python3_sitearch}/lldb/
+Conflicts:      %{python3_sitearch}/lldb/
 
 %description -n python%{_sonum}-lldb
 This package contains the Python bindings to clang (C language) frontend for 
LLVM.
@@ -492,9 +503,18 @@
 %patch12 -p1
 %patch13 -p0
 %patch18 -p1
+%patch19 -p1
+%patch22 -p1
+%patch23 -p1
 
 pushd cfe-%{version}.src
 %patch14 -p1
+%patch20 -p1
+%patch21 -p1
+popd
+
+pushd libcxx-%{version}.src
+%patch24 -p1
 popd
 
 %if %{with lldb}
@@ -600,6 +620,7 @@
     -DCMAKE_C_FLAGS="$flags" \
     -DCMAKE_CXX_FLAGS="$flags" \
     -DENABLE_LINKER_BUILD_ID=ON \
+    -DLLVM_OPTIMIZED_TABLEGEN:BOOL=ON \
     -DLLVM_BUILD_TOOLS:BOOL=OFF \
     -DLLVM_BUILD_UTILS:BOOL=OFF \
     -DLLVM_BUILD_EXAMPLES:BOOL=OFF \
@@ -607,7 +628,7 @@
     -DLLVM_TOOL_CLANG_TOOLS_EXTRA_BUILD:BOOL=OFF \
     -DLLVM_INCLUDE_TESTS:BOOL=OFF \
     -DLLVM_ENABLE_ASSERTIONS=OFF \
-    -DLLVM_TARGETS_TO_BUILD=host \
+    -DLLVM_TARGETS_TO_BUILD=Native \
     -DLLVM_USE_LINKER=gold \
     -DCLANG_ENABLE_ARCMT:BOOL=OFF \
     -DCLANG_ENABLE_STATIC_ANALYZER:BOOL=OFF \
@@ -617,14 +638,17 @@
     -DCMAKE_SKIP_RPATH:BOOL=OFF \
     -DCMAKE_EXE_LINKER_FLAGS="-Wl,--as-needed -Wl,--no-keep-memory" \
     -DCMAKE_MODULE_LINKER_FLAGS="-Wl,--as-needed -Wl,--no-keep-memory" \
-    -DCMAKE_SHARED_LINKER_FLAGS="-Wl,--as-needed -Wl,--no-keep-memory"
-ninja -v -j $ninjaproc
+    -DCMAKE_SHARED_LINKER_FLAGS="-Wl,--as-needed -Wl,--no-keep-memory" \
+    -DPYTHON_EXECUTABLE:FILEPATH=/usr/bin/python3
+ninja -v -j $ninjaproc clang
 cd ..
 
 %define __builddir build
 export PATH=${PWD}/stage1/bin:$PATH
 export CC=${PWD}/stage1/bin/clang
 export CXX=${PWD}/stage1/bin/clang++
+export LLVM_TABLEGEN=${PWD}/stage1/bin/llvm-tblgen
+export CLANG_TABLEGEN=${PWD}/stage1/bin/clang-tblgen
 # -z,now is breaking now, it needs to be fixed
 %cmake \
     -DBUILD_SHARED_LIBS:BOOL=OFF \
@@ -637,6 +661,8 @@
     -DCMAKE_CXX_FLAGS_RELWITHDEBINFO="-O2 -g1 -DNDEBUG" \
 %endif
     -DENABLE_LINKER_BUILD_ID=ON \
+    -DLLVM_TABLEGEN="${LLVM_TABLEGEN}" \
+    -DCLANG_TABLEGEN="${CLANG_TABLEGEN}" \
     -DLLVM_REQUIRES_RTTI=ON \
     -DLLVM_ENABLE_TIMESTAMPS=OFF \
     -DLLVM_ENABLE_ASSERTIONS=OFF \
@@ -656,7 +682,8 @@
     -DCMAKE_SKIP_RPATH:BOOL=OFF \
     -DCMAKE_EXE_LINKER_FLAGS="-Wl,--as-needed -Wl,--build-id=sha1" \
     -DCMAKE_MODULE_LINKER_FLAGS="-Wl,--as-needed -Wl,--build-id=sha1" \
-    -DCMAKE_SHARED_LINKER_FLAGS="-Wl,--as-needed -Wl,--build-id=sha1"
+    -DCMAKE_SHARED_LINKER_FLAGS="-Wl,--as-needed -Wl,--build-id=sha1" \
+    -DPYTHON_EXECUTABLE:FILEPATH=/usr/bin/python3
 ninja -v -j $ninjaproc
 cd ..
 
@@ -700,9 +727,9 @@
 # The python bindings use the unversioned libclang.so,
 # so it doesn't make sense to have multiple versions of it
 %if %{with pyclang}
-install -d %{buildroot}%{python_sitelib}/clang
+install -d %{buildroot}%{python3_sitelib}/clang
 pushd tools/clang/bindings/python
-cp clang/*.py %{buildroot}%{python_sitelib}/clang
+cp clang/*.py %{buildroot}%{python3_sitelib}/clang
 install -d %{buildroot}%{_docdir}/python-clang/examples/cindex
 cp -r examples %{buildroot}%{_docdir}/python-clang
 install -d %{buildroot}%{_docdir}/python-clang/tests/cindex/INPUTS
@@ -727,28 +754,29 @@
 
 %if %{with lldb}
 # Python: fix binary libraries location.
-rm %{buildroot}%{python_sitearch}/lldb/_lldb.so
+rm %{buildroot}%{python3_sitearch}/lldb/_lldb.so
 liblldb=$(basename $(readlink -e %{buildroot}%{_libdir}/liblldb.so))
-ln -vsf "../../../${liblldb}" %{buildroot}%{python_sitearch}/lldb/_lldb.so
-ln -vsf "../../${liblldb}"    %{buildroot}%{python_sitearch}/_lldb.so
+ln -vsf "../../../${liblldb}" %{buildroot}%{python3_sitearch}/lldb/_lldb.so
+ln -vsf "../../${liblldb}"    %{buildroot}%{python3_sitearch}/_lldb.so
 
 # Remove bundled six.py.
-rm -f %{buildroot}%{python_sitearch}/six.*
-
-rm %{buildroot}%{_libdir}/liblldb*.a
+rm -f %{buildroot}%{python3_sitearch}/six.*
 
 # Make consistent with the rest of the executables
 mv %{buildroot}%{_bindir}/lldb-argdumper 
%{buildroot}%{_bindir}/lldb-argdumper-%{version}
 ln -s %{_bindir}/lldb-argdumper-%{version} 
%{buildroot}%{_bindir}/lldb-argdumper
+
+# Change lldb symlinks to work with update-alternatives
+for p in lldb lldb-argdumper lldb-mi lldb-server ; do
+    ln -s -f "%{_sysconfdir}/alternatives/$p" "%{buildroot}%{_bindir}/$p"
+done
 %endif
 
 # Stuff we don't want to include
 rm %{buildroot}%{_mandir}/man1/lit.1
 
-rm %{buildroot}%{_libdir}/libLLVM*.a
 rm %{buildroot}%{_libdir}/cmake/llvm/LLVMStaticExports*.cmake
 
-rm %{buildroot}%{_libdir}/liblld*.a
 rm -rf %{buildroot}%{_includedir}/lld
 
 %if %{with libcxx}
@@ -851,6 +879,13 @@
 %endif
 
 %check
+
+# LLVM test suite is written in python and has troubles with encoding if
+# python 3 is used because it is written with assumption that python will
+# default to UTF-8 encoding. However, it only does if the current locale is
+# UTF-8.
+export LANG=C.UTF-8
+
 cd build
 %ifnarch armv6hl armv7hl armv7l
 %if !0%{?qemu_user_space_build:1}
@@ -1427,7 +1462,7 @@
 %if %{with pyclang}
 %files -n python-clang
 %defattr(-,root,root)
-%{python_sitelib}/clang/
+%{python3_sitelib}/clang/
 %{_docdir}/python-clang/
 %endif
 
@@ -1468,9 +1503,9 @@
 
 %files -n python%{_sonum}-lldb
 %defattr(-,root,root)
-%{python_sitearch}/_lldb.so
-%{python_sitearch}/lldb/
-%{python_sitearch}/readline.so
+%{python3_sitearch}/_lldb.so
+%{python3_sitearch}/lldb/
+%{python3_sitearch}/readline.so
 
 %files -n liblldb%{_sonum}
 %defattr(-,root,root)

++++++ clang-add-python-3-support-to-clang-cindex.patch ++++++
>From 4a1e65760d5fdf77f6dde58df5058362f4e5b54a Mon Sep 17 00:00:00 2001
From: Jonathan Coe <jb...@me.com>
Date: Thu, 20 Apr 2017 10:11:01 +0000
Subject: [PATCH] Add Python 3 support to clang.cindex

Summary:
Introduce an interop string to convert from unicode to c-strings where needed.
Add missing conversions from _CXString to strings in function registrations.
Explicitly evaluate lists where Python 3's lazy iterators would not otherwise 
do so.

This is an improvement upon the reverted change proposed in 
https://reviews.llvm.org/D26082

Reviewers: compnerd, skalinichev, modocache, MathieuDuponchelle

Reviewed By: compnerd

Subscribers: cfe-commits

Tags: #clang-c

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@300829 
91177308-0d34-0410-b5e6-96231b3b80d8

diff --git a/bindings/python/clang/__init__.py 
b/bindings/python/clang/__init__.py
index fba49e38c9..88f3081238 100644
--- a/bindings/python/clang/__init__.py
+++ b/bindings/python/clang/__init__.py
@@ -20,13 +20,5 @@ The available modules are:
     Bindings for the Clang indexing library.
 """
 
-
-# Python 3 uses unicode for strings. The bindings, in particular the 
interaction
-# with ctypes, need modifying to handle conversions between unicode and
-# c-strings.
-import sys 
-if sys.version_info[0] != 2: 
-    raise Exception("Only Python 2 is supported.")
-
 __all__ = ['cindex']
 
diff --git a/bindings/python/clang/cindex.py b/bindings/python/clang/cindex.py
index 48fc8b13a2..0cd5617e43 100644
--- a/bindings/python/clang/cindex.py
+++ b/bindings/python/clang/cindex.py
@@ -67,6 +67,60 @@ import collections
 
 import clang.enumerations
 
+import sys
+if sys.version_info[0] == 3:
+    # Python 3 strings are unicode, translate them to/from utf8 for C-interop.
+    class c_interop_string(c_char_p):
+
+        def __init__(self, p=None):
+            if p is None:
+                p = ""
+            if isinstance(p, str):
+                p = p.encode("utf8")
+            super(c_char_p, self).__init__(p)
+
+        def __str__(self):
+            return self.value
+
+        @property
+        def value(self):
+            if super(c_char_p, self).value is None:
+                return None
+            return super(c_char_p, self).value.decode("utf8")
+
+        @classmethod
+        def from_param(cls, param):
+            if isinstance(param, str):
+                return cls(param)
+            if isinstance(param, bytes):
+                return cls(param)
+            raise TypeError("Cannot convert '{}' to 
'{}'".format(type(param).__name__, cls.__name__))
+
+        @staticmethod
+        def to_python_string(x, *args):
+            return x.value
+
+    def b(x):
+        if isinstance(x, bytes):
+            return x
+        return x.encode('utf8')
+
+    xrange = range
+
+elif sys.version_info[0] == 2:
+    # Python 2 strings are utf8 byte strings, no translation is needed for
+    # C-interop.
+    c_interop_string = c_char_p
+
+    def _to_python_string(x, *args):
+        return x
+
+    c_interop_string.to_python_string = staticmethod(_to_python_string)
+
+    def b(x):
+        return x
+
+
 # ctypes doesn't implicitly convert c_void_p to the appropriate wrapper
 # object. This is a problem, because it means that from_parameter will see an
 # integer and pass the wrong value on platforms where int != void*. Work around
@@ -157,6 +211,7 @@ class _CXString(Structure):
         assert isinstance(res, _CXString)
         return conf.lib.clang_getCString(res)
 
+
 class SourceLocation(Structure):
     """
     A SourceLocation represents a particular location within a source file.
@@ -596,7 +651,7 @@ class CursorKind(BaseEnumeration):
     @staticmethod
     def get_all_kinds():
         """Return all CursorKind enumeration instances."""
-        return filter(None, CursorKind._kinds)
+        return [x for x in CursorKind._kinds if not x is None]
 
     def is_declaration(self):
         """Test if this is a declaration kind."""
@@ -2128,7 +2183,7 @@ class Type(Structure):
         """
         Retrieve the offset of a field in the record.
         """
-        return conf.lib.clang_Type_getOffsetOf(self, c_char_p(fieldname))
+        return conf.lib.clang_Type_getOffsetOf(self, fieldname)
 
     def get_ref_qualifier(self):
         """
@@ -2239,7 +2294,7 @@ class CompletionChunk:
     def spelling(self):
         if self.__kindNumber in SpellingCache:
                 return SpellingCache[self.__kindNumber]
-        return conf.lib.clang_getCompletionChunkText(self.cs, 
self.key).spelling
+        return conf.lib.clang_getCompletionChunkText(self.cs, self.key)
 
     # We do not use @CachedProperty here, as the manual implementation is
     # apparently still significantly faster. Please profile carefully if you
@@ -2345,7 +2400,7 @@ class CompletionString(ClangObject):
         return " | ".join([str(a) for a in self]) \
                + " || Priority: " + str(self.priority) \
                + " || Availability: " + str(self.availability) \
-               + " || Brief comment: " + str(self.briefComment.spelling)
+               + " || Brief comment: " + str(self.briefComment)
 
 availabilityKinds = {
             0: CompletionChunk.Kind("Available"),
@@ -2542,7 +2597,7 @@ class TranslationUnit(ClangObject):
 
         args_array = None
         if len(args) > 0:
-            args_array = (c_char_p * len(args))(* args)
+            args_array = (c_char_p * len(args))(*[b(x) for x in args])
 
         unsaved_array = None
         if len(unsaved_files) > 0:
@@ -2551,8 +2606,8 @@ class TranslationUnit(ClangObject):
                 if hasattr(contents, "read"):
                     contents = contents.read()
 
-                unsaved_array[i].name = name
-                unsaved_array[i].contents = contents
+                unsaved_array[i].name = b(name)
+                unsaved_array[i].contents = b(contents)
                 unsaved_array[i].length = len(contents)
 
         ptr = conf.lib.clang_parseTranslationUnit(index, filename, args_array,
@@ -2797,8 +2852,8 @@ class TranslationUnit(ClangObject):
                     print(value)
                 if not isinstance(value, str):
                     raise TypeError('Unexpected unsaved file contents.')
-                unsaved_files_array[i].name = name
-                unsaved_files_array[i].contents = value
+                unsaved_files_array[i].name = b(name)
+                unsaved_files_array[i].contents = b(value)
                 unsaved_files_array[i].length = len(value)
         ptr = conf.lib.clang_codeCompleteAt(self, path, line, column,
                 unsaved_files_array, len(unsaved_files), options)
@@ -2833,7 +2888,7 @@ class File(ClangObject):
     @property
     def name(self):
         """Return the complete file and path name of the file."""
-        return conf.lib.clang_getCString(conf.lib.clang_getFileName(self))
+        return conf.lib.clang_getFileName(self)
 
     @property
     def time(self):
@@ -3064,7 +3119,7 @@ functionList = [
    [c_object_p]),
 
   ("clang_CompilationDatabase_fromDirectory",
-   [c_char_p, POINTER(c_uint)],
+   [c_interop_string, POINTER(c_uint)],
    c_object_p,
    CompilationDatabase.from_result),
 
@@ -3074,7 +3129,7 @@ functionList = [
    CompileCommands.from_result),
 
   ("clang_CompilationDatabase_getCompileCommands",
-   [c_object_p, c_char_p],
+   [c_object_p, c_interop_string],
    c_object_p,
    CompileCommands.from_result),
 
@@ -3109,7 +3164,7 @@ functionList = [
    c_uint),
 
   ("clang_codeCompleteAt",
-   [TranslationUnit, c_char_p, c_int, c_int, c_void_p, c_int, c_int],
+   [TranslationUnit, c_interop_string, c_int, c_int, c_void_p, c_int, c_int],
    POINTER(CCRStructure)),
 
   ("clang_codeCompleteGetDiagnostic",
@@ -3125,7 +3180,7 @@ functionList = [
    c_object_p),
 
   ("clang_createTranslationUnit",
-   [Index, c_char_p],
+   [Index, c_interop_string],
    c_object_p),
 
   ("clang_CXXConstructor_isConvertingConstructor",
@@ -3215,7 +3270,8 @@ functionList = [
 
   ("clang_formatDiagnostic",
    [Diagnostic, c_uint],
-   _CXString),
+   _CXString,
+   _CXString.from_result),
 
   ("clang_getArgType",
    [Type, c_uint],
@@ -3255,7 +3311,8 @@ functionList = [
 
   ("clang_getCompletionBriefComment",
    [c_void_p],
-   _CXString),
+   _CXString,
+   _CXString.from_result),
 
   ("clang_getCompletionChunkCompletionString",
    [c_void_p, c_int],
@@ -3267,7 +3324,8 @@ functionList = [
 
   ("clang_getCompletionChunkText",
    [c_void_p, c_int],
-   _CXString),
+   _CXString,
+   _CXString.from_result),
 
   ("clang_getCompletionPriority",
    [c_void_p],
@@ -3275,7 +3333,8 @@ functionList = [
 
   ("clang_getCString",
    [_CXString],
-   c_char_p),
+   c_interop_string,
+   c_interop_string.to_python_string),
 
   ("clang_getCursor",
    [TranslationUnit, SourceLocation],
@@ -3422,12 +3481,13 @@ functionList = [
    Type.from_result),
 
   ("clang_getFile",
-   [TranslationUnit, c_char_p],
+   [TranslationUnit, c_interop_string],
    c_object_p),
 
   ("clang_getFileName",
    [File],
-   _CXString), # TODO go through _CXString.from_result?
+   _CXString,
+   _CXString.from_result),
 
   ("clang_getFileTime",
    [File],
@@ -3551,7 +3611,8 @@ functionList = [
 
   ("clang_getTUResourceUsageName",
    [c_uint],
-   c_char_p),
+   c_interop_string,
+   c_interop_string.to_python_string),
 
   ("clang_getTypeDeclaration",
    [Type],
@@ -3646,7 +3707,7 @@ functionList = [
    bool),
 
   ("clang_parseTranslationUnit",
-   [Index, c_char_p, c_void_p, c_int, c_void_p, c_int, c_int],
+   [Index, c_interop_string, c_void_p, c_int, c_void_p, c_int, c_int],
    c_object_p),
 
   ("clang_reparseTranslationUnit",
@@ -3654,7 +3715,7 @@ functionList = [
    c_int),
 
   ("clang_saveTranslationUnit",
-   [TranslationUnit, c_char_p, c_uint],
+   [TranslationUnit, c_interop_string, c_uint],
    c_int),
 
   ("clang_tokenize",
@@ -3726,7 +3787,7 @@ functionList = [
    Type.from_result),
 
   ("clang_Type_getOffsetOf",
-   [Type, c_char_p],
+   [Type, c_interop_string],
    c_longlong),
 
   ("clang_Type_getSizeOf",
@@ -3785,7 +3846,8 @@ def register_functions(lib, ignore_errors):
     def register(item):
         return register_function(lib, item, ignore_errors)
 
-    map(register, functionList)
+    for f in functionList:
+        register(f)
 
 class Config:
     library_path = None
diff --git a/bindings/python/tests/cindex/test_translation_unit.py 
b/bindings/python/tests/cindex/test_translation_unit.py
index be6cd671ae..65d1ee02ff 100644
--- a/bindings/python/tests/cindex/test_translation_unit.py
+++ b/bindings/python/tests/cindex/test_translation_unit.py
@@ -59,9 +59,12 @@ int SOME_DEFINE;
     assert spellings[-1] == 'y'
 
 def test_unsaved_files_2():
-    import StringIO
+    try:
+        from StringIO import StringIO
+    except:
+        from io import StringIO
     tu = TranslationUnit.from_source('fake.c', unsaved_files = [
-            ('fake.c', StringIO.StringIO('int x;'))])
+            ('fake.c', StringIO('int x;'))])
     spellings = [c.spelling for c in tu.cursor.get_children()]
     assert spellings[-1] == 'x'
 
++++++ clang-bindings-allow-null-strings-in-python-3.patch ++++++
>From a6d3ef724655a64ac137945615d3ff002c4f7993 Mon Sep 17 00:00:00 2001
From: Masud Rahman <l...@masudrahman.com>
Date: Sat, 21 Oct 2017 16:13:41 +0000
Subject: [PATCH] [bindings] allow null strings in Python 3

Some API calls accept 'NULL' instead of a char array (e.g. the second
argument to 'clang_ParseTranslationUnit').  For Python 3 compatibility,
all strings are passed through 'c_interop_string' which expects to
receive only 'bytes' or 'str' objects.  This change extends this
behavior to additionally allow 'None' to be supplied.

A test case was added which breaks in Python 3, and is fixed by this
change.  All the test cases pass in both, Python 2 and Python 3.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@316264 
91177308-0d34-0410-b5e6-96231b3b80d8

diff --git a/bindings/python/clang/cindex.py b/bindings/python/clang/cindex.py
index 1dc1760e4f..d72dd14ef9 100644
--- a/bindings/python/clang/cindex.py
+++ b/bindings/python/clang/cindex.py
@@ -94,6 +94,9 @@ if sys.version_info[0] == 3:
                 return cls(param)
             if isinstance(param, bytes):
                 return cls(param)
+            if param is None:
+                # Support passing null to C functions expecting char arrays
+                return None
             raise TypeError("Cannot convert '{}' to 
'{}'".format(type(param).__name__, cls.__name__))
 
         @staticmethod
diff --git a/bindings/python/tests/cindex/test_index.py 
b/bindings/python/tests/cindex/test_index.py
index dc173f04d2..ef76692a52 100644
--- a/bindings/python/tests/cindex/test_index.py
+++ b/bindings/python/tests/cindex/test_index.py
@@ -13,3 +13,5 @@ def test_parse():
     assert isinstance(index, Index)
     tu = index.parse(os.path.join(kInputsDir, 'hello.cpp'))
     assert isinstance(tu, TranslationUnit)
+    tu = index.parse(None, ['-c', os.path.join(kInputsDir, 'hello.cpp')])
+    assert isinstance(tu, TranslationUnit)
++++++ libcxx-fix-python3-syntax-error.patch ++++++
>From 2b495bd9d72a3905b347ee0848c62ac80a23cbc9 Mon Sep 17 00:00:00 2001
From: Eric Fiselier <e...@efcs.ca>
Date: Tue, 7 Feb 2017 21:21:17 +0000
Subject: [PATCH] fix python3 syntax error

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@294355 
91177308-0d34-0410-b5e6-96231b3b80d8
---
 test/support/filesystem_dynamic_test_helper.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/test/support/filesystem_dynamic_test_helper.py 
b/test/support/filesystem_dynamic_test_helper.py
index 1f48c9527..d2b2810d0 100644
--- a/test/support/filesystem_dynamic_test_helper.py
+++ b/test/support/filesystem_dynamic_test_helper.py
@@ -75,7 +75,7 @@ def create_fifo(source):
 
 
 def create_socket(source):
-    mode = 0600|stat.S_IFSOCK
+    mode = 0o600 | stat.S_IFSOCK
     os.mknod(sanitize(source), mode)
 
 
-- 
2.13.6

++++++ llvm-do-not-install-static-libraries.patch ++++++
This has similar effect as simply deleting the static libraries which we don't
want after installation. By not copying them in the first place we reduce the
disk usage during installation.

Index: llvm-4.0.1.src/cmake/modules/AddLLVM.cmake
===================================================================
--- llvm-4.0.1.src.orig/cmake/modules/AddLLVM.cmake
+++ llvm-4.0.1.src/cmake/modules/AddLLVM.cmake
@@ -595,10 +595,18 @@ macro(add_llvm_library name)
         set_property(GLOBAL PROPERTY LLVM_HAS_EXPORTS True)
       endif()
 
-      install(TARGETS ${name}
-              ${export_to_llvmexports}
-              ${install_type} DESTINATION ${install_dir}
-              COMPONENT ${name})
+      if(ARG_SHARED)
+        install(TARGETS ${name}
+                ${export_to_llvmexports}
+                ${install_type} DESTINATION ${install_dir}
+                COMPONENT ${name})
+      else()
+        install(TARGETS ${name}
+                ${export_to_llvmexports}
+                ${install_type} DESTINATION ${install_dir}
+                COMPONENT ${name}
+                EXCLUDE_FROM_ALL)
+      endif()
 
       if (NOT CMAKE_CONFIGURATION_TYPES)
         add_custom_target(install-${name}
Index: llvm-4.0.1.src/lld-4.0.1.src/cmake/modules/AddLLD.cmake
===================================================================
--- llvm-4.0.1.src.orig/lld-4.0.1.src/cmake/modules/AddLLD.cmake
+++ llvm-4.0.1.src/lld-4.0.1.src/cmake/modules/AddLLD.cmake
@@ -17,13 +17,6 @@ macro(add_lld_library name)
       set_property(GLOBAL PROPERTY LLD_HAS_EXPORTS True)
     endif()
 
-    install(TARGETS ${name}
-      COMPONENT ${name}
-      ${export_to_lldtargets}
-      LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
-      ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}
-      RUNTIME DESTINATION bin)
-
     if (${ARG_SHARED} AND NOT CMAKE_CONFIGURATION_TYPES)
       add_custom_target(install-${name}
         DEPENDS ${name}
Index: llvm-4.0.1.src/lldb-4.0.1.src/cmake/modules/AddLLDB.cmake
===================================================================
--- llvm-4.0.1.src.orig/lldb-4.0.1.src/cmake/modules/AddLLDB.cmake
+++ llvm-4.0.1.src/lldb-4.0.1.src/cmake/modules/AddLLDB.cmake
@@ -88,7 +88,8 @@ function(add_lldb_library name)
         install(TARGETS ${name}
           COMPONENT ${name}
           LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
-          ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX})
+          ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}
+          EXCLUDE_FROM_ALL)
       endif()
       if (NOT CMAKE_CONFIGURATION_TYPES)
         add_custom_target(install-${name}
++++++ llvm-lit-Make-util.executeCommand-python3-friendly.patch ++++++
>From 38777f9b2662fb2b24c58345c440d80ae4e5f810 Mon Sep 17 00:00:00 2001
From: Eric Fiselier <e...@efcs.ca>
Date: Wed, 18 Jan 2017 00:12:41 +0000
Subject: [PATCH] [LIT] Make util.executeCommand python3 friendly

Summary: The parameter `input` to `subprocess.Popen.communicate(...)` must be 
an object of type `bytes` . This is strictly enforced in python3. This patch 
(1) allows `to_bytes` to be safely called redundantly. (2) Explicitly convert 
`input` within `executeCommand`. This allows for usages like 
`executeCommand(['clang++', '-'], input='int main() {}\n')`.

Reviewers: ddunbar, BinaryKhaos, modocache, dim, EricWF

Reviewed By: EricWF

Subscribers: llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292308 
91177308-0d34-0410-b5e6-96231b3b80d8
---
 utils/lit/lit/util.py | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/utils/lit/lit/util.py b/utils/lit/lit/util.py
index be37998c6f1..104e9dac464 100644
--- a/utils/lit/lit/util.py
+++ b/utils/lit/lit/util.py
@@ -10,6 +10,8 @@ import threading
 
 def to_bytes(str):
     # Encode to UTF-8 to get binary data.
+    if isinstance(str, bytes):
+        return str
     return str.encode('utf-8')
 
 def to_string(bytes):
@@ -200,6 +202,8 @@ def executeCommand(command, cwd=None, env=None, input=None, 
timeout=0):
         If the timeout is hit an ``ExecuteCommandTimeoutException``
         is raised.
     """
+    if input is not None:
+        input = to_bytes(input)
     p = subprocess.Popen(command, cwd=cwd,
                          stdin=subprocess.PIPE,
                          stdout=subprocess.PIPE,
-- 
2.13.6

++++++ llvm-lit-Re-apply-Fix-some-convoluted-logic-around-Unicod.patch ++++++
>From d1176ce9c6a96426b64e22e7a4777150a904b33b Mon Sep 17 00:00:00 2001
From: "David L. Jones" <d...@google.com>
Date: Thu, 29 Jun 2017 04:37:35 +0000
Subject: [PATCH] [lit] Re-apply: Fix some convoluted logic around Unicode
 encoding, and de-duplicate across modules that used it.

(Take 2: this patch re-applies r306625, which was reverted in r306629. This
patch includes only trivial fixes.)

In Python2 and Python3, the various (non-)?Unicode string types are sort of
spaghetti. Python2 has unicode support tacked on via the 'unicode' type, which
is distinct from 'str' (which are bytes). Python3 takes the "unicode-everywhere"
approach, with 'str' representing a Unicode string.

Both have a 'bytes' type. In Python3, it is the only way to represent raw bytes.
However, in Python2, 'bytes' is an alias for 'str'. This leads to interesting
problems when an interface requires a precise type, but has to run under both
Python2 and Python3.

The previous logic appeared to be correct in all cases, but went through more
layers of indirection than necessary. This change does the necessary conversions
in one shot, with documentation about which paths might be taken in Python2 or
Python3.

Changes from r306625: some tests just print binary outputs, so in those cases,
fall back to str() in Python3. For googletests, add one missing call to
to_string().

(Tested by verifying the visible breakage with Python3. Verified that everything
works in py2 and py3.)

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@306643 
91177308-0d34-0410-b5e6-96231b3b80d8
---
 utils/lit/lit/formats/googletest.py | 31 +++++++------
 utils/lit/lit/util.py               | 89 ++++++++++++++++++++++---------------
 2 files changed, 69 insertions(+), 51 deletions(-)

diff --git a/utils/lit/lit/formats/googletest.py 
b/utils/lit/lit/formats/googletest.py
index 29a92c4e960..f4efe2cf004 100644
--- a/utils/lit/lit/formats/googletest.py
+++ b/utils/lit/lit/formats/googletest.py
@@ -30,19 +30,24 @@ class GoogleTest(TestFormat):
           localConfig: TestingConfig instance"""
 
         try:
-            lines = lit.util.capture([path, '--gtest_list_tests'],
-                                     env=localConfig.environment)
-            if kIsWindows:
-              lines = lines.replace('\r', '')
-            lines = lines.split('\n')
-        except Exception as exc:
-            out = exc.output if isinstance(exc, subprocess.CalledProcessError) 
else ''
-            litConfig.warning("unable to discover google-tests in %r: %s. 
Process output: %s"
-                              % (path, sys.exc_info()[1], out))
+            output = subprocess.check_output([path, '--gtest_list_tests'],
+                                             env=localConfig.environment)
+        except subprocess.CalledProcessError as exc:
+            litConfig.warning(
+                "unable to discover google-tests in %r: %s. Process output: %s"
+                % (path, sys.exc_info()[1], exc.output))
             raise StopIteration
 
         nested_tests = []
-        for ln in lines:
+        for ln in output.splitlines(False):  # Don't keep newlines.
+            ln = lit.util.to_string(ln)
+
+            if 'Running main() from gtest_main.cc' in ln:
+                # Upstream googletest prints this to stdout prior to running
+                # tests. LLVM removed that print statement in r61540, but we
+                # handle it here in case upstream googletest is being used.
+                continue
+
             # The test name list includes trailing comments beginning with
             # a '#' on some lines, so skip those. We don't support test names
             # that use escaping to embed '#' into their name as the names come
@@ -52,12 +57,6 @@ class GoogleTest(TestFormat):
             if not ln.lstrip():
                 continue
 
-            if 'Running main() from gtest_main.cc' in ln:
-                # Upstream googletest prints this to stdout prior to running
-                # tests. LLVM removed that print statement in r61540, but we
-                # handle it here in case upstream googletest is being used.
-                continue
-
             index = 0
             while ln[index*2:index*2+2] == '  ':
                 index += 1
diff --git a/utils/lit/lit/util.py b/utils/lit/lit/util.py
index 8991588a868..bc1a1a4bab0 100644
--- a/utils/lit/lit/util.py
+++ b/utils/lit/lit/util.py
@@ -8,24 +8,57 @@ import subprocess
 import sys
 import threading
 
-def to_bytes(str):
-    # Encode to UTF-8 to get binary data.
-    if isinstance(str, bytes):
-        return str
-    return str.encode('utf-8')
-
-def to_string(bytes):
-    if isinstance(bytes, str):
-        return bytes
-    return to_bytes(bytes)
-
-def convert_string(bytes):
+def to_bytes(s):
+    """Return the parameter as type 'bytes', possibly encoding it.
+
+    In Python2, the 'bytes' type is the same as 'str'. In Python3, they are
+    distinct.
+    """
+    if isinstance(s, bytes):
+        # In Python2, this branch is taken for both 'str' and 'bytes'.
+        # In Python3, this branch is taken only for 'bytes'.
+        return s
+    # In Python2, 's' is a 'unicode' object.
+    # In Python3, 's' is a 'str' object.
+    # Encode to UTF-8 to get 'bytes' data.
+    return s.encode('utf-8')
+
+def to_string(b):
+    """Return the parameter as type 'str', possibly encoding it.
+
+    In Python2, the 'str' type is the same as 'bytes'. In Python3, the
+    'str' type is (essentially) Python2's 'unicode' type, and 'bytes' is
+    distinct.
+    """
+    if isinstance(b, str):
+        # In Python2, this branch is taken for types 'str' and 'bytes'.
+        # In Python3, this branch is taken only for 'str'.
+        return b
+    if isinstance(b, bytes):
+        # In Python2, this branch is never taken ('bytes' is handled as 'str').
+        # In Python3, this is true only for 'bytes'.
+        try:
+            return b.decode('utf-8')
+        except UnicodeDecodeError:
+            # If the value is not valid Unicode, return the default
+            # repr-line encoding.
+            return str(b)
+
+    # By this point, here's what we *don't* have:
+    #
+    #  - In Python2:
+    #    - 'str' or 'bytes' (1st branch above)
+    #  - In Python3:
+    #    - 'str' (1st branch above)
+    #    - 'bytes' (2nd branch above)
+    #
+    # The last type we might expect is the Python2 'unicode' type. There is no
+    # 'unicode' type in Python3 (all the Python3 cases were already handled). 
In
+    # order to get a 'str' object, we need to encode the 'unicode' object.
     try:
-        return to_string(bytes.decode('utf-8'))
-    except AttributeError: # 'str' object has no attribute 'decode'.
-        return str(bytes)
-    except UnicodeError:
-        return str(bytes)
+        return b.encode('utf-8')
+    except AttributeError:
+        raise TypeError('not sure how to convert %s to %s' % (type(b), str))
 
 def detectCPUs():
     """
@@ -39,7 +72,8 @@ def detectCPUs():
             if isinstance(ncpus, int) and ncpus > 0:
                 return ncpus
         else: # OSX:
-            return int(capture(['sysctl', '-n', 'hw.ncpu']))
+            return int(subprocess.check_output(['sysctl', '-n', 'hw.ncpu'],
+                                               stderr=subprocess.STDOUT))
     # Windows:
     if "NUMBER_OF_PROCESSORS" in os.environ:
         ncpus = int(os.environ["NUMBER_OF_PROCESSORS"])
@@ -67,21 +101,6 @@ def mkdir_p(path):
         if e.errno != errno.EEXIST:
             raise
 
-def capture(args, env=None):
-    """capture(command) - Run the given command (or argv list) in a shell and
-    return the standard output. Raises a CalledProcessError if the command
-    exits with a non-zero status."""
-    p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
-                         env=env)
-    out, err = p.communicate()
-    out = convert_string(out)
-    err = convert_string(err)
-    if p.returncode != 0:
-        raise subprocess.CalledProcessError(cmd=args,
-                                            returncode=p.returncode,
-                                            output="{}\n{}".format(out, err))
-    return out
-
 def which(command, paths = None):
     """which(command, [paths]) - Look up the given command in the paths string
     (or the PATH environment variable, if unspecified)."""
@@ -233,8 +252,8 @@ def executeCommand(command, cwd=None, env=None, input=None, 
timeout=0):
             timerObject.cancel()
 
     # Ensure the resulting output is always of string type.
-    out = convert_string(out)
-    err = convert_string(err)
+    out = to_string(out)
+    err = to_string(err)
 
     if hitTimeOut[0]:
         raise ExecuteCommandTimeoutException(
-- 
2.13.6


Reply via email to