Browse Source

meta/lib/oe: add searchfile.py

(From OE-Core rev: e424c0ef22de030cb5ce7244bc398a750f54952a)

Signed-off-by: Frederic Hoerni <fhoerni@witekio.com>
Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Frederic Hoerni 1 tuần trước cách đây
mục cha
commit
f42f724f52
1 tập tin đã thay đổi với 37 bổ sung0 xóa
  1. 37 0
      meta/lib/oe/searchfile.py

+ 37 - 0
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