Skip to content

Commit 55c56f7

Browse files
jonathanpeppersjonpryor
authored andcommitted
[build] option to filter by JI_MAX_JDK on make prepare (dotnet#226)
Context: https://stackoverflow.com/questions/47627499/does-android-studio-3-support-java-9-for-android-development At the current time, we will not be able to use JDK 9 for Android. Some of our build agents (VSTS), now have JDK 9 installed, so we need to make a few changes to make sure JDK 8 is picked up instead. Changes: - Create a `$(JI_MAX_JDK)` option, as a way for `xamarin-android` to exclude JDK 9 - Create new `$(JI_JAVAC_PATH)` and `$(JI_JAR_PATH)` make variables, which will be the full path to `javac` and `jar` - Use `awk` to filter on <= `$(JI_MAX_JDK)` - Use `sed` to find the JDK version number, see options of folder names below - `sort -n` should be used to sort numerically - Set `$(JI_JAVAC_PATH)` and `$(JI_JAR_PATH)` to their full paths - Support both `Darwin` and `Linux`. Windows support is currently handled separately in `xamarin-android` currently ~~Known JDK folder names~~ macOS: 1.6.0.jdk jdk1.7.0_79.jdk jdk1.8.0_101.jdk jdk1.8.0_152.jdk jdk-9.0.1.jdk Ubuntu: java-8-openjdk-amd64 java-9-openjdk-amd64
1 parent 429dc2a commit 55c56f7

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

build-tools/scripts/jdk.mk

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
# $(OS): Optional; **uname**(1) value of the host operating system
77
# $(CONFIGURATION): Build configuration name, e.g. Debug or Release
88
# $(RUNTIME): `mono` executable for the host operating system
9+
# $(JI_MAX_JDK):
10+
# Maximum allowed JDK version, blank by default.
11+
# `xamarin-android` will need to specify 8 here
912
#
1013
# Outputs:
1114
#
@@ -21,6 +24,19 @@
2124
# Location of the Java native library that contains e.g. JNI_CreateJavaVM().
2225

2326
OS ?= $(shell uname)
27+
JI_JAVAC_PATH = javac
28+
JI_JAR_PATH = jar
29+
30+
31+
# Filter on <= JI_MAX_JDK
32+
ifneq ($(JI_MAX_JDK),)
33+
_VERSION_MAX := | awk '$$1 <= $(JI_MAX_JDK)'
34+
endif #JI_MAX_JDK
35+
36+
# Sort numerically on version numbers with `sort -n`, filtering on $(JI_MAX_JDK) if needed
37+
# Replace each line so it starts with a number (sed 's/...'\1 &/), sort on the leading number, then remove the leading number.
38+
# Grab the last path name printed.
39+
_VERSION_SORT := sed 's/[^0-9]*\([0-9.]*\)/\1 &/' $(_VERSION_MAX) | sort -n | sed 's/^[0-9.]* //g' | tail -1
2440

2541
ifeq ($(OS),Darwin)
2642

@@ -58,7 +74,9 @@ _LOCAL_JDK_HEADERS = LocalJDK/System/Library/Frameworks/JavaVM.fr
5874
_APPLE_JDK6_URL = http://adcdownload.apple.com/Developer_Tools/java_for_os_x_2013005_developer_package/java_for_os_x_2013005_dp__11m4609.dmg
5975

6076
ifneq ($(_DARWIN_JDK_FALLBACK_DIRS),)
61-
_DARWIN_JDK_ROOT := $(shell ls -dtr $(_DARWIN_JDK_FALLBACK_DIRS) | sort | tail -1)
77+
_DARWIN_JDK_ROOT := $(shell ls -dtr $(_DARWIN_JDK_FALLBACK_DIRS) | $(_VERSION_SORT))
78+
JI_JAVAC_PATH = $(_DARWIN_JDK_ROOT)/Contents/Home/bin/javac
79+
JI_JAR_PATH = $(_DARWIN_JDK_ROOT)/Contents/Home/bin/jar
6280
JI_JDK_INCLUDE_PATHS = \
6381
$(_DARWIN_JDK_ROOT)/$(_DARWIN_JDK_JNI_INCLUDE_DIR) \
6482
$(_DARWIN_JDK_ROOT)/$(_DARWIN_JDK_JNI_OS_INCLUDE_DIR)
@@ -108,7 +126,7 @@ _LINUX_JAVA_ROOT = $(JAVA_HOME)
108126
endif # No default Java location, $JAVA_HOME check
109127

110128
ifeq ($(wildcard $(_DESKTOP_JAVA_INCLUDE_DIRS)),)
111-
LATEST_JDK := $(shell ls -dtr $(_LINUX_JAVA_FALLBACK_DIRS) | sort | tail -1)
129+
LATEST_JDK := $(shell ls -dtr $(_LINUX_JAVA_FALLBACK_DIRS) | $(_VERSION_SORT))
112130
_DESKTOP_JAVA_INCLUDE_DIRS = $(LATEST_JDK)/$(_LINUX_JAVA_JNI_INCLUDE_DIR)
113131
_LINUX_JAVA_ROOT = $(LATEST_JDK)
114132
endif # No $JAVA_HOME, find the latest version
@@ -125,6 +143,9 @@ JI_JVM_PATH = $(_LINUX_JAVA_ROOT)/jre/lib/$(_LINUX_JAVA_ARCH_32)
125143
endif # (2)
126144
endif # (1)
127145

146+
JI_JAVAC_PATH = $(_LINUX_JAVA_ROOT)/bin/javac
147+
JI_JAR_PATH = $(_LINUX_JAVA_ROOT)/bin/jar
148+
128149
endif # Linux
129150

130151
$(JI_JVM_PATH):
@@ -148,7 +169,7 @@ bin/Build$(CONFIGURATION)/JdkInfo.props: $(JI_JDK_INCLUDE_PATHS) $(JI_JVM_PATH)
148169
echo ' </When>' >> "$@"
149170
echo ' </Choose>' >> "$@"
150171
echo ' <PropertyGroup>' >> "$@"
151-
echo " <JavaCPath Condition=\" '\$$(JavaCPath)' == '' \">javac</JavaCPath>" >> "$@"
152-
echo " <JarPath Condition=\" '\$$(JarPath)' == '' \">jar</JarPath>" >> "$@"
172+
echo " <JavaCPath Condition=\" '\$$(JavaCPath)' == '' \">$(JI_JAVAC_PATH)</JavaCPath>" >> "$@"
173+
echo " <JarPath Condition=\" '\$$(JarPath)' == '' \">$(JI_JAR_PATH)</JarPath>" >> "$@"
153174
echo ' </PropertyGroup>' >> "$@"
154175
echo '</Project>' >> "$@"

0 commit comments

Comments
 (0)