Skip to content

Commit

Permalink
Add json-c
Browse files Browse the repository at this point in the history
Signed-off-by: Sourav Moitra <sourav.moitr@gmail.com>
  • Loading branch information
xw19 committed Jan 29, 2025
1 parent 6cef0fb commit 7712b0f
Show file tree
Hide file tree
Showing 26 changed files with 500 additions and 1,941 deletions.
23 changes: 9 additions & 14 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,12 @@ jobs:
distro: ubuntu_latest
- arch: s390x
distro: ubuntu_latest
- arch: ppc64le
distro: ubuntu_latest
# - arch: ppc64le
# distro: ubuntu_latest
steps:
- uses: actions/checkout@v3.0.2
with:
submodules: true
set-safe-directory: true
- uses: actions/checkout@v4.2.2

- uses: uraimo/run-on-arch-action@v2.2.0
- uses: uraimo/run-on-arch-action@v2.8.1
name: Build
id: build
with:
Expand All @@ -33,18 +30,16 @@ jobs:

githubToken: ${{ github.token }}

setup: |
git submodule update --init --recursive
install: |
apt-get update -q -y
apt-get install -q -y python3 automake libtool autotools-dev git make cmake pkg-config gcc wget xz-utils
apt-get install -q -y python3 automake libtool autotools-dev git make cmake pkg-config gcc wget xz-utils libjson-c-dev
run: |
# Configure and Run libocispec
find $(pwd) -name '.git' -exec bash -c 'git config --global --add safe.directory ${0%/.git}' {} \;
./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=""
./autogen.sh
./configure CFLAGS='-Wall -Wextra -Werror'
make -j $(nproc) distcheck AM_DISTCHECK_DVI_TARGET=""
# check that the working dir is clean
git describe --broken --dirty --all | grep -qv dirty
make clean
Expand Down
6 changes: 0 additions & 6 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,3 @@
[submodule "image-spec"]
path = image-spec
url = https://github.com/opencontainers/image-spec
[submodule "yajl"]
path = yajl
url = https://github.com/containers/yajl.git
[submodule "jansson"]
path = jansson
url = https://github.com/akheron/jansson
20 changes: 20 additions & 0 deletions Containerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM ubuntu:24.04

RUN apt-get update && \
apt-get install -y \
autoconf \
build-essential \
git \
libtool \
pkg-config \
python3 \
libjson-c-dev


COPY . libocispec

RUN cd libocispec && \
./autogen.sh && \
./configure CFLAGS='-Wall -Wextra -Werror' && \
make -j $(nproc) distcheck AM_DISTCHECK_DVI_TARGET="" && \
make clean
28 changes: 2 additions & 26 deletions Makefile.am
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
DIST_SUBDIRS = yajl jansson
SUBDIRS = yajl jansson

AM_CFLAGS = $(WARN_CFLAGS) -I$(top_srcdir)/src -I$(top_builddir)/src

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
Expand Down Expand Up @@ -159,18 +148,6 @@ CLEANFILES += $(HEADER_FILES) $(SOURCE_FILES) $(TMP_H_FILES) $(TMP_C_FILES)

TESTS_LDADD = libocispec.la $(SELINUX_LIBS)

if HAVE_EMBEDDED_YAJL
TESTS_LDADD += yajl/libyajl.la
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
Expand Down Expand Up @@ -266,13 +243,12 @@ EXTRA_DIST = autogen.sh \
runtime-spec \
image-spec \
src/ocispec/json_common.h \
src/ocispec/json_common.c \
src/yajl
src/ocispec/json_common.c

sync:
(cd image-spec; git pull https://github.com/opencontainers/image-spec)
(cd runtime-spec; git pull https://github.com/opencontainers/runtime-spec)
(cd yajl; git pull https://github.com/containers/yajl main)


generate: src/runtime_spec_stamp src/image_spec_stamp src/image_manifest_stamp src/basic-test_stamp

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) and [jansson](https://github.com/akheron/jansson) to be installed and linkable.
Expects [jansson](https://github.com/akheron/jansson) to be installed and linkable.
```sh
$ ./autogen.sh
$ ./configure
Expand Down
4 changes: 0 additions & 4 deletions autogen.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/bin/sh

(cd yajl; ./autogen.sh)

git submodule update --init --recursive

test -n "$srcdir" || srcdir=`dirname "$0"`
Expand All @@ -15,8 +13,6 @@ if ! (autoreconf --version >/dev/null 2>&1); then
exit 1
fi

(cd ./jansson; autoreconf -i)

mkdir -p m4

autoreconf --force --install --verbose
Expand Down
35 changes: 2 additions & 33 deletions configure.ac
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
AC_PREREQ([2.63])
AC_INIT([libocispec], [0.3], [giuseppe@scrivano.org])
AC_INIT([libocispec], [0.4], [giuseppe@scrivano.org])
AC_CONFIG_HEADER([config.h])
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_AUX_DIR([build-aux])
Expand All @@ -12,38 +12,7 @@ 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 jansson])
AC_CONFIG_SUBDIRS([yajl jansson])

AC_ARG_ENABLE(embedded-yajl,
AS_HELP_STRING([--enable-embedded-yajl], [Statically link a modified yajl version]),
[
case "${enableval}" in
yes) embedded_yajl=true ;;
no) embedded_yajl=false ;;
*) AC_MSG_ERROR(bad value ${enableval} for --enable-embedded-yajl) ;;
esac],[embedded_yajl=false])

AM_CONDITIONAL([HAVE_EMBEDDED_YAJL], [test x"$embedded_yajl" = xtrue])
AM_COND_IF([HAVE_EMBEDDED_YAJL], [], [
AC_SEARCH_LIBS(yajl_tree_get, [yajl], [AC_DEFINE([HAVE_YAJL], 1, [Define if libyajl is available])], [AC_MSG_ERROR([*** libyajl headers not found])])
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])
])
AC_SEARCH_LIBS(json_c_version, [json-c], [AC_DEFINE([HAVE_JSONC], 1, [Define if json-c is available])], [AC_MSG_ERROR([*** json-c headers not found])])

# Optionally install the library.
AC_ARG_ENABLE(libocispec-install,
Expand Down
2 changes: 1 addition & 1 deletion image-spec
Submodule image-spec updated 1 files
+2 −0 layer.md
1 change: 0 additions & 1 deletion jansson
Submodule jansson deleted from 684e18
2 changes: 1 addition & 1 deletion ocispec.pc.in
Original file line number Diff line number Diff line change
Expand Up @@ -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 jansson
Requires: jansson
Version: @PACKAGE_VERSION@
Libs: -L${libdir} -locispec
Cflags: -I${includedir}/ocispec
12 changes: 6 additions & 6 deletions src/ocispec/headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def append_header_arr(obj, header, prefix):
typename = helpers.get_name_substr(obj.name, prefix)
header.append(f"}}\n{typename};\n\n")
header.append(f"void free_{typename} ({typename} *ptr);\n\n")
header.append(f"{typename} *make_{typename} (yajl_val tree, const struct parser_context *ctx, parser_error *err);\n\n")
header.append(f"{typename} *make_{typename} (json_object *jtree, const struct parser_context *ctx, parser_error *err);\n\n")


def append_header_map_str_obj(obj, header, prefix):
Expand Down Expand Up @@ -164,7 +164,7 @@ def append_type_c_header(obj, header, prefix):
else:
append_header_child_others(i, header, prefix)
if obj.children is not None:
header.append(" yajl_val _residual;\n")
header.append(" struct json_object *_residual;\n")
if len(present_tags) > 0:
header.append("\n")
for tag in present_tags:
Expand All @@ -173,8 +173,8 @@ def append_type_c_header(obj, header, prefix):
header.append(f"}}\n{typename};\n\n")
header.append(f"void free_{typename} ({typename} *ptr);\n\n")
header.append(f"{typename} *clone_{typename} ({typename} *src);\n")
header.append(f"{typename} *make_{typename} (yajl_val tree, const struct parser_context *ctx, parser_error *err);\n\n")
header.append(f"yajl_gen_status gen_{typename} (yajl_gen g, const {typename} *ptr, const struct parser_context *ctx, parser_error *err);\n\n")
header.append(f"{typename} *make_{typename} (json_object *jtree, const struct parser_context *ctx, parser_error *err);\n\n")
header.append(f"int gen_{typename} (json_object *root, const {typename} *ptr, parser_error *err);\n\n")

def header_reflect_top_array(obj, prefix, header):
c_typ = helpers.get_prefixed_pointer(obj.name, obj.subtyp, prefix) or \
Expand Down Expand Up @@ -206,7 +206,7 @@ def header_reflect_top_array(obj, prefix, header):
header.append(f"{typename} *{typename}_parse_data(const char *jsondata, const struct "\
"parser_context *ctx, parser_error *err);\n\n")
header.append(f"char *{typename}_generate_json(const {typename} *ptr, "\
"const struct parser_context *ctx, parser_error *err);\n\n")
"parser_error *err);\n\n")

def header_reflect(structs, schema_info, header):
'''
Expand Down Expand Up @@ -239,7 +239,7 @@ def header_reflect(structs, schema_info, header):
"parser_error *err);\n\n")
header.append(f"{prefix} *{prefix}_parse_data (const char *jsondata, const struct parser_context *ctx, "\
"parser_error *err);\n\n")
header.append(f"char *{prefix}_generate_json (const {prefix} *ptr, const struct parser_context *ctx, "\
header.append(f"char *{prefix}_generate_json (const {prefix} *ptr,"\
"parser_error *err);\n\n")
elif toptype == 'array':
header_reflect_top_array(structs[length - 1], prefix, header)
Expand Down
Loading

0 comments on commit 7712b0f

Please sign in to comment.