CI: Import sysrepo

...and also ensure that we build sysrepo & libyang first, so that an
eventual failure breaks the build early.

Change-Id: I2a482624da1dee99fbdf98054a7c66e440cf3998
diff --git a/.gitmodules b/.gitmodules
index 5e10dfb..3a4470e 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -16,3 +16,9 @@
 [submodule "submodules/libyang"]
 	path = submodules/libyang
 	url = ../../github/CESNET/libyang
+[submodule "submodules/sysrepo"]
+	path = submodules/sysrepo
+	url = ../../github/sysrepo/sysrepo
+[submodule "submodules/libredblack"]
+	path = submodules/libredblack
+	url = ../../github/sysrepo/libredblack
diff --git a/ci/do-build.sh b/ci/do-build.sh
index ab6a105..fd97da1 100755
--- a/ci/do-build.sh
+++ b/ci/do-build.sh
@@ -12,6 +12,7 @@
 export PKG_CONFIG_PATH=${PREFIX}/lib64/pkgconfig:${PREFIX}/lib/pkgconfig${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH}
 
 if [[ $TH_JOB_NAME =~ .*-sanitizers-.* ]]; then
+    CMAKE_OPTIONS="${CMAKE_OPTIONS} -DUSE_SR_MEM_MGMT:BOOL=OFF"
     # https://gitlab.kitware.com/cmake/cmake/issues/16609
     CMAKE_OPTIONS="${CMAKE_OPTIONS} -DTHREADS_HAVE_PTHREAD_ARG:BOOL=ON"
 fi
@@ -20,6 +21,9 @@
 # - libyang and libnetconf2 copmare CMAKE_BUILD_TYPE to lowercase "debug"...
 CMAKE_OPTIONS="${CMAKE_OPTIONS} -DENABLE_BUILD_TESTS=ON -DENABLE_VALGRIND_TESTS=OFF"
 
+# nuke python2 builds because we cannot write to the site_path
+CMAKE_OPTIONS="${CMAKE_OPTIONS} -DGEN_PYTHON_BINDINGS=OFF"
+
 build_dep_cmake() {
     pushd ${TH_JOB_WORKING_DIR}
     mkdir build-$1
@@ -30,6 +34,15 @@
     popd
 }
 
+build_dep_autoconf() {
+    pushd ${TH_GIT_PATH}/submodules/$1
+    shift
+    ./configure --prefix=${PREFIX} "$@"
+    make -j4
+    make install
+    popd
+}
+
 do_test_dep_cmake() {
     pushd ${TH_JOB_WORKING_DIR}/build-$1
     shift
@@ -40,6 +53,8 @@
 emerge_dep() {
     if [[ -f ${TH_GIT_PATH}/submodules/$1/CMakeLists.txt ]]; then
         build_dep_cmake $1
+    elif [[ -f ${TH_GIT_PATH}/submodules/$1/configure ]]; then
+        build_dep_autoconf "$@"
     else
         echo "Unrecognized buildsystem for $1"
         exit 1
@@ -56,6 +71,17 @@
 else
     # rebuild everything from scratch
 
+    CMAKE_OPTIONS="${CMAKE_OPTIONS} -DGEN_LANGUAGE_BINDINGS=ON -DGEN_PYTHON_BINDINGS=OFF" emerge_dep libyang
+    do_test_dep_cmake libyang -j${CI_PARALLEL_JOBS}
+
+    emerge_dep libredblack --with-pic
+
+    # sysrepo needs to use a persistent repo location
+    CMAKE_OPTIONS="${CMAKE_OPTIONS} -DREPOSITORY_LOC=${PREFIX}/etc-sysrepo" emerge_dep sysrepo
+    # These tests are only those which can run on the global repo.
+    # They also happen to fail when run in parallel. That's expected, they manipulate a shared repository.
+    do_test_dep_cmake sysrepo
+
     emerge_dep Catch
     do_test_dep_cmake Catch -j${CI_PARALLEL_JOBS}
 
@@ -76,9 +102,6 @@
     cp -LR boost ${PREFIX}/include/
     popd
 
-    CMAKE_OPTIONS="${CMAKE_OPTIONS} -DGEN_LANGUAGE_BINDINGS=ON -DGEN_PYTHON_BINDINGS=OFF" emerge_dep libyang
-    do_test_dep_cmake libyang -j${CI_PARALLEL_JOBS}
-
     tar -C ~/target -cvJf ${TH_JOB_WORKING_DIR}/${ARTIFACT} .
     ssh th-ci-logs@ci-logs.gerrit.cesnet.cz mkdir -p artifacts/${TH_JOB_NAME} \
         || true # ignore network errors
diff --git a/submodules/libredblack b/submodules/libredblack
new file mode 160000
index 0000000..a399310
--- /dev/null
+++ b/submodules/libredblack
@@ -0,0 +1 @@
+Subproject commit a399310d99b61eec4d3c0677573ab5dddcf9395d
diff --git a/submodules/sysrepo b/submodules/sysrepo
new file mode 160000
index 0000000..b678168
--- /dev/null
+++ b/submodules/sysrepo
@@ -0,0 +1 @@
+Subproject commit b678168b1513cbf590b5cf968f67f4e3f77b2319