Skip to content

Commit

Permalink
Support deleting static library archives also on Windows
Browse files Browse the repository at this point in the history
Fixes #9414
  • Loading branch information
lb90 committed Nov 18, 2024
1 parent 47a8217 commit 79a20d2
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions mesonbuild/backend/ninjabackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,8 @@ def cmd_quote(arg: str) -> str:
# (see https://ninja-build.org/manual.html#ref_rule_command)
if mesonlib.is_windows():
quote_func = cmd_quote
execute_wrapper = ['cmd', '/c'] # unused
rmfile_prefix = ['del', '/f', '/s', '/q', '{}', '&&']
else:
quote_func = quote_arg
execute_wrapper = []
rmfile_prefix = ['rm', '-f', '{}', '&&']

def gcc_rsp_quote(s: str) -> str:
# see: the function buildargv() in libiberty
Expand Down Expand Up @@ -2314,15 +2310,17 @@ def generate_static_link_rules(self) -> None:
rule = 'STATIC_LINKER{}'.format(self.get_rule_suffix(for_machine))
cmdlist: T.List[T.Union[str, NinjaCommandArg]] = []
args = ['$in']
# FIXME: Must normalize file names with pathlib.Path before writing
# them out to fix this properly on Windows. See:
# https://github.com/mesonbuild/meson/issues/1517
# https://github.com/mesonbuild/meson/issues/1526
if isinstance(static_linker, ArLikeLinker) and not mesonlib.is_windows():
if isinstance(static_linker, ArLikeLinker):
# `ar` has no options to overwrite archives. It always appends,
# which is never what we want. Delete an existing library first if
# it exists. https://github.com/mesonbuild/meson/issues/1355
cmdlist = execute_wrapper + [c.format('$out') for c in rmfile_prefix]
if mesonlib.is_windows():
cmd = ' '.join(['cmd /Q /D /S /V:OFF /C'] + self.environment.get_build_command() + ['--internal', 'rm', '$out', '&&'])
cmdlist += [NinjaCommandArg(cmd, Quoting.none)]
#cmd = (self.environment.get_build_command() + ['--internal', 'rm', '$out', '&&']).join(' ')
#cmdlist += self.environment.get_build_command() + ['--internal', 'rm', '$out', '&&']
else:
cmdlist += ['rm', '-f', '$out', '&&']
cmdlist += static_linker.get_exelist()
cmdlist += ['$LINK_ARGS']
cmdlist += NinjaCommandArg.list(static_linker.get_output_args('$out'), Quoting.none)
Expand Down

0 comments on commit 79a20d2

Please sign in to comment.