meta-app-framework: Update app template scheme 35/27835/3
authorScott Murray <scott.murray@konsulko.com>
Wed, 27 Jul 2022 20:50:30 +0000 (16:50 -0400)
committerJan-Simon Moeller <jsmoeller@linuxfoundation.org>
Fri, 29 Jul 2022 23:02:27 +0000 (23:02 +0000)
Changes to support the move to systemd unit based app enumeration in
applaunchd:
- Bump applaunchd SRCREV to pick up enumeration changes.
- Tweak the polkit rule to match agl-app* instead of agl-app@*
  to allow more flexibility with respect to different app templates.
- Tweak the Description field definition in the agl-app service
  template to just use the instance name, as that field is now used
  for the application display name by applaunchd.
- Add a agl-app-web service template for web apps.
- Add a agl-app.bbclass for use in application recipes to simplify
  installation of the now required systemd template instances and
  potential generation of override files to tweak application
  configuration.
- Split the agl-app and agl-app-web templates into their own packages
  in the applaunchd recipe so they can be depended on by applications
  as required.
- Move applaunchd installed systemd units and override files to
  /lib/systemd/system since that matches the upstream recommendation
  for units installed as part of the system installation.

Bug-AGL: SPEC-4466

Signed-off-by: Scott Murray <scott.murray@konsulko.com>
Change-Id: I32ff6c9624850662856b79a2b14b33a05e7f9a65
Reviewed-on: https://gerrit.automotivelinux.org/gerrit/c/AGL/meta-agl/+/27835
Tested-by: Jenkins Job builder account
ci-image-build: Jenkins Job builder account
ci-image-boot-test: Jenkins Job builder account
Reviewed-by: Jose Dapena Paz <jdapena@igalia.com>
Reviewed-by: Jan-Simon Moeller <jsmoeller@linuxfoundation.org>
meta-app-framework/classes/agl-app.bbclass [new file with mode: 0644]
meta-app-framework/recipes-config/polkit-rule-agl-app/files/50-agl-app.rules
meta-app-framework/recipes-core/applaunchd/applaunchd/agl-app-web@.service [new file with mode: 0644]
meta-app-framework/recipes-core/applaunchd/applaunchd/agl-app@.service
meta-app-framework/recipes-core/applaunchd/applaunchd_git.bb

diff --git a/meta-app-framework/classes/agl-app.bbclass b/meta-app-framework/classes/agl-app.bbclass
new file mode 100644 (file)
index 0000000..6565fdf
--- /dev/null
@@ -0,0 +1,75 @@
+#
+# AGL application systemd unit installation class
+#
+
+# Systemd template unit
+# * agl-app, agl-app-web, agl-app-flutter valid
+AGL_APP_TEMPLATE ?= "agl-app"
+
+# Application ID
+# This is what the application will be referred to in the list
+# exposed to clients by applaunchd, and generally ends up as the
+# identifier used by agl-compositor for application surface
+# activation.
+AGL_APP_ID ?= "${BPN}"
+
+# Application display name
+AGL_APP_NAME ?= "${AGL_APP_ID}"
+
+# Application executable
+# * agl-app template only
+# Use if the application ID and the executable name are both
+# different from the package name and each other as well.
+AGL_APP_EXEC ?= "${AGL_APP_ID}"
+
+# Web application bundle directory (non-absolute, so directory
+# name under /usr/lib/wam_apps)
+# * agl-app-web template only
+# Use if the web application bundle installs to a directory that
+# is not the same as the package name.
+AGL_APP_WAM_DIR ?= "${BPN}"
+
+do_install:append () {
+    install -d ${D}${systemd_system_unitdir}
+    ln -s ${AGL_APP_TEMPLATE}\@.service \
+        ${D}${systemd_system_unitdir}/${AGL_APP_TEMPLATE}\@${AGL_APP_ID}.service
+
+    # NOTE: Unit & Service changes could potentially be collected
+    #       and a single override .conf created, but things will be
+    #       kept simple for now.
+
+    if [ "${AGL_APP_EXEC}" != "${AGL_APP_ID}" ]; then
+        install -d ${D}${systemd_system_unitdir}/${AGL_APP_TEMPLATE}\@${AGL_APP_ID}.service.d
+        cat <<-EOF > ${D}${systemd_system_unitdir}/${AGL_APP_TEMPLATE}\@${AGL_APP_ID}.service.d/exec.conf
+       [Service]
+       ExecStart=
+       ExecStart=${AGL_APP_EXEC}
+       EOF
+    fi
+
+    if [ "${AGL_APP_NAME}" != "${AGL_APP_ID}" ]; then
+        install -d ${D}${systemd_system_unitdir}/${AGL_APP_TEMPLATE}\@${AGL_APP_ID}.service.d
+        cat <<-EOF > ${D}${systemd_system_unitdir}/${AGL_APP_TEMPLATE}\@${AGL_APP_ID}.service.d/name.conf
+       [Unit]
+       Description=
+       Description=${AGL_APP_NAME}
+       EOF
+    fi
+
+    if [ "${AGL_APP_TEMPLATE}" = "agl-app-web" -a "${AGL_APP_ID}" != "${BPN}" ]; then
+        # The application ID does not necessarily match the package name
+        # used in the WAM install hierarchy, and the IDs are hard-coded in
+        # some of the web apps, so if necessary create an override for the
+        # environment variable used in place of directly deriving from %i
+        # (which will always be the app id).
+        install -d ${D}${systemd_system_unitdir}/${AGL_APP_TEMPLATE}\@${AGL_APP_ID}.service.d
+        cat <<-EOF > ${D}${systemd_system_unitdir}/${AGL_APP_TEMPLATE}\@${AGL_APP_ID}.service.d/wam.conf
+       [Service]
+       Environment=AGL_APP_WAM_DIR=${AGL_APP_WAM_DIR}
+       EOF
+    fi
+}
+
+FILES:${PN}:append = " ${systemd_system_unitdir} ${datadir}/icons"
+
+RDEPENDS:${PN}:append = " applaunchd-template-${AGL_APP_TEMPLATE}"
index 5fa34fb..dd4b694 100644 (file)
@@ -1,6 +1,6 @@
 polkit.addRule(function(action, subject) {
     if (action.id == "org.freedesktop.systemd1.manage-units" &&
-        action.lookup("unit").indexOf("agl-app@") == 0 &&
+        action.lookup("unit").indexOf("agl-app") == 0 &&
         subject.user == "agl-driver") {
         return polkit.Result.YES;
     }
diff --git a/meta-app-framework/recipes-core/applaunchd/applaunchd/agl-app-web@.service b/meta-app-framework/recipes-core/applaunchd/applaunchd/agl-app-web@.service
new file mode 100644 (file)
index 0000000..3b736a5
--- /dev/null
@@ -0,0 +1,10 @@
+[Unit]
+Description=%I
+
+[Service]
+Type=simple
+User=agl-driver
+Environment=XDG_RUNTIME_DIR=/run/user/1001/
+Environment=AGL_APP_WAM_DIR=%I
+ExecStart=/usr/bin/WebAppMgr --appid=%I --app-install-dir=/usr/lib/wam_apps/${AGL_APP_WAM_DIR}/
+
index c8361fa..2343488 100644 (file)
@@ -1,8 +1,8 @@
 [Unit]
-Description=Sandboxed %I
+Description=%I
 
 [Service]
 Type=simple
 User=agl-driver
-ExecStart=%i
 Environment=XDG_RUNTIME_DIR=/run/user/1001/
+ExecStart=%i
index 5c2036a..0aef4e0 100644 (file)
@@ -16,10 +16,11 @@ PV = "2.0+git${SRCPV}"
 SRC_URI = " \
     git://gerrit.automotivelinux.org/gerrit/src/applaunchd;protocol=https;branch=${AGL_BRANCH}  \
     file://agl-app@.service \
+    file://agl-app-web@.service \
     file://no-network.conf \
     file://private-tmp.conf \
 "
-SRCREV = "efbd734aca8b813710d7564d79696b1cf150a88c"
+SRCREV = "c675bafdf15cc19276bd8276c34f56404a5ecb62"
 
 S = "${WORKDIR}/git"
 
@@ -27,18 +28,29 @@ inherit meson pkgconfig
 
 do_install:append() {
     # Install generic template for all agl-app services
-    mkdir -p ${D}${sysconfdir}/systemd/system/
-    install -m 644 ${WORKDIR}/agl-app@.service ${D}${sysconfdir}/systemd/system/
+    install -d ${D}${systemd_system_unitdir}
+    install -m 644 ${WORKDIR}/agl-app@.service ${D}${systemd_system_unitdir}/
+    install -m 644 ${WORKDIR}/agl-app-web@.service ${D}${systemd_system_unitdir}/
 
     # Install individual sandboxing overrides/drop-ins to be used by apps
-    mkdir -p ${D}${sysconfdir}/systemd/sandboxing/
-    install -m 644 ${WORKDIR}/no-network.conf ${D}${sysconfdir}/systemd/sandboxing/
-    install -m 644 ${WORKDIR}/private-tmp.conf ${D}${sysconfdir}/systemd/sandboxing/
+    install -d ${D}${systemd_system_unitdir}/sandboxing
+    install -m 644 ${WORKDIR}/no-network.conf ${D}${systemd_system_unitdir}/sandboxing/
+    install -m 644 ${WORKDIR}/private-tmp.conf ${D}${systemd_system_unitdir}/sandboxing/
 }
 
-FILES:${PN} += " ${datadir}/dbus-1/"
+PACKAGE_BEFORE_PN += "${PN}-template-agl-app ${PN}-template-agl-app-web"
+
+FILES:${PN} += "${systemd_system_unitdir} ${datadir}/dbus-1/"
+
+FILES:${PN}-template-agl-app = "${systemd_system_unitdir}/agl-app@.service"
+
+FILES:${PN}-template-agl-app-web = "${systemd_system_unitdir}/agl-app-web@.service"
 
 RDEPENDS:${PN} += " \
     agl-session \
     polkit-rule-agl-app \
 "
+
+RDEPENDS:${PN}-template-agl-app = "${PN}"
+
+RDEPENDS:${PN}-template-agl-app-web = "${PN}"