From patchwork Wed Jun 8 02:47:37 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 69580 Delivered-To: patch@linaro.org Received: by 10.140.106.246 with SMTP id e109csp2273187qgf; Tue, 7 Jun 2016 19:47:17 -0700 (PDT) X-Received: by 10.194.79.168 with SMTP id k8mr1987023wjx.52.1465354037516; Tue, 07 Jun 2016 19:47:17 -0700 (PDT) Return-Path: Received: from theia.denx.de (theia.denx.de. [85.214.87.163]) by mx.google.com with ESMTP id j198si5816451wmj.110.2016.06.07.19.47.17; Tue, 07 Jun 2016 19:47:17 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 85.214.87.163 as permitted sender) client-ip=85.214.87.163; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@nifty.com; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 85.214.87.163 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id B4413A7527; Wed, 8 Jun 2016 04:47:16 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 0rIPCwO2o-yM; Wed, 8 Jun 2016 04:47:16 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 90F0AA74DA; Wed, 8 Jun 2016 04:47:15 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 8BB06A74DA for ; Wed, 8 Jun 2016 04:47:06 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id lve4n-qNveGa for ; Wed, 8 Jun 2016 04:47:06 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from conuserg-10.nifty.com (conuserg-10.nifty.com [210.131.2.77]) by theia.denx.de (Postfix) with ESMTPS id ACB42A74D0 for ; Wed, 8 Jun 2016 04:47:01 +0200 (CEST) Received: from beagle.diag.org (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-10.nifty.com with ESMTP id u582kN0v009611; Wed, 8 Jun 2016 11:46:23 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com u582kN0v009611 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1465353984; bh=EQuRUc0OuflCihN4ED6HfyHh7xXR7c2RY3kAhQlD2W8=; h=From:To:Cc:Subject:Date:From; b=QhUFEes92rMP57DbLvVa/xNFJeKbkvzXL7UaK42L6Ik8dlJLSXO+OnH022Gc/pvnD QN832LT31a3KpH5h4UjE8Kiho2bLzqbnmB0nMRgzGpnSDxlpq6x/mP9SeMyZKQx1iu FNRbGd6PQEY6ZzYOkkVXaNSynWk2BOMRmE5Ll866XfvaeP6GYTd7c1tGU3QoF9ElaX 9IfSiZbjmu1Rc/2UCVZYpPm9zS4vo9Re/VimaOadUhqSEqV1dU+CkWO+i0GeF8Ki9d nYHEf+j2H2z9Be4y/4Gs5yalozqk27fHvPX2EHfh7RZ6ZiLsfutj9PdHig33XsSjkg bVJ6vwclFwNEg== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: u-boot@lists.denx.de Date: Wed, 8 Jun 2016 11:47:37 +0900 Message-Id: <1465354057-486-1-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 1.9.1 Cc: Joe Hershberger Subject: [U-Boot] [PATCH] tools: moveconfig: make Slot.poll() more readable with helper methods X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" 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 --- tools/moveconfig.py | 110 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 67 insertions(+), 43 deletions(-) -- 1.9.1 _______________________________________________ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot diff --git a/tools/moveconfig.py b/tools/moveconfig.py index d9ae833..76a2909 100755 --- a/tools/moveconfig.py +++ b/tools/moveconfig.py @@ -633,13 +633,10 @@ class Slot: """ if self.state != STATE_IDLE: 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.state = STATE_DEFCONFIG self.log = '' + self.do_defconfig() return True def poll(self): @@ -665,55 +662,46 @@ class Slot: return False if self.ps.poll() != 0: - self.log += color_text(self.options.color, COLOR_LIGHT_RED, - "Failed to process.\n") - if self.options.verbose: - self.log += color_text(self.options.color, COLOR_LIGHT_CYAN, - self.ps.stderr.read()) - self.finish(False) - return True + 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.") - if self.state == STATE_AUTOCONF: - (updated, log) = self.parser.update_dotconfig() - self.log += log + return True if self.state == STATE_IDLE else False - if not self.options.force_sync and not updated: - self.finish(True) - return True - if updated: - self.log += color_text(self.options.color, COLOR_LIGHT_GREEN, - "Syncing by savedefconfig...\n") - else: - self.log += "Syncing by savedefconfig (forced by option)...\n" + def handle_error(self): + """Handle error cases.""" - cmd = list(self.make_cmd) - cmd.append('savedefconfig') - self.ps = subprocess.Popen(cmd, stdout=self.devnull, - stderr=subprocess.PIPE) - self.state = STATE_SAVEDEFCONFIG - return False + self.log += color_text(self.options.color, COLOR_LIGHT_RED, + "Failed to process.\n") + if self.options.verbose: + self.log += color_text(self.options.color, COLOR_LIGHT_CYAN, + self.ps.stderr.read()) + self.finish(False) - if self.state == STATE_SAVEDEFCONFIG: - self.log += self.parser.check_defconfig() - orig_defconfig = os.path.join('configs', self.defconfig) - new_defconfig = os.path.join(self.build_dir, 'defconfig') - updated = not filecmp.cmp(orig_defconfig, new_defconfig) + def do_defconfig(self): + """Run 'make _defconfig' to create the .config file.""" - if updated: - self.log += color_text(self.options.color, COLOR_LIGHT_GREEN, - "defconfig was updated.\n") + cmd = list(self.make_cmd) + cmd.append(defconfig) + self.ps = subprocess.Popen(cmd, stdout=self.devnull, + stderr=subprocess.PIPE) + self.state = STATE_DEFCONFIG - if not self.options.dry_run and updated: - shutil.move(new_defconfig, orig_defconfig) - self.finish(True) - return True + 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 True + return cmd = list(self.make_cmd) if self.cross_compile: @@ -723,7 +711,43 @@ class Slot: self.ps = subprocess.Popen(cmd, stdout=self.devnull, stderr=subprocess.PIPE) self.state = STATE_AUTOCONF - return False + + def do_savedefconfig(self): + """Update the .config and run 'make savedefconfig'.""" + + (updated, log) = self.parser.update_dotconfig() + self.log += log + + if not self.options.force_sync and not updated: + self.finish(True) + return + if updated: + self.log += color_text(self.options.color, COLOR_LIGHT_GREEN, + "Syncing by savedefconfig...\n") + else: + self.log += "Syncing by savedefconfig (forced by option)...\n" + + cmd = list(self.make_cmd) + cmd.append('savedefconfig') + self.ps = subprocess.Popen(cmd, stdout=self.devnull, + stderr=subprocess.PIPE) + 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() + orig_defconfig = os.path.join('configs', self.defconfig) + new_defconfig = os.path.join(self.build_dir, 'defconfig') + updated = not filecmp.cmp(orig_defconfig, new_defconfig) + + if updated: + self.log += color_text(self.options.color, COLOR_LIGHT_GREEN, + "defconfig was updated.\n") + + if not self.options.dry_run and updated: + shutil.move(new_defconfig, orig_defconfig) + self.finish(True) def finish(self, success): """Display log along with progress and go to the idle state.