diff mbox

[U-Boot,v2,1/2] tools: moveconfig: Make the slot processing more linear

Message ID 1464838207-10020-1-git-send-email-joe.hershberger@ni.com
State Changes Requested
Delegated to: Masahiro Yamada
Headers show

Commit Message

Joe Hershberger June 2, 2016, 3:30 a.m. UTC
Make the processing of a slot more linear code compared to how it
executes.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

---

Changes in v2:
- New for v2

 tools/moveconfig.py | 59 +++++++++++++++++++++++++++++++----------------------
 1 file changed, 35 insertions(+), 24 deletions(-)

Comments

Masahiro Yamada June 8, 2016, 2:47 a.m. UTC | #1
Hi Joe.


2016-06-02 12:30 GMT+09:00 Joe Hershberger <joe.hershberger@ni.com>:
> Make the processing of a slot more linear code compared to how it
> executes.
>
> Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
>

This patch moves "make defconfig"
from the .add() method to the .poll() method,
but it did not update the comment block.

So, the comment below does not match the code any more.

 def add(self, defconfig):
     """Assign a new subprocess for defconfig and add it to the slot.


But, anyway I do not like to split
the current STATE_IDLE into STATE_IDLE and STATE_INIT.

See my comments in 2/2.
diff mbox

Patch

diff --git a/tools/moveconfig.py b/tools/moveconfig.py
index 2d29e1b..01350ce 100755
--- a/tools/moveconfig.py
+++ b/tools/moveconfig.py
@@ -197,9 +197,10 @@  CROSS_COMPILE = {
 }
 
 STATE_IDLE = 0
-STATE_DEFCONFIG = 1
-STATE_AUTOCONF = 2
-STATE_SAVEDEFCONFIG = 3
+STATE_INIT = 1
+STATE_DEFCONFIG = 2
+STATE_AUTOCONF = 3
+STATE_SAVEDEFCONFIG = 4
 
 ACTION_MOVE = 0
 ACTION_NO_ENTRY = 1
@@ -633,12 +634,9 @@  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.ps = None
         self.defconfig = defconfig
-        self.state = STATE_DEFCONFIG
+        self.state = STATE_INIT
         self.log = ''
         return True
 
@@ -661,6 +659,14 @@  class Slot:
         if self.state == STATE_IDLE:
             return True
 
+        if self.state == STATE_INIT:
+            cmd = list(self.make_cmd)
+            cmd.append(self.defconfig)
+            self.ps = subprocess.Popen(cmd, stdout=self.devnull,
+                                       stderr=subprocess.PIPE)
+            self.state = STATE_DEFCONFIG
+            return False
+
         if self.ps.poll() == None:
             return False
 
@@ -673,6 +679,24 @@  class Slot:
             self.finish(False)
             return True
 
+        if self.state == STATE_DEFCONFIG:
+            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
+
         if self.state == STATE_AUTOCONF:
             (updated, log) = self.parser.update_dotconfig()
             self.log += log
@@ -708,22 +732,9 @@  class Slot:
             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
+        # Undefined state!
+        self.finish(False)
+        return True
 
     def finish(self, success):
         """Display log along with progress and go to the idle state.