Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove get_buildtype_args function #12575

Merged
merged 1 commit into from
Dec 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions mesonbuild/backend/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -1016,11 +1016,6 @@ def generate_basic_compiler_args(self, target: build.BuildTarget, compiler: 'Com
# command-line or default_options inside project().
commands += compiler.get_option_compile_args(copt_proxy)

# Add buildtype args: optimization level, debugging, etc.
buildtype = target.get_option(OptionKey('buildtype'))
assert isinstance(buildtype, str), 'for mypy'
commands += compiler.get_buildtype_args(buildtype)

optimization = target.get_option(OptionKey('optimization'))
assert isinstance(optimization, str), 'for mypy'
commands += compiler.get_optimization_args(optimization)
Expand Down
6 changes: 1 addition & 5 deletions mesonbuild/backend/ninjabackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -1458,15 +1458,13 @@ def generate_cs_resource_tasks(self, target):
return args, deps

def generate_cs_target(self, target: build.BuildTarget):
buildtype = target.get_option(OptionKey('buildtype'))
fname = target.get_filename()
outname_rel = os.path.join(self.get_target_dir(target), fname)
src_list = target.get_sources()
compiler = target.compilers['cs']
rel_srcs = [os.path.normpath(s.rel_to_builddir(self.build_to_src)) for s in src_list]
deps = []
commands = compiler.compiler_args(target.extra_args['cs'])
commands += compiler.get_buildtype_args(buildtype)
commands += compiler.get_optimization_args(target.get_option(OptionKey('optimization')))
commands += compiler.get_debug_args(target.get_option(OptionKey('debug')))
if isinstance(target, build.Executable):
Expand Down Expand Up @@ -1509,7 +1507,6 @@ def generate_cs_target(self, target: build.BuildTarget):

def determine_single_java_compile_args(self, target, compiler):
args = []
args += compiler.get_buildtype_args(target.get_option(OptionKey('buildtype')))
args += self.build.get_global_args(compiler, target.for_machine)
args += self.build.get_project_args(compiler, target.subproject, target.for_machine)
args += target.get_java_args()
Expand Down Expand Up @@ -1742,7 +1739,6 @@ def generate_cython_transpile(self, target: build.BuildTarget) -> \

args: T.List[str] = []
args += cython.get_always_args()
args += cython.get_buildtype_args(target.get_option(OptionKey('buildtype')))
args += cython.get_debug_args(target.get_option(OptionKey('debug')))
args += cython.get_optimization_args(target.get_option(OptionKey('optimization')))
args += cython.get_option_compile_args(target.get_options())
Expand Down Expand Up @@ -3379,7 +3375,7 @@ def generate_link(self, target: build.BuildTarget, outname, obj_list, linker: T.
# Add things like /NOLOGO; usually can't be overridden
commands += linker.get_linker_always_args()
# Add buildtype linker args: optimization level, etc.
commands += linker.get_buildtype_linker_args(target.get_option(OptionKey('buildtype')))
commands += linker.get_optimization_link_args(target.get_option(OptionKey('optimization')))
# Add /DEBUG and the pdb filename when using MSVC
if target.get_option(OptionKey('debug')):
commands += self.get_link_debugfile_args(linker, target)
Expand Down
14 changes: 5 additions & 9 deletions mesonbuild/backend/vs2010backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -1126,9 +1126,8 @@ def get_args_defines_and_inc_dirs(self, target, compiler, generated_files_includ
return (target_args, file_args), (target_defines, file_defines), (target_inc_dirs, file_inc_dirs)

@staticmethod
def get_build_args(compiler, buildtype: str, optimization_level: str, debug: bool, sanitize: str) -> T.List[str]:
build_args = compiler.get_buildtype_args(buildtype)
build_args += compiler.get_optimization_args(optimization_level)
def get_build_args(compiler, optimization_level: str, debug: bool, sanitize: str) -> T.List[str]:
build_args = compiler.get_optimization_args(optimization_level)
build_args += compiler.get_debug_args(debug)
build_args += compiler.sanitizer_compile_args(sanitize)

Expand Down Expand Up @@ -1290,7 +1289,7 @@ def add_non_makefile_vcxproj_elements(
file_args
) -> None:
compiler = self._get_cl_compiler(target)
buildtype_link_args = compiler.get_buildtype_linker_args(self.buildtype)
buildtype_link_args = compiler.get_optimization_link_args(self.optimization)

# Prefix to use to access the build root from the vcxproj dir
down = self.target_to_build_root(target)
Expand Down Expand Up @@ -1403,10 +1402,7 @@ def add_non_makefile_vcxproj_elements(
# Linker options
link = ET.SubElement(compiles, 'Link')
extra_link_args = compiler.compiler_args()
# FIXME: Can these buildtype linker args be added as tags in the
# vcxproj file (similar to buildtype compiler args) instead of in
# AdditionalOptions?
extra_link_args += compiler.get_buildtype_linker_args(self.buildtype)
extra_link_args += compiler.get_optimization_link_args(self.optimization)
# Generate Debug info
if self.debug:
self.generate_debug_information(link)
Expand Down Expand Up @@ -1634,7 +1630,7 @@ def gen_vcxproj(self, target: build.BuildTarget, ofname: str, guid: str, vslite_
gen_hdrs += custom_hdrs

compiler = self._get_cl_compiler(target)
build_args = Vs2010Backend.get_build_args(compiler, self.buildtype, self.optimization, self.debug, self.sanitize)
build_args = Vs2010Backend.get_build_args(compiler, self.optimization, self.debug, self.sanitize)

assert isinstance(target, (build.Executable, build.SharedLibrary, build.StaticLibrary, build.SharedModule)), 'for mypy'
# Prefix to use to access the build root from the vcxproj dir
Expand Down
12 changes: 0 additions & 12 deletions mesonbuild/compilers/asm.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,6 @@ def sanity_check(self, work_dir: str, environment: 'Environment') -> None:
if self.info.cpu_family not in {'x86', 'x86_64'}:
raise EnvironmentException(f'ASM compiler {self.id!r} does not support {self.info.cpu_family} CPU family')

def get_buildtype_args(self, buildtype: str) -> T.List[str]:
# FIXME: Not implemented
return []

def get_pic_args(self) -> T.List[str]:
return []

Expand Down Expand Up @@ -185,10 +181,6 @@ def sanity_check(self, work_dir: str, environment: 'Environment') -> None:
if self.info.cpu_family not in {'x86', 'x86_64'}:
raise EnvironmentException(f'ASM compiler {self.id!r} does not support {self.info.cpu_family} CPU family')

def get_buildtype_args(self, buildtype: str) -> T.List[str]:
# FIXME: Not implemented
return []

def get_pic_args(self) -> T.List[str]:
return []

Expand Down Expand Up @@ -240,10 +232,6 @@ def sanity_check(self, work_dir: str, environment: 'Environment') -> None:
if self.info.cpu_family not in {'arm', 'aarch64'}:
raise EnvironmentException(f'ASM compiler {self.id!r} does not support {self.info.cpu_family} CPU family')

def get_buildtype_args(self, buildtype: str) -> T.List[str]:
# FIXME: Not implemented
return []

def get_pic_args(self) -> T.List[str]:
return []

Expand Down
95 changes: 3 additions & 92 deletions mesonbuild/compilers/compilers.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,78 +190,6 @@ class CompileCheckMode(enum.Enum):
LINK = 'link'


cuda_buildtype_args: T.Dict[str, T.List[str]] = {
'plain': [],
'debug': ['-g', '-G'],
'debugoptimized': ['-g', '-lineinfo'],
'release': [],
'minsize': [],
'custom': [],
}

java_buildtype_args: T.Dict[str, T.List[str]] = {
'plain': [],
'debug': ['-g'],
'debugoptimized': ['-g'],
'release': [],
'minsize': [],
'custom': [],
}

rust_buildtype_args: T.Dict[str, T.List[str]] = {
'plain': [],
'debug': [],
'debugoptimized': [],
'release': [],
'minsize': [],
'custom': [],
}

d_gdc_buildtype_args: T.Dict[str, T.List[str]] = {
'plain': [],
'debug': [],
'debugoptimized': ['-finline-functions'],
'release': ['-finline-functions'],
'minsize': [],
'custom': [],
}

d_ldc_buildtype_args: T.Dict[str, T.List[str]] = {
'plain': [],
'debug': [],
'debugoptimized': ['-enable-inlining', '-Hkeep-all-bodies'],
'release': ['-enable-inlining', '-Hkeep-all-bodies'],
'minsize': [],
'custom': [],
}

d_dmd_buildtype_args: T.Dict[str, T.List[str]] = {
'plain': [],
'debug': [],
'debugoptimized': ['-inline'],
'release': ['-inline'],
'minsize': [],
'custom': [],
}

mono_buildtype_args: T.Dict[str, T.List[str]] = {
'plain': [],
'debug': [],
'debugoptimized': ['-optimize+'],
'release': ['-optimize+'],
'minsize': [],
'custom': [],
}

swift_buildtype_args: T.Dict[str, T.List[str]] = {
'plain': [],
'debug': [],
'debugoptimized': [],
'release': [],
'minsize': [],
'custom': [],
}

gnu_winlibs = ['-lkernel32', '-luser32', '-lgdi32', '-lwinspool', '-lshell32',
'-lole32', '-loleaut32', '-luuid', '-lcomdlg32', '-ladvapi32']

Expand All @@ -279,26 +207,12 @@ class CompileCheckMode(enum.Enum):
's': ['-Os'],
}

cuda_optimization_args: T.Dict[str, T.List[str]] = {
'plain': [],
'0': [],
'g': ['-O0'],
'1': ['-O1'],
'2': ['-O2'],
'3': ['-O3'],
's': ['-O3']
}

cuda_debug_args: T.Dict[bool, T.List[str]] = {
False: [],
True: ['-g']
}

clike_debug_args: T.Dict[bool, T.List[str]] = {
False: [],
True: ['-g']
}


MSCRT_VALS = ['none', 'md', 'mdd', 'mt', 'mtd']

base_options: 'KeyedOptionDictType' = {
Expand Down Expand Up @@ -1067,11 +981,8 @@ def headerpad_args(self) -> T.List[str]:
def bitcode_args(self) -> T.List[str]:
return self.linker.bitcode_args()

def get_buildtype_args(self, buildtype: str) -> T.List[str]:
raise EnvironmentException(f'{self.id} does not implement get_buildtype_args')

def get_buildtype_linker_args(self, buildtype: str) -> T.List[str]:
return self.linker.get_buildtype_args(buildtype)
def get_optimization_link_args(self, optimization_level: str) -> T.List[str]:
return self.linker.get_optimization_link_args(optimization_level)

def get_soname_args(self, env: 'Environment', prefix: str, shlib_name: str,
suffix: str, soversion: str,
Expand Down
20 changes: 6 additions & 14 deletions mesonbuild/compilers/cs.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from ..mesonlib import EnvironmentException
from ..linkers import RSPFileSyntax

from .compilers import Compiler, mono_buildtype_args
from .compilers import Compiler
from .mixins.islinker import BasicLinkerIsCompilerMixin

if T.TYPE_CHECKING:
Expand All @@ -39,7 +39,7 @@
}


class CsCompiler(BasicLinkerIsCompilerMixin, Compiler):

Check warning

Code scanning / CodeQL

Conflicting attributes in base classes Warning

Base classes have conflicting values for attribute 'thread_flags':
Function thread_flags
and
Function thread_flags
.
Base classes have conflicting values for attribute 'can_linker_accept_rsp':
Function can_linker_accept_rsp
and
Function can_linker_accept_rsp
.
Base classes have conflicting values for attribute 'get_option_link_args':
Function get_option_link_args
and
Function get_option_link_args
.
Base classes have conflicting values for attribute 'get_coverage_link_args':
Function get_coverage_link_args
and
Function get_coverage_link_args
.
Base classes have conflicting values for attribute 'get_lto_link_args':
Function get_lto_link_args
and
Function get_lto_link_args
.
Base classes have conflicting values for attribute 'get_linker_exelist':
Function get_linker_exelist
and
Function get_linker_exelist
.
Base classes have conflicting values for attribute 'get_linker_output_args':
Function get_linker_output_args
and
Function get_linker_output_args
.
Base classes have conflicting values for attribute 'get_linker_lib_prefix':
Function get_linker_lib_prefix
and
Function get_linker_lib_prefix
.
Base classes have conflicting values for attribute 'get_link_debugfile_name':
Function get_link_debugfile_name
and
Function get_link_debugfile_name
.
Base classes have conflicting values for attribute 'get_link_debugfile_args':
Function get_link_debugfile_args
and
Function get_link_debugfile_args
.
Base classes have conflicting values for attribute 'get_std_shared_lib_link_args':
Function get_std_shared_lib_link_args
and
Function get_std_shared_lib_link_args
.
Base classes have conflicting values for attribute 'get_link_whole_for':
Function get_link_whole_for
and
Function get_link_whole_for
.
Base classes have conflicting values for attribute 'get_allow_undefined_link_args':
Function get_allow_undefined_link_args
and
Function get_allow_undefined_link_args
.
Base classes have conflicting values for attribute 'no_undefined_link_args':
Function no_undefined_link_args
and
Function no_undefined_link_args
.
Base classes have conflicting values for attribute 'build_rpath_args':
Function build_rpath_args
and
Function build_rpath_args
.
Base classes have conflicting values for attribute 'thread_link_flags':
Function thread_link_flags
and
Function thread_link_flags
.
Base classes have conflicting values for attribute 'get_pie_link_args':
Function get_pie_link_args
and
Function get_pie_link_args
.
Base classes have conflicting values for attribute 'sanitizer_link_args':
Function sanitizer_link_args
and
Function sanitizer_link_args
.
Base classes have conflicting values for attribute 'get_asneeded_args':
Function get_asneeded_args
and
Function get_asneeded_args
.
Base classes have conflicting values for attribute 'bitcode_args':
Function bitcode_args
and
Function bitcode_args
.
Base classes have conflicting values for attribute 'get_optimization_link_args':
Function get_optimization_link_args
and
Function get_optimization_link_args
.
Base classes have conflicting values for attribute 'get_soname_args':
Function get_soname_args
and
Function get_soname_args
.

language = 'cs'

Expand Down Expand Up @@ -113,9 +113,6 @@
def needs_static_linker(self) -> bool:
return False

def get_buildtype_args(self, buildtype: str) -> T.List[str]:
return mono_buildtype_args[buildtype]

def get_debug_args(self, is_debug: bool) -> T.List[str]:
return ['-debug'] if is_debug else []

Expand All @@ -139,16 +136,11 @@

id = 'csc'

def get_buildtype_args(self, buildtype: str) -> T.List[str]:
res = mono_buildtype_args[buildtype]
if not self.info.is_windows():
tmp = []
for flag in res:
if flag == '-debug':
flag = '-debug:portable'
tmp.append(flag)
res = tmp
return res
def get_debug_args(self, is_debug: bool) -> T.List[str]:
if is_debug:
return ['-debug'] if self.info.is_windows() else ['-debug:portable']
else:
return []

def rsp_file_syntax(self) -> 'RSPFileSyntax':
return RSPFileSyntax.MSVC
29 changes: 19 additions & 10 deletions mesonbuild/compilers/cuda.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
EnvironmentException, Popen_safe,
is_windows, LibType, OptionKey, version_compare,
)
from .compilers import (Compiler, cuda_buildtype_args, cuda_optimization_args,
cuda_debug_args)
from .compilers import Compiler

if T.TYPE_CHECKING:
from .compilers import CompileCheckMode
Expand All @@ -39,6 +38,22 @@
from ..programs import ExternalProgram


cuda_optimization_args: T.Dict[str, T.List[str]] = {
'plain': [],
'0': ['-G'],
'g': ['-O0'],
'1': ['-O1'],
'2': ['-O2', '-lineinfo'],
'3': ['-O3'],
's': ['-O3']
}

cuda_debug_args: T.Dict[bool, T.List[str]] = {
False: [],
True: ['-g']
}


class _Phase(enum.Enum):

COMPILER = 'compiler'
Expand Down Expand Up @@ -702,12 +717,6 @@ def get_werror_args(self) -> T.List[str]:
def get_warn_args(self, level: str) -> T.List[str]:
return self.warn_args[level]

def get_buildtype_args(self, buildtype: str) -> T.List[str]:
# nvcc doesn't support msvc's "Edit and Continue" PDB format; "downgrade" to
# a regular PDB to avoid cl's warning to that effect (D9025 : overriding '/ZI' with '/Zi')
host_args = ['/Zi' if arg == '/ZI' else arg for arg in self.host_compiler.get_buildtype_args(buildtype)]
return cuda_buildtype_args[buildtype] + self._to_host_flags(host_args)

def get_include_args(self, path: str, is_system: bool) -> T.List[str]:
if path == '':
path = '.'
Expand All @@ -722,8 +731,8 @@ def get_link_debugfile_args(self, targetfile: str) -> T.List[str]:
def get_depfile_suffix(self) -> str:
return 'd'

def get_buildtype_linker_args(self, buildtype: str) -> T.List[str]:
return self._to_host_flags(self.host_compiler.get_buildtype_linker_args(buildtype), _Phase.LINKER)
def get_optimization_link_args(self, optimization_level: str) -> T.List[str]:
return self._to_host_flags(self.host_compiler.get_optimization_link_args(optimization_level), _Phase.LINKER)

def build_rpath_args(self, env: 'Environment', build_dir: str, from_dir: str,
rpath_paths: T.Tuple[str, ...], build_rpath: str,
Expand Down
4 changes: 0 additions & 4 deletions mesonbuild/compilers/cython.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@ def sanity_check(self, work_dir: str, environment: 'Environment') -> None:
if p.returncode != 0:
raise EnvironmentException(f'Cython compiler {self.id!r} cannot compile programs')

def get_buildtype_args(self, buildtype: str) -> T.List[str]:
# Cython doesn't implement this, but Meson requires an implementation
return []

def get_pic_args(self) -> T.List[str]:
# We can lie here, it's fine
return []
Expand Down
Loading
Loading