settings: meta-zaius: add override

Zaius had a way to override the reboot policy setting. Make sure that
still works with the new settings application.

Change-Id: I51e32705b9aa4787fadab211f57b5fdcf75a3207
Signed-off-by: Deepak Kodihalli <dkodihal@in.ibm.com>
diff --git a/common/recipes-phosphor/settings/phosphor-settings-manager.bb b/common/recipes-phosphor/settings/phosphor-settings-manager.bb
index dcc6fe3..525a9fd 100644
--- a/common/recipes-phosphor/settings/phosphor-settings-manager.bb
+++ b/common/recipes-phosphor/settings/phosphor-settings-manager.bb
@@ -24,7 +24,39 @@
 RDEPENDS_${PN} += "sdbusplus phosphor-dbus-interfaces"
 
 S = "${WORKDIR}/git"
+SRC_URI += "file://merge_settings.py"
 
 EXTRA_OECONF = " \
              SETTINGS_YAML=${STAGING_DIR_NATIVE}${settings_datadir}/defaults.yaml \
              "
+
+# Collect files in SRC_URI that end in ".override.yml" and call a script that
+# writes their contents over that of settings.yaml, which is then updated to
+# the merged data values.
+# This doesn't correctly handle globs in ".override.yml" entries in SRC_URI.
+python do_merge_settings () {
+    import subprocess
+
+    # TODO: Perform the merge in a temporary directory?
+    workdir = d.getVar('WORKDIR', True)
+    nativedir = d.getVar('STAGING_DIR_NATIVE', True)
+    settingsdir = d.getVar('settings_datadir', True)
+    settingsdir = settingsdir[1:]
+    settingsdir = os.path.join(nativedir, settingsdir)
+    cmd = []
+    cmd.append(os.path.join(workdir, 'merge_settings.py'))
+    cmd.append(os.path.join(settingsdir, 'defaults.yaml'))
+
+    fetch = bb.fetch2.Fetch([], d)
+    override_urls = filter(lambda f: f.endswith('.override.yml'), fetch.urls)
+    for url in override_urls:
+        bb.debug(2, 'Overriding with source: ' + url)
+        local_base = os.path.basename(fetch.localpath(url))
+        filename = os.path.join(workdir, local_base)
+        cmd.append(filename)
+
+    # Invoke the script and don't catch any resulting exception.
+    subprocess.check_call(cmd)
+}
+# python-pyyaml-native is installed by do_configure, so put this task after
+addtask merge_settings after do_configure before do_compile