Files
meta-plcos/classes/enable-vendor-revision.bbclass

153 lines
5.1 KiB
Plaintext

#
# Copyright (C) 2024 Wind River Systems, Inc
#
# SPDX-License-Identifier: GPL-2.0
#
# To avoid confusions with PR Server
VENDOR_REVISION_PREFIX ??= ".vr"
VENDOR_REVISION_SKIP ??= ""
# Set it to "0" to enable VR for non-WRLinux provided recipes.
VENDOR_REVISION_WRLINUX_SUPPORTED_ONLY ??= "1"
def get_src_patches(d):
import oe.patch
local_patches = set()
bb.fetch.get_hashvalue(d)
for patch in oe.patch.src_patches(d):
_, _, local, _, _, parm = bb.fetch.decodeurl(patch)
local_patches.add(local)
return local_patches
def is_work_shared(d):
sharedworkdir = os.path.join(d.getVar('TMPDIR'), 'work-shared')
# Due to meta-xilinx used the xlnx-embeddedsw class to hard link
# copy the source files from work share directory to the working
# directory. Add it as corner case of work-shared recipes
if bb.data.inherits_class("xlnx-embeddedsw", d):
return True
return d.getVar('S').startswith(sharedworkdir)
def vr_need_skip(d):
# Only enable vr for supported recipes
if bb.utils.to_boolean(d.getVar('VENDOR_REVISION_WRLINUX_SUPPORTED_ONLY')):
# Check whether the recipe is from Wind River Linux layers
pf = d.getVar('PF')
layer = bb.utils.get_file_layer(d.getVar('FILE'), d)
if not layer in d.getVar('RECIPE_LIST_LAYERS_ORIG').split():
bb.debug(1, 'Skipping VR for %s since it is not from a WRLinux layer.' % d.getVar('PF'))
return True
bpn = d.getVar('BPN')
wrl_supported = d.getVar('WRLINUX_SUPPORTED_RECIPE') or d.getVar('WRLINUX_SUPPORTED_RECIPE:pn-%s' % bpn)
if (not wrl_supported) or wrl_supported.strip() != '1':
bb.debug(1, 'Skipping VR for %s since it is not a WRLinux supported recipe.' % pf)
return True
if bb.utils.to_boolean(d.getVar('VENDOR_REVISION_SKIP')):
return True
if is_work_shared(d):
return False
packages = d.getVar('PACKAGES')
if (not packages) or bb.data.inherits_class('nopackages', d) or \
bb.data.inherits_class('nativesdk', d):
return True
# Skip VR when no patches
if get_src_patches(d):
return False
else:
return True
def get_var_short(var):
return '/'.join(var.split('/')[-4:]).replace('/', '_')
def get_file_short(d):
return get_var_short(d.getVar('FILE'))
def get_current_vendor_revision(d):
year_version = d.getVar('WRLINUX_YEAR_VERSION')
if not year_version:
bb.warn('Failed to get WRLINUX_YEAR_VERSION')
year_version = '0'
update_version = d.getVar('WRLINUX_UPDATE_VERSION') or '0'
if int(update_version) <10:
# Prepend 0 when less than 10
update_version = '0%s' % update_version
vendor_revision = '%s%s' % (year_version, update_version)
vr_prefix = d.getVar('VENDOR_REVISION_PREFIX') or ''
if vr_prefix:
vendor_revision = vr_prefix + vendor_revision
vr_suffix = d.getVar('VENDOR_REVISION_SUFFIX') or ''
if vr_suffix:
vendor_revision += vr_suffix
return vendor_revision
addhandler append_vr_to_pr
append_vr_to_pr[eventmask] = "bb.event.RecipeTaskPreProcess"
python append_vr_to_pr() {
"""
Set PR:append = "VENDOR_REVISION" for the recipes
"""
pf = d.getVar('PF')
# Skip when WRLINUX_VENDOR_REVISION_FILE is NULL
if not d.getVar('WRLINUX_VENDOR_REVISION_FILE'):
bb.debug(1, 'Skipping VR for %s since WRLINUX_VENDOR_REVISION_FILE is NULL.' % pf)
return
# Skip when gen-vendor-revision is inherited
if bb.data.inherits_class('gen-vendor-revision', d):
bb.debug(1, 'Skipping VR for %s since gen-vendor-revision is inherited' % pf)
return
if vr_need_skip(d):
return
# Directly use VENDOR_REVISION if the recipe sets it.
vr = d.getVar('VENDOR_REVISION')
if not vr:
file_short = get_file_short(d)
val = d.getVarFlag('VENDOR_REVISION', file_short)
if val:
# The first item is VENDOR_REVISION
vr = val.split()[0]
# The d.getVarFlag("VENDOR_REVISION", "tmp-glibc_work-shared_qemux86-64_kernel-source")
# return None when kernel doesn't have patches, and vr_need_skip()
# can't skip work-shared recipes. The None is a string here.
if vr == 'None':
return
if not vr:
# It's a new recipe, defult to current VR
vr = get_current_vendor_revision(d)
bb.debug(1, 'Appending VENDOR_REVISION %s to PR' % vr)
d.appendVar('PR', vr)
}
GLOBAL_VENDOR_REVISION_WARN ??= '1'
addhandler warn_for_global_vr
warn_for_global_vr[eventmask] = "bb.event.ConfigParsed"
python warn_for_global_vr() {
# The VENDOR_REVISION should be set via recipe level, otherwise, there
# might be PR bombs or no effect, so warn for global VENDOR_REVISION
global_vr = d.getVar('VENDOR_REVISION')
if global_vr and bb.utils.to_boolean(d.getVar('GLOBAL_VENDOR_REVISION_WARN')):
bb.warn('The global VENDOR_REVISION (%s) may cause unneeded packages upgrading,' % global_vr)
bb.warn('or make VENDOR_REVISION invalid.')
bb.warn('The above warning can be disabled by GLOBAL_VENDOR_REVISION_WARN = "0"\n')
}