From 66b35669e31cfc15061345cba8fcf832825f88a3 Mon Sep 17 00:00:00 2001 From: Alvin Wong Date: Sun, 1 Sep 2024 04:03:00 +0800 Subject: [PATCH 1/3] [4.3] Remove ARFLAGS hack for Windows, replace with TEMPFILE TEMPFILE is the built-in way of SCons to use a response file for command lines that are too long. (cherry picked from commit 28b95ff55010d8f9e3f9feca4f75e5aeaf1ac9aa) --- methods.py | 24 ++++++------------------ platform/windows/detect.py | 5 +++++ 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/methods.py b/methods.py index 91a157152fcf..4029b1af4f2b 100644 --- a/methods.py +++ b/methods.py @@ -467,16 +467,6 @@ def use_windows_spawn_fix(self, platform=None): if os.name != "nt": return # not needed, only for windows - # On Windows, due to the limited command line length, when creating a static library - # from a very high number of objects SCons will invoke "ar" once per object file; - # that makes object files with same names to be overwritten so the last wins and - # the library loses symbols defined by overwritten objects. - # By enabling quick append instead of the default mode (replacing), libraries will - # got built correctly regardless the invocation strategy. - # Furthermore, since SCons will rebuild the library from scratch when an object file - # changes, no multiple versions of the same object file will be present. - self.Replace(ARFLAGS="q") - def mySubProcess(cmdline, env): startupinfo = subprocess.STARTUPINFO() startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW @@ -498,19 +488,17 @@ def mySubProcess(cmdline, env): return rv def mySpawn(sh, escape, cmd, args, env): + # Used by TEMPFILE. + if cmd == "del": + os.remove(args[1]) + return 0 + newargs = " ".join(args[1:]) cmdline = cmd + " " + newargs rv = 0 env = {str(key): str(value) for key, value in iter(env.items())} - 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 - else: - rv = mySubProcess(cmdline, env) + rv = mySubProcess(cmdline, env) return rv diff --git a/platform/windows/detect.py b/platform/windows/detect.py index 4c70bbf43606..72ff967ad6a8 100644 --- a/platform/windows/detect.py +++ b/platform/windows/detect.py @@ -636,6 +636,11 @@ def configure_mingw(env: "SConsEnvironment"): # https://www.scons.org/wiki/LongCmdLinesOnWin32 env.use_windows_spawn_fix() + # In case the command line to AR is too long, use a response file. + env["ARCOM_ORIG"] = env["ARCOM"] + env["ARCOM"] = "${TEMPFILE('$ARCOM_ORIG', '$ARCOMSTR')}" + env["TEMPFILESUFFIX"] = ".rsp" + ## Build type if not env["use_llvm"] and not try_cmd("gcc --version", env["mingw_prefix"], env["arch"]): From 2cafac0fcfce9dd75e4420cac23089a568c448fd Mon Sep 17 00:00:00 2001 From: Alvin Wong Date: Thu, 19 Sep 2024 22:04:55 +0800 Subject: [PATCH 2/3] [4.3] Fix using Binutils AR with TEMPFILE on Windows Set `TEMPFILEARGESCFUNC`[1] to replace backslashes with forward slashes in paths. [1]: https://scons.org/doc/production/HTML/scons-user/apa.html#cv-TEMPFILEARGESCFUNC (cherry picked from commit 454251660c4c227121be6a6bab67b2998ffbf81a) --- platform/windows/detect.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/platform/windows/detect.py b/platform/windows/detect.py index 72ff967ad6a8..245398fc9cdd 100644 --- a/platform/windows/detect.py +++ b/platform/windows/detect.py @@ -631,6 +631,17 @@ def spawn_capture(sh, escape, cmd, args, env): env.AppendUnique(LINKFLAGS=["/STACK:" + str(STACK_SIZE)]) +WINPATHSEP_RE = re.compile(r"\\([^\"'\\]|$)") + + +def tempfile_arg_esc_func(arg): + from SCons.Subst import quote_spaces + + arg = quote_spaces(arg) + # GCC requires double Windows slashes, let's use UNIX separator + return WINPATHSEP_RE.sub(r"/\1", arg) + + def configure_mingw(env: "SConsEnvironment"): # Workaround for MinGW. See: # https://www.scons.org/wiki/LongCmdLinesOnWin32 @@ -640,6 +651,8 @@ def configure_mingw(env: "SConsEnvironment"): env["ARCOM_ORIG"] = env["ARCOM"] env["ARCOM"] = "${TEMPFILE('$ARCOM_ORIG', '$ARCOMSTR')}" env["TEMPFILESUFFIX"] = ".rsp" + if os.name == "nt": + env["TEMPFILEARGESCFUNC"] = tempfile_arg_esc_func ## Build type From 5afbf76cde470e860360c228b6b1a6cb79b6acf1 Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Wed, 25 Sep 2024 17:38:34 +0200 Subject: [PATCH 3/3] [4.3] [SCons] Remove MAXLINELENGTH override for MSVC It's not clear what is the actual max value that windows support, but despite their claim of it being 8191 we have been seeing failure with just 8150. (cherry picked from commit 395a4fc5f27b5cc8b9ebce3d66fd95be2eea9b3b) --- platform/windows/detect.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/platform/windows/detect.py b/platform/windows/detect.py index 245398fc9cdd..1d74bbe02471 100644 --- a/platform/windows/detect.py +++ b/platform/windows/detect.py @@ -387,8 +387,6 @@ def configure_msvc(env: "SConsEnvironment", vcvars_msvc_config): ## Compile/link flags - env["MAXLINELENGTH"] = 8192 # Windows Vista and beyond, so always applicable. - if env["silence_msvc"] and not env.GetOption("clean"): from tempfile import mkstemp