blob: 1d00c110e2815a9a744eeb9eb47d12d16f47d86c [file] [log] [blame]
Patrick Williams92b42cb2022-09-03 06:53:57 -05001#
2# Copyright OpenEmbedded Contributors
3#
4# SPDX-License-Identifier: MIT
5#
6
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007PRSERV_DUMPDIR ??= "${LOG_DIR}/db"
8LOCALCOUNT_DUMPFILE ??= "${PRSERV_DUMPDIR}/prserv-localcount-exports.inc"
9
10python migrate_localcount_handler () {
11 import bb.event
12 if not e.data:
13 return
14
Brad Bishop6e60e8b2018-02-01 10:27:11 -050015 pv = e.data.getVar('PV')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050016 if not 'AUTOINC' in pv:
17 return
18
19 localcounts = bb.persist_data.persist('BB_URI_LOCALCOUNT', e.data)
Brad Bishop6e60e8b2018-02-01 10:27:11 -050020 pn = e.data.getVar('PN')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050021 revs = localcounts.get_by_pattern('%%-%s_rev' % pn)
22 counts = localcounts.get_by_pattern('%%-%s_count' % pn)
23 if not revs or not counts:
24 return
25
26 if len(revs) != len(counts):
27 bb.warn("The number of revs and localcounts don't match in %s" % pn)
28 return
29
Brad Bishop6e60e8b2018-02-01 10:27:11 -050030 version = e.data.getVar('PRAUTOINX')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050031 srcrev = bb.fetch2.get_srcrev(e.data)
32 base_ver = 'AUTOINC-%s' % version[:version.find(srcrev)]
Brad Bishop6e60e8b2018-02-01 10:27:11 -050033 pkgarch = e.data.getVar('PACKAGE_ARCH')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050034 value = max(int(count) for count in counts)
35
36 if len(revs) == 1:
37 if srcrev != ('AUTOINC+%s' % revs[0]):
38 value += 1
39 else:
40 value += 1
41
Brad Bishop6e60e8b2018-02-01 10:27:11 -050042 bb.utils.mkdirhier(e.data.getVar('PRSERV_DUMPDIR'))
43 df = e.data.getVar('LOCALCOUNT_DUMPFILE')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050044 flock = bb.utils.lockfile("%s.lock" % df)
45 with open(df, 'a') as fd:
46 fd.write('PRAUTO$%s$%s$%s = "%s"\n' %
47 (base_ver, pkgarch, srcrev, str(value)))
48 bb.utils.unlockfile(flock)
49}
50
51addhandler migrate_localcount_handler
52migrate_localcount_handler[eventmask] = "bb.event.RecipeParsed"