| Patrick Williams | 847a0c3 | 2020-06-24 15:18:10 -0500 | [diff] [blame] | 1 | #!/usr/bin/env bash | 
 | 2 |  | 
 | 3 | set -e | 
 | 4 |  | 
| Patrick Williams | a4c9edc | 2020-12-17 21:02:36 -0600 | [diff] [blame] | 5 | # Locale can change behavior of utilities like 'sort' but we want the output | 
 | 6 | # to be stable on all machines.  Force the locale to 'C' for consistency. | 
 | 7 | export LC_ALL=C | 
 | 8 |  | 
| Patrick Williams | 018b8ff | 2022-12-05 16:03:46 -0600 | [diff] [blame] | 9 | function show_usage() { | 
| Patrick Williams | 847a0c3 | 2020-06-24 15:18:10 -0500 | [diff] [blame] | 10 |     cat \ | 
| Patrick Williams | 9ede18b | 2022-03-12 07:55:36 -0600 | [diff] [blame] | 11 |         << EOF | 
| Patrick Williams | 847a0c3 | 2020-06-24 15:18:10 -0500 | [diff] [blame] | 12 | Usage: $(basename "$0") [options] <command-args>* | 
 | 13 |  | 
 | 14 | Generate meson.build files from a directory tree containing YAML files and | 
 | 15 | facilitate building the sdbus++ sources. | 
 | 16 |  | 
 | 17 | Options: | 
 | 18 |     --help              - Display this message | 
 | 19 |     --command <cmd>     - Command mode to execute (default 'meson'). | 
 | 20 |     --directory <path>  - Root directory of the YAML source (default '.'). | 
 | 21 |     --output <path>     - Root directory of the output (default '.'). | 
 | 22 |     --tool <path>       - Path to the processing tool (default 'sdbus++'). | 
 | 23 |     --version           - Display this tool's version string. | 
 | 24 |  | 
 | 25 | Commands: | 
 | 26 |     meson               - Generate a tree of meson.build files corresponding | 
 | 27 |                           to the source YAML files. | 
 | 28 |     cpp <intf>          - Generate the source files from a YAML interface. | 
 | 29 |     markdown <intf>     - Generate the markdown files from a YAML interface. | 
 | 30 |     version             - Display this tool's version string. | 
 | 31 |  | 
 | 32 | EOF | 
 | 33 | } | 
 | 34 |  | 
 | 35 | ## The version is somewhat arbitrary but is used to create a warning message | 
 | 36 | ## if a repository contains old copies of the generated meson.build files and | 
 | 37 | ## needs an update.  We should increment the version number whenever the | 
 | 38 | ## resulting meson.build would change. | 
| Patrick Williams | 0ac157a | 2024-09-23 21:57:39 -0400 | [diff] [blame^] | 39 | tool_version="sdbus++-gen-meson version 9" | 
| Patrick Williams | 018b8ff | 2022-12-05 16:03:46 -0600 | [diff] [blame] | 40 | function show_version() { | 
| Patrick Williams | d77548a | 2022-04-29 14:43:15 -0500 | [diff] [blame] | 41 |     echo "${tool_version}" | 
| Patrick Williams | 847a0c3 | 2020-06-24 15:18:10 -0500 | [diff] [blame] | 42 | } | 
 | 43 |  | 
 | 44 | # Set up defaults. | 
 | 45 | sdbuspp="sdbus++" | 
 | 46 | outputdir="." | 
 | 47 | cmd="meson" | 
 | 48 | rootdir="." | 
 | 49 |  | 
 | 50 | # Parse options. | 
 | 51 | options="$(getopt -o hc:d:o:t:v --long help,command:,directory:,output:,tool:,version -- "$@")" | 
| Patrick Williams | d77548a | 2022-04-29 14:43:15 -0500 | [diff] [blame] | 52 | eval set -- "${options}" | 
| Patrick Williams | 847a0c3 | 2020-06-24 15:18:10 -0500 | [diff] [blame] | 53 |  | 
| Patrick Williams | 9ede18b | 2022-03-12 07:55:36 -0600 | [diff] [blame] | 54 | while true; do | 
| Patrick Williams | 847a0c3 | 2020-06-24 15:18:10 -0500 | [diff] [blame] | 55 |     case "$1" in | 
 | 56 |         -h | --help) | 
 | 57 |             show_usage | 
 | 58 |             exit | 
 | 59 |             ;; | 
 | 60 |  | 
 | 61 |         -c | --command) | 
 | 62 |             shift | 
 | 63 |             cmd="$1" | 
 | 64 |             shift | 
 | 65 |             ;; | 
 | 66 |  | 
 | 67 |         -d | --directory) | 
 | 68 |             shift | 
 | 69 |             rootdir="$1" | 
 | 70 |             shift | 
 | 71 |             ;; | 
 | 72 |  | 
 | 73 |         -o | --output) | 
 | 74 |             shift | 
 | 75 |             outputdir="$1" | 
 | 76 |             shift | 
 | 77 |             ;; | 
 | 78 |  | 
 | 79 |         -t | --tool) | 
 | 80 |             shift | 
 | 81 |             sdbuspp="$1" | 
 | 82 |             shift | 
 | 83 |             ;; | 
 | 84 |  | 
 | 85 |         -v | --version) | 
 | 86 |             show_version | 
 | 87 |             exit | 
 | 88 |             ;; | 
 | 89 |  | 
 | 90 |         --) | 
 | 91 |             shift | 
 | 92 |             break | 
 | 93 |             ;; | 
| Patrick Williams | d77548a | 2022-04-29 14:43:15 -0500 | [diff] [blame] | 94 |  | 
 | 95 |         *) | 
 | 96 |             echo "Invalid argument $1" | 
 | 97 |             exit 1 | 
 | 98 |             ;; | 
| Patrick Williams | 847a0c3 | 2020-06-24 15:18:10 -0500 | [diff] [blame] | 99 |     esac | 
 | 100 | done | 
 | 101 |  | 
 | 102 | ## Create an initially empty meson.build file. | 
 | 103 | ## $1 - path to create meson.build at. | 
| Patrick Williams | 018b8ff | 2022-12-05 16:03:46 -0600 | [diff] [blame] | 104 | function meson_empty_file() { | 
| Patrick Williams | 847a0c3 | 2020-06-24 15:18:10 -0500 | [diff] [blame] | 105 |     mkdir -p "$1" | 
 | 106 |     echo "# Generated file; do not modify." > "$1/meson.build" | 
 | 107 | } | 
 | 108 |  | 
 | 109 | ## Create the root-level meson.build | 
 | 110 | ## | 
 | 111 | ## Inserts rules to run the available version of this tool to ensure the | 
 | 112 | ## version has not changed. | 
| Patrick Williams | 018b8ff | 2022-12-05 16:03:46 -0600 | [diff] [blame] | 113 | function meson_create_root() { | 
| Patrick Williams | d77548a | 2022-04-29 14:43:15 -0500 | [diff] [blame] | 114 |     meson_empty_file "${outputdir}" | 
| Patrick Williams | 847a0c3 | 2020-06-24 15:18:10 -0500 | [diff] [blame] | 115 |  | 
| Patrick Williams | d77548a | 2022-04-29 14:43:15 -0500 | [diff] [blame] | 116 |     cat >> "${outputdir}/meson.build" \ | 
| Patrick Williams | 9ede18b | 2022-03-12 07:55:36 -0600 | [diff] [blame] | 117 |         << EOF | 
| Patrick Williams | 847a0c3 | 2020-06-24 15:18:10 -0500 | [diff] [blame] | 118 | sdbuspp_gen_meson_ver = run_command( | 
 | 119 |     sdbuspp_gen_meson_prog, | 
 | 120 |     '--version', | 
| Ed Tanous | 60a9430 | 2023-01-06 13:52:45 -0800 | [diff] [blame] | 121 |     check: true, | 
| Patrick Williams | 847a0c3 | 2020-06-24 15:18:10 -0500 | [diff] [blame] | 122 | ).stdout().strip().split('\n')[0] | 
 | 123 |  | 
| Patrick Williams | d77548a | 2022-04-29 14:43:15 -0500 | [diff] [blame] | 124 | if sdbuspp_gen_meson_ver != '${tool_version}' | 
| Patrick Williams | 847a0c3 | 2020-06-24 15:18:10 -0500 | [diff] [blame] | 125 |     warning('Generated meson files from wrong version of sdbus++-gen-meson.') | 
 | 126 |     warning( | 
| Patrick Williams | d77548a | 2022-04-29 14:43:15 -0500 | [diff] [blame] | 127 |         'Expected "${tool_version}", got:', | 
| Patrick Williams | 847a0c3 | 2020-06-24 15:18:10 -0500 | [diff] [blame] | 128 |         sdbuspp_gen_meson_ver | 
 | 129 |     ) | 
 | 130 | endif | 
 | 131 |  | 
 | 132 | EOF | 
 | 133 | } | 
 | 134 |  | 
 | 135 | ## hash-tables to store: | 
 | 136 | ##      meson_paths - list of subdirectory paths for which an empty meson.build | 
 | 137 | ##                    has already been created. | 
 | 138 | ##      interfaces - list of interface paths which a YAML has been found and | 
 | 139 | ##                   which YAML types (interface, errors, etc.). | 
 | 140 | declare -A meson_paths | 
 | 141 | declare -A interfaces | 
 | 142 |  | 
 | 143 | ## Ensure the meson.build files to a path have been created. | 
 | 144 | ## $1 - The path requiring to be created. | 
| Patrick Williams | 018b8ff | 2022-12-05 16:03:46 -0600 | [diff] [blame] | 145 | function meson_create_path() { | 
| Patrick Williams | 847a0c3 | 2020-06-24 15:18:10 -0500 | [diff] [blame] | 146 |  | 
| Patrick Williams | d77548a | 2022-04-29 14:43:15 -0500 | [diff] [blame] | 147 |     meson_path="${outputdir}" | 
| Patrick Williams | 847a0c3 | 2020-06-24 15:18:10 -0500 | [diff] [blame] | 148 |     prev_meson_path="" | 
 | 149 |  | 
 | 150 |     # Split the path into segments. | 
| Patrick Williams | 9ede18b | 2022-03-12 07:55:36 -0600 | [diff] [blame] | 151 |     for part in $(echo "$1" | tr '/' '\n'); do | 
| Patrick Williams | d77548a | 2022-04-29 14:43:15 -0500 | [diff] [blame] | 152 |         prev_meson_path="${meson_path}" | 
 | 153 |         meson_path="${meson_path}/${part}" | 
| Patrick Williams | 847a0c3 | 2020-06-24 15:18:10 -0500 | [diff] [blame] | 154 |  | 
 | 155 |         # Create the meson.build for this segment if it doesn't already exist. | 
| Patrick Williams | d77548a | 2022-04-29 14:43:15 -0500 | [diff] [blame] | 156 |         if [[ "" == "${meson_paths[${meson_path}]}" ]]; then | 
 | 157 |             meson_paths["${meson_path}"]="1" | 
 | 158 |             meson_empty_file "${meson_path}" | 
| Patrick Williams | 847a0c3 | 2020-06-24 15:18:10 -0500 | [diff] [blame] | 159 |  | 
 | 160 |             # Add the 'subdir' link into the parent's meson.build. | 
 | 161 |             # We need to skip adding the links into the 'root' meson.build | 
 | 162 |             # because most repositories want to selectively add TLDs based | 
 | 163 |             # on config flags.  Let them figure out their own logic for that. | 
| Patrick Williams | d77548a | 2022-04-29 14:43:15 -0500 | [diff] [blame] | 164 |             if [[ ${outputdir} != "${prev_meson_path}" ]]; then | 
 | 165 |                 echo "subdir('${part}')" >> "${prev_meson_path}/meson.build" | 
| Patrick Williams | 847a0c3 | 2020-06-24 15:18:10 -0500 | [diff] [blame] | 166 |             fi | 
 | 167 |         fi | 
 | 168 |     done | 
 | 169 | } | 
 | 170 |  | 
 | 171 | ## Generate the meson target for the source files (.cpp/.hpp) from a YAML | 
 | 172 | ## interface. | 
 | 173 | ## | 
 | 174 | ## $1 - The interface to generate a target for. | 
| Patrick Williams | 018b8ff | 2022-12-05 16:03:46 -0600 | [diff] [blame] | 175 | function meson_cpp_target() { | 
| Patrick Williams | d77548a | 2022-04-29 14:43:15 -0500 | [diff] [blame] | 176 |     mesondir="${outputdir}/$1" | 
 | 177 |     yamldir="$(realpath --relative-to="${mesondir}" "${rootdir}")" | 
| Patrick Williams | 847a0c3 | 2020-06-24 15:18:10 -0500 | [diff] [blame] | 178 |  | 
 | 179 |     # Determine the source and output files based on the YAMLs present. | 
 | 180 |     sources="" | 
 | 181 |     outputs="" | 
| Patrick Williams | 9ede18b | 2022-03-12 07:55:36 -0600 | [diff] [blame] | 182 |     for s in ${interfaces[$1]}; do | 
| Patrick Williams | 0ac157a | 2024-09-23 21:57:39 -0400 | [diff] [blame^] | 183 |         sources="${sources}'${yamldir}/$1.${s}', " | 
| Patrick Williams | 847a0c3 | 2020-06-24 15:18:10 -0500 | [diff] [blame] | 184 |  | 
| Patrick Williams | d77548a | 2022-04-29 14:43:15 -0500 | [diff] [blame] | 185 |         case "${s}" in | 
| Patrick Williams | 847a0c3 | 2020-06-24 15:18:10 -0500 | [diff] [blame] | 186 |             errors.yaml) | 
 | 187 |                 outputs="${outputs}'error.cpp', 'error.hpp', " | 
 | 188 |                 ;; | 
 | 189 |  | 
| Patrick Williams | 0336a2f | 2024-09-05 21:41:07 -0400 | [diff] [blame] | 190 |             events.yaml) | 
 | 191 |                 outputs="${outputs}'event.cpp', 'event.hpp', " | 
 | 192 |                 ;; | 
 | 193 |  | 
| Patrick Williams | 847a0c3 | 2020-06-24 15:18:10 -0500 | [diff] [blame] | 194 |             interface.yaml) | 
| Patrick Williams | 1caa5e8 | 2023-04-19 16:24:38 -0500 | [diff] [blame] | 195 |                 outputs="${outputs}'common.hpp', " | 
| Patrick Williams | 847a0c3 | 2020-06-24 15:18:10 -0500 | [diff] [blame] | 196 |                 outputs="${outputs}'server.cpp', 'server.hpp', " | 
| Patrick Williams | 6403d56 | 2023-08-18 11:34:43 -0500 | [diff] [blame] | 197 |                 outputs="${outputs}'aserver.hpp', " | 
| Patrick Williams | 847a0c3 | 2020-06-24 15:18:10 -0500 | [diff] [blame] | 198 |                 outputs="${outputs}'client.hpp', " | 
 | 199 |                 ;; | 
| Patrick Williams | d77548a | 2022-04-29 14:43:15 -0500 | [diff] [blame] | 200 |  | 
 | 201 |             *) | 
 | 202 |                 echo "Unknown interface type: ${s}" | 
 | 203 |                 exit 1 | 
 | 204 |                 ;; | 
| Patrick Williams | 847a0c3 | 2020-06-24 15:18:10 -0500 | [diff] [blame] | 205 |         esac | 
 | 206 |     done | 
 | 207 |  | 
 | 208 |     # Create the target to generate the 'outputs'. | 
| Patrick Williams | d77548a | 2022-04-29 14:43:15 -0500 | [diff] [blame] | 209 |     cat >> "${mesondir}/meson.build" \ | 
| Patrick Williams | 9ede18b | 2022-03-12 07:55:36 -0600 | [diff] [blame] | 210 |         << EOF | 
| Patrick Williams | 847a0c3 | 2020-06-24 15:18:10 -0500 | [diff] [blame] | 211 | generated_sources += custom_target( | 
 | 212 |     '$1__cpp'.underscorify(), | 
| Patrick Williams | d77548a | 2022-04-29 14:43:15 -0500 | [diff] [blame] | 213 |     input: [ ${sources} ], | 
 | 214 |     output: [ ${outputs} ], | 
| William A. Kennington III | 293c8a2 | 2022-09-02 14:35:54 -0700 | [diff] [blame] | 215 |     depend_files: sdbusplusplus_depfiles, | 
| Patrick Williams | 847a0c3 | 2020-06-24 15:18:10 -0500 | [diff] [blame] | 216 |     command: [ | 
 | 217 |         sdbuspp_gen_meson_prog, '--command', 'cpp', | 
 | 218 |         '--output', meson.current_build_dir(), | 
 | 219 |         '--tool', sdbusplusplus_prog, | 
| Patrick Williams | d77548a | 2022-04-29 14:43:15 -0500 | [diff] [blame] | 220 |         '--directory', meson.current_source_dir() / '${yamldir}', | 
| Patrick Williams | 847a0c3 | 2020-06-24 15:18:10 -0500 | [diff] [blame] | 221 |         '$1', | 
 | 222 |     ], | 
 | 223 | ) | 
 | 224 |  | 
 | 225 | EOF | 
 | 226 | } | 
 | 227 |  | 
 | 228 | ## Generate the meson target for the markdown files from a YAML interface. | 
 | 229 | ## $1 - The interface to generate a target for. | 
| Patrick Williams | 018b8ff | 2022-12-05 16:03:46 -0600 | [diff] [blame] | 230 | function meson_md_target() { | 
| Patrick Williams | d77548a | 2022-04-29 14:43:15 -0500 | [diff] [blame] | 231 |     mesondir="${outputdir}/$(dirname "$1")" | 
 | 232 |     yamldir="$(realpath --relative-to="${mesondir}" "${rootdir}")" | 
| Patrick Williams | 847a0c3 | 2020-06-24 15:18:10 -0500 | [diff] [blame] | 233 |  | 
 | 234 |     # Determine the source files based on the YAMLs present. | 
 | 235 |     sources="" | 
| Patrick Williams | 9ede18b | 2022-03-12 07:55:36 -0600 | [diff] [blame] | 236 |     for s in ${interfaces[$1]}; do | 
| Patrick Williams | 5800d07 | 2024-09-16 22:28:18 -0400 | [diff] [blame] | 237 |         sources="${sources}'${yamldir}/$1.${s}', " | 
| Patrick Williams | 847a0c3 | 2020-06-24 15:18:10 -0500 | [diff] [blame] | 238 |     done | 
 | 239 |  | 
 | 240 |     # Create the target to generate the interface.md file. | 
| Patrick Williams | d77548a | 2022-04-29 14:43:15 -0500 | [diff] [blame] | 241 |     cat >> "${mesondir}/meson.build" \ | 
| Patrick Williams | 9ede18b | 2022-03-12 07:55:36 -0600 | [diff] [blame] | 242 |         << EOF | 
| Patrick Williams | 847a0c3 | 2020-06-24 15:18:10 -0500 | [diff] [blame] | 243 | generated_others += custom_target( | 
 | 244 |     '$1__markdown'.underscorify(), | 
| Patrick Williams | d77548a | 2022-04-29 14:43:15 -0500 | [diff] [blame] | 245 |     input: [ ${sources} ], | 
| Patrick Williams | 847a0c3 | 2020-06-24 15:18:10 -0500 | [diff] [blame] | 246 |     output: [ '$(basename "$1").md' ], | 
| William A. Kennington III | 293c8a2 | 2022-09-02 14:35:54 -0700 | [diff] [blame] | 247 |     depend_files: sdbusplusplus_depfiles, | 
| Patrick Williams | 847a0c3 | 2020-06-24 15:18:10 -0500 | [diff] [blame] | 248 |     command: [ | 
 | 249 |         sdbuspp_gen_meson_prog, '--command', 'markdown', | 
 | 250 |         '--output', meson.current_build_dir(), | 
 | 251 |         '--tool', sdbusplusplus_prog, | 
| Patrick Williams | d77548a | 2022-04-29 14:43:15 -0500 | [diff] [blame] | 252 |         '--directory', meson.current_source_dir() / '${yamldir}', | 
| Patrick Williams | 847a0c3 | 2020-06-24 15:18:10 -0500 | [diff] [blame] | 253 |         '$1', | 
 | 254 |     ], | 
| Patrick Williams | 847a0c3 | 2020-06-24 15:18:10 -0500 | [diff] [blame] | 255 | ) | 
 | 256 |  | 
 | 257 | EOF | 
 | 258 | } | 
 | 259 |  | 
 | 260 | ## Handle command=meson by generating the tree of meson.build files. | 
| Patrick Williams | 018b8ff | 2022-12-05 16:03:46 -0600 | [diff] [blame] | 261 | function cmd_meson() { | 
| Willam A. Kennington III | ce8d16d | 2022-09-07 15:46:40 -0700 | [diff] [blame] | 262 |     # Find and sort all the YAML files | 
| Patrick Williams | 0336a2f | 2024-09-05 21:41:07 -0400 | [diff] [blame] | 263 |     yamls="$(find "${rootdir}" -name '*.interface.yaml' -o -name '*.errors.yaml' -o -name '*.events.yaml')" | 
| Willam A. Kennington III | ce8d16d | 2022-09-07 15:46:40 -0700 | [diff] [blame] | 264 |     yamls="$(echo "${yamls}" | sort)" | 
| Patrick Williams | 847a0c3 | 2020-06-24 15:18:10 -0500 | [diff] [blame] | 265 |  | 
 | 266 |     # Assign the YAML files into the hash-table by interface name. | 
| Patrick Williams | d77548a | 2022-04-29 14:43:15 -0500 | [diff] [blame] | 267 |     for y in ${yamls}; do | 
 | 268 |         rel="$(realpath "--relative-to=${rootdir}" "${y}")" | 
 | 269 |         dir="$(dirname "${rel}")" | 
| Patrick Williams | 847a0c3 | 2020-06-24 15:18:10 -0500 | [diff] [blame] | 270 |         ext="${rel#*.}" | 
| Patrick Williams | d77548a | 2022-04-29 14:43:15 -0500 | [diff] [blame] | 271 |         base="$(basename "${rel}" ".${ext}")" | 
 | 272 |         key="${dir}/${base}" | 
| Patrick Williams | 847a0c3 | 2020-06-24 15:18:10 -0500 | [diff] [blame] | 273 |  | 
| Patrick Williams | d77548a | 2022-04-29 14:43:15 -0500 | [diff] [blame] | 274 |         interfaces["${key}"]="${interfaces[${key}]} ${ext}" | 
| Patrick Williams | 847a0c3 | 2020-06-24 15:18:10 -0500 | [diff] [blame] | 275 |     done | 
 | 276 |  | 
 | 277 |     # Create the meson.build files. | 
 | 278 |     meson_create_root | 
| Patrick Williams | d77548a | 2022-04-29 14:43:15 -0500 | [diff] [blame] | 279 |     # shellcheck disable=SC2312 | 
| Patrick Williams | 847a0c3 | 2020-06-24 15:18:10 -0500 | [diff] [blame] | 280 |     sorted_ifaces="$(echo "${!interfaces[@]}" | tr " " "\n" | sort)" | 
| Patrick Williams | 9ede18b | 2022-03-12 07:55:36 -0600 | [diff] [blame] | 281 |     for i in ${sorted_ifaces}; do | 
| Patrick Williams | d77548a | 2022-04-29 14:43:15 -0500 | [diff] [blame] | 282 |         meson_create_path "${i}" | 
 | 283 |         meson_cpp_target "${i}" | 
 | 284 |         meson_md_target "${i}" | 
| Patrick Williams | 847a0c3 | 2020-06-24 15:18:10 -0500 | [diff] [blame] | 285 |     done | 
 | 286 | } | 
 | 287 |  | 
 | 288 | ## Handle command=cpp by calling sdbus++ as appropriate. | 
 | 289 | ## $1 - interface to generate. | 
 | 290 | ## | 
 | 291 | ## For an interface foo/bar, the outputdir is expected to be foo/bar. | 
| Patrick Williams | 018b8ff | 2022-12-05 16:03:46 -0600 | [diff] [blame] | 292 | function cmd_cpp() { | 
| Patrick Williams | 847a0c3 | 2020-06-24 15:18:10 -0500 | [diff] [blame] | 293 |  | 
| Patrick Williams | d77548a | 2022-04-29 14:43:15 -0500 | [diff] [blame] | 294 |     if [[ "" == "$1" ]]; then | 
| Patrick Williams | 847a0c3 | 2020-06-24 15:18:10 -0500 | [diff] [blame] | 295 |         show_usage | 
 | 296 |         exit 1 | 
 | 297 |     fi | 
 | 298 |  | 
| Patrick Williams | d77548a | 2022-04-29 14:43:15 -0500 | [diff] [blame] | 299 |     if [[ ! -e "${rootdir}/$1.interface.yaml" ]] && | 
| Patrick Williams | 0336a2f | 2024-09-05 21:41:07 -0400 | [diff] [blame] | 300 |     [[ ! -e "${rootdir}/$1.errors.yaml" ]] && | 
 | 301 |     [[ ! -e "${rootdir}/$1.events.yaml" ]]; then | 
| Patrick Williams | 847a0c3 | 2020-06-24 15:18:10 -0500 | [diff] [blame] | 302 |         echo "Missing YAML for $1." | 
 | 303 |         exit 1 | 
 | 304 |     fi | 
 | 305 |  | 
| Patrick Williams | d77548a | 2022-04-29 14:43:15 -0500 | [diff] [blame] | 306 |     mkdir -p "${outputdir}" | 
| Patrick Williams | 847a0c3 | 2020-06-24 15:18:10 -0500 | [diff] [blame] | 307 |  | 
| Patrick Williams | d77548a | 2022-04-29 14:43:15 -0500 | [diff] [blame] | 308 |     sdbusppcmd="${sdbuspp} -r ${rootdir}" | 
| Patrick Williams | 847a0c3 | 2020-06-24 15:18:10 -0500 | [diff] [blame] | 309 |     intf="${1//\//.}" | 
 | 310 |  | 
| Patrick Williams | d77548a | 2022-04-29 14:43:15 -0500 | [diff] [blame] | 311 |     if [[ -e "${rootdir}/$1.interface.yaml" ]]; then | 
| Patrick Williams | 1caa5e8 | 2023-04-19 16:24:38 -0500 | [diff] [blame] | 312 |         ${sdbusppcmd} interface common-header "${intf}" > "${outputdir}/common.hpp" | 
| Patrick Williams | d77548a | 2022-04-29 14:43:15 -0500 | [diff] [blame] | 313 |         ${sdbusppcmd} interface server-header "${intf}" > "${outputdir}/server.hpp" | 
 | 314 |         ${sdbusppcmd} interface server-cpp "${intf}" > "${outputdir}/server.cpp" | 
 | 315 |         ${sdbusppcmd} interface client-header "${intf}" > "${outputdir}/client.hpp" | 
| Patrick Williams | 6403d56 | 2023-08-18 11:34:43 -0500 | [diff] [blame] | 316 |         ${sdbusppcmd} interface aserver-header "${intf}" > "${outputdir}/aserver.hpp" | 
| Patrick Williams | 847a0c3 | 2020-06-24 15:18:10 -0500 | [diff] [blame] | 317 |     fi | 
 | 318 |  | 
| Patrick Williams | d77548a | 2022-04-29 14:43:15 -0500 | [diff] [blame] | 319 |     if [[ -e "${rootdir}/$1.errors.yaml" ]]; then | 
 | 320 |         ${sdbusppcmd} error exception-header "${intf}" > "${outputdir}/error.hpp" | 
 | 321 |         ${sdbusppcmd} error exception-cpp "${intf}" > "${outputdir}/error.cpp" | 
| Patrick Williams | 847a0c3 | 2020-06-24 15:18:10 -0500 | [diff] [blame] | 322 |     fi | 
| Patrick Williams | 0336a2f | 2024-09-05 21:41:07 -0400 | [diff] [blame] | 323 |  | 
 | 324 |     if [[ -e "${rootdir}/$1.events.yaml" ]]; then | 
 | 325 |         ${sdbusppcmd} event exception-header "${intf}" > "${outputdir}/event.hpp" | 
 | 326 |         ${sdbusppcmd} event exception-cpp "${intf}" > "${outputdir}/event.cpp" | 
 | 327 |     fi | 
| Patrick Williams | 847a0c3 | 2020-06-24 15:18:10 -0500 | [diff] [blame] | 328 | } | 
 | 329 |  | 
 | 330 | ## Handle command=markdown by calling sdbus++ as appropriate. | 
 | 331 | ## $1 - interface to generate. | 
 | 332 | ## | 
 | 333 | ## For an interface foo/bar, the outputdir is expected to be foo. | 
| Patrick Williams | 018b8ff | 2022-12-05 16:03:46 -0600 | [diff] [blame] | 334 | function cmd_markdown() { | 
| Patrick Williams | 847a0c3 | 2020-06-24 15:18:10 -0500 | [diff] [blame] | 335 |  | 
| Patrick Williams | d77548a | 2022-04-29 14:43:15 -0500 | [diff] [blame] | 336 |     if [[ "" == "$1" ]]; then | 
| Patrick Williams | 847a0c3 | 2020-06-24 15:18:10 -0500 | [diff] [blame] | 337 |         show_usage | 
 | 338 |         exit 1 | 
 | 339 |     fi | 
 | 340 |  | 
| Patrick Williams | d77548a | 2022-04-29 14:43:15 -0500 | [diff] [blame] | 341 |     if [[ ! -e "${rootdir}/$1.interface.yaml" ]] && | 
| Patrick Williams | 0336a2f | 2024-09-05 21:41:07 -0400 | [diff] [blame] | 342 |     [[ ! -e "${rootdir}/$1.errors.yaml" ]] && | 
 | 343 |     [[ ! -e "${rootdir}/$1.events.yaml" ]]; then | 
| Patrick Williams | 847a0c3 | 2020-06-24 15:18:10 -0500 | [diff] [blame] | 344 |         echo "Missing YAML for $1." | 
 | 345 |         exit 1 | 
 | 346 |     fi | 
 | 347 |  | 
| Patrick Williams | d77548a | 2022-04-29 14:43:15 -0500 | [diff] [blame] | 348 |     mkdir -p "${outputdir}" | 
| Patrick Williams | 847a0c3 | 2020-06-24 15:18:10 -0500 | [diff] [blame] | 349 |  | 
| Patrick Williams | d77548a | 2022-04-29 14:43:15 -0500 | [diff] [blame] | 350 |     sdbusppcmd="${sdbuspp} -r ${rootdir}" | 
| Patrick Williams | 847a0c3 | 2020-06-24 15:18:10 -0500 | [diff] [blame] | 351 |     intf="${1//\//.}" | 
 | 352 |     base="$(basename "$1")" | 
 | 353 |  | 
| Patrick Williams | d77548a | 2022-04-29 14:43:15 -0500 | [diff] [blame] | 354 |     echo -n > "${outputdir}/${base}.md" | 
 | 355 |     if [[ -e "${rootdir}/$1.interface.yaml" ]]; then | 
 | 356 |         ${sdbusppcmd} interface markdown "${intf}" >> "${outputdir}/${base}.md" | 
| Patrick Williams | 847a0c3 | 2020-06-24 15:18:10 -0500 | [diff] [blame] | 357 |     fi | 
 | 358 |  | 
| Patrick Williams | d77548a | 2022-04-29 14:43:15 -0500 | [diff] [blame] | 359 |     if [[ -e "${rootdir}/$1.errors.yaml" ]]; then | 
 | 360 |         ${sdbusppcmd} error markdown "${intf}" >> "${outputdir}/${base}.md" | 
| Patrick Williams | 847a0c3 | 2020-06-24 15:18:10 -0500 | [diff] [blame] | 361 |     fi | 
| Patrick Williams | 0336a2f | 2024-09-05 21:41:07 -0400 | [diff] [blame] | 362 |  | 
 | 363 |     if [[ -e "${rootdir}/$1.events.yaml" ]]; then | 
 | 364 |         ${sdbusppcmd} event markdown "${intf}" >> "${outputdir}/${base}.md" | 
 | 365 |     fi | 
| Patrick Williams | 847a0c3 | 2020-06-24 15:18:10 -0500 | [diff] [blame] | 366 | } | 
 | 367 |  | 
 | 368 | ## Handle command=version. | 
| Patrick Williams | 018b8ff | 2022-12-05 16:03:46 -0600 | [diff] [blame] | 369 | function cmd_version() { | 
| Patrick Williams | 847a0c3 | 2020-06-24 15:18:10 -0500 | [diff] [blame] | 370 |     show_version | 
 | 371 | } | 
 | 372 |  | 
| Patrick Williams | d77548a | 2022-04-29 14:43:15 -0500 | [diff] [blame] | 373 | "cmd_${cmd}" "$*" |