[build] Add sourcelink support for windows pdbs (#2592)

SourceLink embeds the git repo and hash into the pdbs, which allows VS to get the source files exactly matching a pdb directly from github.

Only VS and WinDbg are supported currently, but there are issues in the vscode tools repo to enable it there.
This commit is contained in:
Thad House
2020-08-29 20:27:20 -07:00
committed by GitHub
parent c0de98f9f2
commit 83376bc231
5 changed files with 35 additions and 5 deletions

View File

@@ -110,5 +110,5 @@ ext.getCurrentArch = {
}
wrapper {
gradleVersion = '6.0'
gradleVersion = '6.0.1'
}

View File

@@ -5,5 +5,5 @@ repositories {
}
}
dependencies {
implementation "edu.wpi.first:native-utils:2020.8.0"
implementation "edu.wpi.first:native-utils:2020.10.0"
}

View File

@@ -10,6 +10,8 @@ import org.gradle.api.GradleException;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.Task;
import org.gradle.api.tasks.Copy;
import org.gradle.api.file.CopySpec;
import org.gradle.api.file.FileTree;
import org.gradle.api.tasks.compile.JavaCompile;
import org.gradle.language.base.internal.ProjectLayout;
@@ -32,6 +34,8 @@ import org.gradle.nativeplatform.toolchain.internal.ToolType;
import org.gradle.nativeplatform.toolchain.internal.gcc.AbstractGccCompatibleToolChain;
import org.gradle.nativeplatform.toolchain.internal.msvcpp.VisualCppToolChain;
import org.gradle.nativeplatform.toolchain.internal.tools.ToolRegistry;
import org.gradle.nativeplatform.tasks.CreateStaticLibrary;
import org.gradle.nativeplatform.tasks.AbstractLinkTask;
import org.gradle.platform.base.BinarySpec;
import org.gradle.platform.base.ComponentSpec;
import org.gradle.platform.base.ComponentSpecContainer;
@@ -100,6 +104,23 @@ class SingleNativeBuild implements Plugin<Project> {
baseBin = tmpBaseBin
}
}
if (binary instanceof StaticLibraryBinarySpec) {
File intoDir = ((CreateStaticLibrary)((StaticLibraryBinarySpec)binary).tasks.createStaticLib).outputFile.get().asFile.parentFile
File fromDir = ((CreateStaticLibrary)((StaticLibraryBinarySpec)baseBin).tasks.createStaticLib).outputFile.get().asFile.parentFile
def copyBasePdbName = "copyBasePdbFor" + binary.buildTask.name
def copyTask = project.tasks.register(copyBasePdbName, Copy) { Copy t ->
t.from (fromDir)
t.include '*.pdb'
t.into intoDir
t.dependsOn (((StaticLibraryBinarySpec)baseBin).tasks.createStaticLib)
}
((CreateStaticLibrary)((StaticLibraryBinarySpec)binary).tasks.createStaticLib).dependsOn(copyTask)
}
baseBin.tasks.withType(AbstractNativeSourceCompileTask) { oCompileTask ->
def compileTask = (AbstractNativeSourceCompileTask) oCompileTask
if (binary instanceof SharedLibraryBinarySpec) {

View File

@@ -1,6 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.0-bin.zip
distributionSha256Sum=5a3578b9f0bb162f5e08cf119f447dfb8fa950cedebb4d2a977e912a11a74b91
distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

View File

@@ -10,8 +10,9 @@ nativeUtils {
wpiVersion = "-1"
niLibVersion = "2020.10.1"
opencvVersion = "3.4.7-3"
googleTestVersion = "1.9.0-4-437e100-1"
googleTestVersion = "1.9.0-5-437e100-1"
imguiVersion = "1.76-6"
wpimathVersion = "-1"
}
}
}
@@ -21,6 +22,7 @@ nativeUtils.wpi.addWarningsAsErrors()
nativeUtils.wpi.addReleaseSymbolGeneration()
nativeUtils.setSinglePrintPerPlatform()
nativeUtils.enableSourceLink()
nativeUtils.platformConfigs.each {
if (it.name.contains('windows')) return
@@ -147,6 +149,14 @@ ext.includeStandardZipFormat = { task, value ->
task.from(binary.staticLibraryFile) {
into nativeUtils.getPlatformPath(binary) + '/static'
}
def pdbDir = binary.staticLibraryFile.parentFile
task.from(pdbDir) {
include '*.pdb'
into nativeUtils.getPlatformPath(binary) + '/static'
}
task.from(new File(pdbDir, "SourceLink.json")) {
into nativeUtils.getPlatformPath(binary) + '/static'
}
}
}
}