Parameterize .service file in meson

Depending on environment, TelemetryService may require some services
to be present in the system, or specific order of starting them. This
may be especially needed for some additional sensors providers, or
persistency sync services.

This change is parametrizing following .service file options:
- After=
- Before=
- Requires=
- Wants=

They can be passed as array option to meson, like this:
  -Dservice-[option]="[....]"
Example:
  -Dservice-wants="['some.service', 'other.service']"

Testing done:
- .service file is configured properly when new 4 options are passed.
- .service file remains unchanged if none of new options are passed.

Change-Id: I0982263c8981355db15527163460cc75ae197044
Signed-off-by: Szymon Dompke <szymon.dompke@intel.com>
diff --git a/meson.build b/meson.build
index 9033b37..993f100 100644
--- a/meson.build
+++ b/meson.build
@@ -108,11 +108,35 @@
     pie: true,
 )
 
+service_wants = ''
+if get_option('service-wants').length() > 0
+    service_wants = '\nWants=' + ' '.join(get_option('service-wants'))
+endif
+
+service_requires = ''
+if get_option('service-requires').length() > 0
+    service_requires = '\nRequires=' + ' '.join(get_option('service-requires'))
+endif
+
+service_before = ''
+if get_option('service-before').length() > 0
+    service_before = '\nBefore=' + ' '.join(get_option('service-before'))
+endif
+
+service_after = ''
+if get_option('service-after').length() > 0
+    service_after = ' ' + ' '.join(get_option('service-after'))
+endif
+
 configure_file(
     input: 'xyz.openbmc_project.Telemetry.service.in',
     output: 'xyz.openbmc_project.Telemetry.service',
     configuration: {
         'bindir': get_option('prefix') / get_option('bindir'),
+        'wants': service_wants,
+        'requires': service_requires,
+        'before': service_before,
+        'after': service_after
     },
     install: true,
     install_dir: systemd.get_variable(pkgconfig: 'systemdsystemunitdir'),
diff --git a/meson_options.txt b/meson_options.txt
index e033f4f..c8a46b8 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -15,3 +15,7 @@
        description: 'Max length of any "id" or "name" type field.')
 option('max-prefix-length', type: 'integer', min: 32, value: 256,
        description: 'Max length of dbus prefix for any object.')
+option('service-wants', type: 'array', value: [])
+option('service-requires', type: 'array', value: [])
+option('service-before', type: 'array', value: [])
+option('service-after', type: 'array', value: [])
diff --git a/xyz.openbmc_project.Telemetry.service.in b/xyz.openbmc_project.Telemetry.service.in
index 2bfde55..a922676 100644
--- a/xyz.openbmc_project.Telemetry.service.in
+++ b/xyz.openbmc_project.Telemetry.service.in
@@ -1,6 +1,6 @@
 [Unit]
-Description=Telemetry
-After=dbus.service
+Description=Telemetry@wants@@requires@@before@
+After=dbus.service@after@
 
 [Service]
 ExecStart=@bindir@/telemetry