[JVM-Packages] Auto-detection of MUSL is replaced by system properties (#7921)
This PR removes auto-detection of MUSL-based Linux systems in favor of system properties the user can set to configure a specific path for a native library.
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
Copyright (c) 2014 by Contributors
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
package ml.dmlc.xgboost4j.java;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
import static junit.framework.TestCase.assertTrue;
|
||||
import static ml.dmlc.xgboost4j.java.NativeLibLoader.Arch.X86_64;
|
||||
import static ml.dmlc.xgboost4j.java.NativeLibLoader.LibraryPathProvider.getLibraryPathFor;
|
||||
import static ml.dmlc.xgboost4j.java.NativeLibLoader.OS.LINUX;
|
||||
|
||||
public class LibraryPathProviderTest {
|
||||
|
||||
@Test
|
||||
public void testLibraryPathProviderUsesOsAndArchToResolvePath() {
|
||||
String libraryPath = getLibraryPathFor(LINUX, X86_64, "someLibrary");
|
||||
|
||||
assertTrue(libraryPath.startsWith("/lib/linux/x86_64/"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLibraryPathProviderUsesPropertyValueForPathIfPresent() {
|
||||
String propertyName = "xgboostruntime.native.library";
|
||||
|
||||
executeAndRestoreProperty(propertyName, () -> {
|
||||
System.setProperty(propertyName, "/my/custom/path/to/my/library");
|
||||
String libraryPath = getLibraryPathFor(LINUX, X86_64, "library");
|
||||
|
||||
assertEquals("/my/custom/path/to/my/library", libraryPath);
|
||||
});
|
||||
}
|
||||
|
||||
private static void executeAndRestoreProperty(String propertyName, Runnable action) {
|
||||
String oldValue = System.getProperty(propertyName);
|
||||
|
||||
try {
|
||||
action.run();
|
||||
} finally {
|
||||
if (oldValue != null) {
|
||||
System.setProperty(propertyName, oldValue);
|
||||
} else {
|
||||
System.clearProperty(propertyName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,10 +16,8 @@
|
||||
package ml.dmlc.xgboost4j.java;
|
||||
|
||||
import ml.dmlc.xgboost4j.java.NativeLibLoader.OS;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.experimental.runners.Enclosed;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.runners.Parameterized.Parameters;
|
||||
@@ -40,12 +38,12 @@ public class OsDetectionTest {
|
||||
private static final String OS_NAME_PROPERTY = "os.name";
|
||||
|
||||
@RunWith(Parameterized.class)
|
||||
public static class ParameterizedOSDetectionTest {
|
||||
public static class SupportedOSDetectionTest {
|
||||
|
||||
private final String osNameValue;
|
||||
private final OS expectedOS;
|
||||
|
||||
public ParameterizedOSDetectionTest(String osNameValue, OS expectedOS) {
|
||||
public SupportedOSDetectionTest(String osNameValue, OS expectedOS) {
|
||||
this.osNameValue = osNameValue;
|
||||
this.expectedOS = expectedOS;
|
||||
}
|
||||
@@ -70,32 +68,7 @@ public class OsDetectionTest {
|
||||
}
|
||||
}
|
||||
|
||||
public static class NonParameterizedOSDetectionTest {
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder folder = new TemporaryFolder();
|
||||
|
||||
@Test
|
||||
public void testForRegularLinux() throws Exception {
|
||||
setMappedFilesBaseDir(folder.getRoot().toPath());
|
||||
folder.newFile("ld-2.23.so");
|
||||
|
||||
executeAndRestoreProperty(() -> {
|
||||
System.setProperty(OS_NAME_PROPERTY, "linux");
|
||||
assertSame(detectOS(), LINUX);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testForMuslBasedLinux() throws Exception {
|
||||
setMappedFilesBaseDir(folder.getRoot().toPath());
|
||||
folder.newFile("ld-musl-x86_64.so.1");
|
||||
|
||||
executeAndRestoreProperty(() -> {
|
||||
System.setProperty(OS_NAME_PROPERTY, "linux");
|
||||
assertSame(detectOS(), LINUX_MUSL);
|
||||
});
|
||||
}
|
||||
public static class UnsupportedOSDetectionTest {
|
||||
|
||||
@Test
|
||||
public void testUnsupportedOs() {
|
||||
|
||||
Reference in New Issue
Block a user