blob: 32a340a647c43244346c0d5ba0f93789a734cfe6 [file] [log] [blame]
#!/usr/bin/env bash
set -e
function show_usage {
echo "Usage: $0 [options] <dirs>+"
echo
echo "Generate the sdbus++ sources from a directory path."
echo
echo "Options:"
echo " --tool <path> - path to processing tool (default 'sdbus++')."
echo " --output <path> - directory to place output files (default '.')."
echo " --list-all - include all generated files in stdout list."
echo " --jobs <N> - number to run in parallel (default: $(nproc))."
echo " <dirs>+ - any number of subdirectories to generate."
echo
echo "The output on stdout is a list of generated files, which is intended"
echo "to be consumed by build systems, such as Meson."
echo
echo "This tool, by default, generates all files that are able to be"
echo "created by sdbus++. The output is a list of compilable sources that"
echo "were generated by the tool. The tool may generate outputs which are"
echo "not able to be compiled, such as documentation, but it does not put"
echo "them into stdout unless --list-all is given."
}
sdbuspp="sdbus++"
outputdir="."
listall="no"
parallel=$(nproc || cat /proc/cpuinfo | grep ^processor | wc -l)
options="$(getopt -o ho:t:j: --long help,list-all,output:,tool:,jobs: -- "$@")"
eval set -- "$options"
while true;
do
case "$1" in
-h | --help)
show_usage
exit
;;
-j | --jobs)
shift
parallel="$1"
shift
;;
--list-all)
listall="yes"
shift
;;
-o | --output)
shift
outputdir="$1"
shift
;;
-t | --tool)
shift
sdbuspp="$1"
shift
;;
--)
shift
break
;;
esac
done
if [ "x" == "x$@" ];
then
show_usage
exit 1
fi
# generate_single -- make a single call to sdbus++.
# $1: sdbus++ TYPE
# $2: sdbus++ PROCESS
# $3: sdbus++ ITEM
# $4: relative output file
# $5: 'append-mode' if present.
function generate_single {
if [ "x" == "x$5" ];
then
$sdbuspp $1 $2 $3 > $outputdir/$4 &
else
$sdbuspp $1 $2 $3 >> $outputdir/$4 &
fi
# Always emit generated file name for foo-cpp and foo-header.
# Conditionally emit for everything else depending on $listall.
case "$2" in
*-cpp | *-header)
echo $outputdir/$4
;;
*)
if [ "xyes" == "x$listall" ];
then
echo $outputdir/$4
fi
;;
esac
# Ensure that no more than ${parallel} jobs are running at a time and if so
# wait for at least one to finish.
while [[ $(jobs -r -p | wc -l) -ge $parallel ]];
do
wait -n
done
}
for d in $@;
do
interfaces="$(find $d -name '*.interface.yaml')"
for i in $interfaces;
do
path="${i%.interface.yaml}"
iface="${path//\//.}"
mkdir -p $outputdir/$path
generate_single interface server-header $iface $path/server.hpp
generate_single interface server-cpp $iface $path/server.cpp
generate_single interface client-header $iface $path/client.hpp
generate_single interface markdown $iface $path.md
done
wait # finish all before continuing
errors="$(find $d -name '*.errors.yaml')"
for e in $errors;
do
path="${e%.errors.yaml}"
iface="${path//\//.}"
mkdir -p $outputdir/$path
generate_single error exception-header $iface $path/error.hpp
generate_single error exception-cpp $iface $path/error.cpp
generate_single error markdown $iface $path.md append
done
wait # finish all before continuing
done