Skip to contentSkip to conversation

fetch2: local files only in DL_DIR becomes fatal error

PATCH New Paulo Neves 1 participant 2 messages Jul 14, 2022

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 fetch2: local files only in DL_DIR becomes fatal error

When trying to checksum local files, if a given file is not found anywhere else than the DL_DIR then this means that the the build is inconsistent, and unreproducible.

This also means that if the DL_DIR is removed or not available the build does not know how to fetch the file and will fail. With this commit we fail earlier and consistently on this condition.

---
 lib/bb/fetch2/__init__.py | 6 +++++-
 lib/bb/tests/fetch.py     | 7 +++++++
 2 files changed, 12 insertions(+), 1 deletion(-)
lib/bb/fetch2/__init__.py +5 -1
index ac557176..ef0b18a1 100644
@@ -1233,7 +1233,11 @@ def get_checksum_file_list(d):
                 if f.startswith(dl_dir):
                     # The local fetcher's behaviour is to return a path under DL_DIR if it couldn't find the file anywhere else
                     if os.path.exists(f):
-                        bb.warn("Getting checksum for %s SRC_URI entry %s: file not found except in DL_DIR" % (d.getVar('PN'), os.path.basename(f)))
+                        bb.fatal(("Getting checksum for %s SRC_URI entry %s: file not found except in DL_DIR."
+                            " This means there is no way to get the file except for an orphaned copy"
+                            " in DL_DIR."
+                            "\nThe following paths were searched:"
+                            "\n%s") % (d.getVar('PN'), os.path.basename(f), '\n'.join(paths)))
                     else:
                         bb.warn("Unable to get checksum for %s SRC_URI entry %s: file could not be found" % (d.getVar('PN'), os.path.basename(f)))
                 filelist.append(f + ":" + str(os.path.exists(f)))
lib/bb/tests/fetch.py +7 -0
index ee41bff4..3ebd9fd7 100644
@@ -693,6 +693,13 @@ class FetcherLocalTest(FetcherTest):
         flst.sort()
         return flst
 
+    def test_local_checksum_fails_if_only_in_dldir(self):
+        with open(os.path.join(self.dldir, "on_dl_dir"), "wb"):
+            pass
+        self.d.setVar("SRC_URI", "file://on_dl_dir")
+        with self.assertRaises(bb.BBHandledException):
+            bb.fetch.get_checksum_file_list(self.d)
+
     def test_local(self):
         tree = self.fetchUnpack(['file://a', 'file://dir/c'])
         self.assertEqual(tree, ['a', 'dir/c'])
Signature · 1 line
2.25.1
#1 lore raw

PATCH v2 2/2 fetch: bb.fatal when trying to checksum non-existing files.

If the local fetcher was not able to find the file anywhere but it was included in the SRC_URI for checksumming just make it a fatal error.

---
 lib/bb/fetch2/__init__.py | 4 +++-
 lib/bb/tests/fetch.py     | 5 +++++
 2 files changed, 8 insertions(+), 1 deletion(-)
lib/bb/fetch2/__init__.py +3 -1
index ef0b18a1..05e453cb 100644
@@ -1239,7 +1239,9 @@ def get_checksum_file_list(d):
                             "\nThe following paths were searched:"
                             "\n%s") % (d.getVar('PN'), os.path.basename(f), '\n'.join(paths)))
                     else:
-                        bb.warn("Unable to get checksum for %s SRC_URI entry %s: file could not be found" % (d.getVar('PN'), os.path.basename(f)))
+                        bb.fatal(("Unable to get checksum for %s SRC_URI entry %s: file could not be found"
+                            "\nThe following paths were searched:"
+                            "\n%s") % (d.getVar('PN'), os.path.basename(f), '\n'.join(paths)))
                 filelist.append(f + ":" + str(os.path.exists(f)))
 
     return " ".join(filelist)
lib/bb/tests/fetch.py +5 -0
index 3ebd9fd7..5b577b06 100644
@@ -700,6 +700,11 @@ class FetcherLocalTest(FetcherTest):
         with self.assertRaises(bb.BBHandledException):
             bb.fetch.get_checksum_file_list(self.d)
 
+    def test_local_checksum_fails_no_file(self):
+        self.d.setVar("SRC_URI", "file://404")
+        with self.assertRaises(bb.BBHandledException):
+            bb.fetch.get_checksum_file_list(self.d)
+
     def test_local(self):
         tree = self.fetchUnpack(['file://a', 'file://dir/c'])
         self.assertEqual(tree, ['a', 'dir/c'])
Signature · 1 line
2.25.1