File remove-abseil.patch of Package python-dm-tree

From edcb42955ad1970d0cb4924775323433ca88ce5d Mon Sep 17 00:00:00 2001
From: Iurii Kemaev <iukemaev@google.com>
Date: Wed, 16 Jun 2021 01:45:45 -0700
Subject: [PATCH] Remove abseil dependencies.

PiperOrigin-RevId: 379669838
---
 tree/BUILD   |  2 --
 tree/tree.cc | 74 +++++++++++++++++++++++++++++++++-------------------
 2 files changed, 47 insertions(+), 29 deletions(-)

Index: dm-tree-0.1.8/tree/tree.cc
===================================================================
--- dm-tree-0.1.8.orig/tree/tree.cc
+++ dm-tree-0.1.8/tree/tree.cc
@@ -16,12 +16,11 @@ limitations under the License.
 
 #include <functional>
 #include <memory>
+#include <sstream>
 #include <string>
 #include <unordered_map>
 
 // logging
-#include "absl/strings/str_cat.h"
-#include "absl/strings/string_view.h"
 #include <pybind11/pybind11.h>
 
 #ifdef LOG
@@ -55,11 +54,26 @@ bool IsString(PyObject* o) {
   return PyBytes_Check(o) || PyByteArray_Check(o) || PyUnicode_Check(o);
 }
 
+void AddToStringStream(std::ostringstream&) {}
+
+template <typename T, typename... Args>
+void AddToStringStream(std::ostringstream& sstream, T&& arg, Args&&... args) {
+  sstream << std::forward<T>(arg);
+  AddToStringStream(sstream, std::forward<Args>(args)...);
+}
+
+template <typename... Args>
+std::string StrCat(Args&&... args) {
+  std::ostringstream sstream;
+  AddToStringStream(sstream, std::forward<Args>(args)...);
+  return sstream.str();
+}
+
 // Equivalent to Python's 'o.__class__.__name__'
 // Note that '__class__' attribute is set only in new-style classes.
 // A lot of tensorflow code uses __class__ without checks, so it seems like
 // we only support new-style classes.
-absl::string_view GetClassName(PyObject* o) {
+std::string GetClassName(PyObject* o) {
   // __class__ is equivalent to type() for new style classes.
   // type() is equivalent to PyObject_Type()
   // (https://docs.python.org/3.5/c-api/object.html#c.PyObject_Type)
@@ -69,10 +83,10 @@ absl::string_view GetClassName(PyObject*
 
   // __name__ is the value of `tp_name` after the last '.'
   // (https://docs.python.org/2/c-api/typeobj.html#c.PyTypeObject.tp_name)
-  absl::string_view name(type->tp_name);
+  std::string name(type->tp_name);
   size_t pos = name.rfind('.');
-  if (pos != absl::string_view::npos) {
-    name.remove_prefix(pos + 1);
+  if (pos != std::string::npos) {
+    name.erase(0, pos + 1);
   }
   return name;
 }
@@ -85,7 +99,7 @@ std::string PyObjectToString(PyObject* o
   if (str) {
     std::string s(PyUnicode_AsUTF8(str));
     Py_DECREF(str);
-    return absl::StrCat("type=", GetClassName(o), " str=", s);
+    return StrCat("type=", GetClassName(o), " str=", s);
   } else {
     return "<failed to execute str() on object>";
   }
@@ -436,7 +450,7 @@ void SetDifferentKeysError(PyObject* dic
     return;
   }
   *is_type_error = false;
-  *error_msg = absl::StrCat(
+  *error_msg = StrCat(
       "The two dictionaries don't have the same set of keys. "
       "First structure has keys ",
       PyObjectToString(k1.get()), ", while second structure has keys ",
@@ -465,9 +479,9 @@ bool AssertSameStructureHelper(PyObject*
     std::string non_seq_str =
         is_seq1 ? PyObjectToString(o2) : PyObjectToString(o1);
     *is_type_error = false;
-    *error_msg = absl::StrCat("Substructure \"", seq_str,
-                              "\" is a sequence, while substructure \"",
-                              non_seq_str, "\" is not");
+    *error_msg = StrCat("Substructure \"", seq_str,
+                        "\" is a sequence, while substructure \"", non_seq_str,
+                        "\" is not");
     return true;
   }
 
@@ -510,7 +524,7 @@ bool AssertSameStructureHelper(PyObject*
       Py_DECREF(same_tuples);
       if (not_same_tuples) {
         *is_type_error = true;
-        *error_msg = absl::StrCat(
+        *error_msg = StrCat(
             "The two namedtuples don't have the same sequence type. "
             "First structure ",
             PyObjectToString(o1), " has type ", type1->tp_name,
@@ -527,7 +541,7 @@ bool AssertSameStructureHelper(PyObject*
                   and dict compare equal. */
                && !(IsMappingHelper(o1) && IsMappingHelper(o2))) {
       *is_type_error = true;
-      *error_msg = absl::StrCat(
+      *error_msg = StrCat(
           "The two namedtuples don't have the same sequence type. "
           "First structure ",
           PyObjectToString(o1), " has type ", type1->tp_name,
@@ -593,10 +607,10 @@ bool AssertSameStructureHelper(PyObject*
       return true;
     } else {
       *is_type_error = false;
-      *error_msg = absl::StrCat(
-          "The two structures don't have the same number of elements. ",
-          "First structure: ", PyObjectToString(o1),
-          ". Second structure: ", PyObjectToString(o2));
+      *error_msg =
+          StrCat("The two structures don't have the same number of elements. ",
+                 "First structure: ", PyObjectToString(o1),
+                 ". Second structure: ", PyObjectToString(o2));
       return true;
     }
   }
@@ -692,7 +706,7 @@ PyObject* SameNamedtuples(PyObject* o1,
     Py_RETURN_FALSE;
   }
 
-  if (GetClassName(o1).compare(GetClassName(o2)) == 0) {
+  if (GetClassName(o1) == GetClassName(o2)) {
     Py_RETURN_TRUE;
   } else {
     Py_RETURN_FALSE;
@@ -711,10 +725,10 @@ void AssertSameStructure(PyObject* o1, P
   if (!error_msg.empty()) {
     PyErr_SetString(
         is_type_error ? PyExc_TypeError : PyExc_ValueError,
-        absl::StrCat(
-            "The two structures don't have the same nested structure.\n\n",
-            "First structure: ", PyObjectToString(o1), "\n\nSecond structure: ",
-            PyObjectToString(o2), "\n\nMore specifically: ", error_msg)
+        StrCat("The two structures don't have the same nested structure.\n\n",
+               "First structure: ", PyObjectToString(o1),
+               "\n\nSecond structure: ", PyObjectToString(o2),
+               "\n\nMore specifically: ", error_msg)
             .c_str());
   }
 }
Index: dm-tree-0.1.8/tree/CMakeLists.txt
===================================================================
--- dm-tree-0.1.8.orig/tree/CMakeLists.txt
+++ dm-tree-0.1.8/tree/CMakeLists.txt
@@ -64,55 +64,8 @@ if(NOT pybind11_POPULATED)
     include_directories(${pybind11_INCLUDE_DIR})
 endif()
 
-# Needed to disable Abseil tests.
-set (BUILD_TESTING OFF)
-
-# Include abseil-cpp.
-set(ABSEIL_VER 20210324.2)
-include(ExternalProject)
-set(ABSEIL_CMAKE_ARGS
-    "-DCMAKE_INSTALL_PREFIX=${CMAKE_SOURCE_DIR}/abseil-cpp"
-    "-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}"
-    "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"
-    "-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}"
-    "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
-    "-DCMAKE_POSITION_INDEPENDENT_CODE=${CMAKE_POSITION_INDEPENDENT_CODE}"
-    "-DLIBRARY_OUTPUT_PATH=${CMAKE_SOURCE_DIR}/abseil-cpp/lib")
-if(DEFINED CMAKE_OSX_ARCHITECTURES)
-    set(ABSEIL_CMAKE_ARGS
-        ${ABSEIL_CMAKE_ARGS}
-        "-DCMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES}")
-endif()
-ExternalProject_Add(abseil-cpp
-  GIT_REPOSITORY    https://github.com/abseil/abseil-cpp.git
-  GIT_TAG           ${ABSEIL_VER}
-  PREFIX            ${CMAKE_SOURCE_DIR}/abseil-cpp
-  CMAKE_ARGS        ${ABSEIL_CMAKE_ARGS}
-)
-ExternalProject_Get_Property(abseil-cpp install_dir)
-set(abseil_install_dir ${install_dir})
-include_directories (${abseil_install_dir}/include)
-
-
 # Define pybind11 tree module.
 pybind11_add_module(_tree tree.h tree.cc)
-add_dependencies(_tree abseil-cpp)
-
-if (WIN32 OR MSVC)
-    set(ABSEIL_LIB_PREF "absl")
-    set(LIB_SUFF "lib")
-else()
-    set(ABSEIL_LIB_PREF "libabsl")
-    set(LIB_SUFF "a")
-endif()
-
-# Link abseil static libs.
-# We don't use find_library here to force cmake to build abseil before linking.
-set(ABSEIL_LIBS int128 raw_hash_set raw_logging_internal strings throw_delegate)
-foreach(ABSEIL_LIB IN LISTS ABSEIL_LIBS)
-  target_link_libraries(_tree PRIVATE
-      "${abseil_install_dir}/lib/${ABSEIL_LIB_PREF}_${ABSEIL_LIB}.${LIB_SUFF}")
-endforeach()
 
 # Make the module private to tree package.
 set_target_properties(_tree PROPERTIES OUTPUT_NAME tree/_tree)
openSUSE Build Service is sponsored by