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.

(From OE-Core rev: bff73743280f9eafebe4591f7368ead91a4eb74d)

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Richard Purdie 2013-06-12 16:31:57 +00:00
parent 98abb113a0
commit 53841ce521
19 changed files with 102 additions and 110 deletions

View File

@ -32,12 +32,12 @@ def oe_import(d):
inject(toimport.split(".", 1)[0], imported) inject(toimport.split(".", 1)[0], imported)
python oe_import_eh () { python oe_import_eh () {
if isinstance(e, bb.event.ConfigParsed): oe_import(e.data)
oe_import(e.data) e.data.setVar("NATIVELSBSTRING", lsb_distro_identifier(e.data))
e.data.setVar("NATIVELSBSTRING", lsb_distro_identifier(e.data))
} }
addhandler oe_import_eh addhandler oe_import_eh
oe_import_eh[eventmask] = "bb.event.ConfigParsed"
def lsb_distro_identifier(d): def lsb_distro_identifier(d):
adjust = d.getVar('LSB_DISTRO_ADJUST', True) 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)) 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 addhandler base_eventhandler
base_eventhandler[eventmask] = "bb.event.ConfigParsed bb.event.BuildStarted"
python base_eventhandler() { python base_eventhandler() {
if isinstance(e, bb.event.ConfigParsed): if isinstance(e, bb.event.ConfigParsed):
e.data.setVar('BB_VERSION', bb.__version__) e.data.setVar('BB_VERSION', bb.__version__)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -672,6 +672,7 @@ def copy_data(e):
return sanity_data return sanity_data
addhandler check_sanity_eventhandler addhandler check_sanity_eventhandler
check_sanity_eventhandler[eventmask] = "bb.event.ConfigParsed bb.event.SanityCheck bb.event.NetworkTest"
python check_sanity_eventhandler() { 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": 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) sanity_data = copy_data(e)

View File

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

View File

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

View File

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