From 03e865b6e2b2565e2e09be585f692f8291197cba Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Thu, 25 Jul 2024 09:08:01 -0700 Subject: [PATCH] backend/ninja: use 32k byte limit for command lines on !Windows At an OS level, Unix-like OSes usually have very large or even unlimited sized command line limits. In practice, however, many applications do not handle this (intentionally or otherwise). Notably Wine has the same limits Windows does, 32,768 characters. Because we previously double counted most characters, we papered over most situations that we would need an RSP file on Unix-like OSes with Wine. To fix this issue I have set the command line limit to 32k, this is still a massive command line to pass without an RSP file, and will only cause the use of an RSP file where it is not strictly necessary in a small number of cases, but will fix Wine applications. Projects who wish to not use an RSP file can still set the MESON_RSP_THRESHOLD environment variable to a very large number instead. Fixes: #13414 Fixes: cf0fecfce ("backend/ninja: Fix bug in NinjaRule.length_estimate") --- mesonbuild/backend/ninjabackend.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index 552ddee1244e..b67d8619f5ee 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -99,10 +99,11 @@ def get_rsp_threshold() -> int: # and that has a limit of 8k. limit = 8192 else: - # On Linux, ninja always passes the commandline as a single - # big string to /bin/sh, and the kernel limits the size of a - # single argument; see MAX_ARG_STRLEN - limit = 131072 + # Unix-like OSes usualy have very large command line limits, (On Linux, + # for example, this is limited by the kernel's MAX_ARG_STRLEN). However, + # some programs place much lower limits, notably Wine which enforces a + # 32k limit like Windows. Therefore, we limit the command line to 32k. + limit = 32768 # Be conservative limit = limit // 2 return int(os.environ.get('MESON_RSP_THRESHOLD', limit))