Skip to content

Commit

Permalink
Add dsymutil and strip support for executable and shared library buil…
Browse files Browse the repository at this point in the history
…ders (bug 5997 part 10, r=ds).
  • Loading branch information
David Anderson committed Dec 28, 2013
1 parent e6d789f commit 2f9a0be
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 40 deletions.
13 changes: 3 additions & 10 deletions ambuild2/frontend/amb2/gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,20 +510,13 @@ def addCxxTasks(self, cx, binary):
)
inputs.append(rcNode)

outputs = [binary.outputFile]
if binary.pdbFile:
outputs.append(binary.pdbFile)

linkCmd, binNodes = self.addCommand(
output_file, debug_file = binary.link(
context = cx,
node_type = nodetypes.Command,
folder = folder_node,
data = binary.argv,
inputs = inputs,
outputs = outputs
inputs = inputs
)

return CppNodes(binNodes[0], binNodes[1:])
return CppNodes(output_file, debug_file)

def addFileOp(self, cmd, context, source, output_path):
# Try to detect if our output_path is actually a folder, via trailing
Expand Down
5 changes: 3 additions & 2 deletions ambuild2/frontend/base_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,13 @@ def AddFolder(self, folder):
def AddCopy(self, source, output_path):
return self.generator.addCopy(self, source, output_path)

def AddCommand(self, inputs, argv, outputs, dep_type=None, weak_inputs=[]):
def AddCommand(self, inputs, argv, outputs, folder=-1, dep_type=None, weak_inputs=[]):
return self.generator.addShellCommand(
self,
inputs,
argv,
outputs,
folder = folder,
dep_type = dep_type,
weak_inputs = weak_inputs
)
Expand Down Expand Up @@ -243,7 +244,7 @@ def addFolder(self, context, folder):
def addCopy(self, context, source, output_path):
raise Exception('Must be implemented!')

def addShellCommand(self, context, inputs, argv, outputs, dep_type=None, weak_inputs=[]):
def addShellCommand(self, context, inputs, argv, outputs, folder=-1, dep_type=None, weak_inputs=[]):
raise Exception('Must be implemented!')

def addConfigureFile(self, context, path):
Expand Down
92 changes: 64 additions & 28 deletions ambuild2/frontend/cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ def __init__(self, name, version, behavior, command, objSuffix):
self.behavior = behavior
self.command = command
self.objSuffix = objSuffix
self.debuginfo_argv = []

class MSVC(Vendor):
def __init__(self, command, version):
super(MSVC, self).__init__('msvc', version, 'msvc', command, '.obj')
self.definePrefix = '/D'
self.pdbSuffix = '.pdb'
self.debuginfo_argv = ['/Zi']

@staticmethod
def IncludePath(outputPath, includePath):
Expand Down Expand Up @@ -63,7 +64,6 @@ def __init__(self, name, command, version):
self.majorVersion = int(parts[0])
self.minorVersion = int(parts[1])
self.definePrefix = '-D'
self.pdbSuffix = None

def formatInclude(self, outputPath, includePath):
return ['-I', os.path.normpath(includePath)]
Expand All @@ -74,17 +74,18 @@ def objectArgs(self, sourceFile, objFile):
class GCC(CompatGCC):
def __init__(self, command, version):
super(GCC, self).__init__('gcc', command, version)
self.debuginfo_argv = ['-g3', '-ggdb3']

class Clang(CompatGCC):
def __init__(self, command, version):
super(Clang, self).__init__('clang', command, version)
self.debuginfo_argv = ['-g3']

class SunPro(Vendor):
def __init__(self, command, version):
super(SunPro, self).__init__('sun', version, 'sun', command, '.o')
parts = version.split('.')
self.definePrefix = '-D'
self.pdbSuffix = None
self.debuginfo_argv = ['-g3']

def formatInclude(self, outputPath, includePath):
return ['-I', os.path.normpath(includePath)]
Expand Down Expand Up @@ -272,13 +273,15 @@ class Compiler(object):
def __init__(self, cc, cxx):
self.cc = cc
self.cxx = cxx
self.debuginfo = True
for attr in Compiler.attrs:
setattr(self, attr, [])

def clone(self):
cc = Compiler(self.cc, self.cxx)
cc.cc = self.cc
cc.cxx = self.cxx
cc.debuginfo = self.debuginfo
for attr in Compiler.attrs:
setattr(cc, attr, copy.copy(getattr(self, attr)))
return cc
Expand All @@ -302,6 +305,8 @@ class CCommandEnv(object):
def __init__(self, outputPath, config, compiler):
args = compiler.command.split(' ')
args += config.cflags
if config.debuginfo:
args += compiler.debuginfo_argv
if compiler == config.cxx:
args += config.cxxflags
args += [compiler.definePrefix + define for define in config.defines]
Expand Down Expand Up @@ -442,7 +447,40 @@ def finish(self, cx):
self.linker_ = self.compiler.cc

files = [out.outputFile for out in self.objects + self.resources]
self.argv, self.pdbFile = self.generateBinary(cx, files)
self.argv = self.generateBinary(cx, files)
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

def link(self, context, folder, inputs):
ignore, outputs = context.AddCommand(
inputs = inputs,
argv = self.argv,
outputs = self.linker_outputs,
folder = folder
)
if not self.debug_entry and self.compiler.debuginfo:
self.debug_entry = outputs[-1]
return outputs[0], self.debug_entry

class Program(BinaryBuilder):
def __init__(self, compiler, name):
Expand All @@ -455,20 +493,19 @@ def generateBinary(self, cx, files):

if isinstance(self.linker_, MSVC):
argv.append('/link')
argv.extend(self.linkFlags(cx))
if isinstance(self.linker_, MSVC):
argv.append('/OUT:' + self.outputFile)
argv.append('/DEBUG')
argv.extend(self.linkFlags(cx))
argv.append('/nologo')
argv.append('/PDB:"' + self.name_ + '.pdb"')
argv += [
'/OUT:' + self.outputFile,
'/nologo',
]
if self.compiler.debuginfo:
argv += ['/DEBUG', '/PDB:"' + self.name_ + '.pdb"']
else:
argv.extend(self.linkFlags(cx))
argv.extend(['-o', self.outputFile])

pdbFile = None
if self.linker_.pdbSuffix:
pdbFile = self.name_ + self.linker_.pdbSuffix

return argv, pdbFile
return argv

class Library(BinaryBuilder):
def __init__(self, compiler, name):
Expand All @@ -481,25 +518,24 @@ def generateBinary(self, cx, files):

if isinstance(self.linker_, MSVC):
argv.append('/link')
argv.extend(self.linkFlags(cx))
if isinstance(self.linker_, MSVC):
argv.append('/OUT:' + self.outputFile)
argv.append('/DEBUG')
argv.append('/nologo')
argv.append('/DLL')
argv.append('/PDB:"' + self.name_ + '.pdb"')
argv.extend(self.linkFlags(cx))
argv += [
'/OUT:' + self.outputFile,
'/DEBUG',
'/nologo',
'/DLL',
]
if self.compiler.debuginfo:
argv += ['/DEBUG', '/PDB:"' + self.name_ + '.pdb"']
elif isinstance(self.linker_, CompatGCC):
argv.extend(self.linkFlags(cx))
if util.IsMac():
argv.append('-dynamiclib')
else:
argv.append('-shared')
argv.extend(['-o', self.outputFile])

pdbFile = None
if self.linker_.pdbSuffix:
pdbFile = self.name_ + self.linker_.pdbSuffix

return argv, pdbFile
return argv

class StaticLibrary(BinaryBuilder):
def __init__(self, compiler, name):
Expand All @@ -512,4 +548,4 @@ def generateBinary(self, cx, files):
else:
argv = ['ar', 'rcs', self.outputFile]
argv += files
return argv, None
return argv
26 changes: 26 additions & 0 deletions scripts/ambuild_dsymutil_wrapper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/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
dsymutil $LD_FILE
if [ $? -ne 0 ]; then
exit $?
fi
strip -S $LD_FILE
if [ $? -ne 0 ]; then
exit $?
fi

2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

if sys.platform == 'win32':
scripts.append('scripts/ambuild.bat')
elif sys.platform == 'darwin':
scripts.append('scripts/ambuild_dsymutil_wrapper.sh')

setup(
name = 'AMBuild',
Expand Down
10 changes: 10 additions & 0 deletions tests/dsymutil/AMBuildScript
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# vim: set ts=8 sts=2 tw=99 et ft=python:
import os, sys

builder.DetectCompilers()

program = builder.compiler.Program("hello")
program.sources = [
'main.cpp'
]
builder.Add(program)
6 changes: 6 additions & 0 deletions tests/dsymutil/configure.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# vim: set sts=2 ts=8 sw=2 tw=99 et:
import sys
from ambuild2 import run

builder = run.PrepareBuild(sourcePath = sys.path[0])
builder.Configure()
7 changes: 7 additions & 0 deletions tests/dsymutil/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <stdio.h>

int main()
{
return printf("hello!\n");
}

0 comments on commit 2f9a0be

Please sign in to comment.