Change debug strip to be part of link task (as doLast).

This avoids spurious re-linking.
This commit is contained in:
Peter Johnson
2016-10-21 18:43:55 -07:00
parent cc2cbf810d
commit 06a40680aa
5 changed files with 30 additions and 81 deletions

View File

@@ -44,32 +44,16 @@ ext.setupDebugDefines = { cppCompiler, linker ->
// Used only on Windows.
ext.setupDef = { linker, deffile -> }
ext.releaseSetup = { releaseTasks ->
model {
binaries {
withType(SharedLibraryBinarySpec) { binary ->
if (!project.hasProperty('debug')) {
def library = binary.sharedLibraryFile.absolutePath
def debugLibrary = binary.sharedLibraryFile.absolutePath + ".debug"
if (project.tasks.findByName("firstObjcopy${binary.name}") == null) {
def firstObjcopy = project.tasks.create("firstObjcopy${binary.name}", Exec) { task ->
task.commandLine 'objcopy', '--only-keep-debug', library, debugLibrary
}
def strip = project.tasks.create("strip${binary.name}", Exec) { task ->
task.commandLine 'strip', '-g', library
}
def secondObjcopy = project.tasks.create("secondObjcopy${binary.name}", Exec) { task ->
task.commandLine 'objcopy', "--add-gnu-debuglink=$debugLibrary", library
}
secondObjcopy.dependsOn strip
strip.dependsOn firstObjcopy
binary.tasks.whenObjectAdded { task ->
if (task.name.contains('link')) {
firstObjcopy.dependsOn task
}
}
}
releaseTasks.each { it.dependsOn project.tasks.getByName("secondObjcopy${binary.name}") }
ext.debugStripSetup = {
if (!project.hasProperty('debug')) {
project.tasks.whenObjectAdded { task ->
if (task.name.contains('link') && task.name.contains('SharedLibrary')) {
def library = task.outputFile.absolutePath
def debugLibrary = task.outputFile.absolutePath + ".debug"
task.doLast {
exec { commandLine "objcopy", '--only-keep-debug', library, debugLibrary }
exec { commandLine "strip", '-g', library }
exec { commandLine "objcopy", "--add-gnu-debuglink=$debugLibrary", library }
}
}
}