summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2025-01-15 15:31:49 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2025-06-24 13:53:23 +0100
commitea4b963d9a59210bb9eeaee55dcb6378ef65baba (patch)
tree6997fbe04e03788128f2ec1e7e198874ade561d4
parent838d7a5013136a4e056330b4a9f74c130340d084 (diff)
downloadpoky-ea4b963d9a59210bb9eeaee55dcb6378ef65baba.tar.gz
buildhistory: Drop BUILDHISTORY_RESET due to reliability issues
The implementation of BUILDHISTORY_RESET is problematic, particlarly given that people are trying to create an API with it alongside BUILDHISTORY_PRESERVE which simply doesn't exist and can't work reliably. Worse, the code paths with this bolted on implementation are convoluted and near impossible to follow. BUILDHISTORY_PRESERVE is effectively internal API, used to stop buildhistory removing some files which are needed for data, or are created at different parts of the build. Add a comment to explain what it is doing and why these files are listed. Commit 9f68a45aa238ae5fcdfaca71ba0e7015e9cb720e tried to "fix" preserve support with the reset functionality but it didn't fully work and has just exposed futher issues. There is a further fix however I can brely follow the code and in reviewing it, I've concluded we shouldn't be doing this at all. Due to the way BUILDHISTORY_RESET was implemented, horrible races were introduced making it unclear what happens to the data if builds fail for example, or how sstate interacts with the build since things get reset but stamps do not and tasks may not rerun. It also interacts badly with any additions to the preserve list, due to misunderstandings on what that variable does. Having stared long and hard at the code, and really struggled to understand it, I', of the view that "reset" for CI purposes should be done by the CI itself. The CI can choose to remove some files or all files and decide how to handle failures. It has to handle the buildhistory directory anyway. Therefore drop BUILDHISTORY_RESET support, allowing the "old" codepaths to be dropped. BUILDHISTORY_PRESERVE is better documented to hint that it is internal API and to show what it is really for. If we really do want some functionality list this, it needs to be implemented in a way you can follow the code, and have tests. (From OE-Core rev: 15c5258fd0063ace425b7e904521f1695ffb2a85) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/classes/buildhistory.bbclass74
1 files changed, 6 insertions, 68 deletions
diff --git a/meta/classes/buildhistory.bbclass b/meta/classes/buildhistory.bbclass
index e970182620..4a380c10c6 100644
--- a/meta/classes/buildhistory.bbclass
+++ b/meta/classes/buildhistory.bbclass
@@ -16,28 +16,6 @@ BUILDHISTORY_DIR ?= "${TOPDIR}/buildhistory"
16BUILDHISTORY_DIR_IMAGE = "${BUILDHISTORY_DIR}/images/${MACHINE_ARCH}/${TCLIBC}/${IMAGE_BASENAME}" 16BUILDHISTORY_DIR_IMAGE = "${BUILDHISTORY_DIR}/images/${MACHINE_ARCH}/${TCLIBC}/${IMAGE_BASENAME}"
17BUILDHISTORY_DIR_PACKAGE = "${BUILDHISTORY_DIR}/packages/${MULTIMACH_TARGET_SYS}/${PN}" 17BUILDHISTORY_DIR_PACKAGE = "${BUILDHISTORY_DIR}/packages/${MULTIMACH_TARGET_SYS}/${PN}"
18 18
19# Setting this to non-empty will remove the old content of the buildhistory as part of
20# the current bitbake invocation and replace it with information about what was built
21# during the build.
22#
23# This is meant to be used in continuous integration (CI) systems when invoking bitbake
24# for full world builds. The effect in that case is that information about packages
25# that no longer get build also gets removed from the buildhistory, which is not
26# the case otherwise.
27#
28# The advantage over manually cleaning the buildhistory outside of bitbake is that
29# the "version-going-backwards" check still works. When relying on that, be careful
30# about failed world builds: they will lead to incomplete information in the
31# buildhistory because information about packages that could not be built will
32# also get removed. A CI system should handle that by discarding the buildhistory
33# of failed builds.
34#
35# The expected usage is via auto.conf, but passing via the command line also works
36# with: BB_ENV_PASSTHROUGH_ADDITIONS=BUILDHISTORY_RESET BUILDHISTORY_RESET=1
37BUILDHISTORY_RESET ?= ""
38
39BUILDHISTORY_OLD_DIR = "${BUILDHISTORY_DIR}/${@ "old" if "${BUILDHISTORY_RESET}" else ""}"
40BUILDHISTORY_OLD_DIR_PACKAGE = "${BUILDHISTORY_OLD_DIR}/packages/${MULTIMACH_TARGET_SYS}/${PN}"
41BUILDHISTORY_DIR_SDK = "${BUILDHISTORY_DIR}/sdk/${SDK_NAME}${SDK_EXT}/${IMAGE_BASENAME}" 19BUILDHISTORY_DIR_SDK = "${BUILDHISTORY_DIR}/sdk/${SDK_NAME}${SDK_EXT}/${IMAGE_BASENAME}"
42BUILDHISTORY_IMAGE_FILES ?= "/etc/passwd /etc/group" 20BUILDHISTORY_IMAGE_FILES ?= "/etc/passwd /etc/group"
43BUILDHISTORY_SDK_FILES ?= "conf/local.conf conf/bblayers.conf conf/auto.conf conf/locked-sigs.inc conf/devtool.conf" 21BUILDHISTORY_SDK_FILES ?= "conf/local.conf conf/bblayers.conf conf/auto.conf conf/locked-sigs.inc conf/devtool.conf"
@@ -70,9 +48,10 @@ SSTATEPOSTUNPACKFUNCS[vardepvalueexclude] .= "| buildhistory_emit_outputsigs"
70# necessary because some of these items (package directories, files that 48# necessary because some of these items (package directories, files that
71# we no longer emit) might be obsolete. 49# we no longer emit) might be obsolete.
72# 50#
73# When extending build history, derive your class from buildhistory.bbclass 51# The files listed here are either written by tasks that aren't do_package (e.g.
74# and extend this list here with the additional files created by the derived 52# latest_srcrev from do_fetch) so do_package must not remove them, or, they're
75# class. 53# used to read values in do_package before always being overwritten, e.g. latest,
54# for version backwards checks.
76BUILDHISTORY_PRESERVE = "latest latest_srcrev sysroot" 55BUILDHISTORY_PRESERVE = "latest latest_srcrev sysroot"
77 56
78PATCH_GIT_USER_EMAIL ?= "buildhistory@oe" 57PATCH_GIT_USER_EMAIL ?= "buildhistory@oe"
@@ -108,7 +87,6 @@ python buildhistory_emit_pkghistory() {
108 return 0 87 return 0
109 88
110 pkghistdir = d.getVar('BUILDHISTORY_DIR_PACKAGE') 89 pkghistdir = d.getVar('BUILDHISTORY_DIR_PACKAGE')
111 oldpkghistdir = d.getVar('BUILDHISTORY_OLD_DIR_PACKAGE')
112 90
113 class RecipeInfo: 91 class RecipeInfo:
114 def __init__(self, name): 92 def __init__(self, name):
@@ -203,7 +181,7 @@ python buildhistory_emit_pkghistory() {
203 181
204 def getlastpkgversion(pkg): 182 def getlastpkgversion(pkg):
205 try: 183 try:
206 histfile = os.path.join(oldpkghistdir, pkg, "latest") 184 histfile = os.path.join(pkghistdir, pkg, "latest")
207 return readPackageInfo(pkg, histfile) 185 return readPackageInfo(pkg, histfile)
208 except EnvironmentError: 186 except EnvironmentError:
209 return None 187 return None
@@ -219,20 +197,6 @@ python buildhistory_emit_pkghistory() {
219 items.sort() 197 items.sort()
220 return ' '.join(items) 198 return ' '.join(items)
221 199
222 def preservebuildhistoryfiles(pkg, preserve):
223 if os.path.exists(os.path.join(oldpkghistdir, pkg)):
224 listofobjs = os.listdir(os.path.join(oldpkghistdir, pkg))
225 for obj in listofobjs:
226 if obj not in preserve:
227 continue
228 try:
229 bb.utils.mkdirhier(os.path.join(pkghistdir, pkg))
230 shutil.copyfile(os.path.join(oldpkghistdir, pkg, obj), os.path.join(pkghistdir, pkg, obj))
231 except IOError as e:
232 bb.note("Unable to copy file. %s" % e)
233 except EnvironmentError as e:
234 bb.note("Unable to copy file. %s" % e)
235
236 pn = d.getVar('PN') 200 pn = d.getVar('PN')
237 pe = d.getVar('PE') or "0" 201 pe = d.getVar('PE') or "0"
238 pv = d.getVar('PV') 202 pv = d.getVar('PV')
@@ -260,14 +224,6 @@ python buildhistory_emit_pkghistory() {
260 if not os.path.exists(pkghistdir): 224 if not os.path.exists(pkghistdir):
261 bb.utils.mkdirhier(pkghistdir) 225 bb.utils.mkdirhier(pkghistdir)
262 else: 226 else:
263 # We need to make sure that all files kept in
264 # buildhistory/old are restored successfully
265 # otherwise next block of code wont have files to
266 # check and purge
267 if d.getVar("BUILDHISTORY_RESET"):
268 for pkg in packagelist:
269 preservebuildhistoryfiles(pkg, preserve)
270
271 # Remove files for packages that no longer exist 227 # Remove files for packages that no longer exist
272 for item in os.listdir(pkghistdir): 228 for item in os.listdir(pkghistdir):
273 if item not in preserve: 229 if item not in preserve:
@@ -887,25 +843,7 @@ END
887 843
888python buildhistory_eventhandler() { 844python buildhistory_eventhandler() {
889 if (e.data.getVar('BUILDHISTORY_FEATURES') or "").strip(): 845 if (e.data.getVar('BUILDHISTORY_FEATURES') or "").strip():
890 reset = e.data.getVar("BUILDHISTORY_RESET") 846 if isinstance(e, bb.event.BuildCompleted):
891 olddir = e.data.getVar("BUILDHISTORY_OLD_DIR")
892 if isinstance(e, bb.event.BuildStarted):
893 if reset:
894 import shutil
895 # Clean up after potentially interrupted build.
896 if os.path.isdir(olddir):
897 shutil.rmtree(olddir)
898 rootdir = e.data.getVar("BUILDHISTORY_DIR")
899 bb.utils.mkdirhier(rootdir)
900 entries = [ x for x in os.listdir(rootdir) if not x.startswith('.') ]
901 bb.utils.mkdirhier(olddir)
902 for entry in entries:
903 bb.utils.rename(os.path.join(rootdir, entry),
904 os.path.join(olddir, entry))
905 elif isinstance(e, bb.event.BuildCompleted):
906 if reset:
907 import shutil
908 shutil.rmtree(olddir)
909 if e.data.getVar("BUILDHISTORY_COMMIT") == "1": 847 if e.data.getVar("BUILDHISTORY_COMMIT") == "1":
910 bb.note("Writing buildhistory") 848 bb.note("Writing buildhistory")
911 bb.build.exec_func("buildhistory_write_sigs", d) 849 bb.build.exec_func("buildhistory_write_sigs", d)