Skip to content

Commit 00b353e

Browse files
8269967: JavaFX should fail fast on macOS below minimum version
Reviewed-by: jvos, arapte
1 parent 0c98d96 commit 00b353e

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

buildSrc/mac.gradle

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ def isAarch64 = TARGET_ARCH == "aarch64" || TARGET_ARCH == "arm64";
5959
def macOSMinVersion = isAarch64 ? "11.0" : "10.10";
6060
defineProperty("MACOSX_MIN_VERSION", macOSMinVersion);
6161

62+
def macOSMinVersionArr = macOSMinVersion.split("\\.")
63+
def macOSMinVersionMajor = macOSMinVersionArr[0]
64+
def macOSMinVersionMinor = macOSMinVersionArr[1]
65+
6266
// Create $buildDir/mac_tools.properties file and load props from it
6367
setupTools("mac_tools",
6468
{ propFile ->
@@ -178,7 +182,9 @@ MAC.glass.javahInclude = [
178182
"com/sun/glass/ui/mac/*"]
179183
MAC.glass.nativeSource = file("${project("graphics").projectDir}/src/main/native-glass/mac")
180184
MAC.glass.compiler = compiler
181-
MAC.glass.ccFlags = [ccFlags].flatten()
185+
MAC.glass.ccFlags = [ccFlags,
186+
"-DMACOS_MIN_VERSION_MAJOR=$macOSMinVersionMajor",
187+
"-DMACOS_MIN_VERSION_MINOR=$macOSMinVersionMinor"].flatten()
182188
MAC.glass.linker = linker
183189
MAC.glass.linkFlags = [linkFlags].flatten()
184190
MAC.glass.lib = "glass"

modules/javafx.graphics/src/main/native-glass/mac/GlassApplication.m

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,34 @@ + (BOOL)syncRenderingDisabled {
793793
{
794794
LOG("Java_com_sun_glass_ui_mac_MacApplication__1initIDs");
795795

796+
// Check minimum OS version
797+
NSOperatingSystemVersion osVer;
798+
osVer = [[NSProcessInfo processInfo] operatingSystemVersion];
799+
NSInteger osVerMajor = osVer.majorVersion;
800+
NSInteger osVerMinor = osVer.minorVersion;
801+
802+
// Map 10.16 to 11.0, since macOS will return 10.16 by default (for compatibility)
803+
if (osVerMajor == 10 && osVerMinor >= 16) {
804+
// FIXME: if we ever need to know which minor version of macOS 11.x we
805+
// are running on, we will need to look it up using a similar technique
806+
// to what the JDK does.
807+
osVerMajor = 11;
808+
osVerMinor = 0;
809+
}
810+
811+
if (osVerMajor < MACOS_MIN_VERSION_MAJOR ||
812+
(osVerMajor == MACOS_MIN_VERSION_MAJOR &&
813+
osVerMinor < MACOS_MIN_VERSION_MINOR))
814+
{
815+
NSLog(@"ERROR: macOS version is %d.%d, which is below the minimum of %d.%d",
816+
(int)osVerMajor, (int)osVerMinor, MACOS_MIN_VERSION_MAJOR, MACOS_MIN_VERSION_MINOR);
817+
jclass exceptionClass = (*env)->FindClass(env, "java/lang/RuntimeException");
818+
if (exceptionClass != 0) {
819+
(*env)->ThrowNew(env, exceptionClass, "Unsupported macOS version");
820+
}
821+
return;
822+
}
823+
796824
disableSyncRendering = jDisableSyncRendering ? YES : NO;
797825

798826
jApplicationClass = (*env)->NewGlobalRef(env, jClass);

0 commit comments

Comments
 (0)