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 #10808.

Relates to:
- #11645
- #12096
- #5920
- #5814
- #8220
- #8493
- #9540
- #10487
- #12265
- #8308
- #8214
- #7194
- #11732
  • Loading branch information
bruchar1 committed Dec 5, 2023
1 parent 30184a4 commit 677e04d
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 @@ -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 Down Expand Up @@ -113,9 +113,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 @@ -139,16 +136,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 @@ -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

0 comments on commit 677e04d

Please sign in to comment.