mirror of
https://git.yoctoproject.org/poky
synced 2026-02-08 18:02:12 +01:00
Inheriting image-buildinfo.bbclass primarily slowed down image building for two reasons: 1. The content of the shell command "buildinfo" gets expanded multiple times, each time again checking the state of all layers. 2. When expanded as part of the actual image creation, git is invoked under pseudo, which makes the check quite a bit slower (from a few seconds to a minute with many layers). To fix this, buildinfo now is a Python method which calls the checks only when really executed. Pseudo is told to unload itself when starting git. In addition, "git diff" is invoked with "--quiet", which avoids producing output that is just getting thrown away. As before, any kind of problem or output causes the layer to be marked as "modified". [Revision 2 of the change with some dead code removed] (From OE-Core rev: e59547e4154b772a36f4e58f1d454c0c38653c84) Signed-off-by: Patrick Ohly <patrick.ohly@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
79 lines
2.6 KiB
Plaintext
79 lines
2.6 KiB
Plaintext
#
|
|
# Writes build information to target filesystem on /etc/build
|
|
#
|
|
# Copyright (C) 2014 Intel Corporation
|
|
# Author: Alejandro Enedino Hernandez Samaniego <alejandro.hernandez@intel.com>
|
|
#
|
|
# Licensed under the MIT license, see COPYING.MIT for details
|
|
#
|
|
# Usage: add INHERIT += "image-buildinfo" to your conf file
|
|
#
|
|
|
|
# Desired variables to display
|
|
IMAGE_BUILDINFO_VARS ?= "DISTRO DISTRO_VERSION"
|
|
|
|
# From buildhistory.bbclass
|
|
def image_buildinfo_outputvars(vars, listvars, d):
|
|
vars = vars.split()
|
|
listvars = listvars.split()
|
|
ret = ""
|
|
for var in vars:
|
|
value = d.getVar(var, True) or ""
|
|
if (d.getVarFlag(var, 'type', True) == "list"):
|
|
value = oe.utils.squashspaces(value)
|
|
ret += "%s = %s\n" % (var, value)
|
|
return ret.rstrip('\n')
|
|
|
|
# Gets git branch's status (clean or dirty)
|
|
def get_layer_git_status(path):
|
|
import subprocess
|
|
try:
|
|
subprocess.check_output("cd %s; PSEUDO_UNLOAD=1 git diff --quiet --no-ext-diff" % path,
|
|
shell=True,
|
|
stderr=subprocess.STDOUT)
|
|
return ""
|
|
except subprocess.CalledProcessError, ex:
|
|
# Silently treat errors as "modified", without checking for the
|
|
# (expected) return code 1 in a modified git repo. For example, we get
|
|
# output and a 129 return code when a layer isn't a git repo at all.
|
|
return "-- modified"
|
|
|
|
# Returns layer revisions along with their respective status
|
|
def get_layer_revs(d):
|
|
layers = (d.getVar("BBLAYERS", True) or "").split()
|
|
medadata_revs = ["%-17s = %s:%s %s" % (os.path.basename(i), \
|
|
base_get_metadata_git_branch(i, None).strip(), \
|
|
base_get_metadata_git_revision(i, None), \
|
|
get_layer_git_status(i)) \
|
|
for i in layers]
|
|
return '\n'.join(medadata_revs)
|
|
|
|
def buildinfo_target(d):
|
|
# Get context
|
|
if d.getVar('BB_WORKERCONTEXT', True) != '1':
|
|
return ""
|
|
# Single and list variables to be read
|
|
vars = (d.getVar("IMAGE_BUILDINFO_VARS", True) or "")
|
|
listvars = (d.getVar("IMAGE_BUILDINFO_LVARS", True) or "")
|
|
return image_buildinfo_outputvars(vars, listvars, d)
|
|
|
|
# Write build information to target filesystem
|
|
python buildinfo () {
|
|
with open(d.expand('${IMAGE_ROOTFS}${sysconfdir}/build'), 'w') as build:
|
|
build.writelines((
|
|
'''-----------------------
|
|
Build Configuration: |
|
|
-----------------------
|
|
''',
|
|
buildinfo_target(d),
|
|
'''
|
|
-----------------------
|
|
Layer Revisions: |
|
|
-----------------------
|
|
''',
|
|
get_layer_revs(d)
|
|
))
|
|
}
|
|
|
|
IMAGE_PREPROCESS_COMMAND += "buildinfo;"
|