mirror of
https://xff.cz/git/u-boot/
synced 2025-09-01 16:52:14 +02:00
tools/genboardscfg.py: fix minor problems on termination
This tool deletes the incomplete boards.cfg if it encounters an error or is is terminated by the user. I notice some problems even though they rarely happen. [1] The boards.cfg is removed if the program is terminated during __gen_boards_cfg() function but before boards.cfg is actually touched. In this case, the previous boards.cfg should be kept as it is. [2] If an error occurs while deleting the incomplete boards.cfg, the program throws another exception. This hides the privious exception and we will not be able to know the real cause. Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com> Acked-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
committed by
Tom Rini
parent
d6538d22de
commit
79d45d32bc
@@ -413,63 +413,95 @@ class Indicator:
|
|||||||
sys.stdout.write('\r' + msg)
|
sys.stdout.write('\r' + msg)
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|
||||||
def __gen_boards_cfg(jobs):
|
class BoardsFileGenerator:
|
||||||
"""Generate boards.cfg file.
|
|
||||||
|
|
||||||
Arguments:
|
"""Generator of boards.cfg."""
|
||||||
jobs: The number of jobs to run simultaneously
|
|
||||||
|
|
||||||
Note:
|
def __init__(self):
|
||||||
The incomplete boards.cfg is left over when an error (including
|
"""Prepare basic things for generating boards.cfg."""
|
||||||
the termination by the keyboard interrupt) occurs on the halfway.
|
# All the defconfig files to be processed
|
||||||
"""
|
defconfigs = []
|
||||||
check_top_directory()
|
for (dirpath, dirnames, filenames) in os.walk(CONFIG_DIR):
|
||||||
print 'Generating %s ... (jobs: %d)' % (BOARD_FILE, jobs)
|
dirpath = dirpath[len(CONFIG_DIR) + 1:]
|
||||||
|
for filename in fnmatch.filter(filenames, '*_defconfig'):
|
||||||
|
if fnmatch.fnmatch(filename, '.*'):
|
||||||
|
continue
|
||||||
|
defconfigs.append(os.path.join(dirpath, filename))
|
||||||
|
self.defconfigs = defconfigs
|
||||||
|
self.indicator = Indicator(len(defconfigs))
|
||||||
|
|
||||||
# All the defconfig files to be processed
|
# Parse all the MAINTAINERS files
|
||||||
defconfigs = []
|
maintainers_database = MaintainersDatabase()
|
||||||
for (dirpath, dirnames, filenames) in os.walk(CONFIG_DIR):
|
for (dirpath, dirnames, filenames) in os.walk('.'):
|
||||||
dirpath = dirpath[len(CONFIG_DIR) + 1:]
|
if 'MAINTAINERS' in filenames:
|
||||||
for filename in fnmatch.filter(filenames, '*_defconfig'):
|
maintainers_database.parse_file(os.path.join(dirpath,
|
||||||
if fnmatch.fnmatch(filename, '.*'):
|
'MAINTAINERS'))
|
||||||
continue
|
self.maintainers_database = maintainers_database
|
||||||
defconfigs.append(os.path.join(dirpath, filename))
|
|
||||||
|
|
||||||
# Parse all the MAINTAINERS files
|
def __del__(self):
|
||||||
maintainers_database = MaintainersDatabase()
|
"""Delete the incomplete boards.cfg
|
||||||
for (dirpath, dirnames, filenames) in os.walk('.'):
|
|
||||||
if 'MAINTAINERS' in filenames:
|
|
||||||
maintainers_database.parse_file(os.path.join(dirpath,
|
|
||||||
'MAINTAINERS'))
|
|
||||||
|
|
||||||
# Output lines should be piped into the reformat tool
|
This destructor deletes boards.cfg if the private member 'in_progress'
|
||||||
reformat_process = subprocess.Popen(REFORMAT_CMD, stdin=subprocess.PIPE,
|
is defined as True. The 'in_progress' member is set to True at the
|
||||||
stdout=open(BOARD_FILE, 'w'))
|
beginning of the generate() method and set to False at its end.
|
||||||
pipe = reformat_process.stdin
|
So, in_progress==True means generating boards.cfg was terminated
|
||||||
pipe.write(COMMENT_BLOCK)
|
on the way.
|
||||||
|
"""
|
||||||
|
|
||||||
indicator = Indicator(len(defconfigs))
|
if hasattr(self, 'in_progress') and self.in_progress:
|
||||||
slots = Slots(jobs, pipe, maintainers_database)
|
try:
|
||||||
|
os.remove(BOARD_FILE)
|
||||||
|
except OSError as exception:
|
||||||
|
# Ignore 'No such file or directory' error
|
||||||
|
if exception.errno != errno.ENOENT:
|
||||||
|
raise
|
||||||
|
print 'Removed incomplete %s' % BOARD_FILE
|
||||||
|
|
||||||
# Main loop to process defconfig files:
|
def generate(self, jobs):
|
||||||
# Add a new subprocess into a vacant slot.
|
"""Generate boards.cfg
|
||||||
# Sleep if there is no available slot.
|
|
||||||
for defconfig in defconfigs:
|
|
||||||
while not slots.add(defconfig):
|
|
||||||
while not slots.available():
|
|
||||||
# No available slot: sleep for a while
|
|
||||||
time.sleep(SLEEP_TIME)
|
|
||||||
indicator.inc()
|
|
||||||
|
|
||||||
# wait until all the subprocesses finish
|
This method sets the 'in_progress' member to True at the beginning
|
||||||
while not slots.empty():
|
and sets it to False on success. The boards.cfg should not be
|
||||||
time.sleep(SLEEP_TIME)
|
touched before/after this method because 'in_progress' is used
|
||||||
print ''
|
to detect the incomplete boards.cfg.
|
||||||
|
|
||||||
# wait until the reformat tool finishes
|
Arguments:
|
||||||
reformat_process.communicate()
|
jobs: The number of jobs to run simultaneously
|
||||||
if reformat_process.returncode != 0:
|
"""
|
||||||
sys.exit('"%s" failed' % REFORMAT_CMD[0])
|
|
||||||
|
self.in_progress = True
|
||||||
|
print 'Generating %s ... (jobs: %d)' % (BOARD_FILE, jobs)
|
||||||
|
|
||||||
|
# Output lines should be piped into the reformat tool
|
||||||
|
reformat_process = subprocess.Popen(REFORMAT_CMD,
|
||||||
|
stdin=subprocess.PIPE,
|
||||||
|
stdout=open(BOARD_FILE, 'w'))
|
||||||
|
pipe = reformat_process.stdin
|
||||||
|
pipe.write(COMMENT_BLOCK)
|
||||||
|
|
||||||
|
slots = Slots(jobs, pipe, self.maintainers_database)
|
||||||
|
|
||||||
|
# Main loop to process defconfig files:
|
||||||
|
# Add a new subprocess into a vacant slot.
|
||||||
|
# Sleep if there is no available slot.
|
||||||
|
for defconfig in self.defconfigs:
|
||||||
|
while not slots.add(defconfig):
|
||||||
|
while not slots.available():
|
||||||
|
# No available slot: sleep for a while
|
||||||
|
time.sleep(SLEEP_TIME)
|
||||||
|
self.indicator.inc()
|
||||||
|
|
||||||
|
# wait until all the subprocesses finish
|
||||||
|
while not slots.empty():
|
||||||
|
time.sleep(SLEEP_TIME)
|
||||||
|
print ''
|
||||||
|
|
||||||
|
# wait until the reformat tool finishes
|
||||||
|
reformat_process.communicate()
|
||||||
|
if reformat_process.returncode != 0:
|
||||||
|
sys.exit('"%s" failed' % REFORMAT_CMD[0])
|
||||||
|
|
||||||
|
self.in_progress = False
|
||||||
|
|
||||||
def gen_boards_cfg(jobs):
|
def gen_boards_cfg(jobs):
|
||||||
"""Generate boards.cfg file.
|
"""Generate boards.cfg file.
|
||||||
@@ -480,17 +512,9 @@ def gen_boards_cfg(jobs):
|
|||||||
Arguments:
|
Arguments:
|
||||||
jobs: The number of jobs to run simultaneously
|
jobs: The number of jobs to run simultaneously
|
||||||
"""
|
"""
|
||||||
try:
|
check_top_directory()
|
||||||
__gen_boards_cfg(jobs)
|
generator = BoardsFileGenerator()
|
||||||
except:
|
generator.generate(jobs)
|
||||||
# We should remove incomplete boards.cfg
|
|
||||||
try:
|
|
||||||
os.remove(BOARD_FILE)
|
|
||||||
except OSError as exception:
|
|
||||||
# Ignore 'No such file or directory' error
|
|
||||||
if exception.errno != errno.ENOENT:
|
|
||||||
raise
|
|
||||||
raise
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = optparse.OptionParser()
|
parser = optparse.OptionParser()
|
||||||
|
Reference in New Issue
Block a user