summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Hatle <mark.hatle@kernel.crashing.org>2020-09-02 10:33:22 -0500
committerRichard Purdie <richard.purdie@linuxfoundation.org>2021-02-10 23:55:53 +0000
commita90e96977e60c2e04a05eada239b6f34c5403b58 (patch)
tree861b23db0d554c2ad6a5b9989823230ef97fb3e9
parent73b818a8ca4ac7e41717d3470faca9d8d0e25bd2 (diff)
downloadpoky-a90e96977e60c2e04a05eada239b6f34c5403b58.tar.gz
package.bbclass: hash equivalency and pr service
When the PR service is enabled a number of small changes may happen to variables. In the do_package step a call to package_get_auto_pr will end up setting PRAUTO and modifying PKGV (if AUTOINC is there). PRAUTO is then used by EXTENDPRAUTO, which is then used to generate PKGR. Since this behavior typically happens BEFORE the BB_UNIHASH is calculated for do_package, we need a way to defer the expansion until after we have the unihash value. Writing out the pkgdata files w/o AUTOPR and PKGV (AUTOINC) expanded to placeholder values is the easiest way to deal with this. All other variables are expanded as expected. In the next task, typically do_packagedata, we will then use the UNIHASH from the do_package to get the PR (AUTOPR) as well as generate the AUTOINC replacement value (now PRSERV_PV_AUTOINC). The do_packagedata then translates the placeholders to the final values when copying the data from pkgdata to pkgdata-pdata-input. Also update the prservice test case. With unihash, just changing the do_package (via a _append) will not change the PR. So write the date to a specific file that is incorporated into the unihash to ensure it is always different for the test. Various assert messages were also updated to make it easier to figure out where/why a problem occured. (From OE-Core rev: 0c28edf4bf0d2f92bf3a47406041c63acd90bacf) Signed-off-by: Mark Hatle <mark.hatle@kernel.crashing.org> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org> (cherry picked from commit 2e32f37b0e4abc438c8f60e673cd18a5cc110768) Signed-off-by: Steve Sakoman <steve@sakoman.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/classes/package.bbclass58
-rw-r--r--meta/conf/bitbake.conf1
-rw-r--r--meta/lib/oeqa/selftest/cases/prservice.py8
3 files changed, 55 insertions, 12 deletions
diff --git a/meta/classes/package.bbclass b/meta/classes/package.bbclass
index 7c252dd46b..f8074d866c 100644
--- a/meta/classes/package.bbclass
+++ b/meta/classes/package.bbclass
@@ -7,7 +7,7 @@
7# 7#
8# There are the following default steps but PACKAGEFUNCS can be extended: 8# There are the following default steps but PACKAGEFUNCS can be extended:
9# 9#
10# a) package_get_auto_pr - get PRAUTO from remote PR service 10# a) package_convert_pr_autoinc - convert AUTOINC in PKGV to ${PRSERV_PV_AUTOINC}
11# 11#
12# b) perform_packagecopy - Copy D into PKGD 12# b) perform_packagecopy - Copy D into PKGD
13# 13#
@@ -585,12 +585,20 @@ def runtime_mapping_rename (varname, pkg, d):
585 #bb.note("%s after: %s" % (varname, d.getVar(varname))) 585 #bb.note("%s after: %s" % (varname, d.getVar(varname)))
586 586
587# 587#
588# Package functions suitable for inclusion in PACKAGEFUNCS 588# Used by do_packagedata (and possibly other routines post do_package)
589# 589#
590 590
591package_get_auto_pr[vardepsexclude] = "BB_TASKDEPDATA"
591python package_get_auto_pr() { 592python package_get_auto_pr() {
592 import oe.prservice 593 import oe.prservice
593 import re 594
595 def get_do_package_hash(pn):
596 if d.getVar("BB_RUNTASK") != "do_package":
597 taskdepdata = d.getVar("BB_TASKDEPDATA", False)
598 for dep in taskdepdata:
599 if taskdepdata[dep][1] == "do_package" and taskdepdata[dep][0] == pn:
600 return taskdepdata[dep][6]
601 return None
594 602
595 # Support per recipe PRSERV_HOST 603 # Support per recipe PRSERV_HOST
596 pn = d.getVar('PN') 604 pn = d.getVar('PN')
@@ -602,15 +610,22 @@ python package_get_auto_pr() {
602 610
603 # PR Server not active, handle AUTOINC 611 # PR Server not active, handle AUTOINC
604 if not d.getVar('PRSERV_HOST'): 612 if not d.getVar('PRSERV_HOST'):
605 if 'AUTOINC' in pkgv: 613 d.setVar("PRSERV_PV_AUTOINC", "0")
606 d.setVar("PKGV", pkgv.replace("AUTOINC", "0"))
607 return 614 return
608 615
609 auto_pr = None 616 auto_pr = None
610 pv = d.getVar("PV") 617 pv = d.getVar("PV")
611 version = d.getVar("PRAUTOINX") 618 version = d.getVar("PRAUTOINX")
612 pkgarch = d.getVar("PACKAGE_ARCH") 619 pkgarch = d.getVar("PACKAGE_ARCH")
613 checksum = d.getVar("BB_TASKHASH") 620 checksum = get_do_package_hash(pn)
621
622 # If do_package isn't in the dependencies, we can't get the checksum...
623 if not checksum:
624 bb.warn('Task %s requested do_package unihash, but it was not available.' % d.getVar('BB_RUNTASK'))
625 #taskdepdata = d.getVar("BB_TASKDEPDATA", False)
626 #for dep in taskdepdata:
627 # bb.warn('%s:%s = %s' % (taskdepdata[dep][0], taskdepdata[dep][1], taskdepdata[dep][6]))
628 return
614 629
615 if d.getVar('PRSERV_LOCKDOWN'): 630 if d.getVar('PRSERV_LOCKDOWN'):
616 auto_pr = d.getVar('PRAUTO_' + version + '_' + pkgarch) or d.getVar('PRAUTO_' + version) or None 631 auto_pr = d.getVar('PRAUTO_' + version + '_' + pkgarch) or d.getVar('PRAUTO_' + version) or None
@@ -628,7 +643,7 @@ python package_get_auto_pr() {
628 srcpv = bb.fetch2.get_srcrev(d) 643 srcpv = bb.fetch2.get_srcrev(d)
629 base_ver = "AUTOINC-%s" % version[:version.find(srcpv)] 644 base_ver = "AUTOINC-%s" % version[:version.find(srcpv)]
630 value = conn.getPR(base_ver, pkgarch, srcpv) 645 value = conn.getPR(base_ver, pkgarch, srcpv)
631 d.setVar("PKGV", pkgv.replace("AUTOINC", str(value))) 646 d.setVar("PRSERV_PV_AUTOINC", str(value))
632 647
633 auto_pr = conn.getPR(version, pkgarch, checksum) 648 auto_pr = conn.getPR(version, pkgarch, checksum)
634 except Exception as e: 649 except Exception as e:
@@ -638,6 +653,22 @@ python package_get_auto_pr() {
638 d.setVar('PRAUTO',str(auto_pr)) 653 d.setVar('PRAUTO',str(auto_pr))
639} 654}
640 655
656#
657# Package functions suitable for inclusion in PACKAGEFUNCS
658#
659
660python package_convert_pr_autoinc() {
661 pkgv = d.getVar("PKGV")
662
663 # Adjust pkgv as necessary...
664 if 'AUTOINC' in pkgv:
665 d.setVar("PKGV", pkgv.replace("AUTOINC", "${PRSERV_PV_AUTOINC}"))
666
667 # Change PRSERV_PV_AUTOINC and EXTENDPRAUTO usage to special values
668 d.setVar('PRSERV_PV_AUTOINC', '@PRSERV_PV_AUTOINC@')
669 d.setVar('EXTENDPRAUTO', '@EXTENDPRAUTO@')
670}
671
641LOCALEBASEPN ??= "${PN}" 672LOCALEBASEPN ??= "${PN}"
642 673
643python package_do_split_locales() { 674python package_do_split_locales() {
@@ -2251,7 +2282,7 @@ python do_package () {
2251 package_qa_handle_error("var-undefined", msg, d) 2282 package_qa_handle_error("var-undefined", msg, d)
2252 return 2283 return
2253 2284
2254 bb.build.exec_func("package_get_auto_pr", d) 2285 bb.build.exec_func("package_convert_pr_autoinc", d)
2255 2286
2256 ########################################################################### 2287 ###########################################################################
2257 # Optimisations 2288 # Optimisations
@@ -2323,9 +2354,20 @@ addtask do_package_setscene
2323# Copy from PKGDESTWORK to tempdirectory as tempdirectory can be cleaned at both 2354# Copy from PKGDESTWORK to tempdirectory as tempdirectory can be cleaned at both
2324# do_package_setscene and do_packagedata_setscene leading to races 2355# do_package_setscene and do_packagedata_setscene leading to races
2325python do_packagedata () { 2356python do_packagedata () {
2357 bb.build.exec_func("package_get_auto_pr", d)
2358
2326 src = d.expand("${PKGDESTWORK}") 2359 src = d.expand("${PKGDESTWORK}")
2327 dest = d.expand("${WORKDIR}/pkgdata-pdata-input") 2360 dest = d.expand("${WORKDIR}/pkgdata-pdata-input")
2328 oe.path.copyhardlinktree(src, dest) 2361 oe.path.copyhardlinktree(src, dest)
2362
2363 bb.build.exec_func("packagedata_translate_pr_autoinc", d)
2364}
2365
2366# Translate the EXTENDPRAUTO and AUTOINC to the final values
2367packagedata_translate_pr_autoinc() {
2368 find ${WORKDIR}/pkgdata-pdata-input -type f | xargs --no-run-if-empty \
2369 sed -e 's,@PRSERV_PV_AUTOINC@,${PRSERV_PV_AUTOINC},g' \
2370 -e 's,@EXTENDPRAUTO@,${EXTENDPRAUTO},g' -i
2329} 2371}
2330 2372
2331addtask packagedata before do_build after do_package 2373addtask packagedata before do_build after do_package
diff --git a/meta/conf/bitbake.conf b/meta/conf/bitbake.conf
index 01020c9823..6ada0099eb 100644
--- a/meta/conf/bitbake.conf
+++ b/meta/conf/bitbake.conf
@@ -208,6 +208,7 @@ PF = "${PN}-${EXTENDPE}${PV}-${PR}"
208EXTENDPE = "${@['','${PE}_'][int(d.getVar('PE') or 0) > 0]}" 208EXTENDPE = "${@['','${PE}_'][int(d.getVar('PE') or 0) > 0]}"
209P = "${PN}-${PV}" 209P = "${PN}-${PV}"
210 210
211PRSERV_PV_AUTOINC = "AUTOINC"
211PRAUTO = "" 212PRAUTO = ""
212EXTENDPRAUTO = "${@['.${PRAUTO}', ''][not d.getVar('PRAUTO')]}" 213EXTENDPRAUTO = "${@['.${PRAUTO}', ''][not d.getVar('PRAUTO')]}"
213PRAUTOINX = "${PF}" 214PRAUTOINX = "${PF}"
diff --git a/meta/lib/oeqa/selftest/cases/prservice.py b/meta/lib/oeqa/selftest/cases/prservice.py
index 85b534963d..578b2b4dd9 100644
--- a/meta/lib/oeqa/selftest/cases/prservice.py
+++ b/meta/lib/oeqa/selftest/cases/prservice.py
@@ -23,7 +23,7 @@ class BitbakePrTests(OESelftestTestCase):
23 package_data_file = os.path.join(self.pkgdata_dir, 'runtime', package_name) 23 package_data_file = os.path.join(self.pkgdata_dir, 'runtime', package_name)
24 package_data = ftools.read_file(package_data_file) 24 package_data = ftools.read_file(package_data_file)
25 find_pr = re.search(r"PKGR: r[0-9]+\.([0-9]+)", package_data) 25 find_pr = re.search(r"PKGR: r[0-9]+\.([0-9]+)", package_data)
26 self.assertTrue(find_pr, "No PKG revision found in %s" % package_data_file) 26 self.assertTrue(find_pr, "No PKG revision found via regex 'PKGR: r[0-9]+\.([0-9]+)' in %s" % package_data_file)
27 return int(find_pr.group(1)) 27 return int(find_pr.group(1))
28 28
29 def get_task_stamp(self, package_name, recipe_task): 29 def get_task_stamp(self, package_name, recipe_task):
@@ -40,7 +40,7 @@ class BitbakePrTests(OESelftestTestCase):
40 return str(stamps[0]) 40 return str(stamps[0])
41 41
42 def increment_package_pr(self, package_name): 42 def increment_package_pr(self, package_name):
43 inc_data = "do_package_append() {\n bb.build.exec_func('do_test_prserv', d)\n}\ndo_test_prserv() {\necho \"The current date is: %s\"\n}" % datetime.datetime.now() 43 inc_data = "do_package_append() {\n bb.build.exec_func('do_test_prserv', d)\n}\ndo_test_prserv() {\necho \"The current date is: %s\" > ${PKGDESTWORK}/${PN}.datestamp\n}" % datetime.datetime.now()
44 self.write_recipeinc(package_name, inc_data) 44 self.write_recipeinc(package_name, inc_data)
45 res = bitbake(package_name, ignore_status=True) 45 res = bitbake(package_name, ignore_status=True)
46 self.delete_recipeinc(package_name) 46 self.delete_recipeinc(package_name)
@@ -63,7 +63,7 @@ class BitbakePrTests(OESelftestTestCase):
63 pr_2 = self.get_pr_version(package_name) 63 pr_2 = self.get_pr_version(package_name)
64 stamp_2 = self.get_task_stamp(package_name, track_task) 64 stamp_2 = self.get_task_stamp(package_name, track_task)
65 65
66 self.assertTrue(pr_2 - pr_1 == 1, "Step between pkg revisions is not 1 (was %s - %s)" % (pr_2, pr_1)) 66 self.assertTrue(pr_2 - pr_1 == 1, "New PR %s did not increment as expected (from %s), difference should be 1" % (pr_2, pr_1))
67 self.assertTrue(stamp_1 != stamp_2, "Different pkg rev. but same stamp: %s" % stamp_1) 67 self.assertTrue(stamp_1 != stamp_2, "Different pkg rev. but same stamp: %s" % stamp_1)
68 68
69 def run_test_pr_export_import(self, package_name, replace_current_db=True): 69 def run_test_pr_export_import(self, package_name, replace_current_db=True):
@@ -89,7 +89,7 @@ class BitbakePrTests(OESelftestTestCase):
89 self.increment_package_pr(package_name) 89 self.increment_package_pr(package_name)
90 pr_2 = self.get_pr_version(package_name) 90 pr_2 = self.get_pr_version(package_name)
91 91
92 self.assertTrue(pr_2 - pr_1 == 1, "Step between pkg revisions is not 1 (was %s - %s)" % (pr_2, pr_1)) 92 self.assertTrue(pr_2 - pr_1 == 1, "New PR %s did not increment as expected (from %s), difference should be 1" % (pr_2, pr_1))
93 93
94 def test_import_export_replace_db(self): 94 def test_import_export_replace_db(self):
95 self.run_test_pr_export_import('m4') 95 self.run_test_pr_export_import('m4')