mirror of
https://github.com/Fishwaldo/u-boot.git
synced 2025-04-27 00:31:30 +00:00
tools: moveconfig: make Slot.poll() more readable with helper methods
The Slot.poll() method is already complicated and a new feature we are going to add will make it more difficult to understand the execution flow. Refactor it with helper methods, .handle_error(), .do_defconfig(), .do_autoconf(), .do_savedefconfig, and .update_defconfig(). Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
This commit is contained in:
parent
6a9f79f712
commit
e307fa9d89
1 changed files with 67 additions and 43 deletions
|
@ -633,13 +633,10 @@ class Slot:
|
||||||
"""
|
"""
|
||||||
if self.state != STATE_IDLE:
|
if self.state != STATE_IDLE:
|
||||||
return False
|
return False
|
||||||
cmd = list(self.make_cmd)
|
|
||||||
cmd.append(defconfig)
|
|
||||||
self.ps = subprocess.Popen(cmd, stdout=self.devnull,
|
|
||||||
stderr=subprocess.PIPE)
|
|
||||||
self.defconfig = defconfig
|
self.defconfig = defconfig
|
||||||
self.state = STATE_DEFCONFIG
|
|
||||||
self.log = ''
|
self.log = ''
|
||||||
|
self.do_defconfig()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def poll(self):
|
def poll(self):
|
||||||
|
@ -665,21 +662,65 @@ class Slot:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if self.ps.poll() != 0:
|
if self.ps.poll() != 0:
|
||||||
|
self.handle_error()
|
||||||
|
elif self.state == STATE_DEFCONFIG:
|
||||||
|
self.do_autoconf()
|
||||||
|
elif self.state == STATE_AUTOCONF:
|
||||||
|
self.do_savedefconfig()
|
||||||
|
elif self.state == STATE_SAVEDEFCONFIG:
|
||||||
|
self.update_defconfig()
|
||||||
|
else:
|
||||||
|
sys.exit("Internal Error. This should not happen.")
|
||||||
|
|
||||||
|
return True if self.state == STATE_IDLE else False
|
||||||
|
|
||||||
|
def handle_error(self):
|
||||||
|
"""Handle error cases."""
|
||||||
|
|
||||||
self.log += color_text(self.options.color, COLOR_LIGHT_RED,
|
self.log += color_text(self.options.color, COLOR_LIGHT_RED,
|
||||||
"Failed to process.\n")
|
"Failed to process.\n")
|
||||||
if self.options.verbose:
|
if self.options.verbose:
|
||||||
self.log += color_text(self.options.color, COLOR_LIGHT_CYAN,
|
self.log += color_text(self.options.color, COLOR_LIGHT_CYAN,
|
||||||
self.ps.stderr.read())
|
self.ps.stderr.read())
|
||||||
self.finish(False)
|
self.finish(False)
|
||||||
return True
|
|
||||||
|
|
||||||
if self.state == STATE_AUTOCONF:
|
def do_defconfig(self):
|
||||||
|
"""Run 'make <board>_defconfig' to create the .config file."""
|
||||||
|
|
||||||
|
cmd = list(self.make_cmd)
|
||||||
|
cmd.append(self.defconfig)
|
||||||
|
self.ps = subprocess.Popen(cmd, stdout=self.devnull,
|
||||||
|
stderr=subprocess.PIPE)
|
||||||
|
self.state = STATE_DEFCONFIG
|
||||||
|
|
||||||
|
def do_autoconf(self):
|
||||||
|
"""Run 'make include/config/auto.conf'."""
|
||||||
|
|
||||||
|
self.cross_compile = self.parser.get_cross_compile()
|
||||||
|
if self.cross_compile is None:
|
||||||
|
self.log += color_text(self.options.color, COLOR_YELLOW,
|
||||||
|
"Compiler is missing. Do nothing.\n")
|
||||||
|
self.finish(False)
|
||||||
|
return
|
||||||
|
|
||||||
|
cmd = list(self.make_cmd)
|
||||||
|
if self.cross_compile:
|
||||||
|
cmd.append('CROSS_COMPILE=%s' % self.cross_compile)
|
||||||
|
cmd.append('KCONFIG_IGNORE_DUPLICATES=1')
|
||||||
|
cmd.append('include/config/auto.conf')
|
||||||
|
self.ps = subprocess.Popen(cmd, stdout=self.devnull,
|
||||||
|
stderr=subprocess.PIPE)
|
||||||
|
self.state = STATE_AUTOCONF
|
||||||
|
|
||||||
|
def do_savedefconfig(self):
|
||||||
|
"""Update the .config and run 'make savedefconfig'."""
|
||||||
|
|
||||||
(updated, log) = self.parser.update_dotconfig()
|
(updated, log) = self.parser.update_dotconfig()
|
||||||
self.log += log
|
self.log += log
|
||||||
|
|
||||||
if not self.options.force_sync and not updated:
|
if not self.options.force_sync and not updated:
|
||||||
self.finish(True)
|
self.finish(True)
|
||||||
return True
|
return
|
||||||
if updated:
|
if updated:
|
||||||
self.log += color_text(self.options.color, COLOR_LIGHT_GREEN,
|
self.log += color_text(self.options.color, COLOR_LIGHT_GREEN,
|
||||||
"Syncing by savedefconfig...\n")
|
"Syncing by savedefconfig...\n")
|
||||||
|
@ -691,9 +732,10 @@ class Slot:
|
||||||
self.ps = subprocess.Popen(cmd, stdout=self.devnull,
|
self.ps = subprocess.Popen(cmd, stdout=self.devnull,
|
||||||
stderr=subprocess.PIPE)
|
stderr=subprocess.PIPE)
|
||||||
self.state = STATE_SAVEDEFCONFIG
|
self.state = STATE_SAVEDEFCONFIG
|
||||||
return False
|
|
||||||
|
|
||||||
if self.state == STATE_SAVEDEFCONFIG:
|
def update_defconfig(self):
|
||||||
|
"""Update the input defconfig and go back to the idle state."""
|
||||||
|
|
||||||
self.log += self.parser.check_defconfig()
|
self.log += self.parser.check_defconfig()
|
||||||
orig_defconfig = os.path.join('configs', self.defconfig)
|
orig_defconfig = os.path.join('configs', self.defconfig)
|
||||||
new_defconfig = os.path.join(self.build_dir, 'defconfig')
|
new_defconfig = os.path.join(self.build_dir, 'defconfig')
|
||||||
|
@ -706,24 +748,6 @@ class Slot:
|
||||||
if not self.options.dry_run and updated:
|
if not self.options.dry_run and updated:
|
||||||
shutil.move(new_defconfig, orig_defconfig)
|
shutil.move(new_defconfig, orig_defconfig)
|
||||||
self.finish(True)
|
self.finish(True)
|
||||||
return True
|
|
||||||
|
|
||||||
self.cross_compile = self.parser.get_cross_compile()
|
|
||||||
if self.cross_compile is None:
|
|
||||||
self.log += color_text(self.options.color, COLOR_YELLOW,
|
|
||||||
"Compiler is missing. Do nothing.\n")
|
|
||||||
self.finish(False)
|
|
||||||
return True
|
|
||||||
|
|
||||||
cmd = list(self.make_cmd)
|
|
||||||
if self.cross_compile:
|
|
||||||
cmd.append('CROSS_COMPILE=%s' % self.cross_compile)
|
|
||||||
cmd.append('KCONFIG_IGNORE_DUPLICATES=1')
|
|
||||||
cmd.append('include/config/auto.conf')
|
|
||||||
self.ps = subprocess.Popen(cmd, stdout=self.devnull,
|
|
||||||
stderr=subprocess.PIPE)
|
|
||||||
self.state = STATE_AUTOCONF
|
|
||||||
return False
|
|
||||||
|
|
||||||
def finish(self, success):
|
def finish(self, success):
|
||||||
"""Display log along with progress and go to the idle state.
|
"""Display log along with progress and go to the idle state.
|
||||||
|
|
Loading…
Add table
Reference in a new issue