bootstrap: handle python exception for missing sources files more readable

Message ID 20220420115224.27674-1-henning.schild@siemens.com
State Accepted, archived
Headers show
Series bootstrap: handle python exception for missing sources files more readable | expand

Commit Message

Henning Schild April 20, 2022, 3:52 a.m. UTC
When a file for DISTRO_APT_SOURCES can not be found in any layer, catch
the exception and turn it into a bb.fatal. Which will be much more
readable to users.

Reported-by: Florian Bezdeka <florian.bezdeka@siemens.com>
Signed-off-by: Henning Schild <henning.schild@siemens.com>
---
 .../recipes-core/isar-bootstrap/isar-bootstrap.inc | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

Comments

Anton Mikanovich May 5, 2022, 2:17 a.m. UTC | #1
20.04.2022 14:52, Henning Schild wrote:
> When a file for DISTRO_APT_SOURCES can not be found in any layer, catch
> the exception and turn it into a bb.fatal. Which will be much more
> readable to users.
>
> Reported-by: Florian Bezdeka <florian.bezdeka@siemens.com>
> Signed-off-by: Henning Schild <henning.schild@siemens.com>

Applied to next, thanks.

Patch

diff --git a/meta/recipes-core/isar-bootstrap/isar-bootstrap.inc b/meta/recipes-core/isar-bootstrap/isar-bootstrap.inc
index a6e370e3b7db..b4bd2dad87f7 100644
--- a/meta/recipes-core/isar-bootstrap/isar-bootstrap.inc
+++ b/meta/recipes-core/isar-bootstrap/isar-bootstrap.inc
@@ -147,14 +147,22 @@  def aggregate_aptsources_list(d, file_list, file_out):
             out_fd.write("\n".encode())
 
 def get_aptsources_list(d):
+    import errno
     apt_sources_var = d.getVar("DISTRO_VARS_PREFIX") + "DISTRO_APT_SOURCES"
-    return (d.getVar(apt_sources_var, True) or "").split()
+    list = (d.getVar(apt_sources_var, True) or "").split()
+    ret = []
+    for p in list:
+        try:
+            f = bb.parse.resolve_file(p, d)
+            ret.append(f)
+        except FileNotFoundError as e:
+            bb.fatal(os.strerror(errno.ENOENT) + ' "' + p + '"')
+    return ret
 
 def generate_distro_sources(d):
     apt_sources_list = get_aptsources_list(d)
     for entry in apt_sources_list:
-        entry_real = bb.parse.resolve_file(entry, d)
-        with open(entry_real, "r") as in_fd:
+        with open(entry, "r") as in_fd:
             for line in in_fd:
                 parsed = parse_aptsources_list_line(line)
                 if parsed: