From 61c3f8a4404fd89d272bfcbc850d572880d66b1e Mon Sep 17 00:00:00 2001 From: Feiyun Wang Date: Fri, 31 Mar 2023 20:57:17 +0800 Subject: [PATCH 1/6] Fix #1059: Linking for mingw/x86_64 on MSYS2 fails --- tools/my_spawn.py | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/tools/my_spawn.py b/tools/my_spawn.py index 0b21419a..542d5135 100644 --- a/tools/my_spawn.py +++ b/tools/my_spawn.py @@ -11,23 +11,16 @@ def configure(env): import subprocess def mySubProcess(cmdline, env): - # print "SPAWNED : " + cmdline - startupinfo = subprocess.STARTUPINFO() - startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW - proc = subprocess.Popen( - cmdline, - stdin=subprocess.PIPE, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - startupinfo=startupinfo, - shell=False, + # print("SPAWNED: " + cmdline) + proc = subprocess.run( + args=cmdline, + shell=True, env=env, ) - data, err = proc.communicate() - rv = proc.wait() + rv = proc.returncode if rv: print("=====") - print(err.decode("utf-8")) + print(rv, "(", hex(rv), ")") print("=====") return rv From 8d3dc7551dee75ec50a300c50be3dd278acea43e Mon Sep 17 00:00:00 2001 From: Feiyun Wang Date: Fri, 31 Mar 2023 23:58:54 +0800 Subject: [PATCH 2/6] Fix #1059: Linking for mingw/x86_64 on MSYS2 fails, w/ ar execution speed up --- tools/my_spawn.py | 45 +++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/tools/my_spawn.py b/tools/my_spawn.py index 542d5135..5f5ffa69 100644 --- a/tools/my_spawn.py +++ b/tools/my_spawn.py @@ -11,34 +11,39 @@ def configure(env): import subprocess def mySubProcess(cmdline, env): - # print("SPAWNED: " + cmdline) - proc = subprocess.run( - args=cmdline, - shell=True, - env=env, - ) + # print(cmdline) + proc = subprocess.run(args=cmdline, shell=True, env=env) rv = proc.returncode if rv: print("=====") - print(rv, "(", hex(rv), ")") + print("subprocess.run().returncode=", rv, "(", hex(rv), ")") + print("len(cmdline)=", len(cmdline)) print("=====") return rv def mySpawn(sh, escape, cmd, args, env): - - newargs = " ".join(args[1:]) - cmdline = cmd + " " + newargs - - rv = 0 - if len(cmdline) > 32000 and cmd.endswith("ar"): - cmdline = cmd + " " + args[1] + " " + args[2] + " " - for i in range(3, len(args)): - rv = mySubProcess(cmdline + args[i], env) - if rv: - break + if len(args) > 3 and cmd.endswith("ar"): + # print("Long ar command is split.\nargc=", len(args)) + lead = len(" ".join(args[0:3])) + begin = 3 + length = lead + 1 + len(args[begin]) + rv = 0 + for i in range(4, len(args)): + length += 1 + len(args[i]) + if length >= 8 * 1024 - 32: + cmdline = " ".join(args[0:3] + args[begin:i]) + # print("objs=", i - begin, ", length=", len(cmdline)) + rv = mySubProcess(cmdline, env) + if rv: + break + begin = i + length = lead + 1 + len(args[i]) + if not rv: + cmdline = " ".join(args[0:3] + args[begin:]) + # print("objs=", len(args) - begin, ", length=", len(cmdline)) + rv = mySubProcess(cmdline, env) else: - rv = mySubProcess(cmdline, env) - + rv = mySubProcess(args, env) return rv env["SPAWN"] = mySpawn From 88e135d53b2cc9c2c265b9e415ec87aa6942da60 Mon Sep 17 00:00:00 2001 From: Feiyun Wang Date: Sat, 1 Apr 2023 00:46:28 +0800 Subject: [PATCH 3/6] Fix #1059: Linking for mingw/x86_64 on MSYS2 fails, w/ ar execution speed up --- tools/my_spawn.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/my_spawn.py b/tools/my_spawn.py index 5f5ffa69..8ddda05e 100644 --- a/tools/my_spawn.py +++ b/tools/my_spawn.py @@ -43,7 +43,7 @@ def configure(env): # print("objs=", len(args) - begin, ", length=", len(cmdline)) rv = mySubProcess(cmdline, env) else: - rv = mySubProcess(args, env) + rv = mySubProcess(" ".join(args), env) return rv env["SPAWN"] = mySpawn From 189f56c34e8f77c30fedcbe68bc946f2a75b93f0 Mon Sep 17 00:00:00 2001 From: Feiyun Wang Date: Sat, 1 Apr 2023 01:20:41 +0800 Subject: [PATCH 4/6] Fix #1059: Linking for mingw/x86_64 on MSYS2 fails, w/ ar execution speed up --- tools/my_spawn.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/my_spawn.py b/tools/my_spawn.py index 8ddda05e..95b87fa8 100644 --- a/tools/my_spawn.py +++ b/tools/my_spawn.py @@ -22,12 +22,12 @@ def configure(env): return rv def mySpawn(sh, escape, cmd, args, env): - if len(args) > 3 and cmd.endswith("ar"): + rv = 0 + if len(args) > 4 and cmd.endswith("ar"): # print("Long ar command is split.\nargc=", len(args)) lead = len(" ".join(args[0:3])) begin = 3 length = lead + 1 + len(args[begin]) - rv = 0 for i in range(4, len(args)): length += 1 + len(args[i]) if length >= 8 * 1024 - 32: @@ -37,7 +37,7 @@ def configure(env): if rv: break begin = i - length = lead + 1 + len(args[i]) + length = lead + 1 + len(args[begin]) if not rv: cmdline = " ".join(args[0:3] + args[begin:]) # print("objs=", len(args) - begin, ", length=", len(cmdline)) From fb06503307037aaf66aa2ab54ecbb8ebd27479d8 Mon Sep 17 00:00:00 2001 From: Feiyun Wang Date: Sun, 2 Apr 2023 23:45:48 +0800 Subject: [PATCH 5/6] Fix #1059: Linking for mingw/x86_64 on MSYS2 fails, w/ ar execution speed up Command line length=8153 is OK, while 8159 is broken. --- tools/my_spawn.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/my_spawn.py b/tools/my_spawn.py index 95b87fa8..13ca0a69 100644 --- a/tools/my_spawn.py +++ b/tools/my_spawn.py @@ -30,7 +30,7 @@ def configure(env): length = lead + 1 + len(args[begin]) for i in range(4, len(args)): length += 1 + len(args[i]) - if length >= 8 * 1024 - 32: + if length > 8153: cmdline = " ".join(args[0:3] + args[begin:i]) # print("objs=", i - begin, ", length=", len(cmdline)) rv = mySubProcess(cmdline, env) From 64a818cfd9a30509f5d25110e33f2883cdd2e96a Mon Sep 17 00:00:00 2001 From: Feiyun Wang Date: Tue, 4 Apr 2023 19:54:14 +0800 Subject: [PATCH 6/6] Fix #1059: Linking for mingw/x86_64 on MSYS2 fails, and optimize "ar" command execution Command line length=8158 is the maximum to be OK. --- tools/my_spawn.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tools/my_spawn.py b/tools/my_spawn.py index 13ca0a69..42c9448c 100644 --- a/tools/my_spawn.py +++ b/tools/my_spawn.py @@ -12,8 +12,7 @@ def configure(env): def mySubProcess(cmdline, env): # print(cmdline) - proc = subprocess.run(args=cmdline, shell=True, env=env) - rv = proc.returncode + rv = subprocess.run(args=cmdline, shell=True, env=env).returncode if rv: print("=====") print("subprocess.run().returncode=", rv, "(", hex(rv), ")") @@ -30,7 +29,7 @@ def configure(env): length = lead + 1 + len(args[begin]) for i in range(4, len(args)): length += 1 + len(args[i]) - if length > 8153: + if length > 8158: cmdline = " ".join(args[0:3] + args[begin:i]) # print("objs=", i - begin, ", length=", len(cmdline)) rv = mySubProcess(cmdline, env)