Autodetect -target and -source flags for javac based on JDK version.

This commit is contained in:
Dan 2019-07-25 22:01:42 -04:00
parent 6553ad4409
commit a7ddd8f0c2
1 changed files with 10 additions and 1 deletions

View File

@ -14,6 +14,7 @@ except ImportError:
import os import os
from os import environ from os import environ
from os.path import dirname, join, exists, realpath from os.path import dirname, join, exists, realpath
import re
import sys import sys
from platform import machine from platform import machine
from setup_sdist import SETUP_KWARGS from setup_sdist import SETUP_KWARGS
@ -91,8 +92,16 @@ def find_javac(possible_homes):
def compile_native_invocation_handler(*possible_homes): def compile_native_invocation_handler(*possible_homes):
'''Find javac and compile NativeInvocationHandler.java.''' '''Find javac and compile NativeInvocationHandler.java.'''
javac = find_javac(possible_homes) javac = find_javac(possible_homes)
source_level = '1.6'
# We have to check what version of javac this is, because -target 1.6 is
# no longer supported on JDKs >= 12.
javac_version = subprocess.check_output([javac, '-version'])
for m in re.finditer(r'\d+', javac_version.decode('ascii')):
if int(m.group(0)) >= 12:
source_level = '1.7'
break
subprocess.check_call([ subprocess.check_call([
javac, '-target', '1.6', '-source', '1.6', javac, '-target', source_level, '-source', source_level,
join('jnius', 'src', 'org', 'jnius', 'NativeInvocationHandler.java') join('jnius', 'src', 'org', 'jnius', 'NativeInvocationHandler.java')
]) ])