blob: bc60ca016711eebf8b01a6175f236a0212372277 [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."
14 echo " <dirs>+ - any number of subdirectories to generate."
15 echo
16 echo "The output on stdout is a list of generated files, which is intended"
17 echo "to be consumed by build systems, such as Meson."
18 echo
19 echo "This tool, by default, generates all files that are able to be"
20 echo "created by sdbus++. The output is a list of compilable sources that"
21 echo "were generated by the tool. The tool may generate outputs which are"
22 echo "not able to be compiled, such as documentation, but it does not put"
23 echo "them into stdout unless --list-all is given."
24}
25
26sdbuspp="sdbus++"
27outputdir="."
28listall="no"
29
30options="$(getopt -o ho:t: --long help,list-all,output:,tool: -- "$@")"
31eval set -- "$options"
32
33while true; do
34 case "$1" in
35 -h | --help)
36 show_usage
37 exit
38 ;;
39
40 --list-all)
41 listall="yes"
42 shift
43 ;;
44
45 -o | --output)
46 shift
47 outputdir="$1";
48 shift
49 ;;
50
51 -t | --tool)
52 shift
53 sdbuspp="$1";
54 shift
55 ;;
56
57 --)
58 shift
59 break
60 ;;
61
62 *)
63 break
64 ;;
65 esac
66done
67
68if [ "x" == "x$@" ];
69then
70 show_usage
71 exit 1
72fi
73
74for d in $@;
75do
76 interfaces="$(find $d -name '*.interface.yaml')"
77
78 for i in $interfaces;
79 do
80 path="${i%.interface.yaml}"
81 iface="${path//\//.}"
82
83 mkdir -p $outputdir/$path
84
85 $sdbuspp interface server-header $iface > $outputdir/$path/server.hpp
86 echo $outputdir/$path/server.hpp
87
88 $sdbuspp interface server-cpp $iface > $outputdir/$path/server.cpp
89 echo $outputdir/$path/server.cpp
90
91 $sdbuspp interface client-header $iface > $outputdir/$path/client.hpp
92 echo $outputdir/$path/client.hpp
93
94 $sdbuspp interface markdown $iface > $outputdir/$path.md
95 # markdown files aren't recognized as source files by meson, so don't
96 # emit them by default.
97 if [ "xyes" == "x$listall" ];
98 then
99 echo $outputdir/$path.md
100 fi
101 done
102
103 errors="$(find $d -name '*.errors.yaml')"
104
105 for e in $errors;
106 do
107 path="${e%.errors.yaml}"
108 iface="${path//\//.}"
109
110 mkdir -p $outputdir/$path
111
112 $sdbuspp error exception-header $iface > $outputdir/$path/error.hpp
113 echo $outputdir/$path/error.hpp
114
115 $sdbuspp error exception-cpp $iface > $outputdir/$path/error.cpp
116 echo $outputdir/$path/error.cpp
117
118 $sdbuspp error markdown $iface >> $outputdir/$path.md
119 # markdown files aren't recognized as source files by meson, so don't
120 # emit them by default.
121 if [ "xyes" == "x$listall" ];
122 then
123 echo $outputdir/$path.md
124 fi
125 done
126done