Update msvc_pdb.py from the master branch

This commit is contained in:
Thomas Nagy 2019-11-10 10:40:54 +01:00
parent e485b45472
commit 38b6f24d73
No known key found for this signature in database
GPG Key ID: 49B4C67C05277AAA
1 changed files with 33 additions and 34 deletions

View File

@ -2,46 +2,45 @@
# encoding: utf-8 # encoding: utf-8
# Rafaël Kooi 2019 # Rafaël Kooi 2019
from waflib import TaskGen, Tools from waflib import TaskGen
@TaskGen.feature('c', 'cxx', 'fc') @TaskGen.feature('c', 'cxx', 'fc')
@TaskGen.after_method('propagate_uselib_vars') @TaskGen.after_method('propagate_uselib_vars')
def add_pdb_per_object(self): def add_pdb_per_object(self):
"""For msvc/fortran, specify a unique compile pdb per object, to work """For msvc/fortran, specify a unique compile pdb per object, to work
around LNK4099. Flags are updated with a unique /Fd flag based on the around LNK4099. Flags are updated with a unique /Fd flag based on the
task output name. This is separate from the link pdb. task output name. This is separate from the link pdb.
""" """
if not hasattr(self, 'compiled_tasks'): if not hasattr(self, 'compiled_tasks'):
return return
link_task = getattr(self, 'link_task', None) link_task = getattr(self, 'link_task', None)
for task in self.compiled_tasks: for task in self.compiled_tasks:
node = task.outputs[0].change_ext('.pdb') if task.inputs and task.inputs[0].name.lower().endswith('.rc'):
pdb_flag = '/Fd:' + node.abspath() continue
canAddNode = False add_pdb = False
for flagname in ('CFLAGS', 'CXXFLAGS', 'FCFLAGS'): for flagname in ('CFLAGS', 'CXXFLAGS', 'FCFLAGS'):
if not flagname in task.env: # several languages may be used at once
continue for flag in task.env[flagname]:
if flag[1:].lower() == 'zi':
add_pdb = True
break
flags = task.env[flagname] if add_pdb:
node = task.outputs[0].change_ext('.pdb')
pdb_flag = '/Fd:' + node.abspath()
for i, flag in reversed(list(enumerate(flags))): for flagname in ('CFLAGS', 'CXXFLAGS', 'FCFLAGS'):
# Capture both /Zi and /ZI, which cause the compiler to emit a PDB file. buf = [pdb_flag]
if flag[1:].lower() == 'zi': for flag in task.env[flagname]:
canAddNode = True if flag[1:3] == 'Fd' or flag[1:].lower() == 'fs' or flag[1:].lower() == 'mp':
task.env.append_unique(flagname, pdb_flag) continue
buf.append(flag)
task.env[flagname] = buf
# Strip existing /Fd, /FS, or /MP flags. if link_task and not node in link_task.dep_nodes:
# We have to check for /Fd case sensitive, so that we won't accidentally link_task.dep_nodes.append(node)
# overwrite GCC flags such as "-fdata-sections". if not node in task.outputs:
if flag[1:3] == 'Fd' \ task.outputs.append(node)
or flag[1:].lower() == 'fs' \
or flag[1:].lower() == 'mp':
del task.env[flagname][i]
if canAddNode:
if link_task and not node in link_task.dep_nodes:
link_task.dep_nodes.append(node)
if not node in task.outputs:
task.outputs.append(node)