Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame^] | 1 | # |
| 2 | # Copyright OpenEmbedded Contributors |
| 3 | # |
| 4 | # SPDX-License-Identifier: MIT |
| 5 | # |
| 6 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7 | PRSERV_DUMPDIR ??= "${LOG_DIR}/db" |
| 8 | LOCALCOUNT_DUMPFILE ??= "${PRSERV_DUMPDIR}/prserv-localcount-exports.inc" |
| 9 | |
| 10 | python migrate_localcount_handler () { |
| 11 | import bb.event |
| 12 | if not e.data: |
| 13 | return |
| 14 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 15 | pv = e.data.getVar('PV') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 16 | if not 'AUTOINC' in pv: |
| 17 | return |
| 18 | |
| 19 | localcounts = bb.persist_data.persist('BB_URI_LOCALCOUNT', e.data) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 20 | pn = e.data.getVar('PN') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 21 | 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 Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 30 | version = e.data.getVar('PRAUTOINX') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 31 | srcrev = bb.fetch2.get_srcrev(e.data) |
| 32 | base_ver = 'AUTOINC-%s' % version[:version.find(srcrev)] |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 33 | pkgarch = e.data.getVar('PACKAGE_ARCH') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 34 | 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 Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 42 | bb.utils.mkdirhier(e.data.getVar('PRSERV_DUMPDIR')) |
| 43 | df = e.data.getVar('LOCALCOUNT_DUMPFILE') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 44 | 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 | |
| 51 | addhandler migrate_localcount_handler |
| 52 | migrate_localcount_handler[eventmask] = "bb.event.RecipeParsed" |