-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add sdbus (D-Bus) C++ code generator helper
Signed-off-by: Gunnar Andersson <gunnar_dev@[email protected]>
- Loading branch information
Showing
6 changed files
with
137 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# bashrc to make interactive use in container feasible | ||
alias ls -alF | ||
export PATH="/sdbus-cpp/build/tools/:$PATH" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <input-xml-file> <output-proxy-header> <output-adapter-header>" | ||
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" "$@" |