Files
allwpilib/msvcruntime/build.gradle
Gold856 3bf67edc34 [build] Refactor zip base name generation for consistency (#8831)
Right now, the `zipBaseName` variable in various publish.gradle files
contains the group ID and artifact ID for use by the combiner, however,
they are also duplicated in `artifactGroupId` and `baseArtifactId`,
leading to potential mistakes if they aren't updated together. This
fixes that by adding a new utility function `makeZipBaseName` to
automatically create the right name given a group ID and artifact ID.
This also fixes publishing for thirdparty subprojects, which didn't
update `zipBaseName`.
2026-04-27 11:46:11 -07:00

80 lines
2.2 KiB
Groovy

import org.gradle.nativeplatform.toolchain.internal.msvcpp.VisualStudioLocator
import org.gradle.internal.os.OperatingSystem
plugins {
id 'cpp'
id 'maven-publish'
}
if (OperatingSystem.current().isWindows()) {
def outputsFolder = file("$buildDir/outputs")
def baseArtifactId = 'runtime'
def artifactGroupId = "org.wpilib.msvc"
def zipBaseName = makeZipBaseName(artifactGroupId, baseArtifactId)
def vsLocator = gradle.services.get(VisualStudioLocator)
def vsLocationResult = vsLocator.locateComponent(null)
if (!vsLocationResult.available) {
return
}
def vsLocation = vsLocationResult.component
def visualCppVersion = vsLocation.visualCpp.version
def vsDirectory = vsLocation.visualStudioDir
def defaultRedistFile = file("$vsDirectory\\VC\\Auxiliary\\Build\\Microsoft.VCRedistVersion.default.txt")
if (!defaultRedistFile.exists()) {
logger.warn("Version file for VS Compiler not found")
logger.warn("Expected at $defaultRedistFile")
return
}
def expectedVersion = defaultRedistFile.text.trim()
def runtimeLocation = file("$vsDirectory\\VC\\Redist\\MSVC\\$expectedVersion")
if (runtimeLocation.exists()) {
def x64Folder = null
file("$runtimeLocation\\x64").eachFile {
if (it.name.endsWith('.CRT')) {
x64Folder = it
}
}
def x64ZipTask = tasks.create('x64RuntimeZip', Zip) {
destinationDirectory = outputsFolder
archiveBaseName = zipBaseName
archiveClassifier = 'x64'
from x64Folder
}
addTaskToCopyAllOutputs(x64ZipTask)
build.dependsOn x64ZipTask
publishing {
publications {
runtime(MavenPublication) {
artifact x64ZipTask
artifactId = "${baseArtifactId}"
groupId = artifactGroupId
version = wpilibVersioning.version.get()
}
}
}
} else if (project.hasProperty('buildServer')) {
throw new GradleException("Must find a runtime in CI. Expected at $runtimeLocation")
}
}