binman: drop "faked" return value from check_fake_fname
check_fake_fname sets the faked member of the entry. Use that member to get the faked status instead of a returned value indicating the same. Add type annotations to the modified functions while at it. Signed-off-by: Yannic Moog <y.moog@phytec.de> Reviewed-by: Simon Glass <sjg@chromium.org> Reviewed-by: Bryan Brattlof <bb@ti.com>
This commit is contained in:
@@ -88,6 +88,7 @@ class Entry(object):
|
||||
updated with a hash of the entry contents
|
||||
comp_bintool: Bintools used for compress and decompress data
|
||||
fake_fname: Fake filename, if one was created, else None
|
||||
faked (bool): True if the entry is absent and faked
|
||||
required_props (dict of str): Properties which must be present. This can
|
||||
be added to by subclasses
|
||||
elf_fname (str): Filename of the ELF file, if this entry holds an ELF
|
||||
@@ -1120,7 +1121,7 @@ features to produce new behaviours.
|
||||
if self.missing and not self.optional:
|
||||
missing_list.append(self)
|
||||
|
||||
def check_fake_fname(self, fname, size=0):
|
||||
def check_fake_fname(self, fname: str, size: int = 0) -> str:
|
||||
"""If the file is missing and the entry allows fake blobs, fake it
|
||||
|
||||
Sets self.faked to True if faked
|
||||
@@ -1130,9 +1131,7 @@ features to produce new behaviours.
|
||||
size (int): Size of fake file to create
|
||||
|
||||
Returns:
|
||||
tuple:
|
||||
fname (str): Filename of faked file
|
||||
bool: True if the blob was faked, False if not
|
||||
fname (str): Filename of faked file
|
||||
"""
|
||||
if self.allow_fake and not pathlib.Path(fname).is_file():
|
||||
if not self.fake_fname:
|
||||
@@ -1142,8 +1141,8 @@ features to produce new behaviours.
|
||||
tout.info(f"Entry '{self._node.path}': Faked blob '{outfname}'")
|
||||
self.fake_fname = outfname
|
||||
self.faked = True
|
||||
return self.fake_fname, True
|
||||
return fname, False
|
||||
return self.fake_fname
|
||||
return fname
|
||||
|
||||
def CheckFakedBlobs(self, faked_blobs_list):
|
||||
"""Check if any entries in this section have faked external blobs
|
||||
|
||||
@@ -42,7 +42,7 @@ class Entry_blob(Entry):
|
||||
if fdt_util.GetBool(self._node, 'write-symbols'):
|
||||
self.auto_write_symbols = True
|
||||
|
||||
def ObtainContents(self, fake_size=0):
|
||||
def ObtainContents(self, fake_size: int = 0) -> bool:
|
||||
self._filename = self.GetDefaultFilename()
|
||||
self._pathname = tools.get_input_filename(self._filename,
|
||||
self.external and (self.optional or self.section.GetAllowMissing()))
|
||||
@@ -50,10 +50,9 @@ class Entry_blob(Entry):
|
||||
if not self._pathname:
|
||||
if not fake_size and self.assume_size:
|
||||
fake_size = self.assume_size
|
||||
self._pathname, faked = self.check_fake_fname(self._filename,
|
||||
fake_size)
|
||||
self._pathname = self.check_fake_fname(self._filename, fake_size)
|
||||
self.missing = True
|
||||
if not faked:
|
||||
if not self.faked:
|
||||
content_size = 0
|
||||
if self.assume_size: # Ensure we get test coverage on next line
|
||||
content_size = self.assume_size
|
||||
|
||||
@@ -33,11 +33,11 @@ class Entry_blob_ext_list(Entry_blob):
|
||||
self._filenames = fdt_util.GetStringList(self._node, 'filenames')
|
||||
self._pathnames = []
|
||||
|
||||
def ObtainContents(self):
|
||||
def ObtainContents(self) -> bool:
|
||||
missing = False
|
||||
pathnames = []
|
||||
for fname in self._filenames:
|
||||
fname, _ = self.check_fake_fname(fname)
|
||||
fname = self.check_fake_fname(fname)
|
||||
pathname = tools.get_input_filename(
|
||||
fname, self.external and self.section.GetAllowMissing())
|
||||
# Allow the file to be missing
|
||||
|
||||
Reference in New Issue
Block a user