Skip to contentSkip to conversation

copyleft_filter.bbclass: Allow to filter on name

PATCH In review [email protected] 2 participants 3 messages May 22, 2015 – Jun 4, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 copyleft_filter.bbclass: Allow to filter on name

From: Mariano Lopez <[email protected]>

The archiver uses a license based filter to provide the source code. This patch allows to search on name based on two new variables (SRC_INCLUDE_NAME, SRC_EXCLUDE_NAME). Both variables are empty by default.
The filter by name has higher priority than the license filter.

---
 meta/classes/archiver.bbclass        | 14 ++++++--------
 meta/classes/copyleft_filter.bbclass | 28 ++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+), 8 deletions(-)
meta/classes/archiver.bbclass +6 -8
index b598aa3..138c407 100644
@@ -52,14 +52,12 @@ do_ar_original[dirs] = "${ARCHIVER_OUTDIR} ${ARCHIVER_WORKDIR}"
 python () {
     pn = d.getVar('PN', True)
 
-    if d.getVar('COPYLEFT_LICENSE_INCLUDE', True) or \
-            d.getVar('COPYLEFT_LICENSE_EXCLUDE', True):
-        included, reason = copyleft_should_include(d)
-        if not included:
-            bb.debug(1, 'archiver: %s is excluded: %s' % (pn, reason))
-            return
-        else:
-            bb.debug(1, 'archiver: %s is included: %s' % (pn, reason))
+    included, reason = should_include_src(d)
+    if not included:
+        bb.debug(1, 'archiver: %s is excluded: %s' % (pn, reason))
+        return
+    else:
+        bb.debug(1, 'archiver: %s is included: %s' % (pn, reason))
 
     ar_src = d.getVarFlag('ARCHIVER_MODE', 'src', True)
     ar_dumpdata = d.getVarFlag('ARCHIVER_MODE', 'dumpdata', True)
meta/classes/copyleft_filter.bbclass +28 -0
index 2c1d8f1..d5c3b59 100644
@@ -25,6 +25,14 @@ COPYLEFT_AVAILABLE_RECIPE_TYPES = 'target native nativesdk cross crosssdk cross-
 COPYLEFT_AVAILABLE_RECIPE_TYPES[type] = 'list'
 COPYLEFT_AVAILABLE_RECIPE_TYPES[doc] = 'Space separated list of available recipe types'
 
+SRC_INCLUDE_NAME ?= ''
+SRC_INCLUDE_NAME[type] = 'list'
+SRC_INCLUDE_NAME[doc] = 'Space separated list of recipe names to include'
+
+SRC_EXCLUDE_NAME ?= ''
+SRC_EXCLUDE_NAME[type] = 'list'
+SRC_EXCLUDE_NAME[doc] = 'Space separated list of recipe names to exclude'
+
 def copyleft_recipe_type(d):
     for recipe_type in oe.data.typed_value('COPYLEFT_AVAILABLE_RECIPE_TYPES', d):
         if oe.utils.inherits(d, recipe_type):
@@ -59,4 +67,24 @@ def copyleft_should_include(d):
         else:
             return False, 'recipe has excluded licenses: %s' % ', '.join(reason)
 
+def should_include_src(d):
+    """
+    Determine if this recipe's source should be deployed
+    """
+    from fnmatch import fnmatchcase as fnmatch
+
+    if d.getVar('COPYLEFT_LICENSE_INCLUDE', True) or \
+            d.getVar('COPYLEFT_LICENSE_EXCLUDE', True):
+        is_included, reason = copyleft_should_include(d)
+
+    if any(fnmatch(d.getVar('PN', True), name) \
+            for name in oe.data.typed_value('SRC_INCLUDE_NAME', d)):
+        is_included, reason =  True, 'recipe included by name'
+    if any(fnmatch(d.getVar('PN', True), name) \
+            for name in oe.data.typed_value('SRC_EXCLUDE_NAME', d)):
+        is_included, reason = False, 'recipe excluded by name'
+
+    if 'reason' not in locals():
+        is_included, reason = False, 'recipe did not match any condition'
+    return is_included, reason
 
Signature · 1 line
1.8.4.5
#1 lore raw

Ping

Quoted 82 lines · On 05/22/2015 01:29 AM, [email protected] wrote:

From: Mariano Lopez <[email protected]>

The archiver uses a license based filter to provide the source code. This patch allows to search on name based on two new variables (SRC_INCLUDE_NAME, SRC_EXCLUDE_NAME). Both variables are empty by default.
The filter by name has higher priority than the license filter.

---
  meta/classes/archiver.bbclass        | 14 ++++++--------
  meta/classes/copyleft_filter.bbclass | 28 ++++++++++++++++++++++++++++
  2 files changed, 34 insertions(+), 8 deletions(-)
meta/classes/archiver.bbclass +6 -8
index b598aa3..138c407 100644
@@ -52,14 +52,12 @@ do_ar_original[dirs] = "${ARCHIVER_OUTDIR} ${ARCHIVER_WORKDIR}"
  python () {
      pn = d.getVar('PN', True)
 
-    if d.getVar('COPYLEFT_LICENSE_INCLUDE', True) or \
-            d.getVar('COPYLEFT_LICENSE_EXCLUDE', True):
-        included, reason = copyleft_should_include(d)
-        if not included:
-            bb.debug(1, 'archiver: %s is excluded: %s' % (pn, reason))
-            return
-        else:
-            bb.debug(1, 'archiver: %s is included: %s' % (pn, reason))
+    included, reason = should_include_src(d)
+    if not included:
+        bb.debug(1, 'archiver: %s is excluded: %s' % (pn, reason))
+        return
+    else:
+        bb.debug(1, 'archiver: %s is included: %s' % (pn, reason))
 
      ar_src = d.getVarFlag('ARCHIVER_MODE', 'src', True)
      ar_dumpdata = d.getVarFlag('ARCHIVER_MODE', 'dumpdata', True)
meta/classes/copyleft_filter.bbclass +28 -0
index 2c1d8f1..d5c3b59 100644
@@ -25,6 +25,14 @@ COPYLEFT_AVAILABLE_RECIPE_TYPES = 'target native nativesdk cross crosssdk cross-
  COPYLEFT_AVAILABLE_RECIPE_TYPES[type] = 'list'
  COPYLEFT_AVAILABLE_RECIPE_TYPES[doc] = 'Space separated list of available recipe types'
 
+SRC_INCLUDE_NAME ?= ''
+SRC_INCLUDE_NAME[type] = 'list'
+SRC_INCLUDE_NAME[doc] = 'Space separated list of recipe names to include'
+
+SRC_EXCLUDE_NAME ?= ''
+SRC_EXCLUDE_NAME[type] = 'list'
+SRC_EXCLUDE_NAME[doc] = 'Space separated list of recipe names to exclude'
+
  def copyleft_recipe_type(d):
      for recipe_type in oe.data.typed_value('COPYLEFT_AVAILABLE_RECIPE_TYPES', d):
          if oe.utils.inherits(d, recipe_type):
@@ -59,4 +67,24 @@ def copyleft_should_include(d):
          else:
              return False, 'recipe has excluded licenses: %s' % ', '.join(reason)
 
+def should_include_src(d):
+    """
+    Determine if this recipe's source should be deployed
+    """
+    from fnmatch import fnmatchcase as fnmatch
+
+    if d.getVar('COPYLEFT_LICENSE_INCLUDE', True) or \
+            d.getVar('COPYLEFT_LICENSE_EXCLUDE', True):
+        is_included, reason = copyleft_should_include(d)
+
+    if any(fnmatch(d.getVar('PN', True), name) \
+            for name in oe.data.typed_value('SRC_INCLUDE_NAME', d)):
+        is_included, reason =  True, 'recipe included by name'
+    if any(fnmatch(d.getVar('PN', True), name) \
+            for name in oe.data.typed_value('SRC_EXCLUDE_NAME', d)):
+        is_included, reason = False, 'recipe excluded by name'
+
+    if 'reason' not in locals():
+        is_included, reason = False, 'recipe did not match any condition'
+    return is_included, reason
 
Signature · 1 line
Mariano Lopez
#2 lore raw
In reply to [email protected]

Hi Mariano,

Quoted 75 lines · On Friday 22 May 2015 06:29:25 [email protected] wrote:

From: Mariano Lopez <[email protected]>

The archiver uses a license based filter to provide the source code. This patch allows to search on name based on two new variables (SRC_INCLUDE_NAME, SRC_EXCLUDE_NAME). Both variables are empty by default. The filter by name has higher priority than the license filter.

---
 meta/classes/archiver.bbclass        | 14 ++++++--------
 meta/classes/copyleft_filter.bbclass | 28 ++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+), 8 deletions(-)
meta/classes/archiver.bbclass +6 -8
index b598aa3..138c407 100644
@@ -52,14 +52,12 @@ do_ar_original[dirs] = "${ARCHIVER_OUTDIR}
 ${ARCHIVER_WORKDIR}" python () {
     pn = d.getVar('PN', True)
 
-    if d.getVar('COPYLEFT_LICENSE_INCLUDE', True) or \
-            d.getVar('COPYLEFT_LICENSE_EXCLUDE', True):
-        included, reason = copyleft_should_include(d)
-        if not included:
-            bb.debug(1, 'archiver: %s is excluded: %s' % (pn, reason))
-            return
-        else:
-            bb.debug(1, 'archiver: %s is included: %s' % (pn, reason))
+    included, reason = should_include_src(d)
+    if not included:
+        bb.debug(1, 'archiver: %s is excluded: %s' % (pn, reason))
+        return
+    else:
+        bb.debug(1, 'archiver: %s is included: %s' % (pn, reason))
 
     ar_src = d.getVarFlag('ARCHIVER_MODE', 'src', True)
     ar_dumpdata = d.getVarFlag('ARCHIVER_MODE', 'dumpdata', True)
(quoted diff) +0 -0

b/meta/classes/copyleft_filter.bbclass index 2c1d8f1..d5c3b59 100644

meta/classes/copyleft_filter.bbclass +0 -0
@@ -25,6 +25,14 @@ COPYLEFT_AVAILABLE_RECIPE_TYPES = 'target native

nativesdk cross crosssdk cross- COPYLEFT_AVAILABLE_RECIPE_TYPES[type] = 'list'
COPYLEFT_AVAILABLE_RECIPE_TYPES[doc] = 'Space separated list of available
recipe types'

meta/classes/copyleft_filter.bbclass +8 -0
+SRC_INCLUDE_NAME ?= ''
+SRC_INCLUDE_NAME[type] = 'list'
+SRC_INCLUDE_NAME[doc] = 'Space separated list of recipe names to include'
+
+SRC_EXCLUDE_NAME ?= ''
+SRC_EXCLUDE_NAME[type] = 'list'
+SRC_EXCLUDE_NAME[doc] = 'Space separated list of recipe names to exclude'
+
 def copyleft_recipe_type(d):
     for recipe_type in

oe.data.typed_value('COPYLEFT_AVAILABLE_RECIPE_TYPES', d): if oe.utils.inherits(d, recipe_type):

meta/classes/copyleft_filter.bbclass +10 -0
@@ -59,4 +67,24 @@ def copyleft_should_include(d):
         else:
             return False, 'recipe has excluded licenses: %s' % ',
 '.join(reason)
 
+def should_include_src(d):
+    """
+    Determine if this recipe's source should be deployed
+    """
+    from fnmatch import fnmatchcase as fnmatch
+
+    if d.getVar('COPYLEFT_LICENSE_INCLUDE', True) or \
+            d.getVar('COPYLEFT_LICENSE_EXCLUDE', True):
+        is_included, reason = copyleft_should_include(d)
+

meta/classes/copyleft_filter.bbclass def copyleft_should_include(d): · line 90

Quoted 10 lines
meta/classes/copyleft_filter.bbclass +10 -0
+    if any(fnmatch(d.getVar('PN', True), name) \
+            for name in oe.data.typed_value('SRC_INCLUDE_NAME', d)):
+        is_included, reason =  True, 'recipe included by name'
+    if any(fnmatch(d.getVar('PN', True), name) \
+            for name in oe.data.typed_value('SRC_EXCLUDE_NAME', d)):
+        is_included, reason = False, 'recipe excluded by name'
+
+    if 'reason' not in locals():
+        is_included, reason = False, 'recipe did not match any condition'
+    return is_included, reason

I really need to be more active in reviewing things, sorry about the lack of reply. A couple of comments:

1) It looks like we already have a function in copyleft_filter.bbclass that we should simply be extending i.e. copyleft_should_include() - you would then need to change archiver.bbclass so that it always calls that function instead of being conditional on whether COPYLEFT_LICENSE_INCLUDE or COPYLEFT_LICENSE_EXCLUDE are set.

2) Following on from the above, the new variable ought to be named consistently with the other variables used by the class, e.g. COPYLEFT_PN_INCLUDE and COPYLEFT_PN_EXCLUDE.

Cheers,
Paul

Signature · 2 lines
Paul Eggleton
Intel Open Source Technology Centre