Skip to content

Commit

Permalink
Move get_rsp_threshold function to mesonlib
Browse files Browse the repository at this point in the history
  • Loading branch information
bruchar1 committed Dec 19, 2024
1 parent 1512722 commit e672889
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 20 deletions.
21 changes: 1 addition & 20 deletions mesonbuild/backend/ninjabackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,27 +91,8 @@ def gcc_rsp_quote(s: str) -> str:

return quote_func(s)

def get_rsp_threshold() -> int:
'''Return a conservative estimate of the commandline size in bytes
above which a response file should be used. May be overridden for
debugging by setting environment variable MESON_RSP_THRESHOLD.'''

if mesonlib.is_windows():
# Usually 32k, but some projects might use cmd.exe,
# and that has a limit of 8k.
limit = 8192
else:
# Unix-like OSes usually 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))

# a conservative estimate of the command-line length limit
rsp_threshold = get_rsp_threshold()
rsp_threshold = mesonlib.get_rsp_threshold()

# ninja variables whose value should remain unquoted. The value of these ninja
# variables (or variables we use them in) is interpreted directly by ninja
Expand Down
21 changes: 21 additions & 0 deletions mesonbuild/utils/universal.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class _VerPickleLoadable(Protocol):
'generate_list',
'get_compiler_for_source',
'get_filenames_templates_dict',
'get_rsp_threshold',
'get_variable_regex',
'get_wine_shortpath',
'git',
Expand Down Expand Up @@ -2367,3 +2368,23 @@ def first(iter: T.Iterable[_T], predicate: T.Callable[[_T], bool]) -> T.Optional
if predicate(i):
return i
return None


def get_rsp_threshold() -> int:
'''Return a conservative estimate of the commandline size in bytes
above which a response file should be used. May be overridden for
debugging by setting environment variable MESON_RSP_THRESHOLD.'''

if is_windows():
# Usually 32k, but some projects might use cmd.exe,
# and that has a limit of 8k.
limit = 8192
else:
# Unix-like OSes usually 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))

0 comments on commit e672889

Please sign in to comment.