From 8153911160dbb5878c494369248ea902eca7db12 Mon Sep 17 00:00:00 2001 From: Thad House Date: Sun, 16 Oct 2022 15:37:13 -0700 Subject: [PATCH] [build] Fix MSVC runtime archiver to grab default runtime (#4478) --- msvcruntime/build.gradle | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/msvcruntime/build.gradle b/msvcruntime/build.gradle index b43d52f8ef4..99e14ed62c6 100644 --- a/msvcruntime/build.gradle +++ b/msvcruntime/build.gradle @@ -16,25 +16,31 @@ if (OperatingSystem.current().isWindows()) { def vsLocator = gradle.services.get(VisualStudioLocator) - def vsLocation = vsLocator.locateAllComponents().first() + def vsLocationResult = vsLocator.locateComponent(null) + + if (!vsLocationResult.available) { + return + } + + def vsLocation = vsLocationResult.component def visualCppVersion = vsLocation.visualCpp.version def vsDirectory = vsLocation.visualStudioDir - def runtimeLocation = file("$vsDirectory\\VC\\Redist\\MSVC") - - def runtimeVerNumber = null + def defaultRedistFile = file("$vsDirectory\\VC\\Auxiliary\\Build\\Microsoft.VCRedistVersion.default.txt") - runtimeLocation.eachFile { - def verNumber = VersionNumber.parse(it.name) - if (verNumber.major == visualCppVersion.major && verNumber.minor == visualCppVersion.minor) { - runtimeVerNumber = verNumber - } + if (!defaultRedistFile.exists()) { + logger.warn("Version file for VS Compiler not found") + logger.warn("Expected at $defaultRedistFile") + return } - if (runtimeVerNumber != null) { - runtimeLocation = file("$runtimeLocation\\$runtimeVerNumber") + def expectedVersion = VersionNumber.parse(defaultRedistFile.text.trim()) + + def runtimeLocation = file("$vsDirectory\\VC\\Redist\\MSVC\\$expectedVersion") + + if (runtimeLocation.exists()) { def x64Folder = null @@ -68,5 +74,7 @@ if (OperatingSystem.current().isWindows()) { } } } + } else if (project.hasProperty('buildServer')) { + throw new GradleException("Must find a runtime in CI. Expected at $runtimeLocation") } }