From 8222f988799e30518433fccfc9dd4c6f53d69efe Mon Sep 17 00:00:00 2001
From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
Date: Tue, 26 Feb 2019 14:15:48 +0300
Subject: [PATCH] Extract 'coll' library from 'core'

Core is supposed to be the most basic library, providing only
really common features used everywhere like fiber, diag, memory,
logging. Which can't be said about collations - they are used
only by high level things - SQL, Lua utf8, comparators.

Collations are built now as 'lib/coll' library.

The patch is not necessary for anything, but it is a right thing
to do, while some activity is happening there.
---
 src/CMakeLists.txt                | 2 +-
 src/box/coll_id.c                 | 2 +-
 src/box/coll_id_def.h             | 2 +-
 src/box/sql/expr.c                | 2 +-
 src/box/sql/fk_constraint.c       | 2 +-
 src/box/sql/func.c                | 2 +-
 src/box/sql/select.c              | 2 +-
 src/box/sql/vdbeaux.c             | 2 +-
 src/box/sql/where.c               | 2 +-
 src/box/sql/whereexpr.c           | 2 +-
 src/box/tuple_compare.cc          | 2 +-
 src/box/tuple_hash.cc             | 2 +-
 src/lib/CMakeLists.txt            | 1 +
 src/lib/coll/CMakeLists.txt       | 2 ++
 src/lib/{core => coll}/coll.c     | 0
 src/lib/{core => coll}/coll.h     | 0
 src/lib/{core => coll}/coll_def.c | 0
 src/lib/{core => coll}/coll_def.h | 0
 src/lib/core/CMakeLists.txt       | 2 --
 src/lua/utf8.c                    | 2 +-
 src/main.cc                       | 2 +-
 test/unit/CMakeLists.txt          | 2 +-
 test/unit/coll.cpp                | 4 ++--
 23 files changed, 20 insertions(+), 19 deletions(-)
 create mode 100644 src/lib/coll/CMakeLists.txt
 rename src/lib/{core => coll}/coll.c (100%)
 rename src/lib/{core => coll}/coll.h (100%)
 rename src/lib/{core => coll}/coll_def.c (100%)
 rename src/lib/{core => coll}/coll_def.h (100%)

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index b115e14c9a..481618f207 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -162,7 +162,7 @@ endif()
 
 set_source_files_compile_flags(${server_sources})
 add_library(server STATIC ${server_sources})
-target_link_libraries(server core http_parser bit uri uuid ${ICU_LIBRARIES})
+target_link_libraries(server core coll http_parser bit uri uuid)
 
 # Rule of thumb: if exporting a symbol from a static library, list the
 # library here.
diff --git a/src/box/coll_id.c b/src/box/coll_id.c
index b56c749617..5abeaed21f 100644
--- a/src/box/coll_id.c
+++ b/src/box/coll_id.c
@@ -30,7 +30,7 @@
  */
 #include "coll_id.h"
 #include "coll_id_def.h"
-#include "coll.h"
+#include "coll/coll.h"
 #include "error.h"
 #include "diag.h"
 
diff --git a/src/box/coll_id_def.h b/src/box/coll_id_def.h
index 489280c00b..8592092746 100644
--- a/src/box/coll_id_def.h
+++ b/src/box/coll_id_def.h
@@ -33,7 +33,7 @@
 
 #include <stddef.h>
 #include <stdint.h>
-#include <coll_def.h>
+#include "coll/coll_def.h"
 #include "opt_def.h"
 
 /** Collation identifier definition. */
diff --git a/src/box/sql/expr.c b/src/box/sql/expr.c
index c914cfb68a..a75f237563 100644
--- a/src/box/sql/expr.c
+++ b/src/box/sql/expr.c
@@ -34,7 +34,7 @@
  * for generating VDBE code that evaluates expressions in sql.
  */
 #include "box/coll_id_cache.h"
-#include "coll.h"
+#include "coll/coll.h"
 #include "sqlInt.h"
 #include "tarantoolInt.h"
 #include "box/schema.h"
diff --git a/src/box/sql/fk_constraint.c b/src/box/sql/fk_constraint.c
index 93c01a0e7b..4066b1cf1c 100644
--- a/src/box/sql/fk_constraint.c
+++ b/src/box/sql/fk_constraint.c
@@ -33,7 +33,7 @@
  * This file contains code used by the compiler to add foreign key
  * support to compiled SQL statements.
  */
-#include "coll.h"
+#include "coll/coll.h"
 #include "sqlInt.h"
 #include "box/fk_constraint.h"
 #include "box/schema.h"
diff --git a/src/box/sql/func.c b/src/box/sql/func.c
index 69571e984d..267a18e089 100644
--- a/src/box/sql/func.c
+++ b/src/box/sql/func.c
@@ -37,7 +37,7 @@
 #include "sqlInt.h"
 #include "vdbeInt.h"
 #include "version.h"
-#include "coll.h"
+#include "coll/coll.h"
 #include <unicode/ustring.h>
 #include <unicode/ucasemap.h>
 #include <unicode/ucnv.h>
diff --git a/src/box/sql/select.c b/src/box/sql/select.c
index d9c63377d0..782da1f7cb 100644
--- a/src/box/sql/select.c
+++ b/src/box/sql/select.c
@@ -33,7 +33,7 @@
  * This file contains C code routines that are called by the parser
  * to handle SELECT statements in sql.
  */
-#include "coll.h"
+#include "coll/coll.h"
 #include "sqlInt.h"
 #include "tarantoolInt.h"
 #include "vdbeInt.h"
diff --git a/src/box/sql/vdbeaux.c b/src/box/sql/vdbeaux.c
index 071609d834..0cc3c14874 100644
--- a/src/box/sql/vdbeaux.c
+++ b/src/box/sql/vdbeaux.c
@@ -34,7 +34,7 @@
  * a VDBE (or an "sql_stmt" as it is known to the outside world.)
  */
 #include "fiber.h"
-#include "coll.h"
+#include "coll/coll.h"
 #include "box/session.h"
 #include "box/schema.h"
 #include "box/tuple_format.h"
diff --git a/src/box/sql/where.c b/src/box/sql/where.c
index 5345ddd444..5a3c9be1a5 100644
--- a/src/box/sql/where.c
+++ b/src/box/sql/where.c
@@ -37,7 +37,7 @@
  * so is applicable.  Because this module is responsible for selecting
  * indices, you might also think of this module as the "query optimizer".
  */
-#include "coll.h"
+#include "coll/coll.h"
 #include "sqlInt.h"
 #include "tarantoolInt.h"
 #include "vdbeInt.h"
diff --git a/src/box/sql/whereexpr.c b/src/box/sql/whereexpr.c
index fa906e3055..6df28ad8ad 100644
--- a/src/box/sql/whereexpr.c
+++ b/src/box/sql/whereexpr.c
@@ -38,7 +38,7 @@
  * analyzing Expr objects in the WHERE clause.
  */
 #include "box/coll_id_cache.h"
-#include "coll.h"
+#include "coll/coll.h"
 #include "sqlInt.h"
 #include "whereInt.h"
 
diff --git a/src/box/tuple_compare.cc b/src/box/tuple_compare.cc
index cbdd150b8f..cf4519ccbf 100644
--- a/src/box/tuple_compare.cc
+++ b/src/box/tuple_compare.cc
@@ -30,7 +30,7 @@
  */
 #include "tuple_compare.h"
 #include "tuple.h"
-#include "coll.h"
+#include "coll/coll.h"
 #include "trivia/util.h" /* NOINLINE */
 #include <math.h>
 
diff --git a/src/box/tuple_hash.cc b/src/box/tuple_hash.cc
index 0aed4c14cb..9ee4355038 100644
--- a/src/box/tuple_hash.cc
+++ b/src/box/tuple_hash.cc
@@ -32,7 +32,7 @@
 #include "tuple_hash.h"
 #include "tuple.h"
 #include "third_party/PMurHash.h"
-#include "coll.h"
+#include "coll/coll.h"
 #include <math.h>
 
 /* Tuple and key hasher */
diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt
index 9e90c75aba..39795bbaef 100644
--- a/src/lib/CMakeLists.txt
+++ b/src/lib/CMakeLists.txt
@@ -9,6 +9,7 @@ add_subdirectory(uri)
 add_subdirectory(http_parser)
 add_subdirectory(core)
 add_subdirectory(uuid)
+add_subdirectory(coll)
 if(ENABLE_BUNDLED_MSGPUCK)
     add_subdirectory(msgpuck EXCLUDE_FROM_ALL)
 endif()
diff --git a/src/lib/coll/CMakeLists.txt b/src/lib/coll/CMakeLists.txt
new file mode 100644
index 0000000000..c01e608bb1
--- /dev/null
+++ b/src/lib/coll/CMakeLists.txt
@@ -0,0 +1,2 @@
+add_library(coll STATIC coll.c coll_def.c)
+target_link_libraries(coll core ${ICU_LIBRARIES})
diff --git a/src/lib/core/coll.c b/src/lib/coll/coll.c
similarity index 100%
rename from src/lib/core/coll.c
rename to src/lib/coll/coll.c
diff --git a/src/lib/core/coll.h b/src/lib/coll/coll.h
similarity index 100%
rename from src/lib/core/coll.h
rename to src/lib/coll/coll.h
diff --git a/src/lib/core/coll_def.c b/src/lib/coll/coll_def.c
similarity index 100%
rename from src/lib/core/coll_def.c
rename to src/lib/coll/coll_def.c
diff --git a/src/lib/core/coll_def.h b/src/lib/coll/coll_def.h
similarity index 100%
rename from src/lib/core/coll_def.h
rename to src/lib/coll/coll_def.h
diff --git a/src/lib/core/CMakeLists.txt b/src/lib/core/CMakeLists.txt
index 6238f3ceea..eb10b11c3f 100644
--- a/src/lib/core/CMakeLists.txt
+++ b/src/lib/core/CMakeLists.txt
@@ -24,8 +24,6 @@ set(core_sources
     util.c
     random.c
     trigger.cc
-    coll.c
-    coll_def.c
     mpstream.c
     port.c
 )
diff --git a/src/lua/utf8.c b/src/lua/utf8.c
index 6d3e4d39ac..a009a46558 100644
--- a/src/lua/utf8.c
+++ b/src/lua/utf8.c
@@ -30,7 +30,7 @@
  */
 #include <unicode/ucasemap.h>
 #include <unicode/uchar.h>
-#include <coll.h>
+#include "coll/coll.h"
 #include "lua/utils.h"
 #include "lua/utf8.h"
 #include "diag.h"
diff --git a/src/main.cc b/src/main.cc
index df74689078..39d5fb3510 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -58,7 +58,7 @@
 #include <say.h>
 #include <rmean.h>
 #include <limits.h>
-#include "coll.h"
+#include "coll/coll.h"
 #include "trivia/util.h"
 #include "backtrace.h"
 #include "tt_pthread.h"
diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt
index 18118d3746..04bc659e79 100644
--- a/test/unit/CMakeLists.txt
+++ b/test/unit/CMakeLists.txt
@@ -193,7 +193,7 @@ add_executable(vy_cache.test vy_cache.c ${ITERATOR_TEST_SOURCES})
 target_link_libraries(vy_cache.test ${ITERATOR_TEST_LIBS})
 
 add_executable(coll.test coll.cpp)
-target_link_libraries(coll.test core unit ${ICU_LIBRARIES} misc)
+target_link_libraries(coll.test coll unit misc)
 
 add_executable(tuple_bigref.test tuple_bigref.c)
 target_link_libraries(tuple_bigref.test tuple unit)
diff --git a/test/unit/coll.cpp b/test/unit/coll.cpp
index 94374a7b06..5a7f49195f 100644
--- a/test/unit/coll.cpp
+++ b/test/unit/coll.cpp
@@ -7,8 +7,8 @@
 #include <diag.h>
 #include <fiber.h>
 #include <memory.h>
-#include "coll_def.h"
-#include "coll.h"
+#include "coll/coll_def.h"
+#include "coll/coll.h"
 #include "unit.h"
 #include "third_party/PMurHash.h"
 
-- 
GitLab