]> code.ossystems Code Review - openembedded-core.git/commitdiff
lib/qa.py: raise ValueError if file isn't an ELF
authorRoss Burton <ross.burton@intel.com>
Mon, 15 Feb 2016 17:48:25 +0000 (17:48 +0000)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Tue, 16 Feb 2016 11:16:49 +0000 (11:16 +0000)
Instead of raising a generic Exception that can't be handled specifically, raise
a ValueError.  Also update the callers so any unexpected exceptions are not
ignored.

Also, rename isBigEngian() to isBigEndian().

Signed-off-by: Ross Burton <ross.burton@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta/classes/insane.bbclass
meta/classes/uninative.bbclass
meta/lib/oe/qa.py

index 530e711ec4df876f63721bf6d2a3fe23e25996f4..aef08fe28eede5e0aa83138ea090cb6dc604f0b6 100644 (file)
@@ -792,7 +792,9 @@ def package_qa_walk(warnfuncs, errorfuncs, skip, package, d):
             elf = oe.qa.ELFFile(path)
             try:
                 elf.open()
-            except:
+            except (IOError, ValueError):
+                # IOError can happen if the packaging control files disappear,
+                # ValueError means the file isn't an ELF.
                 elf = None
             for func in warnfuncs:
                 func(path, package, d, elf, warnings)
index 0448cf6cdcb4c61f405d8c8ed5448acc2dca6843..b14cec065ee1e8acbe1200562ad364ecdd6b2233 100644 (file)
@@ -80,7 +80,7 @@ python uninative_changeinterp () {
             elf = oe.qa.ELFFile(f)
             try:
                 elf.open()
-            except:
+            except ValueError:
                 continue
 
             #bb.warn("patchelf-uninative --set-interpreter %s %s" % (d.getVar("UNINATIVE_LOADER", True), f))
index 21fb9977ced3ab43d9b5177753a915fd0dce76b1..2ad6c63bdc33514a678ff5c011f214ebd81ab571 100644 (file)
@@ -23,7 +23,7 @@ class ELFFile:
     def my_assert(self, expectation, result):
         if not expectation == result:
             #print "'%x','%x' %s" % (ord(expectation), ord(result), self.name)
-            raise Exception("This does not work as expected")
+            raise ValueError("%s is not an ELF" % self.name)
 
     def __init__(self, name, bits = 0):
         self.name = name
@@ -32,7 +32,7 @@ class ELFFile:
 
     def open(self):
         if not os.path.isfile(self.name):
-            raise Exception("File is not a normal file")
+            raise ValueError("%s is not a normal file" % self.name)
 
         self.file = file(self.name, "r")
         self.data = self.file.read(ELFFile.EI_NIDENT+4)
@@ -49,24 +49,24 @@ class ELFFile:
                 self.bits = 64
             else:
                 # Not 32-bit or 64.. lets assert
-                raise Exception("ELF but not 32 or 64 bit.")
+                raise ValueError("ELF but not 32 or 64 bit.")
         elif self.bits == 32:
             self.my_assert(self.data[ELFFile.EI_CLASS], chr(ELFFile.ELFCLASS32))
         elif self.bits == 64:
             self.my_assert(self.data[ELFFile.EI_CLASS], chr(ELFFile.ELFCLASS64))
         else:
-            raise Exception("Must specify unknown, 32 or 64 bit size.")
+            raise ValueError("Must specify unknown, 32 or 64 bit size.")
         self.my_assert(self.data[ELFFile.EI_VERSION], chr(ELFFile.EV_CURRENT) )
 
         self.sex = self.data[ELFFile.EI_DATA]
         if self.sex == chr(ELFFile.ELFDATANONE):
-            raise Exception("self.sex == ELFDATANONE")
+            raise ValueError("self.sex == ELFDATANONE")
         elif self.sex == chr(ELFFile.ELFDATA2LSB):
             self.sex = "<"
         elif self.sex == chr(ELFFile.ELFDATA2MSB):
             self.sex = ">"
         else:
-            raise Exception("Unknown self.sex")
+            raise ValueError("Unknown self.sex")
 
     def osAbi(self):
         return ord(self.data[ELFFile.EI_OSABI])
@@ -80,7 +80,7 @@ class ELFFile:
     def isLittleEndian(self):
         return self.sex == "<"
 
-    def isBigEngian(self):
+    def isBigEndian(self):
         return self.sex == ">"
 
     def machine(self):