diff --git a/helpers/sdbus-c++-xml2cpp/Dockerfile b/helpers/sdbus-c++-xml2cpp/Dockerfile new file mode 100644 index 0000000..384ae4e --- /dev/null +++ b/helpers/sdbus-c++-xml2cpp/Dockerfile @@ -0,0 +1,7 @@ +FROM debian:bullseye-slim +RUN apt-get update && apt-get install -y git build-essential cmake pkg-config libsystemd-dev libexpat-dev +COPY bashrc /root/.bashrc +COPY build.sh . +RUN ./build.sh +WORKDIR /work +CMD /sdbus-cpp/build/tools/sdbus-c++-xml2cpp diff --git a/helpers/sdbus-c++-xml2cpp/Makefile b/helpers/sdbus-c++-xml2cpp/Makefile new file mode 100644 index 0000000..eaf8da4 --- /dev/null +++ b/helpers/sdbus-c++-xml2cpp/Makefile @@ -0,0 +1,54 @@ +# SPDX-FileCopyrightText: Copyright (c) 2023 MBition GmbH. +# SPDX-License-Identifier: MPL-2.0 + +IMAGE_NAME ?= ifex_local/sdbus-xml2cpp +CONTAINER_NAME ?= sdbus-xml2cpp +CONTAINER_HOSTNAME ?= sdbus-xml2cpp + +.PHONY: _reset build rebuild buildnew run clean logs shell stop kill rm rmi + +default: + @echo "make [build|buildnew|run|clean|logs|shell|stop|kill|rm|rmi]" + +build: + docker build --tag=${IMAGE_NAME}:latest . + +# Build container fully from scratch, without reusing cached steps +buildnew: + docker build --no-cache --tag=${IMAGE_NAME}:latest . + +# Run container (detached) +run_selinux: + ZFLAG=:z make run + +run: + @docker rm -f ${CONTAINER_NAME} + @docker run -ti -h "${CONTAINER_HOSTNAME}" -v ${PWD}/..:/work${ZFLAG} --name=${CONTAINER_NAME} ${IMAGE_NAME}:latest + +run_shell: + @docker rm -f ${CONTAINER_NAME} + @docker run -ti -h "${CONTAINER_HOSTNAME}" -v ${PWD}/..:/work${ZFLAG} --name=${CONTAINER_NAME} ${IMAGE_NAME}:latest /bin/bash + +# Force remove container and image +clean: kill rm rmi + +logs: + docker logs -f ${CONTAINER_NAME} + +shell: + docker exec -it ${CONTAINER_NAME} /bin/bash + +stop: + docker stop ${CONTAINER_NAME} || true + +# Force stop and remove container +kill: + docker kill ${CONTAINER_NAME} || echo "Cannot kill - probably not running" + docker rm ${CONTAINER_NAME} || echo "Container removed already" + +rm: + docker kill ${CONTAINER_NAME} 2>/dev/null && echo killed || echo "Container seems stopped already" + docker rm ${CONTAINER_NAME} || echo "Container seems removed already" + +rmi: + @docker rmi ${IMAGE_NAME}:latest 2>/dev/null && echo removed image || echo "Image seems removed already" diff --git a/helpers/sdbus-c++-xml2cpp/README.md b/helpers/sdbus-c++-xml2cpp/README.md new file mode 100644 index 0000000..df13be9 --- /dev/null +++ b/helpers/sdbus-c++-xml2cpp/README.md @@ -0,0 +1,23 @@ +# sdbus-c++-xml2cpp + +This is a code generator from the +[sdbus-cpp](https://github.com/Kistler-Group/sdbus-cpp) project. + +**sdbus-cpp** is a C++ binding for D-Bus, which is layered on top of sdbus, a +D-Bus implementation by the systemd project. + +**sdbus-c++-xml2cpp** translates a D-Bus interface description in D-Bus +introspection format (XML) into C++ proxy and adapter/stub code. + +For **IFEX** this means we do not need to generate C++ code to interface with a +D-Bus library like sdbus - instead the D-Bus XML introspection format is +generated from IFEX to describe the interface, and a code generator like this +one can then be used to get C++ code. + +This directory contains only a container description to compile and "package" +the `sdbus-c++-xml2cpp` tool into something that can be run with docker. +Alternatively, the `build.sh` script can be reused in another setup. It +encodes the few commands to compile the `sdbus-cpp` project, specifically with +the code generator included. The script does not install the dependencies +needed to compile sdbus-cpp since that requires distro-specific commands +anyway => Look at the Dockerfile for what is needed. diff --git a/helpers/sdbus-c++-xml2cpp/bashrc b/helpers/sdbus-c++-xml2cpp/bashrc new file mode 100644 index 0000000..baf14d3 --- /dev/null +++ b/helpers/sdbus-c++-xml2cpp/bashrc @@ -0,0 +1,3 @@ +# bashrc to make interactive use in container feasible +alias ls -alF +export PATH="/sdbus-cpp/build/tools/:$PATH" diff --git a/helpers/sdbus-c++-xml2cpp/build.sh b/helpers/sdbus-c++-xml2cpp/build.sh new file mode 100755 index 0000000..a326005 --- /dev/null +++ b/helpers/sdbus-c++-xml2cpp/build.sh @@ -0,0 +1,12 @@ +#!/bin/sh -xe + +if [ ! -d sdbus-cpp ] ; then + git clone --depth=1 https://github.com/Kistler-Group/sdbus-cpp +fi +cd sdbus-cpp +rm -rf build +mkdir -p build +cd build +cmake .. -DCMAKE_BUILD_TYPE=Release -DBUILD_CODE_GEN=True +cmake --build . +tools/sdbus-c++-xml2cpp -h diff --git a/helpers/sdbus-c++-xml2cpp/sdbus-c++-xml2cpp-generate b/helpers/sdbus-c++-xml2cpp/sdbus-c++-xml2cpp-generate new file mode 100755 index 0000000..c065e7a --- /dev/null +++ b/helpers/sdbus-c++-xml2cpp/sdbus-c++-xml2cpp-generate @@ -0,0 +1,38 @@ +#!/bin/sh + +# Wrapper to call "dockerized" sdbus-c++-xml2cpp tool + +# Settings: +# docker, podman, ... +CTR_TOOL=docker +CTR_NAME=ifex_local/sdbus-xml2cpp +BINARY=/sdbus-cpp/build/tools/sdbus-c++-xml2cpp + +# The tool can't seem to write to stdout :( +# So... we'll have to pass in both input and output file names + +if [ $# -lt 1 ] ; then + echo "IFEX: Docker wrapper for sdbus-c++-xml2cpp tool." + echo "This generates both proxy and adapter/stub for the input D-Bus XML instrospection formatted file." + echo "It is required to generate both outputs -- if one output is not needed, throw it away..." + echo "If any output file is not specified, its file name will be generated." + echo "Since it bind-maps a directory into a container, all files must be local filenames in the *current directory* only!" + echo "Usage: $0 " + exit 1 +fi + +# Drop suffix if any +xmlfile="$1" ; shift +filebase=${xmlfile%.xml} +proxyfile="$1" ; shift 2>/dev/null +if [ -z "$proxyfile" ] ; then + proxyfile="$filebase.proxy.h" + echo "Proxy file will be written to $proxyfile" +fi +adapterfile="$1" ; shift 2>/dev/null +if [ -z "$adapterfile" ] ; then + adapterfile="$filebase.adapter.h" + echo "Adapter file will be written to $adapterfile" +fi + +$CTR_TOOL run -t --rm --volume $PWD:/work ${CTR_NAME} ${BINARY} --proxy="$proxyfile" --adapter="$adapterfile" "$xmlfile" "$@"