Skip to content

Commit

Permalink
Switch to json-c
Browse files Browse the repository at this point in the history
Signed-off-by: Sourav Moitra <[email protected]>
  • Loading branch information
xw19 committed Jan 29, 2025
1 parent fc09e1b commit b90839b
Show file tree
Hide file tree
Showing 11 changed files with 312 additions and 499 deletions.
20 changes: 2 additions & 18 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ jobs:
distro: ubuntu_latest
steps:
- uses: actions/[email protected]
with:
submodules: true
set-safe-directory: true

- uses: uraimo/[email protected]
name: Build
Expand All @@ -33,29 +30,16 @@ jobs:

githubToken: ${{ github.token }}

setup: |
git submodule update --init --recursive
git clone https://github.com/akheron/jansson
# Install jansson
cd jansson;
autoreconf -fi;
./configure;
make;
make install;
cd ..
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
export JANSSON_CFLAGS=-I/usr/local/include;
export JANSSON_LIBS=/usr/local/lib/libjansson.so
find $(pwd) -name '.git' -exec bash -c 'git config --global --add safe.directory ${0%/.git}' {} \;
./autogen.sh
./configure CFLAGS='-Wall -Wextra -Werror'
make -j $(nproc) distcheck AM_DISTCHECK_DVI_TARGET="" TESTS=""
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
15 changes: 5 additions & 10 deletions Containerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ubuntu:22.04
FROM ubuntu:24.04

RUN apt-get update && \
apt-get install -y \
Expand All @@ -7,19 +7,14 @@ RUN apt-get update && \
git \
libtool \
pkg-config \
python3
python3 \
libjson-c-dev


COPY . libocispec

RUN git clone https://github.com/akheron/jansson

RUN cd jansson && autoreconf -fi && ./configure && make && make install

RUN cd libocispec && \
export JANSSON_CFLAGS=-I/usr/local/include && \
export JANSSON_LIBS=/usr/local/lib/libjansson.so && \
./autogen.sh && \
./configure CFLAGS='-Wall -Wextra -Werror' && \
make -j $(nproc) distcheck DISTCHECK_CONFIGURE_FLAGS="--enable-embedded-yajl" AM_DISTCHECK_DVI_TARGET="" TESTS="" && \
make clean
make -j $(nproc) distcheck AM_DISTCHECK_DVI_TARGET="" TESTS="" && \
make clean
6 changes: 1 addition & 5 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +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_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
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
8 changes: 4 additions & 4 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} (json_t *jtree, 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(" json_t *_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} (json_t *jtree, const struct parser_context *ctx, parser_error *err);\n\n")
header.append(f"int gen_{typename} (json_t *root, const {typename} *ptr, 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
Loading

0 comments on commit b90839b

Please sign in to comment.