Skip to content

Commit

Permalink
build: replace scripts with custom Ant tasks
Browse files Browse the repository at this point in the history
Eliminates the annoying Nashorn deprecation warnings when building with
JDK 11 or higher.
  • Loading branch information
Spasi committed Jun 20, 2020
1 parent 0f3869e commit db98a0b
Show file tree
Hide file tree
Showing 9 changed files with 163 additions and 92 deletions.
3 changes: 2 additions & 1 deletion .idea/libraries/Ant_Launcher.xml → .idea/libraries/Ant.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions .idea/modules/ant.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/modules/templates.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 17 additions & 1 deletion build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 13,7 @@
<import file="${config}/${platform}/build.xml"/>

<!-- Initialize build -->
<target name="init" description="Initializes the directories required by the build process" depends="bindings">
<target name="init" description="Initializes the directories required by the build process">
<fail message="LWJGL requires Ant version 1.9.3 or higher.">
<condition>
<not><antversion atleast="1.9.3"/></not>
Expand All @@ -27,6 27,22 @@

<mkdir-symlink dir="bin"/>

<!-- Compile custom Ant tasks -->
<mkdir dir="${bin.ant}"/>
<lwjgl.javac
destdir="${bin.ant}"
classpath="${ant.core.lib}"

srcdir="${src.ant}/java"
includes="org/lwjgl/**"

taskname="javac: Custom Ant Tasks"
/>

<taskdef name="logLevel" classname="org.lwjgl.SetLogLevel" classpath="${bin.ant}"/>
<taskdef name="bindingConfig" classname="org.lwjgl.BindingConfig" classpath="${bin.ant}"/>
<bindingConfig/>

<ant antfile="update-dependencies.xml" target="check-dependencies" inheritAll="false"/>

<taskdef resource="org/jetbrains/kotlin/ant/antlib.xml" classpath="${kotlinc}/lib/kotlin-ant.jar"/>
Expand Down
89 changes: 6 additions & 83 deletions config/build-bindings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,92 78,15 @@ This script is included in /config/build-definitions.xml.
<!-- Set the path to the Oculus SDK to enable. -->
<!-- TODO: add headers in here -->
<property name="OCULUS_SDK_PATH" location="../OculusSDK" relative="false"/>
<condition property="binding.ovr" value="true" else="false">
<and>
<isset property="OCULUS_SDK_PATH"/>
<available file="${OCULUS_SDK_PATH}/LibOVR/Include/OVR_CAPI.h"/>
</and>
</condition>

<!-- // ================================ // -->

<target name="bindings">
<condition property="binding.ovr" value="true" else="false">
<and>
<isset property="OCULUS_SDK_PATH"/>
<available file="${OCULUS_SDK_PATH}/LibOVR/Include/OVR_CAPI.h"/>
</and>
</condition>

<local name="dependency_problem"/>
<condition property="dependency_problem" value="1">
<and>
<istrue value="${binding.ovr}"/>

<and>
<isfalse value="${binding.opengl}"/>
<isfalse value="${binding.vulkan}"/>
</and>
</and>
</condition>
<fail if="dependency_problem" message="The OpenGL or Vulkan bindings are required."/>

<condition property="dependency_problem" value="1">
<and>
<istrue value="${binding.nanovg}"/>
<or>
<isfalse value="${binding.stb}"/>
<and>
<isfalse value="${binding.bgfx}"/>
<isfalse value="${binding.opengl}"/>
<isfalse value="${binding.opengles}"/>
</and>
</or>
</and>
</condition>
<fail if="dependency_problem" message="The stb and OpenGL or OpenGL ES bindings are required."/>

<script language="javascript">
var props = LWJGL.getProperties();

var modules = ["core"];
var bindings = ["-Dbinding.DISABLE_CHECKS=" props.get("binding.DISABLE_CHECKS")];

for each (p in props.entrySet()) {
var name = p.key;
if (name.startsWith("binding.") &amp;&amp; p.value == "true") {
var module = name.substring(8);

modules.push(module);
bindings.push("-D" name "=true");
}
}

LWJGL.setProperty("binding.core", "true");
LWJGL.setProperty("generator.bindings", bindings.join(" "));
LWJGL.setProperty("module.list", modules.join(","));

var classes = [];
var templates = [];
var sources = [];

modules.forEach(function(it) {
LWJGL.setProperty("module." it ".path", it == "core" ? "org/lwjgl" : "org/lwjgl/" it);

classes.push("bin/classes/lwjgl/" it);

var src = "modules/lwjgl/" it "/src";

templates.push(src "/templates/kotlin");
sources.push(src "/generated/java");
if (java.nio.file.Files.isDirectory(java.nio.file.Paths.get(src "/main/java"))) {
sources.push(src "/main/java");
}
});

LWJGL.setProperty("module.classpath", classes.join(java.io.File.pathSeparator));
LWJGL.setProperty("module.templatepath", templates.join(java.io.File.pathSeparator));
LWJGL.setProperty("module.sourcepath", sources.join(java.io.File.pathSeparator));
LWJGL.setProperty("module.javadocsourcepath", sources.filter(function(it) {
return it.indexOf('driftfx/src/main/java') === -1;
}).join(java.io.File.pathSeparator));
</script>
</target>

<macrodef name="forEachBinding">
<element name="body" implicit="yes"/>
<sequential>
Expand Down
10 changes: 4 additions & 6 deletions config/build-definitions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 66,13 @@ This script is included in /build.xml and /config/update-dependencies.xml.

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

<property name="src.ant" location="modules/ant/src/main" relative="true"/>
<property name="src.extract" location="modules/extract/src/main" relative="true"/>
<property name="src.generator" location="modules/generator/src/main" relative="true"/>

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

<property name="bin.ant" location="bin/classes/ant" relative="true"/>
<property name="bin.extract" location="bin/classes/extract" relative="true"/>
<property name="bin.generator" location="bin/classes/generator" relative="true"/>
<property name="bin.javadoc" location="bin/javadoc" relative="true"/>
Expand Down Expand Up @@ -204,13 206,9 @@ This script is included in /build.xml and /config/update-dependencies.xml.
<macrodef name="quiet">
<element name="body" implicit="yes"/>
<sequential>
<script language="javascript">
project.getBuildListeners().firstElement().setMessageOutputLevel(org.apache.tools.ant.Project.MSG_WARN);
</script>
<logLevel level="error"/>
<body/>
<script language="javascript">
project.getBuildListeners().firstElement().setMessageOutputLevel(org.apache.tools.ant.Project.MSG_INFO);
</script>
<logLevel level="info"/>
</sequential>
</macrodef>

Expand Down
90 changes: 90 additions & 0 deletions modules/ant/src/main/java/org/lwjgl/BindingConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 1,90 @@
/*
* Copyright LWJGL. All rights reserved.
* License terms: https://www.lwjgl.org/license
*/
package org.lwjgl;

import org.apache.tools.ant.*;

import java.io.*;
import java.nio.file.*;
import java.util.*;
import java.util.stream.*;

import static java.lang.String.*;

public class BindingConfig extends Task {

private boolean isTrue(String name) {
return "true".equals(getProject().getProperty(name));
}

private boolean isFalse(String name) {
return "false".equals(getProject().getProperty(name));
}

@Override public void execute() {
if (isTrue("binding.nanovg")) {
if (isFalse("binding.stb") || !(
isTrue("binding.bgfx") ||
isTrue("binding.opengl") ||
isTrue("binding.opengles"))
) {
throw new BuildException("The nanovg module depends on the stb and one of bgfx/OpenGL/OpenGL ES modules.");
}
}

if (isTrue("binding.ovr")) {
if (isFalse("binding.opengl") && isFalse("binding.vulkan")) {
throw new BuildException("The OpenGL or Vulkan bindings are required.");
}
}

Project LWJGL = getProject();

ArrayList<String> modules = new ArrayList<>(64);
modules.add("core");

ArrayList<String> bindings = new ArrayList<>(64);
bindings.add("-Dbinding.DISABLE_CHECKS=" LWJGL.getProperty("binding.DISABLE_CHECKS"));

for (Map.Entry<String, Object> p : LWJGL.getProperties().entrySet()) {
String name = p.getKey();
if (name.startsWith("binding.") && "true".equals(p.getValue())) {
modules.add(name.substring(8));
bindings.add("-D" name "=true");
}
}

LWJGL.setProperty("binding.core", "true");
LWJGL.setProperty("generator.bindings", join(" ", bindings));
LWJGL.setProperty("module.list", join(",", modules));

ArrayList<String> classes = new ArrayList<>(modules.size());
ArrayList<String> templates = new ArrayList<>(modules.size());
ArrayList<String> sources = new ArrayList<>(modules.size() * 2);

modules.forEach(it -> {
LWJGL.setProperty("module." it ".path", it.equals("core") ? "org/lwjgl" : "org/lwjgl/" it);

classes.add("bin/classes/lwjgl/" it);

String src = "modules/lwjgl/" it "/src";

templates.add(src "/templates/kotlin");
sources.add(src "/generated/java");
if (Files.isDirectory(Paths.get(src "/main/java"))) {
sources.add(src "/main/java");
}
});

LWJGL.setProperty("module.classpath", join(File.pathSeparator, classes));
LWJGL.setProperty("module.templatepath", join(File.pathSeparator, templates));
LWJGL.setProperty("module.sourcepath", join(File.pathSeparator, sources));
LWJGL.setProperty("module.javadocsourcepath", sources
.stream()
.filter(it -> !it.contains("driftfx/src/main/java"))
.collect(Collectors.joining(File.pathSeparator)));
}

}
26 changes: 26 additions & 0 deletions modules/ant/src/main/java/org/lwjgl/SetLogLevel.java
Original file line number Diff line number Diff line change
@@ -0,0 1,26 @@
/*
* Copyright LWJGL. All rights reserved.
* License terms: https://www.lwjgl.org/license
*/
package org.lwjgl;

import org.apache.tools.ant.*;
import org.apache.tools.ant.types.*;

public class SetLogLevel extends org.apache.tools.ant.Task {

private LogLevel logLevel = LogLevel.INFO;

@Override public void execute() {
for (BuildListener listener : getProject().getBuildListeners()) {
if (listener instanceof BuildLogger) {
((BuildLogger)listener).setMessageOutputLevel(logLevel.getLevel());
}
}
}

public void setLevel(LogLevel logLevel) {
this.logLevel = logLevel;
}

}

0 comments on commit db98a0b

Please sign in to comment.