meta-phosphor: os-release: fix task caching with DISTRO_VERSION
It was reported that the following sequence would not cause
`os-release` to rebuild:
```
bitbake os-release
git commit --amend
bitbake os-release
```
This is due to how bitbake task hashing is implemented with respect
to weak variables. In 439c59b, DISTRO_VERSION was changed to a
weak variable, but it is included in the 'vardeps' chain for
'do_compile'. When bitbake computes the hash for a task, typically
the contents of the variables are used for the hashing, but for weak
variables only the definition is used. (Confirmed by adding bb.note
debugs to `poky/bitbake/lib/bb/data.py`)
The new, weak DISTRO_VERSION is intended to be populated with contents
from a `git describe` operation. Those contents must be used in the
hashing of the 'do_compile' task and not the definition. This can be
accomplished by creating an indirection using a strong variable.
The dependency chain and hash evaluation will be as follows:
```
do_compile -> DISTRO_VERSION -> PHOSPHOR_OS_RELEASE_DISTRO_VERSION
hash(do_compile) = ... +
DISTRO_VERSION:${PHOSPHOR_OS_RELEASE_DISTRO_VERSION} +
PHOSPHOR_...DISTRO_VERSION=2.11.0-dev-...
```
Prior to this fix the hash evaluation was:
```
hash(do_compile) = ... +
DISTRO_VERSION:${@run_git...}
```
Fixes 439c59b425cf403355571875b3fa714782dcf15b.
Tested: Ensure the above reported sequence causes a rebuild of
os-release with expected data.
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: I0bd93d3d88bf62dfe03549419fe98ab85f10a68c
diff --git a/meta-phosphor/recipes-core/os-release/os-release.bbappend b/meta-phosphor/recipes-core/os-release/os-release.bbappend
index f42235e..1a3b228 100644
--- a/meta-phosphor/recipes-core/os-release/os-release.bbappend
+++ b/meta-phosphor/recipes-core/os-release/os-release.bbappend
@@ -15,7 +15,15 @@
bb.warn("Unexpected exception from 'git' call: %s" % e)
pass
-DISTRO_VERSION ??= "${@run_git(d, 'describe --dirty')}"
+# DISTRO_VERSION can be overridden by a bbappend or config, so it must be a
+# weak override. But, when a variable is weakly overridden the definition
+# and not the contents are used in the task-hash (for sstate reuse). We need
+# a strong variable in the vardeps chain for do_compile so that we get the
+# contents of the 'git describe --dirty' call. Create a strong/immediate
+# indirection via PHOSPHOR_OS_RELEASE_DISTRO_VERSION.
+PHOSPHOR_OS_RELEASE_DISTRO_VERSION := "${@run_git(d, 'describe --dirty')}"
+DISTRO_VERSION ??= "${PHOSPHOR_OS_RELEASE_DISTRO_VERSION}"
+
VERSION = "${@'-'.join(d.getVar('VERSION_ID').split('-')[0:2])}"
BUILD_ID := "${@run_git(d, 'describe --abbrev=0')}"