Bladeren bron

classes/conf: Add eventmasks for event handlers

Now that bitbake supports masking events for event handlers, lets use
this so event handlers are only called for events they care about. This
lets us simplify the code indentation a bit at least as well as mildly
improving the event handling performance.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Richard Purdie 11 jaren geleden
bovenliggende
commit
bff7374328

+ 4 - 3
meta/classes/base.bbclass

@@ -32,12 +32,12 @@ def oe_import(d):
         inject(toimport.split(".", 1)[0], imported)
 
 python oe_import_eh () {
-    if isinstance(e, bb.event.ConfigParsed):
-        oe_import(e.data)
-        e.data.setVar("NATIVELSBSTRING", lsb_distro_identifier(e.data))
+    oe_import(e.data)
+    e.data.setVar("NATIVELSBSTRING", lsb_distro_identifier(e.data))
 }
 
 addhandler oe_import_eh
+oe_import_eh[eventmask] = "bb.event.ConfigParsed"
 
 def lsb_distro_identifier(d):
     adjust = d.getVar('LSB_DISTRO_ADJUST', True)
@@ -299,6 +299,7 @@ def buildcfg_neededvars(d):
         bb.fatal('The following variable(s) were not set: %s\nPlease set them directly, or choose a MACHINE or DISTRO that sets them.' % ', '.join(pesteruser))
 
 addhandler base_eventhandler
+base_eventhandler[eventmask] = "bb.event.ConfigParsed bb.event.BuildStarted"
 python base_eventhandler() {
     if isinstance(e, bb.event.ConfigParsed):
         e.data.setVar('BB_VERSION', bb.__version__)

+ 1 - 0
meta/classes/bugzilla.bbclass

@@ -71,6 +71,7 @@ def bugzilla_add_comment(debug_file, server, args, bug_number, text):
         return False
 
 addhandler bugzilla_eventhandler
+bugzilla_eventhandler[eventmask] = "bb.event.MsgNote bb.build.TaskFailed"
 python bugzilla_eventhandler() {
     import glob
     import xmlrpclib, httplib

+ 4 - 4
meta/classes/buildhistory.bbclass

@@ -525,13 +525,13 @@ END
 }
 
 python buildhistory_eventhandler() {
-    if isinstance(e, bb.event.BuildCompleted):
-        if e.data.getVar('BUILDHISTORY_FEATURES', True).strip():
-            if e.data.getVar("BUILDHISTORY_COMMIT", True) == "1":
-                bb.build.exec_func("buildhistory_commit", e.data)
+    if e.data.getVar('BUILDHISTORY_FEATURES', True).strip():
+        if e.data.getVar("BUILDHISTORY_COMMIT", True) == "1":
+            bb.build.exec_func("buildhistory_commit", e.data)
 }
 
 addhandler buildhistory_eventhandler
+buildhistory_eventhandler[eventmask] = "bb.event.BuildCompleted"
 
 
 # FIXME this ought to be moved into the fetcher

+ 1 - 0
meta/classes/buildstats.bbclass

@@ -278,4 +278,5 @@ python run_buildstats () {
 }
 
 addhandler run_buildstats
+run_buildstats[eventmask] = "bb.event.BuildStarted bb.event.BuildCompleted bb.build.TaskStarted bb.build.TaskSucceeded bb.build.TaskFailed"
 

+ 1 - 3
meta/classes/cross.bbclass

@@ -58,9 +58,6 @@ do_populate_sysroot[sstate-inputdirs] = "${SYSROOT_DESTDIR}/${STAGING_DIR_NATIVE
 do_populate_sysroot[stamp-extra-info] = ""
 
 python cross_virtclass_handler () {
-    if not isinstance(e, bb.event.RecipePreFinalise):
-        return
-
     classextend = e.data.getVar('BBCLASSEXTEND', True) or ""
     if "cross" not in classextend:
         return
@@ -73,6 +70,7 @@ python cross_virtclass_handler () {
 }
 
 addhandler cross_virtclass_handler
+cross_virtclass_handler[eventmask] = "bb.event.RecipePreFinalise"
 
 do_install () {
 	oe_runmake 'DESTDIR=${D}' install

+ 22 - 22
meta/classes/distrodata.bbclass

@@ -1,15 +1,14 @@
 include conf/distro/include/package_regex.inc
 addhandler distro_eventhandler
+distro_eventhandler[eventmask] = "bb.event.BuildStarted"
 python distro_eventhandler() {
-
-    if bb.event.getName(e) == "BuildStarted":
-        import oe.distro_check as dc
-        logfile = dc.create_log_file(e.data, "distrodata.csv")
-        lf = bb.utils.lockfile("%s.lock" % logfile)
-        f = open(logfile, "a")
-        f.write("Package,Description,Owner,License,VerMatch,Version,Upsteam,Reason,Recipe Status,Distro 1,Distro 2,Distro 3\n")
-        f.close()
-        bb.utils.unlockfile(lf)
+    import oe.distro_check as dc
+    logfile = dc.create_log_file(e.data, "distrodata.csv")
+    lf = bb.utils.lockfile("%s.lock" % logfile)
+    f = open(logfile, "a")
+    f.write("Package,Description,Owner,License,VerMatch,Version,Upsteam,Reason,Recipe Status,Distro 1,Distro 2,Distro 3\n")
+    f.close()
+    bb.utils.unlockfile(lf)
 
     return
 }
@@ -197,6 +196,7 @@ do_distrodataall() {
 }
 
 addhandler checkpkg_eventhandler
+ checkpkg_eventhandler[eventmask] = "bb.event.BuildStarted bb.event.BuildCompleted"
 python checkpkg_eventhandler() {
     def parse_csv_file(filename):
         package_dict = {}
@@ -793,11 +793,11 @@ do_checkpkgall() {
 }
 
 addhandler distro_check_eventhandler
+distro_check_eventhandler bb.event.BuildStarted
 python distro_check_eventhandler() {
-    if bb.event.getName(e) == "BuildStarted":
-        """initialize log files."""
-        import oe.distro_check as dc
-        result_file = dc.create_log_file(e.data, "distrocheck.csv")
+    """initialize log files."""
+    import oe.distro_check as dc
+    result_file = dc.create_log_file(e.data, "distrocheck.csv")
     return
 }
 
@@ -839,16 +839,16 @@ do_distro_checkall() {
 #then we can search those recipes which license text isn't exsit in common-licenses directory
 #
 addhandler checklicense_eventhandler
+checklicense_eventhandler[eventmask] = "bb.event.BuildStarted"
 python checklicense_eventhandler() {
-    if bb.event.getName(e) == "BuildStarted":
-        """initialize log files."""
-        import oe.distro_check as dc
-        logfile = dc.create_log_file(e.data, "missinglicense.csv")
-        lf = bb.utils.lockfile("%s.lock" % logfile)
-        f = open(logfile, "a")
-        f.write("Package\tLicense\tMissingLicense\n")
-        f.close()
-        bb.utils.unlockfile(lf)
+    """initialize log files."""
+    import oe.distro_check as dc
+    logfile = dc.create_log_file(e.data, "missinglicense.csv")
+    lf = bb.utils.lockfile("%s.lock" % logfile)
+    f = open(logfile, "a")
+    f.write("Package\tLicense\tMissingLicense\n")
+    f.close()
+    bb.utils.unlockfile(lf)
     return
 }
 

+ 34 - 34
meta/classes/migrate_localcount.bbclass

@@ -6,41 +6,41 @@ python migrate_localcount_handler () {
     if not e.data:
         return
 
-    if isinstance(e, bb.event.RecipeParsed):
-        pv = e.data.getVar('PV', True)
-        if not 'AUTOINC' in pv:
-            return
-
-        localcounts = bb.persist_data.persist('BB_URI_LOCALCOUNT', e.data)
-        pn = e.data.getVar('PN', True)
-        revs = localcounts.get_by_pattern('%%-%s_rev' % pn)
-        counts = localcounts.get_by_pattern('%%-%s_count' % pn)
-        if not revs or not counts:
-            return
-
-        if len(revs) != len(counts):
-            bb.warn("The number of revs and localcounts don't match in %s" % pn)
-            return
-
-        version = e.data.getVar('PRAUTOINX', True)
-        srcrev = bb.fetch2.get_srcrev(e.data)
-        base_ver = 'AUTOINC-%s' % version[:version.find(srcrev)]
-        pkgarch = e.data.getVar('PACKAGE_ARCH', True)
-        value = max(int(count) for count in counts)
-
-        if len(revs) == 1:
-            if srcrev != ('AUTOINC+%s' % revs[0]):
-                value += 1
-        else:
-            value += 1
+    pv = e.data.getVar('PV', True)
+    if not 'AUTOINC' in pv:
+        return
+
+    localcounts = bb.persist_data.persist('BB_URI_LOCALCOUNT', e.data)
+    pn = e.data.getVar('PN', True)
+    revs = localcounts.get_by_pattern('%%-%s_rev' % pn)
+    counts = localcounts.get_by_pattern('%%-%s_count' % pn)
+    if not revs or not counts:
+        return
 
-        bb.utils.mkdirhier(e.data.getVar('PRSERV_DUMPDIR', True))
-        df = e.data.getVar('LOCALCOUNT_DUMPFILE', True)
-        flock = bb.utils.lockfile("%s.lock" % df)
-        with open(df, 'a') as fd:
-            fd.write('PRAUTO$%s$%s$%s = "%s"\n' %
-                    (base_ver, pkgarch, srcrev, str(value)))
-        bb.utils.unlockfile(flock)
+    if len(revs) != len(counts):
+        bb.warn("The number of revs and localcounts don't match in %s" % pn)
+        return
+
+    version = e.data.getVar('PRAUTOINX', True)
+    srcrev = bb.fetch2.get_srcrev(e.data)
+    base_ver = 'AUTOINC-%s' % version[:version.find(srcrev)]
+    pkgarch = e.data.getVar('PACKAGE_ARCH', True)
+    value = max(int(count) for count in counts)
+
+    if len(revs) == 1:
+        if srcrev != ('AUTOINC+%s' % revs[0]):
+            value += 1
+    else:
+        value += 1
+
+    bb.utils.mkdirhier(e.data.getVar('PRSERV_DUMPDIR', True))
+    df = e.data.getVar('LOCALCOUNT_DUMPFILE', True)
+    flock = bb.utils.lockfile("%s.lock" % df)
+    with open(df, 'a') as fd:
+        fd.write('PRAUTO$%s$%s$%s = "%s"\n' %
+                (base_ver, pkgarch, srcrev, str(value)))
+    bb.utils.unlockfile(flock)
 }
 
 addhandler migrate_localcount_handler
+migrate_localcount_handler[eventmask] = "bb.event.RecipeParsed"

+ 1 - 3
meta/classes/multilib.bbclass

@@ -1,7 +1,4 @@
 python multilib_virtclass_handler () {
-    if not isinstance(e, bb.event.RecipePreFinalise):
-        return
-
     cls = e.data.getVar("BBEXTENDCURR", True)
     variant = e.data.getVar("BBEXTENDVARIANT", True)
     if cls != "multilib" or not variant:
@@ -60,6 +57,7 @@ python multilib_virtclass_handler () {
 }
 
 addhandler multilib_virtclass_handler
+multilib_virtclass_handler[eventmask] = "bb.event.RecipePreFinalise"
 
 STAGINGCC_prepend = "${BBEXTENDVARIANT}-"
 

+ 1 - 0
meta/classes/multilib_global.bbclass

@@ -43,4 +43,5 @@ python multilib_virtclass_handler_global () {
 }
 
 addhandler multilib_virtclass_handler_global
+multilib_virtclass_handler_global[eventmask] = "bb.event.RecipePreFinalise bb.event.RecipeParsed"
 

+ 1 - 3
meta/classes/native.bbclass

@@ -104,9 +104,6 @@ CLASSOVERRIDE = "class-native"
 PATH_prepend = "${COREBASE}/scripts/native-intercept:"
 
 python native_virtclass_handler () {
-    if not isinstance(e, bb.event.RecipePreFinalise):
-        return
-
     classextend = e.data.getVar('BBCLASSEXTEND', True) or ""
     if "native" not in classextend:
         return
@@ -152,6 +149,7 @@ python native_virtclass_handler () {
 }
 
 addhandler native_virtclass_handler
+native_virtclass_handler[eventmask] = "bb.event.RecipePreFinalise"
 
 do_package[noexec] = "1"
 do_packagedata[noexec] = "1"

+ 1 - 3
meta/classes/nativesdk.bbclass

@@ -60,9 +60,6 @@ export PKG_CONFIG_DIR = "${STAGING_DIR_HOST}${libdir}/pkgconfig"
 export PKG_CONFIG_SYSROOT_DIR = "${STAGING_DIR_HOST}"
 
 python nativesdk_virtclass_handler () {
-    if not isinstance(e, bb.event.RecipePreFinalise):
-        return
-
     pn = e.data.getVar("PN", True)
     if not pn.endswith("-nativesdk") or pn.startswith("nativesdk-"):
         return
@@ -89,5 +86,6 @@ python () {
 }
 
 addhandler nativesdk_virtclass_handler
+nativesdk_virtclass_handler[eventmask] = "bb.event.RecipePreFinalise"
 
 do_populate_sysroot[stamp-extra-info] = ""

+ 25 - 25
meta/classes/packageinfo.bbclass

@@ -1,29 +1,29 @@
 python packageinfo_handler () {
-    if isinstance(e, bb.event.RequestPackageInfo):
-        import oe.packagedata
-        pkginfolist = []
-        tmpdir = e.data.getVar('TMPDIR', True)
-        target_vendor = e.data.getVar('TARGET_VENDOR', True)
-        target_os = e.data.getVar('TARGET_OS', True)
-        package_archs = e.data.getVar('PACKAGE_ARCHS', True)
-        packaging = e.data.getVar('PACKAGE_CLASSES', True).split()[0].split('_')[1]
-        deploy_dir = e.data.getVar('DEPLOY_DIR', True) + '/' + packaging
-                                           
-        for arch in package_archs.split():
-            pkgdata_dir = tmpdir + '/pkgdata/' + arch + target_vendor + '-' + target_os + '/runtime/'
-            if os.path.exists(pkgdata_dir):
-                for root, dirs, files in os.walk(pkgdata_dir):
-                    for pkgname in files:
-                        if pkgname.endswith('.packaged'):
-                            pkgname = pkgname[:-9]
-                            pkgdatafile = root + pkgname
-                            try:
-                                sdata = oe.packagedata.read_pkgdatafile(pkgdatafile)
-                                sdata['PKG'] = pkgname
-                                pkginfolist.append(sdata)
-                            except Exception as e:
-                                bb.warn("Failed to read pkgdata file %s: %s: %s" % (pkgdatafile, e.__class__, str(e)))
-        bb.event.fire(bb.event.PackageInfo(pkginfolist), e.data)
+    import oe.packagedata
+    pkginfolist = []
+    tmpdir = e.data.getVar('TMPDIR', True)
+    target_vendor = e.data.getVar('TARGET_VENDOR', True)
+    target_os = e.data.getVar('TARGET_OS', True)
+    package_archs = e.data.getVar('PACKAGE_ARCHS', True)
+    packaging = e.data.getVar('PACKAGE_CLASSES', True).split()[0].split('_')[1]
+    deploy_dir = e.data.getVar('DEPLOY_DIR', True) + '/' + packaging
+                                       
+    for arch in package_archs.split():
+        pkgdata_dir = tmpdir + '/pkgdata/' + arch + target_vendor + '-' + target_os + '/runtime/'
+        if os.path.exists(pkgdata_dir):
+            for root, dirs, files in os.walk(pkgdata_dir):
+                for pkgname in files:
+                    if pkgname.endswith('.packaged'):
+                        pkgname = pkgname[:-9]
+                        pkgdatafile = root + pkgname
+                        try:
+                            sdata = oe.packagedata.read_pkgdatafile(pkgdatafile)
+                            sdata['PKG'] = pkgname
+                            pkginfolist.append(sdata)
+                        except Exception as e:
+                            bb.warn("Failed to read pkgdata file %s: %s: %s" % (pkgdatafile, e.__class__, str(e)))
+    bb.event.fire(bb.event.PackageInfo(pkginfolist), e.data)
 }
 
 addhandler packageinfo_handler
+packageinfo_handler[eventmask] = "bb.event.RequestPackageInfo"

+ 1 - 0
meta/classes/prexport.bbclass

@@ -55,3 +55,4 @@ python prexport_handler () {
 }
 
 addhandler prexport_handler
+prexport_handler bb.event.RecipeParsed bb.event.ParseStarted bb.event.ParseCompleted"

+ 1 - 0
meta/classes/primport.bbclass

@@ -18,3 +18,4 @@ python primport_handler () {
 }
 
 addhandler primport_handler
+primport_handler[eventmask] = "bb.event.ParseCompleted bb.event.ParseStarted"

+ 1 - 3
meta/classes/recipe_sanity.bbclass

@@ -140,9 +140,6 @@ do_recipe_sanity_all () {
 addtask recipe_sanity_all after do_recipe_sanity
 
 python recipe_sanity_eh () {
-    if bb.event.getName(e) != "ConfigParsed":
-        return
-
     d = e.data
 
     cfgdata = {}
@@ -168,3 +165,4 @@ python recipe_sanity_eh () {
     DataSmart.renameVar = myrename
 }
 addhandler recipe_sanity_eh
+recipe_sanity_eh[eventmask] = "bb.event.ConfigParsed"

+ 1 - 0
meta/classes/sanity.bbclass

@@ -672,6 +672,7 @@ def copy_data(e):
     return sanity_data
 
 addhandler check_sanity_eventhandler
+check_sanity_eventhandler[eventmask] = "bb.event.ConfigParsed bb.event.SanityCheck bb.event.NetworkTest"
 python check_sanity_eventhandler() {
     if bb.event.getName(e) == "ConfigParsed" and e.data.getVar("BB_WORKERCONTEXT", True) != "1" and e.data.getVar("DISABLE_SANITY_CHECKS", True) != "1":
         sanity_data = copy_data(e)

+ 4 - 4
meta/classes/typecheck.bbclass

@@ -4,9 +4,9 @@
 
 python check_types() {
     import oe.types
-    if isinstance(e, bb.event.ConfigParsed):
-        for key in e.data.keys():
-            if e.data.getVarFlag(key, "type"):
-                oe.data.typed_value(key, e.data)
+    for key in e.data.keys():
+        if e.data.getVarFlag(key, "type"):
+            oe.data.typed_value(key, e.data)
 }
 addhandler check_types
+check_types[eventmask] = "bb.event.ConfigParsed"

+ 1 - 2
meta/conf/distro/include/csl-versions.inc

@@ -88,8 +88,6 @@ def csl_get_gdb_version(d):
 		return first_line.split()[-1]
 
 python csl_version_handler () {
-    if not isinstance(e, bb.event.ConfigParsed):
-        return
     d = e.data
     ld = d.createCopy()
     ld.finalize()
@@ -101,6 +99,7 @@ python csl_version_handler () {
     d.setVar('CSL_VER_GDB', csl_get_gdb_version(ld))
 }
 addhandler csl_version_handler
+csl_version_handler[eventmask] = "bb.event.ConfigParsed"
 
 # Ensure that any variable which includes the --sysroot (CC, CXX, etc) also
 # depends on the toolchain version

+ 2 - 6
meta/conf/distro/include/tcmode-external-sourcery.inc

@@ -79,9 +79,6 @@ EXTERNAL_TOOLCHAIN_SYSROOT_CMD += "${@csl_multilib_arg(d)}"
 # to our staging toolchain bindir.
 
 python toolchain_metadata_setup () {
-    if not isinstance(e, bb.event.ConfigParsed):
-        return
-
     d = e.data
 
     l = d.createCopy()
@@ -90,17 +87,16 @@ python toolchain_metadata_setup () {
         d.setVar('TOOLCHAIN_PATH_ADD', '')
 }
 addhandler toolchain_metadata_setup
+toolchain_metadata_setup[eventmask] = "bb.event.ConfigParsed"
 
 python toolchain_setup () {
-    if not isinstance(e, bb.event.BuildStarted):
-        return
-
     d = e.data
 
     if not d.getVar('TOOLCHAIN_PATH_ADD', True):
         populate_toolchain_links(d)
 }
 addhandler toolchain_setup
+toolchain_setup[eventmask] = "bb.event.BuildStarted"
 
 def populate_toolchain_links(d):
     import errno