Skip to content

Commit c5c858a

Browse files
Spasialexytomi
andcommitted
[cherrypick] build(core) detect JDK version with custom task
Taken and slightly modified from LWJGL@8fd5f8d This stops BindingConfig from being called repeatedly when chaining tasks like we do in `ci_build_android.bash` which causes issues as it sets `-Dbinding.core=true` after hardcoding its inclusion in the modules list. This causes `core` to duplicate at the end of the property `module.list` which messes with `ModuleInfoGen` as it tries to move a file it already moved before, that being the `module-info.class` file for `core`. Co-authored-by: tomikun <60690056+alexytomi@users.noreply.github.com>
1 parent 32b88d1 commit c5c858a

3 files changed

Lines changed: 66 additions & 45 deletions

File tree

build.xml

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,6 @@
2727

2828
<mkdir-symlink dir="bin"/>
2929

30-
<!-- Compile custom Ant tasks -->
31-
<mkdir dir="${bin.ant}"/>
32-
<lwjgl.javac
33-
destdir="${bin.ant}"
34-
classpath="${ant.core.lib}"
35-
36-
srcdir="${src.ant}/java"
37-
includes="org/lwjgl/**"
38-
39-
taskname="javac: Custom Ant Tasks"
40-
/>
41-
42-
<taskdef name="logLevel" classname="org.lwjgl.SetLogLevel" classpath="${bin.ant}"/>
43-
<taskdef name="bindingConfig" classname="org.lwjgl.BindingConfig" classpath="${bin.ant}"/>
44-
<bindingConfig/>
45-
4630
<ant antfile="update-dependencies.xml" target="check-dependencies" inheritAll="false"/>
4731

4832
<taskdef resource="org/jetbrains/kotlin/ant/antlib.xml" classpath="${kotlinc}/lib/kotlin-ant.jar"/>

config/build-definitions.xml

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,27 @@ Defines global properties and useful macros.
99
This script is included in /build.xml and /config/update-dependencies.xml.
1010
-->
1111
<project name="definitions" basedir="../" xmlns:if="ant:if" xmlns:unless="ant:unless">
12+
<property name="bin.ant" location="bin/classes/ant" relative="true"/>
13+
14+
<!-- Compile custom Ant tasks -->
15+
<mkdir dir="bin/classes/ant"/>
16+
<javac
17+
sourcepath="" debug="yes" source="8" target="8" encoding="UTF-8" includeantruntime="false" nowarn="true"
18+
19+
destdir="bin/classes/ant"
20+
classpath="${ant.core.lib}"
21+
22+
srcdir="modules/ant/src/main/java"
23+
includes="org/lwjgl/**"
24+
25+
taskname="javac: Custom Ant Tasks"
26+
/>
27+
28+
<!-- Define custom Ant tasks -->
29+
<taskdef name="logLevel" classname="org.lwjgl.SetLogLevel" classpath="${bin.ant}"/>
30+
<taskdef name="bindingConfig" classname="org.lwjgl.BindingConfig" classpath="${bin.ant}"/>
31+
<taskdef name="detectJDKVersion" classname="org.lwjgl.DetectJDKVersion" classpath="${bin.ant}"/>
32+
1233
<property environment="env"/>
1334

1435
<!--
@@ -82,13 +103,11 @@ This script is included in /build.xml and /config/update-dependencies.xml.
82103

83104
<property name="module.lwjgl" location="modules/lwjgl" relative="true"/>
84105

85-
<property name="src.ant" location="modules/ant/src/main" relative="true"/>
86106
<property name="src.extract" location="modules/extract/src/main" relative="true"/>
87107
<property name="src.generator" location="modules/generator/src/main" relative="true"/>
88108

89109
<property name="test.resources" location="modules/samples/src/test/resources" relative="true"/>
90110

91-
<property name="bin.ant" location="bin/classes/ant" relative="true"/>
92111
<property name="bin.extract" location="bin/classes/extract" relative="true"/>
93112
<property name="bin.generator" location="bin/classes/generator" relative="true"/>
94113
<property name="bin.javadoc" location="bin/javadoc" relative="true"/>
@@ -134,29 +153,7 @@ This script is included in /build.xml and /config/update-dependencies.xml.
134153

135154
<property name="lib.native" location="${lib}/native/${platform}/${build.arch}" relative="true"/>
136155

137-
<!--
138-
Detect version of JDK running the Ant build.
139-
140-
VNUM = [1-9][0-9]*((\.0)*\.[1-9][0-9]*)*
141-
PRE = [a-zA-Z0-9]+
142-
java.version = $VNUM(\-$PRE)?
143-
-->
144-
<local name="java.version.regex"/>
145-
<property name="java.version.regex" value="((\.0)*\.[1-9][0-9]*)*(-[a-zA-Z0-9]+)?"/> <!-- without the major number -->
146-
147-
<condition property="jdk21"> <matches string="${java.version}" pattern="^21${java.version.regex}$"/> </condition>
148-
<condition property="jdk20"><or><isset property="jdk21"/><matches string="${java.version}" pattern="^20${java.version.regex}$"/></or></condition>
149-
<condition property="jdk19"><or><isset property="jdk20"/><matches string="${java.version}" pattern="^19${java.version.regex}$"/></or></condition>
150-
<condition property="jdk18"><or><isset property="jdk19"/><matches string="${java.version}" pattern="^18${java.version.regex}$"/></or></condition>
151-
<condition property="jdk17"><or><isset property="jdk18"/><matches string="${java.version}" pattern="^17${java.version.regex}$"/></or></condition>
152-
<condition property="jdk16"><or><isset property="jdk17"/><matches string="${java.version}" pattern="^16${java.version.regex}$"/></or></condition>
153-
<condition property="jdk15"><or><isset property="jdk16"/><matches string="${java.version}" pattern="^15${java.version.regex}$"/></or></condition>
154-
<condition property="jdk14"><or><isset property="jdk15"/><matches string="${java.version}" pattern="^14${java.version.regex}$"/></or></condition>
155-
<condition property="jdk13"><or><isset property="jdk14"/><matches string="${java.version}" pattern="^13${java.version.regex}$"/></or></condition>
156-
<condition property="jdk12"><or><isset property="jdk13"/><matches string="${java.version}" pattern="^12${java.version.regex}$"/></or></condition>
157-
<condition property="jdk11"><or><isset property="jdk12"/><matches string="${java.version}" pattern="^11${java.version.regex}$"/></or></condition>
158-
<condition property="jdk10"><or><isset property="jdk11"/><matches string="${java.version}" pattern="^10${java.version.regex}$"/></or></condition>
159-
<condition property= "jdk9"><or><isset property="jdk10"/><matches string="${java.version}" pattern= "^9${java.version.regex}$"/></or></condition>
156+
<detectJDKVersion/>
160157

161158
<!-- May be set in the ant command line to test multi-release implementations. -->
162159
<condition property="core.java20"><isset property="core.java21"/></condition>
@@ -185,33 +182,34 @@ This script is included in /build.xml and /config/update-dependencies.xml.
185182
<property name="bin.native" location="bin/${platform}/${build.arch}" relative="true"/>
186183

187184
<import file="build-bindings.xml"/>
185+
<bindingConfig/>
188186

189187
<presetdef name="lwjgl.javac">
190-
<javac sourcepath="" debug="yes" source="8" target="8" encoding="UTF-8">
188+
<javac sourcepath="" debug="yes" source="8" target="8" encoding="UTF-8" includeantruntime="false">
191189
<compilerarg line='--boot-class-path "${env.JAVA8_HOME}/jre/lib/rt.jar"' if:set="set-boot-class-path"/>
192190
<compilerarg value="-Xlint:all"/>
193191
<compilerarg value="-XDignore.symbol.file"/> <!-- Suppresses internal API (e.g. Unsafe) usage warnings -->
194192
</javac>
195193
</presetdef>
196194

197195
<presetdef name="lwjgl.javac9">
198-
<javac sourcepath="" debug="yes" encoding="UTF-8">
196+
<javac sourcepath="" debug="yes" encoding="UTF-8" includeantruntime="false">
199197
<compilerarg line="--release 9"/>
200198
<compilerarg value="-Xlint:all"/>
201199
<compilerarg value="-XDignore.symbol.file"/>
202200
</javac>
203201
</presetdef>
204202

205203
<presetdef name="lwjgl.javac10">
206-
<javac sourcepath="" debug="yes" encoding="UTF-8">
204+
<javac sourcepath="" debug="yes" encoding="UTF-8" includeantruntime="false">
207205
<compilerarg line="--release 10"/>
208206
<compilerarg value="-Xlint:all"/>
209207
<compilerarg value="-XDignore.symbol.file"/>
210208
</javac>
211209
</presetdef>
212210

213211
<presetdef name="lwjgl.javac16">
214-
<javac sourcepath="" debug="yes" encoding="UTF-8">
212+
<javac sourcepath="" debug="yes" encoding="UTF-8" includeantruntime="false">
215213
<compilerarg line="--release 16"/>
216214
<compilerarg value="-Xlint:all"/>
217215
<compilerarg value="-XDignore.symbol.file"/>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright LWJGL. All rights reserved.
3+
* License terms: https://www.lwjgl.org/license
4+
*/
5+
package org.lwjgl;
6+
7+
import org.apache.tools.ant.*;
8+
9+
import java.util.regex.*;
10+
11+
public class DetectJDKVersion extends Task {
12+
13+
@Override public void execute() {
14+
15+
String javaVersion = System.getProperty("java.version");
16+
17+
Matcher matcher = Pattern
18+
.compile("^([1-9][0-9]*)(?:(?:\\.0)*\\.[1-9][0-9]*)*(?:-[a-zA-Z0-9]+)?")
19+
.matcher(javaVersion);
20+
21+
if (!matcher.find()) {
22+
if (javaVersion.startsWith("1.")) {
23+
if (!javaVersion.startsWith("1.8.")) {
24+
throw new BuildException("JDK 8 or newer is required.");
25+
}
26+
return;
27+
}
28+
throw new BuildException("Failed to parse java.version: " + javaVersion);
29+
}
30+
31+
int version = Integer.parseInt(matcher.group(1));
32+
33+
Project LWJGL = getProject();
34+
for (int v = version; 9 <= v; v--) {
35+
LWJGL.setProperty("jdk" + v, "true");
36+
}
37+
}
38+
39+
}

0 commit comments

Comments
 (0)