From 06a40680aaf83ab1f8dfd764fbc78c1726d273a1 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Fri, 21 Oct 2016 18:43:55 -0700 Subject: [PATCH] Change debug strip to be part of link task (as doLast). This avoids spurious re-linking. --- cameraserver.gradle | 8 +------- toolchains/arm.gradle | 36 ++++++++++-------------------------- toolchains/linux.gradle | 36 ++++++++++-------------------------- toolchains/mac.gradle | 29 ++++++++--------------------- toolchains/windows.gradle | 2 +- 5 files changed, 30 insertions(+), 81 deletions(-) diff --git a/cameraserver.gradle b/cameraserver.gradle index a45cfdb774..cc541a728c 100644 --- a/cameraserver.gradle +++ b/cameraserver.gradle @@ -152,13 +152,7 @@ def cameraserverZipTask = { project -> project.build.dependsOn project.cameraserverZip - def releaseTasks = [project.cameraserverZip] - - if (includeJava) { - releaseTasks.add(project.jar) - } - - project.releaseSetup(releaseTasks) + project.debugStripSetup() project.tasks.whenTaskAdded { task -> def name = task.name.toLowerCase() diff --git a/toolchains/arm.gradle b/toolchains/arm.gradle index 8cfeaeef11..59173c2aa2 100644 --- a/toolchains/arm.gradle +++ b/toolchains/arm.gradle @@ -77,32 +77,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 "${compilerPrefix}objcopy", '--only-keep-debug', library, debugLibrary - } - def strip = project.tasks.create("strip${binary.name}", Exec) { task -> - task.commandLine "${compilerPrefix}strip", '-g', library - } - def secondObjcopy = project.tasks.create("secondObjcopy${binary.name}", Exec) { task -> - task.commandLine "${compilerPrefix}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 "${compilerPrefix}objcopy", '--only-keep-debug', library, debugLibrary } + exec { commandLine "${compilerPrefix}strip", '-g', library } + exec { commandLine "${compilerPrefix}objcopy", "--add-gnu-debuglink=$debugLibrary", library } } } } diff --git a/toolchains/linux.gradle b/toolchains/linux.gradle index f1206ade29..f2d6b37430 100644 --- a/toolchains/linux.gradle +++ b/toolchains/linux.gradle @@ -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 } } } } diff --git a/toolchains/mac.gradle b/toolchains/mac.gradle index 56bb1cb204..f80a1314fd 100644 --- a/toolchains/mac.gradle +++ b/toolchains/mac.gradle @@ -33,27 +33,14 @@ 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 - if (project.tasks.findByName("strip${binary.name}") == null) { - def dsymutil = project.tasks.create("dsymutil${binary.name}", Exec) { task -> - task.commandLine 'dsymutil', library - } - def strip = project.tasks.create("strip${binary.name}", Exec) { task -> - task.commandLine 'strip', '-S', library - } - strip.dependsOn dsymutil - binary.tasks.whenObjectAdded { task -> - if (task.name.contains('link')) { - dsymutil.dependsOn task - } - } - } - releaseTasks.each { it.dependsOn project.tasks.getByName("strip${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 + task.doLast { + exec { commandLine "dsymutil", library } + exec { commandLine "strip", '-S', library } } } } diff --git a/toolchains/windows.gradle b/toolchains/windows.gradle index df31ee98b8..e093962709 100644 --- a/toolchains/windows.gradle +++ b/toolchains/windows.gradle @@ -49,4 +49,4 @@ ext.setupDef = { linker, deffile -> // This is a noop on Windows. On gcc platforms, we strip the release binary and create a separate // debug library, but Windows already separates debug symbols into a .pdb file. -ext.releaseSetup = { releaseTasks -> } +ext.debugStripSetup = { }