Generate debugging information during compilation (bug 5227, r=ds).
This commit is contained in:
		
							parent
							
								
									4e7a9cf30b
								
							
						
					
					
						commit
						0f62a8ec2f
					
				@ -1,8 +1,28 @@
 | 
			
		||||
# vim: set ts=2 sw=2 tw=99 noet ft=python:
 | 
			
		||||
import os
 | 
			
		||||
import sys
 | 
			
		||||
from ambuild.command import Command
 | 
			
		||||
from ambuild.command import ShellCommand
 | 
			
		||||
from ambuild.command import SymlinkCommand
 | 
			
		||||
 | 
			
		||||
class ExtractDebugInfoCommand(Command):
 | 
			
		||||
	def __init__(self, binary, outfile):
 | 
			
		||||
		Command.__init__(self)
 | 
			
		||||
		self.binary = binary
 | 
			
		||||
		self.outfile = outfile
 | 
			
		||||
 | 
			
		||||
	def run(self, runner, job):
 | 
			
		||||
		if not self.binary.NeedsRelink(self.outfile):
 | 
			
		||||
			return
 | 
			
		||||
 | 
			
		||||
		if AMBuild.target['platform'] == 'linux':
 | 
			
		||||
			job.AddCommand(ShellCommand('objcopy --only-keep-debug ' + self.outfile + ' ' + self.outfile + '.dbg'))
 | 
			
		||||
			job.AddCommand(ShellCommand('objcopy --strip-debug ' + self.outfile))
 | 
			
		||||
			job.AddCommand(ShellCommand('objcopy --add-gnu-debuglink=' + os.path.basename(self.outfile) + '.dbg ' + self.outfile))
 | 
			
		||||
		elif AMBuild.target['platform'] == 'darwin':
 | 
			
		||||
			job.AddCommand(ShellCommand('dsymutil ' + self.outfile))
 | 
			
		||||
			job.AddCommand(ShellCommand('strip -S ' + self.outfile))
 | 
			
		||||
 | 
			
		||||
class SM:
 | 
			
		||||
	def __init__(self):
 | 
			
		||||
		self.compiler = Cpp.Compiler()
 | 
			
		||||
@ -117,6 +137,7 @@ class SM:
 | 
			
		||||
				self.compiler.AddToListVar('CFLAGS', '-Wno-unused')
 | 
			
		||||
				self.compiler.AddToListVar('CFLAGS', '-Wno-switch')
 | 
			
		||||
				self.compiler.AddToListVar('CFLAGS', '-msse')
 | 
			
		||||
				self.compiler.AddToListVar('CFLAGS', '-g3')
 | 
			
		||||
				self.compiler.AddToListVar('CFLAGS', '-m32')
 | 
			
		||||
				self.compiler.AddToListVar('POSTLINKFLAGS', '-m32')
 | 
			
		||||
				self.compiler.AddToListVar('CXXFLAGS', '-fno-exceptions')
 | 
			
		||||
@ -176,9 +197,7 @@ class SM:
 | 
			
		||||
			if AMBuild.options.debug == '1':
 | 
			
		||||
				self.compiler.AddToListVar('CDEFINES', 'DEBUG')
 | 
			
		||||
				self.compiler.AddToListVar('CDEFINES', '_DEBUG')
 | 
			
		||||
				if self.vendor == 'gcc' or self.vendor == 'clang':
 | 
			
		||||
					self.compiler.AddToListVar('CFLAGS', '-g3')
 | 
			
		||||
				elif self.vendor == 'msvc':
 | 
			
		||||
				if self.vendor == 'msvc':
 | 
			
		||||
					self.compiler.AddToListVar('CFLAGS', '/Od')
 | 
			
		||||
					self.compiler.AddToListVar('CFLAGS', '/RTC1')
 | 
			
		||||
 | 
			
		||||
@ -265,6 +284,10 @@ class SM:
 | 
			
		||||
		else:
 | 
			
		||||
			return
 | 
			
		||||
 | 
			
		||||
	def ExtractDebugInfo(self, job, binary):
 | 
			
		||||
		src = os.path.join('..', AMBuild.outputFolder, job.workFolder, binary.binaryFile)
 | 
			
		||||
		job.AddCommand(ExtractDebugInfoCommand(binary, src))
 | 
			
		||||
 | 
			
		||||
	def PreSetupHL2Job(self, job, builder, sdk):
 | 
			
		||||
		info = self.sdkInfo[sdk]
 | 
			
		||||
		sdkPath = AMBuild.cache[info['sdk']]
 | 
			
		||||
 | 
			
		||||
@ -120,5 +120,6 @@ for i in SM.sdkInfo:
 | 
			
		||||
			binary.AddObjectFiles(['libprotobuf.a'])
 | 
			
		||||
	
 | 
			
		||||
	SM.AutoVersion('core', binary)
 | 
			
		||||
	SM.ExtractDebugInfo(extension, binary)
 | 
			
		||||
	binary.SendToJob()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -58,5 +58,6 @@ else:
 | 
			
		||||
	files.append('thread/PosixThreads.cpp')
 | 
			
		||||
binary.AddSourceFiles('core/logic', files)
 | 
			
		||||
SM.AutoVersion('core/logic', binary)
 | 
			
		||||
SM.ExtractDebugInfo(extension, binary)
 | 
			
		||||
binary.SendToJob()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -19,6 +19,7 @@ binary.AddSourceFiles('extensions/bintools', [
 | 
			
		||||
	'sdk/smsdk_ext.cpp'
 | 
			
		||||
	])
 | 
			
		||||
SM.AutoVersion('extensions/bintools', binary)
 | 
			
		||||
SM.ExtractDebugInfo(extension, binary)
 | 
			
		||||
binary.SendToJob()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -15,5 +15,6 @@ binary.AddSourceFiles('extensions/clientprefs', [
 | 
			
		||||
	'sdk/smsdk_ext.cpp'
 | 
			
		||||
	])
 | 
			
		||||
SM.AutoVersion('extensions/clientprefs', binary)
 | 
			
		||||
SM.ExtractDebugInfo(extension, binary)
 | 
			
		||||
binary.SendToJob()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -29,4 +29,5 @@ for i in SM.sdkInfo:
 | 
			
		||||
		])
 | 
			
		||||
	SM.PostSetupHL2Job(extension, binary, i)
 | 
			
		||||
	SM.AutoVersion('extensions/cstrike', binary)
 | 
			
		||||
	SM.ExtractDebugInfo(extension, binary)
 | 
			
		||||
	binary.SendToJob()
 | 
			
		||||
@ -82,5 +82,6 @@ elif AMBuild.target['platform'] == 'windows':
 | 
			
		||||
	binary['POSTLINKFLAGS'].extend([path, 'ws2_32.lib'])
 | 
			
		||||
 | 
			
		||||
SM.AutoVersion('extensions/curl', binary)
 | 
			
		||||
SM.ExtractDebugInfo(extension, binary)
 | 
			
		||||
binary.SendToJob()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -11,5 +11,6 @@ binary.AddSourceFiles('extensions/geoip', [
 | 
			
		||||
if AMBuild.target['platform'] == 'windows':
 | 
			
		||||
	binary['POSTLINKFLAGS'].append('wsock32.lib')
 | 
			
		||||
SM.AutoVersion('extensions/geoip', binary)
 | 
			
		||||
SM.ExtractDebugInfo(extension, binary)
 | 
			
		||||
binary.SendToJob()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -34,5 +34,6 @@ binary.AddSourceFiles('extensions/mysql', [
 | 
			
		||||
	'extension.cpp'
 | 
			
		||||
	])
 | 
			
		||||
SM.AutoVersion('extensions/mysql', binary)
 | 
			
		||||
SM.ExtractDebugInfo(extension, binary)
 | 
			
		||||
binary.SendToJob()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -23,5 +23,6 @@ binary.AddSourceFiles('extensions/regex', [
 | 
			
		||||
	'sdk/smsdk_ext.cpp',
 | 
			
		||||
	])
 | 
			
		||||
SM.AutoVersion('extensions/regex', binary)
 | 
			
		||||
SM.ExtractDebugInfo(extension, binary)
 | 
			
		||||
binary.SendToJob()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -26,5 +26,6 @@ for i in SM.sdkInfo:
 | 
			
		||||
		])
 | 
			
		||||
	SM.PostSetupHL2Job(extension, binary, i)
 | 
			
		||||
	SM.AutoVersion('extensions/sdkhooks', binary)
 | 
			
		||||
	SM.ExtractDebugInfo(extension, binary)
 | 
			
		||||
	binary.SendToJob()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -48,5 +48,6 @@ for i in SM.sdkInfo:
 | 
			
		||||
		])
 | 
			
		||||
	SM.PostSetupHL2Job(extension, binary, i)
 | 
			
		||||
	SM.AutoVersion('extensions/sdktools', binary)
 | 
			
		||||
	SM.ExtractDebugInfo(extension, binary)
 | 
			
		||||
	binary.SendToJob()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -17,5 +17,6 @@ files = [
 | 
			
		||||
	]
 | 
			
		||||
binary.AddSourceFiles('extensions/sqlite', files)
 | 
			
		||||
SM.AutoVersion('extensions/sqlite', binary)
 | 
			
		||||
SM.ExtractDebugInfo(extension, binary)
 | 
			
		||||
binary.SendToJob()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -26,5 +26,6 @@ if 'ep2v' in SM.sdkInfo:
 | 
			
		||||
		])
 | 
			
		||||
	SM.PostSetupHL2Job(extension, binary, 'ep2v')
 | 
			
		||||
	SM.AutoVersion('extensions/tf2', binary)
 | 
			
		||||
	SM.ExtractDebugInfo(extension, binary)
 | 
			
		||||
	binary.SendToJob()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -15,5 +15,6 @@ binary.AddSourceFiles('extensions/topmenus', [
 | 
			
		||||
	'sdk/sm_memtable.cpp'
 | 
			
		||||
	])
 | 
			
		||||
SM.AutoVersion('extensions/topmenus', binary)
 | 
			
		||||
SM.ExtractDebugInfo(extension, binary)
 | 
			
		||||
binary.SendToJob()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -14,5 +14,6 @@ binary.AddSourceFiles('extensions/updater', [
 | 
			
		||||
	'sdk/smsdk_ext.cpp'
 | 
			
		||||
	])
 | 
			
		||||
SM.AutoVersion('extensions/updater', binary)
 | 
			
		||||
SM.ExtractDebugInfo(extension, binary)
 | 
			
		||||
binary.SendToJob()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -17,5 +17,6 @@ binary.AddSourceFiles('loader', [
 | 
			
		||||
	'loader.cpp'
 | 
			
		||||
	])
 | 
			
		||||
SM.AutoVersion('loader', binary)
 | 
			
		||||
SM.ExtractDebugInfo(loader, binary)
 | 
			
		||||
binary.SendToJob()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -67,5 +67,6 @@ elif AMBuild.target['platform'] == 'darwin' and isinstance(binary, Cpp.LibraryBu
 | 
			
		||||
	binary.compiler['POSTLINKFLAGS'].extend(['-compatibility_version', '1.0.0'])
 | 
			
		||||
	binary.compiler['POSTLINKFLAGS'].extend(['-current_version', AMBuild.cache['version']])
 | 
			
		||||
 | 
			
		||||
SM.ExtractDebugInfo(extension, binary)
 | 
			
		||||
binary.SendToJob()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -40,5 +40,6 @@ binary.AddSourceFiles('sourcepawn/jit', [
 | 
			
		||||
	'../../knight/shared/KeCodeAllocator.cpp'
 | 
			
		||||
	])
 | 
			
		||||
SM.AutoVersion('sourcepawn/jit', binary)
 | 
			
		||||
SM.ExtractDebugInfo(extension, binary)
 | 
			
		||||
binary.SendToJob()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -255,6 +255,14 @@ AddHL2Library('sdktools.ext', 'extensions')
 | 
			
		||||
bincopies.append(CopyFile(os.path.join('..', 'spcomp', 'spcomp' + osutil.ExecutableSuffix()),
 | 
			
		||||
                          os.path.join('addons', 'sourcemod', 'scripting')))
 | 
			
		||||
 | 
			
		||||
# Each platform's version of dump_syms needs the path in a different format.
 | 
			
		||||
if AMBuild.target['platform'] == 'linux':
 | 
			
		||||
	debug_info.append('spcomp' + '/' + 'spcomp')
 | 
			
		||||
elif AMBuild.target['platform'] == 'darwin':
 | 
			
		||||
	debug_info.append('spcomp' + '/' + 'spcomp' + '.dSYM')
 | 
			
		||||
elif AMBuild.target['platform'] == 'windows':
 | 
			
		||||
	debug_info.append('spcomp' + '\\' + 'spcomp' + '.pdb'
 | 
			
		||||
 | 
			
		||||
job.AddCommandGroup(bincopies)
 | 
			
		||||
 | 
			
		||||
if AMBuild.target['platform'] == 'windows':
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user