From patchwork Mon Nov 30 15:28:39 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Purdie X-Patchwork-Id: 106521 Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) by mx.groups.io with SMTP id smtpd.msgproc01-g2.34602.1796052541477384894 for ; Mon, 30 Nov 2026 07:29:01 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@linuxfoundation.org header.s=google header.b=Lo8R17ZK; spf=pass (domain: linuxfoundation.org, ip: 209.85.221.43, mailfrom: richard.purdie@linuxfoundation.org) Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-492f0a1b685so7677135f8f.0 for ; Mon, 30 Nov 2026 07:29:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=google; t=1796052540; x=1796657340; darn=lists.openembedded.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to:content-type; bh=JUCFxZCctXDLLqLbqxTIWnX3pI2wXRsdOr/Sk6sC0hE=; b=Lo8R17ZKcQkwzNPC6v5fbVOVToILkahl3+u5glHTQapC9/n98z82VUkWQiLumaVAZS VvdxarZZ54YI4cco+tFf+70Bm6edj1JLRQJvP3Xoyu5dGXRrJCi1QXCe8l7P3xbSRkrs ZIDzxje6efXgtC+xO30L5mptM2StPOPNLCBmw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796052540; x=1796657340; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to:content-type; bh=JUCFxZCctXDLLqLbqxTIWnX3pI2wXRsdOr/Sk6sC0hE=; b=MEwAjUHIAtKEYtqQCCmq4ggZesdgTtBi/zyz+EqsHxdwhgKZEY7hEJj9mMvvuFWOsw /kNrW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wYXZtCcfQ== X-Received: by 2002:a05:6000:40c9:b0:4aa:f8a3:3cf6 with SMTP id ffacd0b85a97d-4abb3955aa0mr68929795f8f.30.1796052539654; Mon, 30 Nov 2026 07:28:59 -0800 (PST) Return-Path: Received: from max.int.rpsys.net ([2001:8b0:aba:5f3c:2444:81bb:2aff:8d84]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4ab6baa397asm66033172f8f.48.2026.11.30.07.28.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 07:28:58 -0800 (PST) From: Richard Purdie To: bitbake-devel@lists.openembedded.org Subject: [PATCH 09/17] utils: Switch to use layerdata in get_file_layer() Date: Mon, 30 Nov 2026 15:28:39 +0000 Message-ID: <20261130152847.3472849-9-richard.purdie@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20261130152847.3472849-1-richard.purdie@linuxfoundation.org> References: <20261130152847.3472849-1-richard.purdie@linuxfoundation.org> MIME-Version: 1.0 List-Id: X-Webhook-Received: from 45-33-107-173.ip.linodeusercontent.com [45.33.107.173] by lin-tor-korg-lkml-alma10-1 with HTTPS for ; Mon, 30 Nov 2026 15:29:02 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/bitbake-devel/message/20498 After the layer changes, we should use layerdata to obtain layer information. Add an indirect function for when layerdata is already present so IPC can be avoided when using tinfoil. This is used by bblayers to avoid code duplication. The code correctly resolves symlinks to the correct layer. Signed-off-by: Richard Purdie --- lib/bb/utils.py | 79 ++++++++++++++++++++++--------------------------- 1 file changed, 35 insertions(+), 44 deletions(-) diff --git a/lib/bb/utils.py b/lib/bb/utils.py index 046bf4b8bc6..94e27dcaa52 100644 --- a/lib/bb/utils.py +++ b/lib/bb/utils.py @@ -1868,59 +1868,50 @@ def edit_bblayers_conf(bblayers_conf, add, remove, edit_cb=None): return (notadded, notremoved) -def get_collection_res(d): - collections = (d.getVar('BBFILE_COLLECTIONS') or '').split() - collection_res = {} - for collection in collections: - collection_res[collection] = d.getVar('BBFILE_PATTERN_%s' % collection) or '' - return collection_res +def get_file_layer_from_layerdata(filename, layerdata): + """Determine the layer containing the specified file from a layerdata + dictionary, as set in the ``layerdata`` variable. This is useful where + the layerdata has already been obtained, avoiding the variable lookup. + + Arguments: + + - ``filename``: the filename to look for. + - ``layerdata``: dictionary of layer names to layer information. + + Returns the name of the layer containing the file, or ``None`` if the + file isn't within any of the layers. + """ + def find(fn): + # Layers can't nest so the first match is the only match + for layername, layer in layerdata.items(): + if fn.startswith(layer.path + "/"): + return layername + return None + + # The layer paths are canonical. The filename as given usually matches + # so only resolve it if it doesn't. + layername = find(filename) + if layername is None: + realfn = os.path.realpath(filename) + if realfn != filename: + layername = find(realfn) + return layername -def get_file_layer(filename, d, collection_res={}): - """Determine the collection (or layer name, as defined by a layer's +def get_file_layer(filename, d): + """Determine the layer (as named by ``LAYERNAME`` in the layer's ``layer.conf`` file) containing the specified file. Arguments: - ``filename``: the filename to look for. - ``d``: the data store. - - ``collection_res``: dictionary with the layer names as keys and file - patterns to match as defined with the BBFILE_COLLECTIONS and - BBFILE_PATTERN variables respectively. The return value of - ``bb.utils.get_collection_res()`` is the default if this variable is - not specified. - - Returns the layer name containing the file. If multiple layers contain the - file, the last matching layer name from collection_res is returned. - """ - if not collection_res: - collection_res = get_collection_res(d) - - def path_to_layer(path): - # Use longest path so we handle nested layers - matchlen = 0 - match = None - for collection, regex in collection_res.items(): - if len(regex) > matchlen and re.match(regex, path): - matchlen = len(regex) - match = collection - return match - - result = None - bbfiles = (d.getVar('BBFILES_PRIORITIZED') or '').split() - bbfilesmatch = False - for bbfilesentry in bbfiles: - if fnmatch.fnmatchcase(filename, bbfilesentry): - bbfilesmatch = True - result = path_to_layer(bbfilesentry) - break - - if not bbfilesmatch: - # Probably a bbclass - result = path_to_layer(filename) - - return result + + Returns the name of the layer containing the file, or ``None`` if the + file isn't within any configured layer. + """ + return get_file_layer_from_layerdata(filename, d.getVar('layerdata', False) or {}) # Constant taken from http://linux.die.net/include/linux/prctl.h