From c3619a14327b9451fd06f960506de258aad72d29 Mon Sep 17 00:00:00 2001 From: Sascha Grunert Date: Wed, 16 Oct 2024 14:46:26 +0200 Subject: [PATCH] Add jansson JSON library This is the first step in migrating from yajl to jansson. We now enable to link it in the same way and add it as dependency to the project. Signed-off-by: Sascha Grunert --- .github/workflows/test.yaml | 6 +++--- .gitmodules | 3 +++ Makefile.am | 14 ++++++++++++-- README.md | 2 +- autogen.sh | 2 ++ configure.ac | 19 +++++++++++++++++-- jansson | 1 + ocispec.pc.in | 2 +- 8 files changed, 40 insertions(+), 9 deletions(-) create mode 160000 jansson diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 8bed8dd9..af94a9f7 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -42,9 +42,9 @@ jobs: run: | find $(pwd) -name '.git' -exec bash -c 'git config --global --add safe.directory ${0%/.git}' {} \; - ./autogen.sh --enable-embedded-yajl - ./configure --enable-embedded-yajl CFLAGS='-Wall -Wextra -Werror' - make -j $(nproc) distcheck DISTCHECK_CONFIGURE_FLAGS="--enable-embedded-yajl" + ./autogen.sh --enable-embedded-yajl --enable-embedded-jansson + ./configure --enable-embedded-yajl --enable-embedded-jansson CFLAGS='-Wall -Wextra -Werror' + make -j $(nproc) distcheck DISTCHECK_CONFIGURE_FLAGS="--enable-embedded-yajl --enable-embedded-jansson" AM_DISTCHECK_DVI_TARGET="" TESTS="" # check that the working dir is clean git describe --broken --dirty --all | grep -qv dirty make clean diff --git a/.gitmodules b/.gitmodules index 0381f810..78677c15 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,3 +7,6 @@ [submodule "yajl"] path = yajl url = https://github.com/containers/yajl.git +[submodule "jansson"] + path = jansson + url = https://github.com/akheron/jansson diff --git a/Makefile.am b/Makefile.am index cb73891b..bfafca2c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,5 +1,5 @@ -DIST_SUBDIRS = yajl -SUBDIRS = yajl +DIST_SUBDIRS = yajl jansson +SUBDIRS = yajl jansson AM_CFLAGS = $(WARN_CFLAGS) -I$(top_srcdir)/src -I$(top_builddir)/src @@ -7,6 +7,10 @@ if HAVE_EMBEDDED_YAJL AM_CFLAGS += -I$(top_srcdir)/yajl/src/headers endif HAVE_EMBEDDED_YAJL +if HAVE_EMBEDDED_JANSSON +AM_CFLAGS += -I$(top_srcdir)/jansson/src +endif HAVE_EMBEDDED_JANSSON + CLEANFILES = $(man_MANS) src/runtime_spec_stamp src/image_spec_stamp src/image_manifest_stamp src/basic-test_stamp GITIGNOREFILES = build-aux/ gtk-doc.make config.h.in aclocal.m4 @@ -161,6 +165,12 @@ else TESTS_LDADD += $(YAJL_LIBS) endif +if HAVE_EMBEDDED_JANSSON +TESTS_LDADD += jansson/src/.libs/libjansson.la +else +TESTS_LDADD += $(JANSSON_LIBS) +endif + libocispec_a_SOURCES = libocispec.a: libocispec.la $(BUILT_SOURCES) src/runtime_spec_stamp src/image_spec_stamp src/image_manifest_stamp src/basic-test_stamp diff --git a/README.md b/README.md index 17e15a7a..dd3e8827 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ from C, and generate json string from corresponding struct. The parser is generated directly from the JSON schema in the source repository. ## Installation -Expects [yajl](https://github.com/containers/yajl) to be installed and linkable. +Expects [yajl](https://github.com/containers/yajl) and [jansson](https://github.com/akheron/jansson) to be installed and linkable. ```sh $ ./autogen.sh $ ./configure diff --git a/autogen.sh b/autogen.sh index d8bbf0ed..de5c0463 100755 --- a/autogen.sh +++ b/autogen.sh @@ -15,6 +15,8 @@ if ! (autoreconf --version >/dev/null 2>&1); then exit 1 fi +(cd ./jansson; autoreconf -i) + mkdir -p m4 autoreconf --force --install --verbose diff --git a/configure.ac b/configure.ac index 6125dcbe..180d0b4d 100644 --- a/configure.ac +++ b/configure.ac @@ -12,8 +12,8 @@ AM_INIT_AUTOMAKE([1.11 -Wno-portability foreign tar-ustar no-dist-gzip dist-xz s AM_MAINTAINER_MODE([enable]) AM_SILENT_RULES([yes]) -AM_EXTRA_RECURSIVE_TARGETS([yajl]) -AC_CONFIG_SUBDIRS([yajl]) +AM_EXTRA_RECURSIVE_TARGETS([yajl jansson]) +AC_CONFIG_SUBDIRS([yajl jansson]) AC_ARG_ENABLE(embedded-yajl, AS_HELP_STRING([--enable-embedded-yajl], [Statically link a modified yajl version]), @@ -30,6 +30,21 @@ AC_SEARCH_LIBS(yajl_tree_get, [yajl], [AC_DEFINE([HAVE_YAJL], 1, [Define if liby PKG_CHECK_MODULES([YAJL], [yajl >= 2.0.0]) ]) +AC_ARG_ENABLE(embedded-jansson, +AS_HELP_STRING([--enable-embedded-jansson], [Statically link a jansson version]), +[ +case "${enableval}" in + yes) embedded_jansson=true ;; + no) embedded_jansson=false ;; + *) AC_MSG_ERROR(bad value ${enableval} for --enable-embedded-jansson) ;; +esac],[embedded_jansson=false]) + +AM_CONDITIONAL([HAVE_EMBEDDED_JANSSON], [test x"$embedded_jansson" = xtrue]) +AM_COND_IF([HAVE_EMBEDDED_JANSSON], [], [ +AC_SEARCH_LIBS(json_object, [jansson], [AC_DEFINE([HAVE_JANSSON], 1, [Define if libjansson is available])], [AC_MSG_ERROR([*** libjansson headers not found])]) +PKG_CHECK_MODULES([JANSSON], [jansson >= 2.14]) +]) + # Optionally install the library. AC_ARG_ENABLE(libocispec-install, AS_HELP_STRING([--enable-libocispec-install], [Enable libocispec installation]), diff --git a/jansson b/jansson new file mode 160000 index 00000000..684e18c9 --- /dev/null +++ b/jansson @@ -0,0 +1 @@ +Subproject commit 684e18c927e89615c2d501737e90018f4930d6c5 diff --git a/ocispec.pc.in b/ocispec.pc.in index 9255abde..32673036 100644 --- a/ocispec.pc.in +++ b/ocispec.pc.in @@ -5,7 +5,7 @@ includedir=@includedir@ Name: @PACKAGE_NAME@ Description: A library for easily parsing [OCI runtime](https://github.com/opencontainers/runtime-spec) and [OCI image](https://github.com/opencontainers/image-spec) files. -Requires: yajl +Requires: yajl jansson Version: @PACKAGE_VERSION@ Libs: -L${libdir} -locispec Cflags: -I${includedir}/ocispec