meta-phosphor: fans: enable non-native recipes

There exists a number native class recipes throughout meta-phosphor that
simply provide a data (often YAML) file as input to building another
application.

Having these data file recipes implemented as native class recipes
prevents the use of machine overrides because bitbake (rightfully so)
discards machine qualifiers from native recipes.  Further, data files
aren't really any different than library header files and those are
consumed by recipes as target class recipes that are DEPENDed on.  Do
the same thing for data file recipes.

A number of steps (patches) are required to ensure backward
compatibility while other BSP layers make the transition to target class
recipes.

This patch is the first step in the sequence.  Each native class recipe
is duplicated with (approximately) the following transformation applied:

1 - remove "inherit native"
2 - add "inherit allarch"
3 - Add appropriate files to FILES_${PN}

Also fixed a couple idiosyncrasies like SRC_URI += and LIC_FILES_CHKSUM
that are not required.

Finally, add a temporary layer of indirection around STAGING_DIR_NATIVE
and STAGING_DIR_HOST to the fan metadata until other BSP layers have
fully transitioned to target class config recipes.

(From meta-phosphor rev: 19ee51f5cdce2ff2f076a3ca9263dabc79072ba9)

Change-Id: I9671cc5343ed29a7ccfcee4cc00ebaaa9327e359
Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
diff --git a/meta-phosphor/conf/distro/include/phosphor-defaults.inc b/meta-phosphor/conf/distro/include/phosphor-defaults.inc
index 2fed684..ee38c56 100644
--- a/meta-phosphor/conf/distro/include/phosphor-defaults.inc
+++ b/meta-phosphor/conf/distro/include/phosphor-defaults.inc
@@ -1,3 +1,5 @@
+PHOSPHOR_FAN_CONFIG_USE_NATIVE_SYSROOT ?= "1"
+PHOSPHOR_FAN_CONFIG_RECIPE_SUFFIX = "${@bb.utils.contains('PHOSPHOR_FAN_CONFIG_USE_NATIVE_SYSROOT', '1', '-native', '', d)}"
 OBMC_BMC_INSTANCES ?= "0"
 OBMC_CHASSIS_INSTANCES ?= "0"
 OBMC_CHECKSTOP_INSTANCES ?= "0"
@@ -194,21 +196,20 @@
 PREFERRED_PROVIDER_virtual/phosphor-logging-callouts ?= \
     "phosphor-logging-callouts-example-native"
 
-# The phosphor-fan-presence application is data driven and requires an
-# input YAML that maps fans to their tach sensors.
-# This virtual is a native recipe that provides that mapping by installing
-# configuration files in the format and native sysroot location expected by
-# the phosphor-fan-presence build process in the native sysroot.
+# The phosphor-fan-presence application is data driven and requires an input
+# YAML that maps fans to their tach sensors.  This virtual is a recipe that
+# provides that mapping by installing configuration files in the format and
+# sysroot location expected by the phosphor-fan-presence build process in the
+# sysroot.
 PREFERRED_PROVIDER_virtual/phosphor-fan-presence-config ?= \
-    "phosphor-fan-presence-config-native"
+    "phosphor-fan-presence-config${PHOSPHOR_FAN_CONFIG_RECIPE_SUFFIX}"
 
-# The phosphor-fan-control application is data driven and requires a YAML
-# file to define the fans in the system.
-# This virtual is a native recipe that provides that definition by installing
-# the YAML file in the format and native sysroot location expected by
-# the phosphor-fan-control build process in the native sysroot.
+# The phosphor-fan-control application is data driven and requires a YAML file
+# to define the fans in the system.  This virtual is a recipe that provides
+# that definition by installing the YAML file in the format and sysroot
+# location expected by the phosphor-fan-control build process in the sysroot.
 PREFERRED_PROVIDER_virtual/phosphor-fan-control-fan-config ?= \
-    "phosphor-fan-control-fan-config-native"
+    "phosphor-fan-control-fan-config${PHOSPHOR_FAN_CONFIG_RECIPE_SUFFIX}"
 
 # The phosphor-gpio-monitor application is data-driven and requires an input.
 # The application then watches the passed in input event entry for the
diff --git a/meta-phosphor/conf/distro/include/phosphor-mrw.inc b/meta-phosphor/conf/distro/include/phosphor-mrw.inc
index 9b2cb45..2e8de5f 100644
--- a/meta-phosphor/conf/distro/include/phosphor-mrw.inc
+++ b/meta-phosphor/conf/distro/include/phosphor-mrw.inc
@@ -13,5 +13,5 @@
 PREFERRED_PROVIDER_virtual/phosphor-ipmi-inventory-sel_df-mrw ?= "phosphor-ipmi-inventory-sel-mrw-native"
 PREFERRED_PROVIDER_virtual/phosphor-led-manager-config-native_df-mrw ?= "phosphor-led-manager-config-mrw-native"
 PREFERRED_PROVIDER_virtual/phosphor-logging-callouts_df-mrw ?= "phosphor-logging-callouts-mrw-native"
-PREFERRED_PROVIDER_virtual/phosphor-fan-presence-config_df-mrw ?= "phosphor-fan-presence-mrw-native"
-PREFERRED_PROVIDER_virtual/phosphor-fan-control-fan-config_df-mrw ?= "phosphor-fan-control-fan-config-mrw-native"
+PREFERRED_PROVIDER_virtual/phosphor-fan-presence-config_df-mrw ?= "phosphor-fan-presence-mrw${PHOSPHOR_FAN_CONFIG_RECIPE_SUFFIX}"
+PREFERRED_PROVIDER_virtual/phosphor-fan-control-fan-config_df-mrw ?= "phosphor-fan-control-fan-config-mrw${PHOSPHOR_FAN_CONFIG_RECIPE_SUFFIX}"
diff --git a/meta-phosphor/recipes-phosphor/fans/phosphor-fan-control-events-config.bb b/meta-phosphor/recipes-phosphor/fans/phosphor-fan-control-events-config.bb
new file mode 100644
index 0000000..360650f
--- /dev/null
+++ b/meta-phosphor/recipes-phosphor/fans/phosphor-fan-control-events-config.bb
@@ -0,0 +1,17 @@
+SUMMARY = "Phosphor zone events definition default data"
+PR = "r1"
+LICENSE = "Apache-2.0"
+LIC_FILES_CHKSUM = "file://${PHOSPHORBASE}/COPYING.apache-2.0;md5=34400b68072d710fecd0a2940a0d1658"
+
+inherit allarch
+inherit phosphor-fan
+
+S = "${WORKDIR}"
+
+SRC_URI = "file://events.yaml"
+
+do_install() {
+    install -D events.yaml ${D}${control_datadir}/events.yaml
+}
+
+FILES_${PN} += "${control_datadir}/events.yaml"
diff --git a/meta-phosphor/recipes-phosphor/fans/phosphor-fan-control-fan-config-mrw.bb b/meta-phosphor/recipes-phosphor/fans/phosphor-fan-control-fan-config-mrw.bb
new file mode 100644
index 0000000..38a424b
--- /dev/null
+++ b/meta-phosphor/recipes-phosphor/fans/phosphor-fan-control-fan-config-mrw.bb
@@ -0,0 +1,24 @@
+SUMMARY = "Generate fan control YAML from the MRW"
+PR = "r1"
+LICENSE = "Apache-2.0"
+
+inherit allarch
+inherit phosphor-fan
+inherit mrw-xml
+
+S = "${WORKDIR}"
+DEPENDS = "mrw-native mrw-perl-tools-native"
+PROVIDES += "virtual/phosphor-fan-control-fan-config"
+
+do_compile() {
+    ${bindir}/perl-native/perl \
+        ${bindir}/gen_fan_zone_yaml.pl \
+        -i ${STAGING_DIR_NATIVE}${mrw_datadir}/${MRW_XML} \
+        -o fans.yaml
+}
+
+do_install() {
+        install -D fans.yaml ${D}${control_datadir}/fans.yaml
+}
+
+FILES_${PN} += "${control_datadir}/fans.yaml"
diff --git a/meta-phosphor/recipes-phosphor/fans/phosphor-fan-control-fan-config.bb b/meta-phosphor/recipes-phosphor/fans/phosphor-fan-control-fan-config.bb
new file mode 100644
index 0000000..b82da0a
--- /dev/null
+++ b/meta-phosphor/recipes-phosphor/fans/phosphor-fan-control-fan-config.bb
@@ -0,0 +1,18 @@
+SUMMARY = "Phosphor fan definition example data"
+PR = "r1"
+LICENSE = "Apache-2.0"
+LIC_FILES_CHKSUM = "file://${PHOSPHORBASE}/COPYING.apache-2.0;md5=34400b68072d710fecd0a2940a0d1658"
+
+inherit allarch
+inherit phosphor-fan
+
+S = "${WORKDIR}"
+PROVIDES += "virtual/phosphor-fan-control-fan-config"
+
+SRC_URI = "file://fans.yaml"
+
+do_install() {
+    install -D fans.yaml ${D}${control_datadir}/fans.yaml
+}
+
+FILES_${PN} += "${control_datadir}/fans.yaml"
diff --git a/meta-phosphor/recipes-phosphor/fans/phosphor-fan-control-zone-conditions-config.bb b/meta-phosphor/recipes-phosphor/fans/phosphor-fan-control-zone-conditions-config.bb
new file mode 100644
index 0000000..1dc1149
--- /dev/null
+++ b/meta-phosphor/recipes-phosphor/fans/phosphor-fan-control-zone-conditions-config.bb
@@ -0,0 +1,17 @@
+SUMMARY = "Phosphor zone conditions definition default data"
+PR = "r1"
+LICENSE = "Apache-2.0"
+LIC_FILES_CHKSUM = "file://${PHOSPHORBASE}/COPYING.apache-2.0;md5=34400b68072d710fecd0a2940a0d1658"
+
+inherit allarch
+inherit phosphor-fan
+
+S = "${WORKDIR}"
+
+SRC_URI = "file://zone_conditions.yaml"
+
+do_install() {
+    install -D zone_conditions.yaml ${D}${control_datadir}/zone_conditions.yaml
+}
+
+FILES_${PN} += "${control_datadir}/zone_conditions.yaml"
diff --git a/meta-phosphor/recipes-phosphor/fans/phosphor-fan-control-zone-config.bb b/meta-phosphor/recipes-phosphor/fans/phosphor-fan-control-zone-config.bb
new file mode 100644
index 0000000..e649777
--- /dev/null
+++ b/meta-phosphor/recipes-phosphor/fans/phosphor-fan-control-zone-config.bb
@@ -0,0 +1,17 @@
+SUMMARY = "Phosphor fan zone definition default data"
+PR = "r1"
+LICENSE = "Apache-2.0"
+LIC_FILES_CHKSUM = "file://${PHOSPHORBASE}/COPYING.apache-2.0;md5=34400b68072d710fecd0a2940a0d1658"
+
+inherit allarch
+inherit phosphor-fan
+
+S = "${WORKDIR}"
+
+SRC_URI = "file://zones.yaml"
+
+do_install() {
+    install -D zones.yaml ${D}${control_datadir}/zones.yaml
+}
+
+FILES_${PN} += "${control_datadir}/zones.yaml"
diff --git a/meta-phosphor/recipes-phosphor/fans/phosphor-fan-monitor-config.bb b/meta-phosphor/recipes-phosphor/fans/phosphor-fan-monitor-config.bb
new file mode 100644
index 0000000..9285981
--- /dev/null
+++ b/meta-phosphor/recipes-phosphor/fans/phosphor-fan-monitor-config.bb
@@ -0,0 +1,18 @@
+SUMMARY = "Phosphor fan monitor definition default data"
+PR = "r1"
+LICENSE = "Apache-2.0"
+LIC_FILES_CHKSUM = "file://${PHOSPHORBASE}/COPYING.apache-2.0;md5=34400b68072d710fecd0a2940a0d1658"
+
+inherit allarch
+inherit phosphor-fan
+
+S = "${WORKDIR}"
+
+SRC_URI = "file://monitor.yaml"
+
+do_install() {
+    DEST=${D}${monitor_datadir}
+    install -D monitor.yaml ${D}${monitor_datadir}/monitor.yaml
+}
+
+FILES_${PN} += "${monitor_datadir}/monitor.yaml"
diff --git a/meta-phosphor/recipes-phosphor/fans/phosphor-fan-presence-config.bb b/meta-phosphor/recipes-phosphor/fans/phosphor-fan-presence-config.bb
new file mode 100644
index 0000000..30da6ea
--- /dev/null
+++ b/meta-phosphor/recipes-phosphor/fans/phosphor-fan-presence-config.bb
@@ -0,0 +1,24 @@
+# Provides the config file for the phosphor-fan-presence application.
+# The default config file is empty.  To provide a real one,
+# append this recipe in a layer, add:
+# FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
+# and provide a config file.
+
+SUMMARY = "Config file for phosphor-fan-presence"
+PR = "r1"
+LICENSE = "Apache-2.0"
+LIC_FILES_CHKSUM = "file://${PHOSPHORBASE}/COPYING.apache-2.0;md5=34400b68072d710fecd0a2940a0d1658"
+
+inherit allarch
+inherit phosphor-fan
+
+S = "${WORKDIR}"
+PROVIDES += "virtual/phosphor-fan-presence-config"
+
+SRC_URI = "file://config.yaml"
+
+do_install() {
+        install -D config.yaml ${D}${presence_datadir}/config.yaml
+}
+
+FILES_${PN} += "${presence_datadir}/config.yaml"
diff --git a/meta-phosphor/recipes-phosphor/fans/phosphor-fan-presence-mrw.bb b/meta-phosphor/recipes-phosphor/fans/phosphor-fan-presence-mrw.bb
new file mode 100644
index 0000000..31b7654
--- /dev/null
+++ b/meta-phosphor/recipes-phosphor/fans/phosphor-fan-presence-mrw.bb
@@ -0,0 +1,24 @@
+SUMMARY = "Generate fan presence YAML from the MRW"
+PR = "r1"
+LICENSE = "Apache-2.0"
+
+inherit allarch
+inherit phosphor-fan
+inherit mrw-xml
+
+DEPENDS = "mrw-native mrw-perl-tools-native"
+PROVIDES += "virtual/phosphor-fan-presence-config"
+
+FILES_${PN} += "${presence_datadir}/config.yaml"
+
+S = "${WORKDIR}"
+
+do_install() {
+        DEST=${D}${presence_datadir}
+        install -d ${DEST}
+
+        ${bindir}/perl-native/perl \
+            ${bindir}/gen_presence_yaml.pl \
+            -i ${STAGING_DIR_NATIVE}${mrw_datadir}/${MRW_XML} \
+            -o ${DEST}/config.yaml
+}
diff --git a/meta-phosphor/recipes-phosphor/fans/phosphor-fan_git.bb b/meta-phosphor/recipes-phosphor/fans/phosphor-fan_git.bb
index 2e6225a..dc82cba 100644
--- a/meta-phosphor/recipes-phosphor/fans/phosphor-fan_git.bb
+++ b/meta-phosphor/recipes-phosphor/fans/phosphor-fan_git.bb
@@ -10,6 +10,7 @@
 inherit obmc-phosphor-systemd
 inherit phosphor-fan
 
+PHOSPHOR_FAN_STAGING_DIR = "${@bb.utils.contains('PHOSPHOR_FAN_CONFIG_USE_NATIVE_SYSROOT', '1', '${STAGING_DIR_NATIVE}', '${STAGING_DIR_HOST}', d)}"
 S = "${WORKDIR}/git"
 
 # Common build dependencies
@@ -39,7 +40,7 @@
 # ${PN}-presence-tach specific configuration
 PACKAGECONFIG[presence] = " \
         --enable-presence \
-        PRESENCE_CONFIG=${STAGING_DIR_NATIVE}${presence_datadir}/config.yaml, \
+        PRESENCE_CONFIG=${PHOSPHOR_FAN_STAGING_DIR}${presence_datadir}/config.yaml, \
         --disable-presence, \
         virtual/phosphor-fan-presence-config \
         , \
@@ -58,16 +59,16 @@
 # --------------------------------------
 # ${PN}-control specific configuration
 PACKAGECONFIG[control] = "--enable-control \
-     FAN_DEF_YAML_FILE=${STAGING_DIR_NATIVE}${control_datadir}/fans.yaml \
-     FAN_ZONE_YAML_FILE=${STAGING_DIR_NATIVE}${control_datadir}/zones.yaml \
-     ZONE_EVENTS_YAML_FILE=${STAGING_DIR_NATIVE}${control_datadir}/events.yaml \
-     ZONE_CONDITIONS_YAML_FILE=${STAGING_DIR_NATIVE}${control_datadir}/zone_conditions.yaml \
+     FAN_DEF_YAML_FILE=${PHOSPHOR_FAN_STAGING_DIR}${control_datadir}/fans.yaml \
+     FAN_ZONE_YAML_FILE=${PHOSPHOR_FAN_STAGING_DIR}${control_datadir}/zones.yaml \
+     ZONE_EVENTS_YAML_FILE=${PHOSPHOR_FAN_STAGING_DIR}${control_datadir}/events.yaml \
+     ZONE_CONDITIONS_YAML_FILE=${PHOSPHOR_FAN_STAGING_DIR}${control_datadir}/zone_conditions.yaml \
      FAN_ZONE_OUTPUT_DIR=${S}/control, \
     --disable-control, \
     virtual/phosphor-fan-control-fan-config \
-    phosphor-fan-control-zone-config-native \
-    phosphor-fan-control-events-config-native \
-    phosphor-fan-control-zone-conditions-config-native \
+    phosphor-fan-control-zone-config${PHOSPHOR_FAN_CONFIG_RECIPE_SUFFIX} \
+    phosphor-fan-control-events-config${PHOSPHOR_FAN_CONFIG_RECIPE_SUFFIX} \
+    phosphor-fan-control-zone-conditions-config${PHOSPHOR_FAN_CONFIG_RECIPE_SUFFIX} \
     , \
 "
 
@@ -89,10 +90,10 @@
 # --------------------------------------
 # ${PN}-monitor specific configuration
 PACKAGECONFIG[monitor] = "--enable-monitor \
-     FAN_MONITOR_YAML_FILE=${STAGING_DIR_NATIVE}${monitor_datadir}/monitor.yaml \
+     FAN_MONITOR_YAML_FILE=${PHOSPHOR_FAN_STAGING_DIR}${monitor_datadir}/monitor.yaml \
      FAN_MONITOR_OUTPUT_DIR=${S}/monitor, \
     --disable-monitor, \
-    phosphor-fan-monitor-config-native \
+    phosphor-fan-monitor-config${PHOSPHOR_FAN_CONFIG_RECIPE_SUFFIX} \
     , \
 "