blob: a38b5fdaf85e6d9a418b504bca01203a22fbf7d9 [file] [log] [blame]
Patrick Williams185d2792020-05-19 16:41:45 -05001#!/usr/bin/env bash
2
3set -e
4
5function show_usage {
6 echo "Usage: $0 [options] <dirs>+"
7 echo
8 echo "Generate the sdbus++ sources from a directory path."
9 echo
10 echo "Options:"
11 echo " --tool <path> - path to processing tool (default 'sdbus++')."
12 echo " --output <path> - directory to place output files (default '.')."
13 echo " --list-all - include all generated files in stdout list."
Patrick Williamsbb140d12020-06-05 16:29:10 -050014 echo " --jobs <N> - number to run in parallel (default: $(nproc))."
Patrick Williams185d2792020-05-19 16:41:45 -050015 echo " <dirs>+ - any number of subdirectories to generate."
16 echo
17 echo "The output on stdout is a list of generated files, which is intended"
18 echo "to be consumed by build systems, such as Meson."
19 echo
20 echo "This tool, by default, generates all files that are able to be"
21 echo "created by sdbus++. The output is a list of compilable sources that"
22 echo "were generated by the tool. The tool may generate outputs which are"
23 echo "not able to be compiled, such as documentation, but it does not put"
24 echo "them into stdout unless --list-all is given."
25}
26
Patrick Williamsbb140d12020-06-05 16:29:10 -050027# Ensure that no more than ${parallel} jobs are running at a time and if so
28# wait for at least one to finish.
29function wait_n {
30 while true;
31 do
32 if [[ $(jobs -r -p | wc -l) -ge $parallel ]];
33 then
34 wait -n
35 else
36 break
37 fi
38 done
39}
40
Patrick Williams185d2792020-05-19 16:41:45 -050041sdbuspp="sdbus++"
42outputdir="."
43listall="no"
Patrick Williamsbb140d12020-06-05 16:29:10 -050044parallel=$(nproc)
Patrick Williams185d2792020-05-19 16:41:45 -050045
Patrick Williamsbb140d12020-06-05 16:29:10 -050046options="$(getopt -o ho:t:j: --long help,list-all,output:,tool:,jobs: -- "$@")"
Patrick Williams185d2792020-05-19 16:41:45 -050047eval set -- "$options"
48
Patrick Williamsbb140d12020-06-05 16:29:10 -050049while true;
50do
Patrick Williams185d2792020-05-19 16:41:45 -050051 case "$1" in
52 -h | --help)
53 show_usage
54 exit
55 ;;
56
Patrick Williamsbb140d12020-06-05 16:29:10 -050057 -j | --jobs)
58 shift
59 parallel="$1"
60 shift
61 ;;
62
Patrick Williams185d2792020-05-19 16:41:45 -050063 --list-all)
64 listall="yes"
65 shift
66 ;;
67
68 -o | --output)
69 shift
Patrick Williamsbb140d12020-06-05 16:29:10 -050070 outputdir="$1"
Patrick Williams185d2792020-05-19 16:41:45 -050071 shift
72 ;;
73
74 -t | --tool)
75 shift
Patrick Williamsbb140d12020-06-05 16:29:10 -050076 sdbuspp="$1"
Patrick Williams185d2792020-05-19 16:41:45 -050077 shift
78 ;;
79
80 --)
81 shift
82 break
83 ;;
Patrick Williams185d2792020-05-19 16:41:45 -050084 esac
85done
86
87if [ "x" == "x$@" ];
88then
89 show_usage
90 exit 1
91fi
92
93for d in $@;
94do
95 interfaces="$(find $d -name '*.interface.yaml')"
96
97 for i in $interfaces;
98 do
99 path="${i%.interface.yaml}"
100 iface="${path//\//.}"
101
102 mkdir -p $outputdir/$path
103
Patrick Williamsbb140d12020-06-05 16:29:10 -0500104 $sdbuspp interface server-header $iface > $outputdir/$path/server.hpp &
Patrick Williams185d2792020-05-19 16:41:45 -0500105 echo $outputdir/$path/server.hpp
Patrick Williamsbb140d12020-06-05 16:29:10 -0500106 wait_n
Patrick Williams185d2792020-05-19 16:41:45 -0500107
Patrick Williamsbb140d12020-06-05 16:29:10 -0500108 $sdbuspp interface server-cpp $iface > $outputdir/$path/server.cpp &
Patrick Williams185d2792020-05-19 16:41:45 -0500109 echo $outputdir/$path/server.cpp
Patrick Williamsbb140d12020-06-05 16:29:10 -0500110 wait_n
Patrick Williams185d2792020-05-19 16:41:45 -0500111
Patrick Williamsbb140d12020-06-05 16:29:10 -0500112 $sdbuspp interface client-header $iface > $outputdir/$path/client.hpp &
Patrick Williams185d2792020-05-19 16:41:45 -0500113 echo $outputdir/$path/client.hpp
Patrick Williamsbb140d12020-06-05 16:29:10 -0500114 wait_n
Patrick Williams185d2792020-05-19 16:41:45 -0500115
Patrick Williamsbb140d12020-06-05 16:29:10 -0500116 $sdbuspp interface markdown $iface > $outputdir/$path.md &
Patrick Williams185d2792020-05-19 16:41:45 -0500117 # markdown files aren't recognized as source files by meson, so don't
118 # emit them by default.
119 if [ "xyes" == "x$listall" ];
120 then
121 echo $outputdir/$path.md
122 fi
Patrick Williamsbb140d12020-06-05 16:29:10 -0500123 wait_n
Patrick Williams185d2792020-05-19 16:41:45 -0500124 done
Patrick Williamsbb140d12020-06-05 16:29:10 -0500125 wait # finish all before continuing
Patrick Williams185d2792020-05-19 16:41:45 -0500126
127 errors="$(find $d -name '*.errors.yaml')"
128
129 for e in $errors;
130 do
131 path="${e%.errors.yaml}"
132 iface="${path//\//.}"
133
134 mkdir -p $outputdir/$path
135
Patrick Williamsbb140d12020-06-05 16:29:10 -0500136 $sdbuspp error exception-header $iface > $outputdir/$path/error.hpp &
Patrick Williams185d2792020-05-19 16:41:45 -0500137 echo $outputdir/$path/error.hpp
Patrick Williamsbb140d12020-06-05 16:29:10 -0500138 wait_n
Patrick Williams185d2792020-05-19 16:41:45 -0500139
Patrick Williamsbb140d12020-06-05 16:29:10 -0500140 $sdbuspp error exception-cpp $iface > $outputdir/$path/error.cpp &
Patrick Williams185d2792020-05-19 16:41:45 -0500141 echo $outputdir/$path/error.cpp
Patrick Williamsbb140d12020-06-05 16:29:10 -0500142 wait_n
Patrick Williams185d2792020-05-19 16:41:45 -0500143
Patrick Williamsbb140d12020-06-05 16:29:10 -0500144 $sdbuspp error markdown $iface >> $outputdir/$path.md &
Patrick Williams185d2792020-05-19 16:41:45 -0500145 # markdown files aren't recognized as source files by meson, so don't
146 # emit them by default.
147 if [ "xyes" == "x$listall" ];
148 then
149 echo $outputdir/$path.md
150 fi
Patrick Williamsbb140d12020-06-05 16:29:10 -0500151 wait_n
Patrick Williams185d2792020-05-19 16:41:45 -0500152 done
Patrick Williamsbb140d12020-06-05 16:29:10 -0500153 wait # finish all before continuing
Patrick Williams185d2792020-05-19 16:41:45 -0500154done