1# WARNING!
2#
3# These modifications to os-release disable the bitbake parse
4# cache (for the os-release recipe only).  Before copying
5# and pasting into another recipe ensure it is understood
6# what that means!
7
8OS_RELEASE_ROOTPATH ?= "${COREBASE}"
9
10def run_git(d, cmd):
11    try:
12        oeroot = d.getVar('OS_RELEASE_ROOTPATH', True)
13        return bb.process.run(("export PSEUDO_DISABLED=1; " +
14                               "git --work-tree %s --git-dir %s/.git %s")
15            % (oeroot, oeroot, cmd))[0].strip('\n')
16    except Exception as e:
17        bb.warn("Unexpected exception from 'git' call: %s" % e)
18        pass
19
20# DISTRO_VERSION can be overridden by a bbappend or config, so it must be a
21# weak override.  But, when a variable is weakly overridden the definition
22# and not the contents are used in the task-hash (for sstate reuse).  We need
23# a strong variable in the vardeps chain for do_compile so that we get the
24# contents of the 'git describe --dirty' call.  Create a strong/immediate
25# indirection via PHOSPHOR_OS_RELEASE_DISTRO_VERSION.
26PHOSPHOR_OS_RELEASE_DISTRO_VERSION := "${@run_git(d, 'describe --dirty')}"
27DISTRO_VERSION ??= "${PHOSPHOR_OS_RELEASE_DISTRO_VERSION}"
28
29VERSION = "${@'-'.join(d.getVar('VERSION_ID').split('-')[0:2])}"
30
31BUILD_ID := "${@run_git(d, 'describe --abbrev=0')}"
32OPENBMC_TARGET_MACHINE = "${MACHINE}"
33
34OS_RELEASE_FIELDS:append = " BUILD_ID OPENBMC_TARGET_MACHINE EXTENDED_VERSION"
35
36# Ensure the git commands run every time bitbake is invoked.
37BB_DONT_CACHE = "1"
38
39# Make os-release available to other recipes.
40SYSROOT_DIRS:append = " ${sysconfdir}"
41