@cryptotaxi247 / netdata-1 / commits / 6887d7354

Added code to bundle libJudy on systems which do not provide a usable copy of it. (#9776)

* Add installer code to bundle libJudy. * Update libJudy build to work on more systems. * Added libtool to deps. * First part of configure changes - detection of library * Configure change part two: integrating flags into the build I've tested the build works and that the symbols end up correct in the compiled binary, but I have not tested that dbengine is working properly after the changes. * Add required configure options for bundling libJudy. * Bail early if a libJudy build step fails. * Added messges for specific reasons libJudy is being built. * Fix bail condition for bundling failures. We don't care about whether the cloud is required or not, just whether the user asked for a local build of libJudy or not. * Fix logic for deciding when to bundle libJudy. * Fix judy build to clean up properly if it fails. Co-authored-by: Andrew Moss <1043609+amoss@users.noreply.github.com>

Austin S. Hemmelgarn committed Sep 1, 2020 at 08:48 UTC 6887d73545db62bcda8c7cf829389ac6f19d5131
6 files changed +157 -26
Makefile.am
+2
@@ -66,6 +66,8 @@ dist_noinst_DATA = \
66 packaging/go.d.checksums \
67 packaging/jsonc.version \
68 packaging/jsonc.checksums \
69 + packaging/judy.version \
70 + packaging/judy.checksums \
71 packaging/libwebsockets.version \
72 packaging/libwebsockets.checksums \
73 packaging/mosquitto.version \
configure.ac
+55 -25
@@ -328,14 +328,6 @@ AC_CHECK_LIB(
328 [LZ4_LIBS="-llz4"]
329 )
330
331 -# -----------------------------------------------------------------------------
332 -# Judy General purpose dynamic array
333 -
334 -AC_CHECK_LIB(
335 - [Judy],
336 - [JudyLIns],
337 - [JUDY_LIBS="-lJudy"]
338 -)
331
332
333 # -----------------------------------------------------------------------------
@@ -416,6 +408,44 @@ OPTIONAL_JSONC_LIBS="${JSONC_LIBS}"
408 test "${enable_dbengine}" = "yes" -a -z "${LZ4_LIBS}" && \
409 AC_MSG_ERROR([liblz4 required but not found. Try installing 'liblz4-dev' or 'lz4-devel'.])
410
411 +
412 +AC_ARG_WITH([libJudy],
413 + [AS_HELP_STRING([--with-libJudy=PREFIX],[Use a specific Judy library (default is system-library)])],
414 + [
415 + libJudy_dir="$withval"
416 + AC_MSG_CHECKING(for libJudy in $withval)
417 + if test -f "${libJudy_dir}/libJudy.a" -a -f "${libJudy_dir}/Judy.h"; then
418 + LIBS_BACKUP="${LIBS}"
419 + LIBS="${libJudy_dir}/libJudy.a"
420 + AC_LINK_IFELSE([AC_LANG_SOURCE([[#include "${libJudy_dir}/Judy.h"
421 + int main (int argc, char **argv) {
422 + Pvoid_t PJLArray = (Pvoid_t) NULL;
423 + Word_t * PValue;
424 + Word_t Index;
425 + JLI(PValue, PJLArray, Index);
426 + }]])],
427 + [HAVE_libJudy_a="yes"],
428 + [HAVE_libJudy_a="no"])
429 + LIBS="${LIBS_BACKUP}"
430 + JUDY_LIBS="${libJudy_dir}/libJudy.a"
431 + JUDY_CFLAGS="-I${libJudy_dir}"
432 + AC_MSG_RESULT([$HAVE_libJudy_a])
433 + else
434 + libjudy_dir=""
435 + HAVE_libJudy_a="no"
436 + AC_MSG_RESULT([$HAVE_libJudy_a])
437 + fi
438 + ],
439 + [HAVE_libJudy_a="no"])
440 +
441 +if test "${HAVE_libJudy_a}" = "no"; then
442 + AC_CHECK_LIB(
443 + [Judy],
444 + [JudyLIns],
445 + [JUDY_LIBS="-lJudy"]
446 + )
447 +fi
448 +
449 test "${enable_dbengine}" = "yes" -a -z "${JUDY_LIBS}" && \
450 AC_MSG_ERROR([libJudy required but not found. Try installing 'libjudy-dev' or 'Judy-devel'.])
451
@@ -457,23 +487,23 @@ AM_CONDITIONAL([ENABLE_HTTPS], [test "${enable_https}" = "yes"])
487 # JSON-C
488
489 if test "${enable_jsonc}" != "no" -a -z "${JSONC_LIBS}"; then
460 - # Try and detect manual static build presence (from netdata-installer.sh)
461 - AC_MSG_CHECKING([if statically built json-c is present])
462 - HAVE_libjson_c_a="no"
463 - if test -f "externaldeps/jsonc/libjson-c.a"; then
464 - LIBS_BKP="${LIBS}"
465 - LIBS="externaldeps/jsonc/libjson-c.a"
466 - AC_LINK_IFELSE([AC_LANG_SOURCE([[#include "externaldeps/jsonc/json-c/json.h"
467 - int main (int argc, char **argv) {
468 - struct json_object *jobj;
469 - char *str = "{ \"msg-type\": \"random\" }";
470 - jobj = json_tokener_parse(str);
471 - json_object_get_type(jobj);
472 - }]])],
473 - [HAVE_libjson_c_a="yes"],
474 - [HAVE_libjson_c_a="no"])
475 - LIBS="${LIBS_BKP}"
476 - fi
490 + # Try and detect manual static build presence (from netdata-installer.sh)
491 + AC_MSG_CHECKING([if statically built json-c is present])
492 + HAVE_libjson_c_a="no"
493 + if test -f "externaldeps/jsonc/libjson-c.a"; then
494 + LIBS_BKP="${LIBS}"
495 + LIBS="externaldeps/jsonc/libjson-c.a"
496 + AC_LINK_IFELSE([AC_LANG_SOURCE([[#include "externaldeps/jsonc/json-c/json.h"
497 + int main (int argc, char **argv) {
498 + struct json_object *jobj;
499 + char *str = "{ \"msg-type\": \"random\" }";
500 + jobj = json_tokener_parse(str);
501 + json_object_get_type(jobj);
502 + }]])],
503 + [HAVE_libjson_c_a="yes"],
504 + [HAVE_libjson_c_a="no"])
505 + LIBS="${LIBS_BKP}"
506 + fi
507
508 if test "${HAVE_libjson_c_a}" = "yes"; then
509 AC_DEFINE([LINK_STATIC_JSONC], [1], [static json-c should be used])
netdata-installer.sh
+90 -1
@@ -282,7 +282,10 @@ while [ -n "${1}" ]; do
282 "--enable-plugin-freeipmi") NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--enable-plugin-freeipmi/} --enable-plugin-freeipmi" ;;
283 "--disable-plugin-freeipmi") NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--disable-plugin-freeipmi/} --disable-plugin-freeipmi" ;;
284 "--disable-https") NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--disable-https/} --disable-https" ;;
285 - "--disable-dbengine") NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--disable-dbengine/} --disable-dbengine" ;;
285 + "--disable-dbengine")
286 + NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--disable-dbengine/} --disable-dbengine"
287 + NETDATA_DISABLE_DBENGINE=1
288 + ;;
289 "--enable-plugin-nfacct") NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--enable-plugin-nfacct/} --enable-plugin-nfacct" ;;
290 "--disable-plugin-nfacct") NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--disable-plugin-nfacct/} --disable-plugin-nfacct" ;;
291 "--enable-plugin-xenstat") NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--enable-plugin-xenstat/} --enable-plugin-xenstat" ;;
@@ -319,6 +322,9 @@ while [ -n "${1}" ]; do
322 "--build-json-c")
323 NETDATA_BUILD_JSON_C=1
324 ;;
325 + "--build-judy")
326 + NETDATA_BUILD_JUDY=1
327 + ;;
328 "--install")
329 NETDATA_PREFIX="${2}/netdata"
330 shift 1
@@ -670,6 +676,89 @@ bundle_libwebsockets
676
677 # -----------------------------------------------------------------------------
678
679 +build_judy() {
680 + local env_cmd=''
681 +
682 + if [ -z "${DONT_SCRUB_CFLAGS_EVEN_THOUGH_IT_MAY_BREAK_THINGS}" ]; then
683 + env_cmd="env CFLAGS= CXXFLAGS= LDFLAGS="
684 + fi
685 +
686 + pushd "${1}" > /dev/null || return 1
687 + if run ${env_cmd} libtoolize --force --copy && \
688 + run ${env_cmd} aclocal && \
689 + run ${env_cmd} autoheader && \
690 + run ${env_cmd} automake --add-missing --force --copy --include-deps && \
691 + run ${env_cmd} autoconf && \
692 + run ${env_cmd} ./configure && \
693 + run ${env_cmd} make -C src && \
694 + run ${env_cmd} ar -r src/libJudy.a src/Judy*/*.o ; then
695 + popd > /dev/null || return 1
696 + else
697 + popd > /dev/null || return 1
698 + return 1
699 + fi
700 +}
701 +
702 +copy_judy() {
703 + target_dir="${PWD}/externaldeps/libjudy"
704 +
705 + run mkdir -p "${target_dir}" || return 1
706 +
707 + run cp "${1}/src/libJudy.a" "${target_dir}/libJudy.a" || return 1
708 + run cp "${1}/src/Judy.h" "${target_dir}/Judy.h" || return 1
709 +}
710 +
711 +bundle_judy() {
712 + # If --build-judy flag or no Judy on the system and we're building the dbengine, bundle our own libJudy.
713 + # shellcheck disable=SC2235
714 + if [ -n "${NETDATA_DISABLE_DBENGINE}" ] || ( [ -z "${NETDATA_BUILD_JUDY}" ] && [ -e /usr/include/Judy.h ] ); then
715 + return 0
716 + elif [ -n "${NETDATA_BUILD_JUDY}" ] ; then
717 + progress "User requested bundling of libJudy, building it now"
718 + elif [ ! -e /usr/include/Judy.h ] ; then
719 + progress "/usr/include/Judy.h does not exist, but we need libJudy, building our own copy"
720 + fi
721 +
722 + progress "Prepare libJudy"
723 +
724 + JUDY_PACKAGE_VERSION="$(cat packaging/judy.version)"
725 +
726 + tmp="$(mktemp -d -t netdata-judy-XXXXXX)"
727 + JUDY_PACKAGE_BASENAME="v${JUDY_PACKAGE_VERSION}.tar.gz"
728 +
729 + if fetch_and_verify "judy" \
730 + "https://github.com/netdata/libjudy/archive/${JUDY_PACKAGE_BASENAME}" \
731 + "${JUDY_PACKAGE_BASENAME}" \
732 + "${tmp}" \
733 + "${NETDATA_LOCAL_TARBALL_OVERRIDE_JUDY}"; then
734 + if run tar -xf "${tmp}/${JUDY_PACKAGE_BASENAME}" -C "${tmp}" &&
735 + build_judy "${tmp}/libjudy-${JUDY_PACKAGE_VERSION}" &&
736 + copy_judy "${tmp}/libjudy-${JUDY_PACKAGE_VERSION}" &&
737 + rm -rf "${tmp}"; then
738 + run_ok "libJudy built and prepared."
739 + NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS} --with-libjudy=externaldeps/libJudy"
740 + else
741 + run_failed "Failed to build libJudy."
742 + if [ -n "${NETDATA_BUILD_JUDY}" ]; then
743 + exit 1
744 + else
745 + defer_error_highlighted "Failed to build libJudy. dbengine support will be disabled."
746 + fi
747 + fi
748 + else
749 + run_failed "Unable to fetch sources for libJudy."
750 + if [ -n "${NETDATA_BUILD_JUDY}" ]; then
751 + exit 1
752 + else
753 + defer_error_highlighted "Unable to fetch sources for libJudy. dbengine support will be disabled."
754 + fi
755 + fi
756 +}
757 +
758 +bundle_judy
759 +
760 +# -----------------------------------------------------------------------------
761 +
762 build_jsonc() {
763 local env_cmd=''
764
packaging/installer/install-required-packages.sh
+8
@@ -650,6 +650,13 @@ declare -A pkg_automake=(
650 ['default']="automake"
651 )
652
653 +# required to bundle libJudy
654 +declare -A pkg_libtool=(
655 + ['gentoo']="sys-devel/libtool"
656 + ['clearlinux']="c-basic"
657 + ['default']="libtool"
658 +)
659 +
660 # Required to build libwebsockets and libmosquitto on some systems.
661 declare -A pkg_cmake=(
662 ['gentoo']="dev-util/cmake"
@@ -1291,6 +1298,7 @@ packages() {
1298 suitable_package autoconf-archive
1299 require_cmd autogen || suitable_package autogen
1300 require_cmd automake || suitable_package automake
1301 + require_cmd libtoolize || suitable_package libtool
1302 require_cmd pkg-config || suitable_package pkg-config
1303 require_cmd cmake || suitable_package cmake
1304
packaging/judy.checksums new
+1
@@ -0,0 +1 @@
1 +694c735258267c7fb3cffc913985cd3b910bb6222330bada0d9ddbe2263c32a0 v1.0.5-netdata1.tar.gz
packaging/judy.version new
+1
@@ -0,0 +1 @@
1 +1.0.5-netdata1