Skip to content

Commit

Permalink
Use fix_flags for cmake to double quote the entire flag when there is…
Browse files Browse the repository at this point in the history
… a space in it
  • Loading branch information
langmm committed Jul 16, 2024
1 parent 172078f commit ddd8ec7
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
6 changes: 3 additions & 3 deletions yggdrasil/command_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -699,9 +699,9 @@ def func(cls, args, return_str=False):
no_additional_stages=True,
skip_no_additional_stages_flag=True,
dry_run=args.dry_run)
out = ' '.join(flags)
out = tool.fix_flags(out, context='cmd', tool=tool,
for_gnu=args.gnu_style_flags)
out = ' '.join(
tool.fix_flags(flags, context='cmd', tool=tool,
for_gnu=args.gnu_style_flags))
# if platform._is_win: # pragma: windows
# if args.gnu_style_flags:
# out = out.replace('/', '-')
Expand Down
18 changes: 18 additions & 0 deletions yggdrasil/drivers/CMakeModelDriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,24 @@ def get_executable_command(cls, args, **kwargs):
return super(CMakeConfigure, cls).get_executable_command(
new_args, **kwargs)

@classmethod
def fix_flags(cls, flags, **kwargs):
r"""Update a string containing flags so that it can be used in
the given context.
Args:
flags (str): String containing flags.
**kwargs: Additional keyword arguments are passed to the
parent class.
"""
if ((isinstance(flags, str) and ' ' in flags
and kwargs.get('context', None) == 'flag')):
if '"' in flags:
flags = flags.replace('"', '\\"')
flags = f'"{flags}"'
return super(CMakeConfigure, cls).fix_flags(flags, **kwargs)

@classmethod
def fix_path(cls, path, **kwargs):
r"""Update a path so it can be used in the given context. This
Expand Down
17 changes: 11 additions & 6 deletions yggdrasil/drivers/CompiledModelDriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -3498,7 +3498,7 @@ def tool_flags(self, tooltype='basetool', no_additional_stages=False,
**self.specialization.remainder(kwargs))
kwargs = self.tool_kwargs(tooltype, **kwargs)
tool = self.tool(tooltype)
out = tool.get_flags(**kwargs)
out = tool.fix_flags(tool.get_flags(**kwargs), context='flag')
next_tool = self.next_tool(tool, self['libtype'])
if ((next_tool
and not (no_additional_stages
Expand Down Expand Up @@ -3851,11 +3851,12 @@ def _build_env(self, key, to_update=None,
context='env', tool=tool)
kenv = self.parameters.get(
f'env_{k}_flags', tool.default_flags_env)
out[kenv] = fixer.fix_flags(
' '.join(self.get(f'{k}_flags', dry_run=True,
no_additional_stages=True,
skip_no_additional_stages_flag=True)),
context='env', tool=tool)
out[kenv] = ' '.join(
fixer.fix_flags(
self.get(f'{k}_flags', dry_run=True,
no_additional_stages=True,
skip_no_additional_stages_flag=True),
context='env', tool=tool))
for k in tool.additional_flags_env:
out[k] = ''
return out
Expand Down Expand Up @@ -4520,6 +4521,10 @@ def fix_flags(cls, flags, context='flag', tool=None, for_gnu=None):
tool = cls
if for_gnu is None:
for_gnu = cls.is_gnu
if isinstance(flags, list):
return [cls.fix_flags(x, context=context, tool=tool,
for_gnu=for_gnu)
for x in flags]
out = flags
if tool.toolset == 'msvc' and for_gnu:
out = out.replace('/', '-')
Expand Down

0 comments on commit ddd8ec7

Please sign in to comment.