treewide: Leverage sdbus++-gen-meson

This makes us more consistent with other projects instead of writing
meson builds for sdbus++ by hand.

Change-Id: I38b69bc67b6a3d80cda1b508a76e106a50d8ab93
Signed-off-by: Willam A. Kennington III <wak@google.com>
diff --git a/example/gen/meson.build b/example/gen/meson.build
new file mode 100644
index 0000000..2756633
--- /dev/null
+++ b/example/gen/meson.build
@@ -0,0 +1,14 @@
+# Generated file; do not modify.
+sdbuspp_gen_meson_ver = run_command(
+    sdbuspp_gen_meson_prog,
+    '--version',
+).stdout().strip().split('\n')[0]
+
+if sdbuspp_gen_meson_ver != 'sdbus++-gen-meson version 4'
+    warning('Generated meson files from wrong version of sdbus++-gen-meson.')
+    warning(
+        'Expected "sdbus++-gen-meson version 4", got:',
+        sdbuspp_gen_meson_ver
+    )
+endif
+
diff --git a/example/gen/net/meson.build b/example/gen/net/meson.build
new file mode 100644
index 0000000..5ea98c6
--- /dev/null
+++ b/example/gen/net/meson.build
@@ -0,0 +1,2 @@
+# Generated file; do not modify.
+subdir('poettering')
diff --git a/example/gen/net/poettering/Calculator/meson.build b/example/gen/net/poettering/Calculator/meson.build
new file mode 100644
index 0000000..6b469e6
--- /dev/null
+++ b/example/gen/net/poettering/Calculator/meson.build
@@ -0,0 +1,15 @@
+# Generated file; do not modify.
+generated_sources += custom_target(
+    'net/poettering/Calculator__cpp'.underscorify(),
+    input: [ '../../../../yaml/net/poettering/Calculator.interface.yaml',  ],
+    output: [ 'error.cpp', 'error.hpp', 'server.cpp', 'server.hpp', 'client.hpp',  ],
+    depend_files: sdbusplusplus_depfiles,
+    command: [
+        sdbuspp_gen_meson_prog, '--command', 'cpp',
+        '--output', meson.current_build_dir(),
+        '--tool', sdbusplusplus_prog,
+        '--directory', meson.current_source_dir() / '../../../../yaml',
+        'net/poettering/Calculator',
+    ],
+)
+
diff --git a/example/gen/net/poettering/meson.build b/example/gen/net/poettering/meson.build
new file mode 100644
index 0000000..a91287e
--- /dev/null
+++ b/example/gen/net/poettering/meson.build
@@ -0,0 +1,16 @@
+# Generated file; do not modify.
+subdir('Calculator')
+generated_others += custom_target(
+    'net/poettering/Calculator__markdown'.underscorify(),
+    input: [ '../../../yaml/net/poettering/Calculator.interface.yaml',  ],
+    output: [ 'Calculator.md' ],
+    depend_files: sdbusplusplus_depfiles,
+    command: [
+        sdbuspp_gen_meson_prog, '--command', 'markdown',
+        '--output', meson.current_build_dir(),
+        '--tool', sdbusplusplus_prog,
+        '--directory', meson.current_source_dir() / '../../../yaml',
+        'net/poettering/Calculator',
+    ],
+)
+
diff --git a/example/gen/regenerate-meson b/example/gen/regenerate-meson
new file mode 100755
index 0000000..235d551
--- /dev/null
+++ b/example/gen/regenerate-meson
@@ -0,0 +1,4 @@
+#!/bin/bash
+cd "$(dirname "$0")" || exit
+export PATH="${PWD}/../../tools:${PATH}"
+exec sdbus++-gen-meson --command meson --directory ../yaml --output .
diff --git a/example/gen/run-ci b/example/gen/run-ci
new file mode 100755
index 0000000..0a248a0
--- /dev/null
+++ b/example/gen/run-ci
@@ -0,0 +1,15 @@
+#!/bin/bash
+cd "$(dirname "$0")" || exit
+./regenerate-meson || exit
+rc=0
+git --no-pager diff --exit-code -- . || rc=$?
+untracked="$(git ls-files --others --exclude-standard -- .)" || rc=$?
+if [[ -n "${untracked}" ]]; then
+  echo "Untracked files:" >&2
+  echo "${untracked}" >&2
+  rc=1
+fi
+if (( rc != 0 )); then
+  echo "Generated meson files differ from expected values" >&2
+  exit 1
+fi
diff --git a/example/meson.build b/example/meson.build
index b338dc1..17fd569 100644
--- a/example/meson.build
+++ b/example/meson.build
@@ -44,10 +44,16 @@
     dependencies: asio_dep,
 )
 
-subdir('net/poettering/Calculator')
+generated_sources = []
+generated_others = []
+subdir('gen')
+subdir('gen/net')
+
 executable(
     'calculator-server',
     'calculator-server.cpp',
-    calculator_sources,
+    generated_sources,
+    implicit_include_directories: false,
+    include_directories: include_directories('gen'),
     dependencies: sdbusplus_dep,
 )
diff --git a/example/net/poettering/Calculator/meson.build b/example/net/poettering/Calculator/meson.build
deleted file mode 100644
index f77fc5b..0000000
--- a/example/net/poettering/Calculator/meson.build
+++ /dev/null
@@ -1,29 +0,0 @@
-calculator_sources = []
-
-calculator_sources += custom_target(
-    'Calculator__cpp',
-    input: '../Calculator.interface.yaml',
-    output: [ 'server.cpp', 'server.hpp', 'client.hpp' ],
-    depend_files: sdbusplusplus_depfiles,
-    command: [
-        sdbuspp_gen_meson_prog, '--command', 'cpp',
-        '--output', meson.current_build_dir(),
-        '--tool', sdbusplusplus_prog,
-        '--directory', meson.current_source_dir() / '../../..',
-        'net/poettering/Calculator',
-    ],
-)
-
-calculator_sources += custom_target(
-    'Calculator__errors',
-    input: '../Calculator.errors.yaml',
-    output: [ 'error.cpp', 'error.hpp' ],
-    depend_files: sdbusplusplus_depfiles,
-    command: [
-        sdbuspp_gen_meson_prog, '--command', 'cpp',
-        '--output', meson.current_build_dir(),
-        '--tool', sdbusplusplus_prog,
-        '--directory', meson.current_source_dir() / '../../..',
-        'net/poettering/Calculator',
-    ],
-)
diff --git a/example/net/poettering/Calculator.errors.yaml b/example/yaml/net/poettering/Calculator.errors.yaml
similarity index 100%
rename from example/net/poettering/Calculator.errors.yaml
rename to example/yaml/net/poettering/Calculator.errors.yaml
diff --git a/example/net/poettering/Calculator.interface.yaml b/example/yaml/net/poettering/Calculator.interface.yaml
similarity index 100%
rename from example/net/poettering/Calculator.interface.yaml
rename to example/yaml/net/poettering/Calculator.interface.yaml
diff --git a/test/gen/meson.build b/test/gen/meson.build
new file mode 100644
index 0000000..2756633
--- /dev/null
+++ b/test/gen/meson.build
@@ -0,0 +1,14 @@
+# Generated file; do not modify.
+sdbuspp_gen_meson_ver = run_command(
+    sdbuspp_gen_meson_prog,
+    '--version',
+).stdout().strip().split('\n')[0]
+
+if sdbuspp_gen_meson_ver != 'sdbus++-gen-meson version 4'
+    warning('Generated meson files from wrong version of sdbus++-gen-meson.')
+    warning(
+        'Expected "sdbus++-gen-meson version 4", got:',
+        sdbuspp_gen_meson_ver
+    )
+endif
+
diff --git a/test/gen/regenerate-meson b/test/gen/regenerate-meson
new file mode 100755
index 0000000..235d551
--- /dev/null
+++ b/test/gen/regenerate-meson
@@ -0,0 +1,4 @@
+#!/bin/bash
+cd "$(dirname "$0")" || exit
+export PATH="${PWD}/../../tools:${PATH}"
+exec sdbus++-gen-meson --command meson --directory ../yaml --output .
diff --git a/test/gen/run-ci b/test/gen/run-ci
new file mode 100755
index 0000000..0a248a0
--- /dev/null
+++ b/test/gen/run-ci
@@ -0,0 +1,15 @@
+#!/bin/bash
+cd "$(dirname "$0")" || exit
+./regenerate-meson || exit
+rc=0
+git --no-pager diff --exit-code -- . || rc=$?
+untracked="$(git ls-files --others --exclude-standard -- .)" || rc=$?
+if [[ -n "${untracked}" ]]; then
+  echo "Untracked files:" >&2
+  echo "${untracked}" >&2
+  rc=1
+fi
+if (( rc != 0 )); then
+  echo "Generated meson files differ from expected values" >&2
+  exit 1
+fi
diff --git a/test/gen/server/Test/meson.build b/test/gen/server/Test/meson.build
new file mode 100644
index 0000000..7a1d3b7
--- /dev/null
+++ b/test/gen/server/Test/meson.build
@@ -0,0 +1,15 @@
+# Generated file; do not modify.
+generated_sources += custom_target(
+    'server/Test__cpp'.underscorify(),
+    input: [ '../../../yaml/server/Test.interface.yaml',  ],
+    output: [ 'server.cpp', 'server.hpp', 'client.hpp',  ],
+    depend_files: sdbusplusplus_depfiles,
+    command: [
+        sdbuspp_gen_meson_prog, '--command', 'cpp',
+        '--output', meson.current_build_dir(),
+        '--tool', sdbusplusplus_prog,
+        '--directory', meson.current_source_dir() / '../../../yaml',
+        'server/Test',
+    ],
+)
+
diff --git a/test/gen/server/meson.build b/test/gen/server/meson.build
new file mode 100644
index 0000000..6ab2512
--- /dev/null
+++ b/test/gen/server/meson.build
@@ -0,0 +1,16 @@
+# Generated file; do not modify.
+subdir('Test')
+generated_others += custom_target(
+    'server/Test__markdown'.underscorify(),
+    input: [ '../../yaml/server/Test.interface.yaml',  ],
+    output: [ 'Test.md' ],
+    depend_files: sdbusplusplus_depfiles,
+    command: [
+        sdbuspp_gen_meson_prog, '--command', 'markdown',
+        '--output', meson.current_build_dir(),
+        '--tool', sdbusplusplus_prog,
+        '--directory', meson.current_source_dir() / '../../yaml',
+        'server/Test',
+    ],
+)
+
diff --git a/test/meson.build b/test/meson.build
index 64dbc0e..4fa39d2 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -81,23 +81,34 @@
     ),
 )
 
-subdir('server/Test')
+generated_sources = []
+generated_others = []
+subdir('gen')
+subdir('gen/server')
+
+server_test_pre = declare_dependency(
+    include_directories: include_directories('gen'),
+    dependencies: sdbusplus_dep)
+
 server_test_lib = static_library(
     'server-test',
-    server_test_sources,
-    dependencies: sdbusplus_dep,
-)
-server_test_hpp = []
-foreach f : server_test_sources.to_list()
-    if f.full_path().endswith('.hpp')
-        server_test_hpp += f
-    endif
+    generated_sources,
+    implicit_include_directories: false,
+    dependencies: server_test_pre)
+
+generated_sources_header = []
+foreach s : generated_sources
+    foreach f : s.to_list()
+        if f.full_path().endswith('.hpp')
+            generated_sources_header += f
+        endif
+    endforeach
 endforeach
+
 server_test_dep = declare_dependency(
-    link_with: server_test_lib,
-    dependencies: sdbusplus_dep,
-    sources: server_test_hpp,
-)
+  sources: generated_sources_header,
+  link_with: server_test_lib,
+  dependencies: server_test_pre)
 
 test(
     'test-server',
diff --git a/test/server/Test/meson.build b/test/server/Test/meson.build
deleted file mode 100644
index 37e56a5..0000000
--- a/test/server/Test/meson.build
+++ /dev/null
@@ -1,13 +0,0 @@
-server_test_sources = custom_target(
-    'server_test__cpp',
-    input: '../Test.interface.yaml',
-    output: [ 'server.cpp', 'server.hpp', 'client.hpp' ],
-    depend_files: sdbusplusplus_depfiles,
-    command: [
-        sdbuspp_gen_meson_prog, '--command', 'cpp',
-        '--output', meson.current_build_dir(),
-        '--tool', sdbusplusplus_prog,
-        '--directory', meson.current_source_dir() / '../..',
-        'server/Test',
-    ],
-)
diff --git a/test/server/Test.interface.yaml b/test/yaml/server/Test.interface.yaml
similarity index 100%
rename from test/server/Test.interface.yaml
rename to test/yaml/server/Test.interface.yaml
diff --git a/tools/sdbus++-gen-meson b/tools/sdbus++-gen-meson
index 7e46f9c..27c0f4e 100755
--- a/tools/sdbus++-gen-meson
+++ b/tools/sdbus++-gen-meson
@@ -252,25 +252,9 @@
 
 ## Handle command=meson by generating the tree of meson.build files.
 function cmd_meson {
-    TLDs="com net org xyz"
-    yamls=""
-
-    # Find all the YAML files in the TLD subdirectories.
-    for d in ${TLDs}; do
-        dir="${rootdir}/${d}"
-        if [[ ! -d ${dir} ]]; then
-            continue
-        fi
-
-        yamls="\
-            ${yamls} \
-            $(find "${dir}" -name '*.interface.yaml' -o -name '*.errors.yaml') \
-            "
-    done
-
-    # Sort YAMLs
-    # shellcheck disable=SC2312
-    yamls="$(echo "${yamls}" | tr " " "\n" | sort)"
+    # Find and sort all the YAML files
+    yamls="$(find "${rootdir}" -name '*.interface.yaml' -o -name '*.errors.yaml')"
+    yamls="$(echo "${yamls}" | sort)"
 
     # Assign the YAML files into the hash-table by interface name.
     for y in ${yamls}; do