Skip to content

Commit

Permalink
Remove get_buildtype_args function
Browse files Browse the repository at this point in the history
This is a first step to make `buildtype` a true alias of `debug` and
`optimization` options.

See mesonbuild#10808.

Relates to:
- mesonbuild#11645
- mesonbuild#12096
- mesonbuild#5920
- mesonbuild#5814
- mesonbuild#8220
- mesonbuild#8493
- mesonbuild#9540
- mesonbuild#10487
- mesonbuild#12265
- mesonbuild#8308
- mesonbuild#8214
- mesonbuild#7194
- mesonbuild#11732
  • Loading branch information
bruchar1 authored and gerioldman committed Jul 2, 2024
1 parent 9a69214 commit 6f40300
Show file tree
Hide file tree
Showing 26 changed files with 108 additions and 363 deletions.
5 changes: 0 additions & 5 deletions mesonbuild/backend/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -1001,11 +1001,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 @@ -1444,15 +1444,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 @@ -1495,7 +1493,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 @@ -1726,7 +1723,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 @@ -3358,7 +3354,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 @@ -1103,9 +1103,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 @@ -1267,7 +1266,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 @@ -1380,10 +1379,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 @@ -1611,7 +1607,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 @@ -181,78 +181,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 @@ -270,26 +198,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 @@ -1070,11 +984,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 @@ -10,7 +10,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 Down Expand Up @@ -103,9 +103,6 @@ def sanity_check(self, work_dir: str, environment: 'Environment') -> None:
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 @@ -129,16 +126,11 @@ class VisualStudioCsCompiler(CsCompiler):

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 @@ -14,8 +14,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 @@ -29,6 +28,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 @@ -692,12 +707,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 @@ -712,8 +721,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

0 comments on commit 6f40300

Please sign in to comment.