[1/1] distro_features_check.bbclass: show all error info at one time

Submitted by Kang Kai on Dec. 6, 2018, 1:41 p.m. | Patch ID: 156957

Details

Message ID 226bbb49f1868d91cb552ce0ad3fe8ee3bf26f04.1544100963.git.kai.kang@windriver.com
State Accepted
Commit d0441c40afdba119a65189d6a5aca5c533f68279
Headers show

Commit Message

Kang Kai Dec. 6, 2018, 1:41 p.m.
From: Kai Kang <kai.kang@windriver.com>

In distro_features_check.bbclass it checks whether items in
REQUIRED_DISTRO_FEATURES and CONFLICT_DISTRO_FEATURES exist in
DISTRO_FEATURES. But it only shows one required or conflict distro
feature when error occurs. Update to show them all at one time.

Signed-off-by: Kai Kang <kai.kang@windriver.com>
---
 meta/classes/distro_features_check.bbclass | 29 +++++++++-------------
 1 file changed, 12 insertions(+), 17 deletions(-)

Patch hide | download patch | download mbox

diff --git a/meta/classes/distro_features_check.bbclass b/meta/classes/distro_features_check.bbclass
index 9b78b03ef6..eeaa3b44cb 100644
--- a/meta/classes/distro_features_check.bbclass
+++ b/meta/classes/distro_features_check.bbclass
@@ -11,27 +11,22 @@ 
 
 python () {
     # Assume at least one var is set.
-    distro_features = (d.getVar('DISTRO_FEATURES') or "").split()
+    distro_features = set((d.getVar('DISTRO_FEATURES') or '').split())
 
-    any_of_distro_features = d.getVar('ANY_OF_DISTRO_FEATURES')
+    any_of_distro_features = set((d.getVar('ANY_OF_DISTRO_FEATURES') or '').split())
     if any_of_distro_features:
-        any_of_distro_features = any_of_distro_features.split()
-        if set.isdisjoint(set(any_of_distro_features),set(distro_features)):
-            raise bb.parse.SkipRecipe("one of '%s' needs to be in DISTRO_FEATURES" % any_of_distro_features)
+        if set.isdisjoint(any_of_distro_features, distro_features):
+            raise bb.parse.SkipRecipe("one of '%s' needs to be in DISTRO_FEATURES" % ' '.join(any_of_distro_features))
 
-    required_distro_features = d.getVar('REQUIRED_DISTRO_FEATURES')
+    required_distro_features = set((d.getVar('REQUIRED_DISTRO_FEATURES') or '').split())
     if required_distro_features:
-        required_distro_features = required_distro_features.split()
-        for f in required_distro_features:
-            if f in distro_features:
-                continue
-            else:
-                raise bb.parse.SkipRecipe("missing required distro feature '%s' (not in DISTRO_FEATURES)" % f)
+        missing = set.difference(required_distro_features, distro_features)
+        if missing:
+            raise bb.parse.SkipRecipe("missing required distro feature%s '%s' (not in DISTRO_FEATURES)" % ('s' if len(missing) > 1 else '', ' '.join(missing)))
 
-    conflict_distro_features = d.getVar('CONFLICT_DISTRO_FEATURES')
+    conflict_distro_features = set((d.getVar('CONFLICT_DISTRO_FEATURES') or '').split())
     if conflict_distro_features:
-        conflict_distro_features = conflict_distro_features.split()
-        for f in conflict_distro_features:
-            if f in distro_features:
-                raise bb.parse.SkipRecipe("conflicting distro feature '%s' (in DISTRO_FEATURES)" % f)
+        conflicts = set.intersection(conflict_distro_features, distro_features)
+        if conflicts:
+            raise bb.parse.SkipRecipe("conflicting distro feature%s '%s' (in DISTRO_FEATURES)" % ('s' if len(conflicts) > 1 else '', ' '.join(conflicts)))
 }

Comments

Kang Kai Dec. 19, 2018, 1:53 a.m.
On 2018/12/6 下午9:41, kai.kang@windriver.com wrote:
> From: Kai Kang <kai.kang@windriver.com>
>
> In distro_features_check.bbclass it checks whether items in
> REQUIRED_DISTRO_FEATURES and CONFLICT_DISTRO_FEATURES exist in
> DISTRO_FEATURES. But it only shows one required or conflict distro
> feature when error occurs. Update to show them all at one time.
>
> Signed-off-by: Kai Kang <kai.kang@windriver.com>
> ---
>   meta/classes/distro_features_check.bbclass | 29 +++++++++-------------
>   1 file changed, 12 insertions(+), 17 deletions(-)
>
> diff --git a/meta/classes/distro_features_check.bbclass b/meta/classes/distro_features_check.bbclass
> index 9b78b03ef6..eeaa3b44cb 100644
> --- a/meta/classes/distro_features_check.bbclass
> +++ b/meta/classes/distro_features_check.bbclass
> @@ -11,27 +11,22 @@
>   
>   python () {
>       # Assume at least one var is set.
> -    distro_features = (d.getVar('DISTRO_FEATURES') or "").split()
> +    distro_features = set((d.getVar('DISTRO_FEATURES') or '').split())
>   
> -    any_of_distro_features = d.getVar('ANY_OF_DISTRO_FEATURES')
> +    any_of_distro_features = set((d.getVar('ANY_OF_DISTRO_FEATURES') or '').split())
>       if any_of_distro_features:
> -        any_of_distro_features = any_of_distro_features.split()
> -        if set.isdisjoint(set(any_of_distro_features),set(distro_features)):
> -            raise bb.parse.SkipRecipe("one of '%s' needs to be in DISTRO_FEATURES" % any_of_distro_features)
> +        if set.isdisjoint(any_of_distro_features, distro_features):
> +            raise bb.parse.SkipRecipe("one of '%s' needs to be in DISTRO_FEATURES" % ' '.join(any_of_distro_features))
>   
> -    required_distro_features = d.getVar('REQUIRED_DISTRO_FEATURES')
> +    required_distro_features = set((d.getVar('REQUIRED_DISTRO_FEATURES') or '').split())
>       if required_distro_features:
> -        required_distro_features = required_distro_features.split()
> -        for f in required_distro_features:
> -            if f in distro_features:
> -                continue
> -            else:
> -                raise bb.parse.SkipRecipe("missing required distro feature '%s' (not in DISTRO_FEATURES)" % f)
> +        missing = set.difference(required_distro_features, distro_features)
> +        if missing:
> +            raise bb.parse.SkipRecipe("missing required distro feature%s '%s' (not in DISTRO_FEATURES)" % ('s' if len(missing) > 1 else '', ' '.join(missing)))
>   
> -    conflict_distro_features = d.getVar('CONFLICT_DISTRO_FEATURES')
> +    conflict_distro_features = set((d.getVar('CONFLICT_DISTRO_FEATURES') or '').split())
>       if conflict_distro_features:
> -        conflict_distro_features = conflict_distro_features.split()
> -        for f in conflict_distro_features:
> -            if f in distro_features:
> -                raise bb.parse.SkipRecipe("conflicting distro feature '%s' (in DISTRO_FEATURES)" % f)
> +        conflicts = set.intersection(conflict_distro_features, distro_features)
> +        if conflicts:
> +            raise bb.parse.SkipRecipe("conflicting distro feature%s '%s' (in DISTRO_FEATURES)" % ('s' if len(conflicts) > 1 else '', ' '.join(conflicts)))
>   }

Any comment on this patch? Thanks.