Skip to content

Commit

Permalink
Add a wrapper script to objcopy + strip executables and shared librar…
Browse files Browse the repository at this point in the history
…ies (bug 5997 part 12, r=ds).
  • Loading branch information
dvander committed Dec 30, 2013
1 parent 2f9a0be commit fa828fb
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 20 deletions.
49 changes: 30 additions & 19 deletions ambuild2/frontend/cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,25 +451,33 @@ def finish(self, cx):
self.linker_outputs = [self.outputFile]
self.debug_entry = None

if self.compiler.debuginfo and not isinstance(self, StaticLibrary):
if isinstance(self.linker_, MSVC):
self.linker_outputs += [self.name_ + '.pdb']
elif cx.target_platform is 'mac':
bundle_folder = os.path.join(self.localFolder, self.outputFile + '.dSYM')
bundle_entry = cx.AddFolder(bundle_folder)
bundle_layout = [
'Contents',
'Contents/Resources',
'Contents/Resources/DWARF',
]
for folder in bundle_layout:
cx.AddFolder(os.path.join(bundle_folder, folder))
self.linker_outputs += [
self.outputFile + '.dSYM/Contents/Info.plist',
self.outputFile + '.dSYM/Contents/Resources/DWARF/' + self.outputFile
]
self.debug_entry = bundle_entry
self.argv = ['ambuild_dsymutil_wrapper.sh', self.outputFile] + self.argv
if self.compiler.debuginfo:
self.perform_symbol_steps(cx)

def perform_symbol_steps(self, cx):
if isinstance(self.linker_, MSVC):
self.linker_outputs += [self.name_ + '.pdb']
elif cx.target_platform is 'mac':
bundle_folder = os.path.join(self.localFolder, self.outputFile + '.dSYM')
bundle_entry = cx.AddFolder(bundle_folder)
bundle_layout = [
'Contents',
'Contents/Resources',
'Contents/Resources/DWARF',
]
for folder in bundle_layout:
cx.AddFolder(os.path.join(bundle_folder, folder))
self.linker_outputs += [
self.outputFile + '.dSYM/Contents/Info.plist',
self.outputFile + '.dSYM/Contents/Resources/DWARF/' + self.outputFile
]
self.debug_entry = bundle_entry
self.argv = ['ambuild_dsymutil_wrapper.sh', self.outputFile] + self.argv
elif cx.target_platform is 'linux':
self.linker_outputs += [
self.outputFile + '.dbg'
]
self.argv = ['ambuild_objcopy_wrapper.sh', self.outputFile] + self.argv

def link(self, context, folder, inputs):
ignore, outputs = context.AddCommand(
Expand Down Expand Up @@ -549,3 +557,6 @@ def generateBinary(self, cx, files):
argv = ['ar', 'rcs', self.outputFile]
argv += files
return argv

def perform_symbol_steps(self, cx):
pass
29 changes: 29 additions & 0 deletions scripts/ambuild_objcopy_wrapper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

if [ $# -lt 3 ]; then
echo "Usage: <file> <linker> <...linker args>";
exit 1;
fi

LD_FILE=$1
LD_EXEC=$2

shift;
shift;

$LD_EXEC $@
if [ $? -ne 0 ]; then
exit $?
fi
objcopy --only-keep-debug $LD_FILE $LD_FILE.dbg
if [ $? -ne 0 ]; then
exit $?
fi
objcopy --strip-debug $LD_FILE
if [ $? -ne 0 ]; then
exit $?
fi
objcopy --add-gnu-debuglink=$LD_FILE.dbg $LD_FILE
if [ $? -ne 0 ]; then
exit $?
fi
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
scripts.append('scripts/ambuild.bat')
elif sys.platform == 'darwin':
scripts.append('scripts/ambuild_dsymutil_wrapper.sh')
else:
scripts.append('scripts/ambuild_objcopy_wrapper.sh')

setup(
name = 'AMBuild',
Expand All @@ -29,4 +31,3 @@
scripts = scripts
)


0 comments on commit fa828fb

Please sign in to comment.