blob: a81f68c83ff223e95e41e34e579395ee7f80281f [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 ;;
Patrick Williams185d2792020-05-19 16:41:45 -050061 esac
62done
63
64if [ "x" == "x$@" ];
65then
66 show_usage
67 exit 1
68fi
69
70for d in $@;
71do
72 interfaces="$(find $d -name '*.interface.yaml')"
73
74 for i in $interfaces;
75 do
76 path="${i%.interface.yaml}"
77 iface="${path//\//.}"
78
79 mkdir -p $outputdir/$path
80
81 $sdbuspp interface server-header $iface > $outputdir/$path/server.hpp
82 echo $outputdir/$path/server.hpp
83
84 $sdbuspp interface server-cpp $iface > $outputdir/$path/server.cpp
85 echo $outputdir/$path/server.cpp
86
87 $sdbuspp interface client-header $iface > $outputdir/$path/client.hpp
88 echo $outputdir/$path/client.hpp
89
90 $sdbuspp interface markdown $iface > $outputdir/$path.md
91 # markdown files aren't recognized as source files by meson, so don't
92 # emit them by default.
93 if [ "xyes" == "x$listall" ];
94 then
95 echo $outputdir/$path.md
96 fi
97 done
98
99 errors="$(find $d -name '*.errors.yaml')"
100
101 for e in $errors;
102 do
103 path="${e%.errors.yaml}"
104 iface="${path//\//.}"
105
106 mkdir -p $outputdir/$path
107
108 $sdbuspp error exception-header $iface > $outputdir/$path/error.hpp
109 echo $outputdir/$path/error.hpp
110
111 $sdbuspp error exception-cpp $iface > $outputdir/$path/error.cpp
112 echo $outputdir/$path/error.cpp
113
114 $sdbuspp error markdown $iface >> $outputdir/$path.md
115 # markdown files aren't recognized as source files by meson, so don't
116 # emit them by default.
117 if [ "xyes" == "x$listall" ];
118 then
119 echo $outputdir/$path.md
120 fi
121 done
122done