binman: Put fake files in a subdirectory
At present fake files from a previous build appear to be real files for
a subsequent build, since they sit in the output directory.
This can cause problems, since binman may need to parse the file, e.g.
with the Intel description.bin files.
Fix this by putting them in a 'binman-fake' subdirectory. Keep a track
of the fake filename so we only create it once. Subsequent builds will
still see that the file is missing and mark it as fake.
Update a few tests to check the behaviour.
Signed-off-by: Simon Glass <sjg@chromium.org>
diff --git a/tools/binman/entry.py b/tools/binman/entry.py
index e3767ae..28a7510 100644
--- a/tools/binman/entry.py
+++ b/tools/binman/entry.py
@@ -9,6 +9,7 @@
import os
import pathlib
import sys
+import time
from binman import bintool
from binman import comp_util
@@ -82,7 +83,10 @@
missing_bintools: List of missing bintools for this entry
update_hash: True if this entry's "hash" subnode should be
updated with a hash of the entry contents
+ fake_fname: Fake filename, if one was created, else None
"""
+ fake_dir = None
+
def __init__(self, section, etype, node, name_prefix=''):
# Put this here to allow entry-docs and help to work without libfdt
global state
@@ -116,6 +120,7 @@
self.bintools = {}
self.missing_bintools = []
self.update_hash = True
+ self.fake_fname = None
@staticmethod
def FindEntryClass(etype, expanded):
@@ -1014,12 +1019,14 @@
bool: True if the blob was faked, False if not
"""
if self.allow_fake and not pathlib.Path(fname).is_file():
- outfname = tools.get_output_filename(os.path.basename(fname))
- with open(outfname, "wb") as out:
- out.truncate(size)
+ if not self.fake_fname:
+ outfname = os.path.join(self.fake_dir, os.path.basename(fname))
+ with open(outfname, "wb") as out:
+ out.truncate(size)
+ tout.info(f"Entry '{self._node.path}': Faked blob '{outfname}'")
+ self.fake_fname = outfname
self.faked = True
- tout.info(f"Entry '{self._node.path}': Faked file '{outfname}'")
- return outfname, True
+ return self.fake_fname, True
return fname, False
def CheckFakedBlobs(self, faked_blobs_list):
@@ -1169,3 +1176,11 @@
fname = tools.get_output_filename(f'{prefix}.{uniq}')
tools.write_file(fname, data)
return data, fname, uniq
+
+ @classmethod
+ def create_fake_dir(cls):
+ """Create the directory for fake files"""
+ cls.fake_dir = tools.get_output_filename('binman-fake')
+ if not os.path.exists(cls.fake_dir):
+ os.mkdir(cls.fake_dir)
+ tout.notice(f"Fake-blob dir is '{cls.fake_dir}'")