Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame^] | 1 | import org.gradle.nativeplatform.toolchain.internal.msvcpp.VisualStudioLocator |
| 2 | import org.gradle.internal.os.OperatingSystem |
| 3 | import org.gradle.util.VersionNumber |
| 4 | |
| 5 | plugins { |
| 6 | id 'cpp' |
| 7 | id 'maven-publish' |
| 8 | } |
| 9 | |
| 10 | if (OperatingSystem.current().isWindows()) { |
| 11 | def outputsFolder = file("$buildDir/outputs") |
| 12 | |
| 13 | def baseArtifactId = 'runtime' |
| 14 | def artifactGroupId = "edu.wpi.first.msvc" |
| 15 | def zipBaseName = "_GROUP_edu_wpi_first_msvc_ID_runtime_CLS" |
| 16 | |
| 17 | def vsLocator = gradle.services.get(VisualStudioLocator) |
| 18 | |
| 19 | def vsLocation = vsLocator.locateAllComponents().first() |
| 20 | |
| 21 | def visualCppVersion = vsLocation.visualCpp.version |
| 22 | |
| 23 | def vsDirectory = vsLocation.visualStudioDir |
| 24 | |
| 25 | def runtimeLocation = file("$vsDirectory\\VC\\Redist\\MSVC") |
| 26 | |
| 27 | def runtimeVerNumber = null |
| 28 | |
| 29 | runtimeLocation.eachFile { |
| 30 | def verNumber = VersionNumber.parse(it.name) |
| 31 | if (verNumber.major == visualCppVersion.major && verNumber.minor == visualCppVersion.minor) { |
| 32 | runtimeVerNumber = verNumber |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | if (runtimeVerNumber != null) { |
| 37 | runtimeLocation = file("$runtimeLocation\\$runtimeVerNumber") |
| 38 | |
| 39 | def x86Folder = null |
| 40 | |
| 41 | file("$runtimeLocation\\x86").eachFile { |
| 42 | if (it.name.endsWith('.CRT')) { |
| 43 | x86Folder = it |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | def x64Folder = null |
| 48 | |
| 49 | file("$runtimeLocation\\x64").eachFile { |
| 50 | if (it.name.endsWith('.CRT')) { |
| 51 | x64Folder = it |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | def x86ZipTask = tasks.create('x86RuntimeZip', Zip) { |
| 56 | destinationDirectory = outputsFolder |
| 57 | archiveBaseName = zipBaseName |
| 58 | classifier = 'x86' |
| 59 | |
| 60 | from x86Folder |
| 61 | } |
| 62 | |
| 63 | def x64ZipTask = tasks.create('x64RuntimeZip', Zip) { |
| 64 | destinationDirectory = outputsFolder |
| 65 | archiveBaseName = zipBaseName |
| 66 | classifier = 'x64' |
| 67 | |
| 68 | from x64Folder |
| 69 | } |
| 70 | |
| 71 | addTaskToCopyAllOutputs(x86ZipTask) |
| 72 | addTaskToCopyAllOutputs(x64ZipTask) |
| 73 | |
| 74 | build.dependsOn x86ZipTask |
| 75 | build.dependsOn x64ZipTask |
| 76 | |
| 77 | publishing { |
| 78 | publications { |
| 79 | |
| 80 | runtime(MavenPublication) { |
| 81 | artifact x86ZipTask |
| 82 | artifact x64ZipTask |
| 83 | |
| 84 | artifactId = "${baseArtifactId}" |
| 85 | groupId artifactGroupId |
| 86 | version wpilibVersioning.version.get() |
| 87 | } |
| 88 | } |
| 89 | } |
| 90 | } |
| 91 | } |