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