diff mbox series

[1/2] meta/lib/oe: add searchfile.py

Message ID 20250520075325.64756-2-fhoerni.opensource@witekio.com
State New
Headers show
Series image_types_wic: fix dependencies on wks files | expand

Commit Message

fhoerni.opensource@witekio.com May 20, 2025, 7:53 a.m. UTC
From: Frederic Hoerni <fhoerni@witekio.com>

Signed-off-by: Frederic Hoerni <fhoerni@witekio.com>
---
 meta/lib/oe/searchfile.py | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)
 create mode 100644 meta/lib/oe/searchfile.py
diff mbox series

Patch

diff --git a/meta/lib/oe/searchfile.py b/meta/lib/oe/searchfile.py
new file mode 100644
index 0000000000..a7a222dedb
--- /dev/null
+++ b/meta/lib/oe/searchfile.py
@@ -0,0 +1,37 @@ 
+#
+# Copyright OpenEmbedded Contributors
+#
+# SPDX-License-Identifier: GPL-2.0-only
+#
+
+import bb.utils
+import os
+
+
+def search_file(path, files, d):
+    """
+    Locate one of ``files`` in the list of paths ``path``.
+
+    Arguments:
+
+    -  ``path`` : list of colon-separated paths (like ``$PATH``).
+    -  ``files``: list of file names to search (may be absolute paths).
+    - ``d``     : Bitbake's data store.
+
+    Returns the first file found, otherwise an empty string.
+
+    This function also adds dependencies of the bitbake parse cache on all
+    eligible paths so that the cache becomes invalid when one of these paths
+    gets created (ie: the user adds a new overriding file).
+    """
+    for f in files:
+        if os.path.isabs(f):
+            bb.parse.mark_dependency(d, f)
+            if os.path.exists(f):
+                return f
+        else:
+            searched, attempts = bb.utils.which(path, f, history=True)
+            for af in attempts:
+                bb.parse.mark_dependency(d, af)
+            if searched:
+                return searched