ninjabackend: Use rsp_file_syntax method

This also makes us of the new enum value in the backend, for better type
saftey.
pull/8532/head
Dylan Baker 4 years ago
parent 320412b3bb
commit 2be074b1d4
  1. 33
      mesonbuild/backend/ninjabackend.py
  2. 7
      mesonbuild/compilers/d.py
  3. 2
      mesonbuild/environment.py

@ -32,14 +32,11 @@ from .. import compilers
from ..arglist import CompilerArgs from ..arglist import CompilerArgs
from ..compilers import ( from ..compilers import (
Compiler, CCompiler, Compiler, CCompiler,
DmdDCompiler,
FortranCompiler, FortranCompiler,
LLVMDCompiler,
PGICCompiler, PGICCompiler,
VisualStudioCsCompiler,
VisualStudioLikeCompiler, VisualStudioLikeCompiler,
) )
from ..linkers import ArLinker, VisualStudioLinker from ..linkers import ArLinker, RSPFileSyntax
from ..mesonlib import ( from ..mesonlib import (
File, LibType, MachineChoice, MesonException, OrderedSet, PerMachine, File, LibType, MachineChoice, MesonException, OrderedSet, PerMachine,
ProgressBar, quote_arg, unholder, ProgressBar, quote_arg, unholder,
@ -51,6 +48,8 @@ from ..interpreter import Interpreter
if T.TYPE_CHECKING: if T.TYPE_CHECKING:
from ..linkers import StaticLinker from ..linkers import StaticLinker
from ..compilers.cs import CsCompiler
FORTRAN_INCLUDE_PAT = r"^\s*#?include\s*['\"](\w+\.\w+)['\"]" FORTRAN_INCLUDE_PAT = r"^\s*#?include\s*['\"](\w+\.\w+)['\"]"
FORTRAN_MODULE_PAT = r"^\s*\bmodule\b\s+(\w+)\s*(?:!+.*)*$" FORTRAN_MODULE_PAT = r"^\s*\bmodule\b\s+(\w+)\s*(?:!+.*)*$"
@ -92,12 +91,6 @@ else:
rmfile_prefix = ['rm', '-f', '{}', '&&'] rmfile_prefix = ['rm', '-f', '{}', '&&']
def dlang_cl_rsp(compiler: Compiler) -> bool:
'''Return whether the D compiler accepts cl style RSP quote'''
return (isinstance(compiler, DmdDCompiler) or
mesonlib.is_windows() and isinstance(compiler, LLVMDCompiler))
def get_rsp_threshold(): def get_rsp_threshold():
'''Return a conservative estimate of the commandline size in bytes '''Return a conservative estimate of the commandline size in bytes
above which a response file should be used. May be overridden for above which a response file should be used. May be overridden for
@ -183,7 +176,7 @@ class NinjaComment:
class NinjaRule: class NinjaRule:
def __init__(self, rule, command, args, description, def __init__(self, rule, command, args, description,
rspable = False, deps = None, depfile = None, extra = None, rspable = False, deps = None, depfile = None, extra = None,
rspfile_quote_style = 'gcc'): rspfile_quote_style: RSPFileSyntax = RSPFileSyntax.GCC):
def strToCommandArg(c): def strToCommandArg(c):
if isinstance(c, NinjaCommandArg): if isinstance(c, NinjaCommandArg):
@ -217,7 +210,7 @@ class NinjaRule:
self.rspable = rspable # if a rspfile can be used self.rspable = rspable # if a rspfile can be used
self.refcount = 0 self.refcount = 0
self.rsprefcount = 0 self.rsprefcount = 0
self.rspfile_quote_style = rspfile_quote_style # rspfile quoting style is 'gcc' or 'cl' self.rspfile_quote_style = rspfile_quote_style
if self.depfile == '$DEPFILE': if self.depfile == '$DEPFILE':
self.depfile += '_UNQUOTED' self.depfile += '_UNQUOTED'
@ -235,7 +228,7 @@ class NinjaRule:
return ninja_quote(qf(str(x))) return ninja_quote(qf(str(x)))
def write(self, outfile): def write(self, outfile):
if self.rspfile_quote_style == 'cl': if self.rspfile_quote_style is RSPFileSyntax.MSVC:
rspfile_quote_func = cmd_quote rspfile_quote_func = cmd_quote
else: else:
rspfile_quote_func = gcc_rsp_quote rspfile_quote_func = gcc_rsp_quote
@ -395,7 +388,7 @@ class NinjaBuildElement:
outfile.write(line) outfile.write(line)
if use_rspfile: if use_rspfile:
if self.rule.rspfile_quote_style == 'cl': if self.rule.rspfile_quote_style is RSPFileSyntax.MSVC:
qf = cmd_quote qf = cmd_quote
else: else:
qf = gcc_rsp_quote qf = gcc_rsp_quote
@ -1872,7 +1865,7 @@ int dummy;
pool = None pool = None
self.add_rule(NinjaRule(rule, cmdlist, args, description, self.add_rule(NinjaRule(rule, cmdlist, args, description,
rspable=static_linker.can_linker_accept_rsp(), rspable=static_linker.can_linker_accept_rsp(),
rspfile_quote_style='cl' if isinstance(static_linker, VisualStudioLinker) else 'gcc', rspfile_quote_style=static_linker.rsp_file_syntax(),
extra=pool)) extra=pool))
def generate_dynamic_link_rules(self): def generate_dynamic_link_rules(self):
@ -1895,8 +1888,7 @@ int dummy;
pool = None pool = None
self.add_rule(NinjaRule(rule, command, args, description, self.add_rule(NinjaRule(rule, command, args, description,
rspable=compiler.can_linker_accept_rsp(), rspable=compiler.can_linker_accept_rsp(),
rspfile_quote_style='cl' if (compiler.get_argument_syntax() == 'msvc' or rspfile_quote_style=compiler.rsp_file_syntax(),
dlang_cl_rsp(compiler)) else 'gcc',
extra=pool)) extra=pool))
args = self.environment.get_build_command() + \ args = self.environment.get_build_command() + \
@ -1918,14 +1910,14 @@ int dummy;
description = 'Compiling Java object $in' description = 'Compiling Java object $in'
self.add_rule(NinjaRule(rule, command, [], description)) self.add_rule(NinjaRule(rule, command, [], description))
def generate_cs_compile_rule(self, compiler): def generate_cs_compile_rule(self, compiler: 'CsCompiler') -> None:
rule = self.compiler_to_rule_name(compiler) rule = self.compiler_to_rule_name(compiler)
command = compiler.get_exelist() command = compiler.get_exelist()
args = ['$ARGS', '$in'] args = ['$ARGS', '$in']
description = 'Compiling C Sharp target $out' description = 'Compiling C Sharp target $out'
self.add_rule(NinjaRule(rule, command, args, description, self.add_rule(NinjaRule(rule, command, args, description,
rspable=mesonlib.is_windows(), rspable=mesonlib.is_windows(),
rspfile_quote_style='cl' if isinstance(compiler, VisualStudioCsCompiler) else 'gcc')) rspfile_quote_style=compiler.rsp_file_syntax()))
def generate_vala_compile_rules(self, compiler): def generate_vala_compile_rules(self, compiler):
rule = self.compiler_to_rule_name(compiler) rule = self.compiler_to_rule_name(compiler)
@ -2019,8 +2011,7 @@ https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47485'''))
depfile = '$DEPFILE' depfile = '$DEPFILE'
self.add_rule(NinjaRule(rule, command, args, description, self.add_rule(NinjaRule(rule, command, args, description,
rspable=compiler.can_linker_accept_rsp(), rspable=compiler.can_linker_accept_rsp(),
rspfile_quote_style='cl' if (compiler.get_argument_syntax() == 'msvc' or rspfile_quote_style=compiler.rsp_file_syntax(),
dlang_cl_rsp(compiler)) else 'gcc',
deps=deps, depfile=depfile)) deps=deps, depfile=depfile))
def generate_pch_rule_for(self, langname, compiler): def generate_pch_rule_for(self, langname, compiler):

@ -22,6 +22,7 @@ from ..mesonlib import (
) )
from ..arglist import CompilerArgs from ..arglist import CompilerArgs
from ..linkers import RSPFileSyntax
from .compilers import ( from .compilers import (
d_dmd_buildtype_args, d_dmd_buildtype_args,
d_gdc_buildtype_args, d_gdc_buildtype_args,
@ -36,7 +37,7 @@ if T.TYPE_CHECKING:
from ..dependencies import Dependency, ExternalProgram from ..dependencies import Dependency, ExternalProgram
from ..envconfig import MachineInfo from ..envconfig import MachineInfo
from ..environment import Environment from ..environment import Environment
from ..linkers import DynamicLinker, RSPFileSyntax from ..linkers import DynamicLinker
else: else:
CompilerMixinBase = object CompilerMixinBase = object
@ -780,7 +781,7 @@ class LLVMDCompiler(DmdLikeCompilerMixin, DCompiler):
def get_disable_assert_args(self) -> T.List[str]: def get_disable_assert_args(self) -> T.List[str]:
return ['--release'] return ['--release']
def rsp_file_syntax(self) -> 'RSPFileSyntax': def rsp_file_syntax(self) -> RSPFileSyntax:
# We use `mesonlib.is_windows` here because we want to konw what the # We use `mesonlib.is_windows` here because we want to konw what the
# build machine is, not the host machine. This really means whe whould # build machine is, not the host machine. This really means whe whould
# have the Environment not the MachineInfo in the compiler. # have the Environment not the MachineInfo in the compiler.
@ -867,5 +868,5 @@ class DmdDCompiler(DmdLikeCompilerMixin, DCompiler):
def get_disable_assert_args(self) -> T.List[str]: def get_disable_assert_args(self) -> T.List[str]:
return ['-release'] return ['-release']
def rsp_file_syntax(self) -> 'RSPFileSyntax': def rsp_file_syntax(self) -> RSPFileSyntax:
return RSPFileSyntax.MSVC return RSPFileSyntax.MSVC

@ -2061,7 +2061,7 @@ class Environment:
if 'DMD32 D Compiler' in out or 'DMD64 D Compiler' in out: if 'DMD32 D Compiler' in out or 'DMD64 D Compiler' in out:
return DLinker(linker, compiler.arch) return DLinker(linker, compiler.arch)
if 'LDC - the LLVM D compiler' in out: if 'LDC - the LLVM D compiler' in out:
return DLinker(linker, compiler.arch) return DLinker(linker, compiler.arch, rsp_syntax=compiler.rsp_file_syntax())
if 'GDC' in out and ' based on D ' in out: if 'GDC' in out and ' based on D ' in out:
return DLinker(linker, compiler.arch) return DLinker(linker, compiler.arch)
if err.startswith('Renesas') and ('rlink' in linker or 'rlink.exe' in linker): if err.startswith('Renesas') and ('rlink' in linker or 'rlink.exe' in linker):

Loading…
Cancel
Save