[wpiutil] Remove RuntimeDetector and simplify RuntimeLoader (#6600)

This commit is contained in:
Jade
2024-05-25 01:48:59 +08:00
committed by GitHub
parent 72a6d22d9a
commit 6220c6be4d
22 changed files with 99 additions and 474 deletions

View File

@@ -35,6 +35,48 @@ public final class CombinedRuntimeLoader {
extractionDirectory = directory;
}
/**
* Returns platform path.
*
* @return The current platform path.
* @throws IllegalStateException Thrown if the operating system is unknown.
*/
public static String getPlatformPath() {
String filePath;
String arch = System.getProperty("os.arch");
boolean intel32 = "x86".equals(arch) || "i386".equals(arch);
boolean intel64 = "amd64".equals(arch) || "x86_64".equals(arch);
if (System.getProperty("os.name").startsWith("Windows")) {
if (intel32) {
filePath = "/windows/x86/";
} else {
filePath = "/windows/x86-64/";
}
} else if (System.getProperty("os.name").startsWith("Mac")) {
filePath = "/osx/universal/";
} else if (System.getProperty("os.name").startsWith("Linux")) {
if (intel32) {
filePath = "/linux/x86/";
} else if (intel64) {
filePath = "/linux/x86-64/";
} else if (new File("/usr/local/frc/bin/frcRunRobot.sh").exists()) {
filePath = "/linux/athena/";
} else if ("arm".equals(arch) || "arm32".equals(arch)) {
filePath = "/linux/arm32/";
} else if ("aarch64".equals(arch) || "arm64".equals(arch)) {
filePath = "/linux/arm64/";
} else {
filePath = "/linux/nativearm/";
}
} else {
throw new IllegalStateException();
}
return filePath;
}
/**
* Sets DLL directory.
*
@@ -47,11 +89,11 @@ public final class CombinedRuntimeLoader {
StringBuilder msg = new StringBuilder(512);
msg.append(libraryName)
.append(" could not be loaded from path\n" + "\tattempted to load for platform ")
.append(RuntimeDetector.getPlatformPath())
.append(CombinedRuntimeLoader.getPlatformPath())
.append("\nLast Load Error: \n")
.append(ule.getMessage())
.append('\n');
if (RuntimeDetector.isWindows()) {
if (System.getProperty("os.name").startsWith("Windows")) {
msg.append(
"A common cause of this error is missing the C++ runtime.\n"
+ "Download the latest at https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads\n");
@@ -78,7 +120,7 @@ public final class CombinedRuntimeLoader {
map = mapper.readValue(stream, typeRef);
}
var platformPath = Paths.get(RuntimeDetector.getPlatformPath());
var platformPath = Paths.get(CombinedRuntimeLoader.getPlatformPath());
var platform = platformPath.getName(0).toString();
var arch = platformPath.getName(1).toString();
@@ -91,7 +133,7 @@ public final class CombinedRuntimeLoader {
if (extractionPathString == null) {
String hash = (String) map.get("hash");
var defaultExtractionRoot = RuntimeLoader.getDefaultExtractionRoot();
var defaultExtractionRoot = CombinedRuntimeLoader.getExtractionDirectory();
var extractionPath = Paths.get(defaultExtractionRoot, platform, arch, hash);
extractionPathString = extractionPath.toString();
@@ -141,7 +183,7 @@ public final class CombinedRuntimeLoader {
String currentPath = null;
String oldDllDirectory = null;
try {
if (RuntimeDetector.isWindows()) {
if (System.getProperty("os.name").startsWith("Windows")) {
var extractionPathString = getExtractionDirectory();
oldDllDirectory = setDllDirectory(extractionPathString);
}
@@ -180,7 +222,7 @@ public final class CombinedRuntimeLoader {
String currentPath = "";
try {
if (RuntimeDetector.isWindows()) {
if (System.getProperty("os.name").startsWith("Windows")) {
var extractionPathString = getExtractionDirectory();
// Load windows, set dll directory
currentPath = Paths.get(extractionPathString, "WindowsLoaderHelper.dll").toString();