]> granicus.if.org Git - esp-idf/commitdiff
tools: re-run idf.py in MSYS with winpty
authorRoland Dobai <dobai.roland@gmail.com>
Fri, 22 Feb 2019 15:07:26 +0000 (16:07 +0100)
committerRoland Dobai <dobai.roland@gmail.com>
Mon, 11 Mar 2019 07:54:44 +0000 (08:54 +0100)
This is done in order to cancel subprocesses on keyboard interrupt
(CTRL+C).

tools/idf.py

index 03fe9a1b9385847b9d693d8edd47f2b8f522d6ab..801a4d0b7b1ff336c5af4bcf09ecf4589ed8a421 100755 (executable)
@@ -520,7 +520,20 @@ def main():
 
 if __name__ == "__main__":
     try:
-        main()
+        # On MSYS2 we need to run idf.py with "winpty" in order to be able to cancel the subprocesses properly on
+        # keyboard interrupt (CTRL+C).
+        # Using an own global variable for indicating that we are running with "winpty" seems to be the most suitable
+        # option as os.environment['_'] contains "winpty" only when it is run manually from console.
+        WINPTY_VAR = 'WINPTY'
+        WINPTY_EXE = 'winpty'
+        if ('MSYSTEM' in os.environ) and (not os.environ['_'].endswith(WINPTY_EXE) and WINPTY_VAR not in os.environ):
+            os.environ[WINPTY_VAR] = '1'    # the value is of no interest to us
+            # idf.py calls itself with "winpty" and WINPTY global variable set
+            ret = subprocess.call([WINPTY_EXE, sys.executable] + sys.argv, env=os.environ)
+            if ret:
+                raise SystemExit(ret)
+        else:
+            main()
     except FatalError as e:
         print(e)
         sys.exit(2)