metadata_scm.bbclass: Add git human readable ref function
PATCH 1/2 metadata_scm.bbclass: Add git human readable ref function
This function finds the most recent tag reachable from the current commit and computes a nice reference. In order to avoid code duplication, I generalized the branch and revision functions as well (base_get_metadata_git_branch, base_get_metadata_git_revision).
--- meta/classes/metadata_scm.bbclass | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-)
meta/classes/metadata_scm.bbclass +8 -9
@@ -23,20 +23,19 @@ def base_get_metadata_svn_revision(path, d): pass return revision -def base_get_metadata_git_branch(path, d): +def base_get_metadata_git(path, cmd, d): import bb.process - try: - rev, _ = bb.process.run('git rev-parse --abbrev-ref HEAD', cwd=path) + rev, _ = bb.process.run(cmd, cwd=path) except bb.process.ExecutionError: rev = '<unknown>' return rev.strip() +def base_get_metadata_git_branch(path, d): + return base_get_metadata_git(path, 'git rev-parse --abbrev-ref HEAD', d) + def base_get_metadata_git_revision(path, d): - import bb.process + return base_get_metadata_git(path, 'git rev-parse HEAD', d) - try: - rev, _ = bb.process.run('git rev-parse HEAD', cwd=path) - except bb.process.ExecutionError: - rev = '<unknown>' - return rev.strip() +def base_get_metadata_git_describe(path, d): + return base_get_metadata_git(path, 'git describe --tags', d)
Signature · 1 line
2.23.0
PATCH 2/2 image-buildinfo.bbclass: Introduce IMAGE_BUILDINFO_GITDESCRIBE
This knob can switch in between having full revisions and having git describe references in the build info file. By default it is set to 0 to maintain the old behaviour.
--- meta/classes/image-buildinfo.bbclass | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
meta/classes/image-buildinfo.bbclass +12 -2
@@ -15,6 +15,9 @@ IMAGE_BUILDINFO_VARS ?= "DISTRO DISTRO_VERSION" # Desired location of the output file in the image. IMAGE_BUILDINFO_FILE ??= "${sysconfdir}/build" +# By default use HEAD revision. Set this to 1 for git human readable revisions. +IMAGE_BUILDINFO_GITDESCRIBE ?= "0" + # From buildhistory.bbclass def image_buildinfo_outputvars(vars, d): vars = vars.split()
@@ -45,9 +48,16 @@ def get_layer_git_status(path): # Returns layer revisions along with their respective status def get_layer_revs(d): layers = (d.getVar("BBLAYERS") or "").split() - medadata_revs = ["%-17s = %s:%s %s" % (os.path.basename(i), \ + gitdescribe = d.getVar("IMAGE_BUILDINFO_GITDESCRIBE") or "0" + + if gitdescribe == "1": + revision_func = base_get_metadata_git_describe + else: + revision_func = base_get_metadata_git_revision + + medadata_revs = ["%-27s = %s:%s %s" % (os.path.basename(i), \ base_get_metadata_git_branch(i, None).strip(), \ - base_get_metadata_git_revision(i, None), \ + revision_func(i, None), \ get_layer_git_status(i)) \ for i in layers] return '\n'.join(medadata_revs)
Signature · 1 line
2.23.0
Re: [PATCH 2/2] image-buildinfo.bbclass: Introduce IMAGE_BUILDINFO_GITDESCRIBE
Quoted 9 lines · Andrei Gherzan
This knob can switch in between having full revisions and having git describe references in the build info file. By default it is set to 0 to
maintain the old behaviour.Signed-off-by Andrei Gherzan <[email protected]>--- meta/classes/image-buildinfo.bbclass | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
I'm not sure we want to even encourage this. We probably do want to print/store the full hashes as output from this class as they may be used by CI or in bug reports. The could be unique at the time of printing but clash later. The output is also dependent on the fetched tree.
Cheers,
Richard
Re: [PATCH 2/2] image-buildinfo.bbclass: Introduce IMAGE_BUILDINFO_GITDESCRIBE
Quoted 11 lines · Richard Purdie
Quoted 9 lines · Andrei Gherzan
This knob can switch in between having full revisions and having git describe references in the build info file. By default it is set to 0 to
maintain the old behaviour.Signed-off-by Andrei Gherzan <[email protected]>--- meta/classes/image-buildinfo.bbclass | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
Quoted 5 lines
I'm not sure we want to even encourage this. We probably do want to print/store the full hashes as output from this class as they may be used by CI or in bug reports. The could be unique at the time of printing but clash later. The output is also dependent on the fetched tree.
Wait. There is indeed an issue: it should fallback to full hashes when human readable tags are not available. I'll address. When tags are available, the describe will give you the hask as well including a delta integer. Is that what you were concerned about?
Signature · 1 line
Andrei Gherzan