Skip to content

Commit 804d977

Browse files
committed
Merge pull request #96407 from alvinhochun/mingw-ar-long-command-tempfile
Remove `ARFLAGS` hack for Windows, replace with `TEMPFILE`
2 parents 8ba3c2a + 28b95ff commit 804d977

File tree

2 files changed

+11
-18
lines changed

2 files changed

+11
-18
lines changed

methods.py

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -467,16 +467,6 @@ def use_windows_spawn_fix(self, platform=None):
467467
if os.name != "nt":
468468
return # not needed, only for windows
469469

470-
# On Windows, due to the limited command line length, when creating a static library
471-
# from a very high number of objects SCons will invoke "ar" once per object file;
472-
# that makes object files with same names to be overwritten so the last wins and
473-
# the library loses symbols defined by overwritten objects.
474-
# By enabling quick append instead of the default mode (replacing), libraries will
475-
# got built correctly regardless the invocation strategy.
476-
# Furthermore, since SCons will rebuild the library from scratch when an object file
477-
# changes, no multiple versions of the same object file will be present.
478-
self.Replace(ARFLAGS="q")
479-
480470
def mySubProcess(cmdline, env):
481471
startupinfo = subprocess.STARTUPINFO()
482472
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
@@ -500,19 +490,17 @@ def mySubProcess(cmdline, env):
500490
return rv
501491

502492
def mySpawn(sh, escape, cmd, args, env):
493+
# Used by TEMPFILE.
494+
if cmd == "del":
495+
os.remove(args[1])
496+
return 0
497+
503498
newargs = " ".join(args[1:])
504499
cmdline = cmd + " " + newargs
505500

506501
rv = 0
507502
env = {str(key): str(value) for key, value in iter(env.items())}
508-
if len(cmdline) > 32000 and cmd.endswith("ar"):
509-
cmdline = cmd + " " + args[1] + " " + args[2] + " "
510-
for i in range(3, len(args)):
511-
rv = mySubProcess(cmdline + args[i], env)
512-
if rv:
513-
break
514-
else:
515-
rv = mySubProcess(cmdline, env)
503+
rv = mySubProcess(cmdline, env)
516504

517505
return rv
518506

platform/windows/detect.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,11 @@ def configure_mingw(env: "SConsEnvironment"):
709709
# https://www.scons.org/wiki/LongCmdLinesOnWin32
710710
env.use_windows_spawn_fix()
711711

712+
# In case the command line to AR is too long, use a response file.
713+
env["ARCOM_ORIG"] = env["ARCOM"]
714+
env["ARCOM"] = "${TEMPFILE('$ARCOM_ORIG', '$ARCOMSTR')}"
715+
env["TEMPFILESUFFIX"] = ".rsp"
716+
712717
## Build type
713718

714719
if not env["use_llvm"] and not try_cmd("gcc --version", env["mingw_prefix"], env["arch"]):

0 commit comments

Comments
 (0)