msvc: unify debug filename handling

The MSVC code is extremely confusing, and it turns out it actually
constructs debug (pdb) files names/path independently in separate
places. This is really hard to parse. Instead, refactor it so that the
source of the debug filename is within the target itself
(get_debug_filename). Add a couple of generic methods to retrieve the
full path of the debug filename name in the backend and use that when
needed.
pull/12340/head
Dudemanguy 2 years ago committed by Dylan Baker
parent ed9d03a088
commit 4fadb2a296
  1. 14
      mesonbuild/backend/backends.py
  2. 16
      mesonbuild/backend/ninjabackend.py
  3. 10
      mesonbuild/build.py
  4. 3
      mesonbuild/linkers/linkers.py

@ -316,6 +316,20 @@ class Backend:
def get_target_filename_abs(self, target: T.Union[build.Target, build.CustomTargetIndex]) -> str:
return os.path.join(self.environment.get_build_dir(), self.get_target_filename(target))
def get_target_debug_filename(self, target: build.BuildTarget) -> T.Optional[str]:
assert isinstance(target, build.BuildTarget), target
if target.get_debug_filename():
debug_filename = target.get_debug_filename()
return os.path.join(self.get_target_dir(target), debug_filename)
else:
return None
def get_target_debug_filename_abs(self, target: build.BuildTarget) -> T.Optional[str]:
assert isinstance(target, build.BuildTarget), target
if not target.get_debug_filename():
return None
return os.path.join(self.environment.get_build_dir(), self.get_target_debug_filename(target))
def get_source_dir_include_args(self, target: build.BuildTarget, compiler: 'Compiler', *, absolute_path: bool = False) -> T.List[str]:
curdir = target.get_subdir()
if absolute_path:

@ -2797,16 +2797,18 @@ https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47485'''))
# this is actually doable, please send patches.
if target.has_pch():
tfilename = self.get_target_filename_abs(target)
tfilename = self.get_target_debug_filename_abs(target)
if not tfilename:
tfilename = self.get_target_filename_abs(target)
return compiler.get_compile_debugfile_args(tfilename, pch=True)
else:
return compiler.get_compile_debugfile_args(objfile, pch=False)
def get_link_debugfile_name(self, linker, target, outname) -> T.Optional[str]:
return linker.get_link_debugfile_name(outname)
def get_link_debugfile_name(self, linker, target) -> T.Optional[str]:
return linker.get_link_debugfile_name(self.get_target_debug_filename(target))
def get_link_debugfile_args(self, linker, target, outname):
return linker.get_link_debugfile_args(outname)
def get_link_debugfile_args(self, linker, target):
return linker.get_link_debugfile_args(self.get_target_debug_filename(target))
def generate_llvm_ir_compile(self, target, src):
base_proxy = target.get_options()
@ -3440,8 +3442,8 @@ https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47485'''))
commands += linker.get_buildtype_linker_args(target.get_option(OptionKey('buildtype')))
# Add /DEBUG and the pdb filename when using MSVC
if target.get_option(OptionKey('debug')):
commands += self.get_link_debugfile_args(linker, target, outname)
debugfile = self.get_link_debugfile_name(linker, target, outname)
commands += self.get_link_debugfile_args(linker, target)
debugfile = self.get_link_debugfile_name(linker, target)
if debugfile is not None:
implicit_outs += [debugfile]
# Add link args specific to this BuildTarget type, such as soname args,

@ -737,6 +737,8 @@ class BuildTarget(Target):
self.name_prefix_set = False
self.name_suffix_set = False
self.filename = 'no_name'
# The debugging information file this target will generate
self.debug_filename = None
# The list of all files outputted by this target. Useful in cases such
# as Vala which generates .vapi and .h besides the compiled output.
self.outputs = [self.filename]
@ -1262,6 +1264,14 @@ class BuildTarget(Target):
def get_filename(self) -> str:
return self.filename
def get_debug_filename(self) -> T.Optional[str]:
"""
The name of debuginfo file that will be created by the compiler
Returns None if the build won't create any debuginfo file
"""
return self.debug_filename
def get_outputs(self) -> T.List[str]:
return self.outputs

@ -1272,8 +1272,7 @@ class VisualStudioLikeLinkerMixin(DynamicLinkerBase):
return self._apply_prefix('/DLL')
def get_debugfile_name(self, targetfile: str) -> str:
basename = targetfile.rsplit('.', maxsplit=1)[0]
return basename + '.pdb'
return targetfile
def get_debugfile_args(self, targetfile: str) -> T.List[str]:
return self._apply_prefix(['/DEBUG', '/PDB:' + self.get_debugfile_name(targetfile)])

Loading…
Cancel
Save