diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py index 4cee7a498..a8bf387f9 100644 --- a/mesonbuild/backend/backends.py +++ b/mesonbuild/backend/backends.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: diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index 04f3505f4..2b9a64eb5 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -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, diff --git a/mesonbuild/build.py b/mesonbuild/build.py index 621b6c780..4c07d9691 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -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 diff --git a/mesonbuild/linkers/linkers.py b/mesonbuild/linkers/linkers.py index 0c2bf73be..5911a9fa3 100644 --- a/mesonbuild/linkers/linkers.py +++ b/mesonbuild/linkers/linkers.py @@ -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)])