Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to json c #157

Open
wants to merge 3 commits into
base: switch-to-c-json
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
./configure --enable-embedded-yajl CFLAGS='-Wall -Wextra -Werror'
make -j $(nproc) distcheck DISTCHECK_CONFIGURE_FLAGS="--enable-embedded-yajl"
./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
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +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
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
18 changes: 2 additions & 16 deletions Makefile.am
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
DIST_SUBDIRS = yajl
SUBDIRS = yajl

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

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 @@ -155,12 +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

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 @@ -256,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) to be installed and linkable.
Expects [jansson](https://github.com/akheron/jansson) to be installed and linkable.
```sh
$ ./autogen.sh
$ ./configure
Expand Down
2 changes: 0 additions & 2 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 Down
20 changes: 2 additions & 18 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,23 +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])
AC_CONFIG_SUBDIRS([yajl])

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_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
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
Loading