From c6ec13e6bfe5292181370e47b813212eb193a0fb Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Sat, 29 May 2021 14:24:53 -0700 Subject: [PATCH] Only try to get RSP syntax if RSP is supported (#8804) --- mesonbuild/backend/ninjabackend.py | 36 +++++++++++++++++++----------- mesonbuild/linkers.py | 2 +- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index 6bd7ba61f..4e826ee13 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -1840,6 +1840,17 @@ int dummy; # Introspection information self.create_target_source_introspection(target, swiftc, compile_args + header_imports + module_includes, relsrc, rel_generated) + def _rsp_options(self, tool: T.Union['Compiler', 'StaticLinker', 'DynamicLinker']) -> T.Dict[str, T.Union[bool, RSPFileSyntax]]: + """Helper method to get rsp options. + + rsp_file_syntax() is only guaranteed to be implemented if + can_linker_accept_rsp() returns True. + """ + options = dict(rspable=tool.can_linker_accept_rsp()) + if options['rspable']: + options['rspfile_quote_style'] = tool.rsp_file_syntax() + return options + def generate_static_link_rules(self): num_pools = self.environment.coredata.options[OptionKey('backend_max_links')].value if 'java' in self.environment.coredata.compilers.host: @@ -1868,10 +1879,9 @@ int dummy; pool = 'pool = link_pool' else: pool = None - self.add_rule(NinjaRule(rule, cmdlist, args, description, - rspable=static_linker.can_linker_accept_rsp(), - rspfile_quote_style=static_linker.rsp_file_syntax(), - extra=pool)) + + options = self._rsp_options(static_linker) + self.add_rule(NinjaRule(rule, cmdlist, args, description, **options, extra=pool)) def generate_dynamic_link_rules(self): num_pools = self.environment.coredata.options[OptionKey('backend_max_links')].value @@ -1891,10 +1901,9 @@ int dummy; pool = 'pool = link_pool' else: pool = None - self.add_rule(NinjaRule(rule, command, args, description, - rspable=compiler.can_linker_accept_rsp(), - rspfile_quote_style=compiler.rsp_file_syntax(), - extra=pool)) + + options = self._rsp_options(compiler) + self.add_rule(NinjaRule(rule, command, args, description, **options, extra=pool)) args = self.environment.get_build_command() + \ ['--internal', @@ -1977,8 +1986,10 @@ https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47485''')) command = compiler.get_exelist() args = ['$ARGS'] + NinjaCommandArg.list(compiler.get_output_args('$out'), Quoting.none) + compiler.get_compile_only_args() + ['$in'] description = 'Compiling LLVM IR object $in' - self.add_rule(NinjaRule(rule, command, args, description, - rspable=compiler.can_linker_accept_rsp())) + + options = self._rsp_options(compiler) + + self.add_rule(NinjaRule(rule, command, args, description, **options)) self.created_llvm_ir_rule[compiler.for_machine] = True def generate_compile_rule_for(self, langname, compiler): @@ -2014,9 +2025,8 @@ https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47485''')) else: deps = 'gcc' depfile = '$DEPFILE' - self.add_rule(NinjaRule(rule, command, args, description, - rspable=compiler.can_linker_accept_rsp(), - rspfile_quote_style=compiler.rsp_file_syntax(), + options = self._rsp_options(compiler) + self.add_rule(NinjaRule(rule, command, args, description, **options, deps=deps, depfile=depfile)) def generate_pch_rule_for(self, langname, compiler): diff --git a/mesonbuild/linkers.py b/mesonbuild/linkers.py index acb2c4490..7b938ac8e 100644 --- a/mesonbuild/linkers.py +++ b/mesonbuild/linkers.py @@ -112,7 +112,7 @@ class StaticLinker: be implemented """ assert not self.can_linker_accept_rsp(), f'{self.id} linker accepts RSP, but doesn\' provide a supported format, this is a bug' - raise mesonlib.EnvironmentException(f'{self.id} does no implemnt rsp format, this shouldn\'t be called') + raise mesonlib.EnvironmentException(f'{self.id} does not implemnt rsp format, this shouldn\'t be called') class VisualStudioLikeLinker: