From 3fdc9861f677bdac1dd469f70787b32a0af3e3d6 Mon Sep 17 00:00:00 2001
From: Esben Haabendal <esben.haabendal@huawei.com>
Date: Wed, 6 Jul 2022 12:30:16 +0200
Subject: [PATCH] openharmony-standard: Ensure proper distro configuration

This will skip the recipe if openharmony is not enabled in DISTRO_FEATURES,
if TOOLCHAIN is not clang or if RUNTIME is not llvm.

Signed-off-by: Esben Haabendal <esben.haabendal@huawei.com>
---
 .../openharmony/openharmony-standard_3.0.bb   |  6 +++++-
 .../openharmony/openharmony-standard_3.1.bb   |  6 +++++-
 .../openharmony/sanity-check.inc              | 20 +++++++++++++++++++
 3 files changed, 30 insertions(+), 2 deletions(-)
 create mode 100644 recipes-openharmony/openharmony/sanity-check.inc

diff --git a/recipes-openharmony/openharmony/openharmony-standard_3.0.bb b/recipes-openharmony/openharmony/openharmony-standard_3.0.bb
index 6b0d7208..0c6f1053 100644
--- a/recipes-openharmony/openharmony/openharmony-standard_3.0.bb
+++ b/recipes-openharmony/openharmony/openharmony-standard_3.0.bb
@@ -12,11 +12,15 @@ PD & OFL-1.1 & OpenSSL & MulanPSL-2.0 & bzip2-1.0.6 & ISC & ICU & IJG & Libpng &
 MPL-1.1 & MPL-2.0 & FTL"
 LIC_FILES_CHKSUM = "file://build/LICENSE;md5=cfba563cea4ce607306f8a392f19bf6c"
 
+require sanity-check.inc
+
 DEPENDS += "nodejs-native"
 DEPENDS += "bison-native"
 DEPENDS += "ruby-native"
 
-require ${PN}-sources-${OPENHARMONY_VERSION}.inc
+# Note: Using include instead of require to avoid parser error skipping recipe
+include ${PN}-sources-${OPENHARMONY_VERSION}.inc
+
 require musl-ldso-paths-sanity-check.inc
 
 FILESEXTRAPATHS:prepend := "${THISDIR}/openharmony-${OPENHARMONY_VERSION}:"
diff --git a/recipes-openharmony/openharmony/openharmony-standard_3.1.bb b/recipes-openharmony/openharmony/openharmony-standard_3.1.bb
index 5007c1cb..3450f15a 100644
--- a/recipes-openharmony/openharmony/openharmony-standard_3.1.bb
+++ b/recipes-openharmony/openharmony/openharmony-standard_3.1.bb
@@ -12,6 +12,8 @@ PD & OFL-1.1 & OpenSSL & MulanPSL-2.0 & bzip2-1.0.6 & ISC & ICU & IJG & Libpng &
 MPL-1.1 & MPL-2.0 & FTL"
 LIC_FILES_CHKSUM = "file://build/LICENSE;md5=cfba563cea4ce607306f8a392f19bf6c"
 
+require sanity-check.inc
+
 DEPENDS += "nodejs-native"
 DEPENDS += "bison-native"
 DEPENDS += "ruby-native"
@@ -23,7 +25,9 @@ DEPENDS += "fts"
 FILESEXTRAPATHS:prepend := "${THISDIR}/openharmony-${OPENHARMONY_VERSION}:"
 FILESEXTRAPATHS:prepend := "${THISDIR}/openharmony-standard-${OPENHARMONY_VERSION}:"
 
-require ${PN}-sources-${OPENHARMONY_VERSION}.inc
+# Note: Using include instead of require to avoid parser error skipping recipe
+include ${PN}-sources-${OPENHARMONY_VERSION}.inc
+
 require java-tools.inc
 require musl-ldso-paths-sanity-check.inc
 
diff --git a/recipes-openharmony/openharmony/sanity-check.inc b/recipes-openharmony/openharmony/sanity-check.inc
new file mode 100644
index 00000000..ac8b09b7
--- /dev/null
+++ b/recipes-openharmony/openharmony/sanity-check.inc
@@ -0,0 +1,20 @@
+# SPDX-FileCopyrightText: Huawei Inc.
+#
+# SPDX-License-Identifier: Apache-2.0
+
+# Skip recipe if openharmony is not in DISTRO_FEATURES
+inherit features_check
+REQUIRED_DISTRO_FEATURES = "openharmony"
+
+# Skip recipe if TOOLCHAIN != "clang" or RUNTIME != "llvm"
+python () {
+    toolchain = d.getVar('TOOLCHAIN')
+    runtime = d.getVar('RUNTIME')
+    tclibc = d.getVar('TCLIBC')
+    if toolchain != "clang":
+        raise bb.parse.SkipRecipe("TOOLCHAIN is not clang")
+    if runtime != "llvm":
+        raise bb.parse.SkipRecipe("RUNTIME is not llvm")
+    if tclibc != "musl":
+        raise bb.parse.SkipRecipe("TCLIBC is not musl")
+}
-- 
GitLab