Skip to content

Commit

Permalink
feat(build): compile module-info with version info. Close #685
Browse files Browse the repository at this point in the history
  • Loading branch information
Spasi committed Oct 10, 2021
1 parent d0fcfd2 commit cef7b03
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 18 deletions.
40 changes: 35 additions & 5 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -932,8 +932,12 @@
</target>

<target name="-build-version" depends="compile">
<local name="stderr"/>
<java classname="org.lwjgl.Version" fork="true" failonerror="true" outputproperty="build.version" errorproperty="stderr">
<!-- -Dbuild.version is manually specified only when building a release -->
<condition property="build.release" value="true" else="false">
<isset property="build.version"/>
</condition>

<java classname="org.lwjgl.Version" fork="true" failonerror="true" outputproperty="build.version" errorproperty="build.version.plain" unless:set="build.version">
<classpath>
<pathelement path="${bin.lwjgl}/core"/>
<pathelement path="${lib}/native"/>
Expand Down Expand Up @@ -1204,12 +1208,14 @@
<java
classpath="bin/classes/generator"
classname="org.lwjgl.generator.util.ModuleInfoGen"
fork="true"
failonerror="true"
taskname="module-info-gen :: native :: ${module}"
if:set="jdk9"
>
<arg value="${module.name}"/>
<arg value="${module}"/>
<jvmarg value="-Dmodule.name.source=${module.name}"/>
<jvmarg value="-Dmodule.name.release=${module}"/>
<jvmarg value="-Dmodule.version=${module.version}"/>
</java>

<!-- Create native jar files -->
Expand Down Expand Up @@ -1392,11 +1398,33 @@

<!-- Set the LWJGL_BUILD_OFFLINE=true environment variable for local builds. -->
<target name="release" depends="-check-release-jdk,compile,-compile-generator,-build-version">
<!--
CUSTOM BUILD (LOCAL):
* build.version="M.m.r SNAPSHOT"
* build.revision=
* revision="SNAPSHOT"
* module.version="M.m.r-snapshot"
SNAPSHOT BUILD (CI): -Dbuild.revision=R
* build.version="M.m.r SNAPSHOT"
* build.revision="R"
* revision="build R"
* module.version="M.m.r-snapshot+R"
RELEASE BUILD (LOCAL): -Dbuild.version=M.m.r -Dbuild.revision=R
* build.version="M.m.r"
* build.revision="R"
* revision="build R"
* module.version="M.m.r+R"
-->
<local name="revision"/>
<condition property="revision" value="build ${build.revision}" else="SNAPSHOT">
<isset property="build.revision"/>
</condition>

<property name="module.version" value="${build.version}+${build.revision}" if:true="${build.release}"/>
<condition property="module.version" value="${build.version.plain}-snapshot+${build.revision}" else="${build.version.plain}-snapshot" unless:true="${build.release}">
<isset property="build.revision"/>
</condition>

<delete dir="${release}"/>
<mkdir dir="${release}"/>

Expand All @@ -1413,11 +1441,13 @@
<java
classpath="bin/classes/generator"
classname="org.lwjgl.generator.util.ModuleInfoGen"
fork="true"
failonerror="true"
taskname="module-info-gen :: java"
if:set="jdk9"
>
<arg value="${module.list}"/>
<jvmarg value="-Dmodule.name.list=${module.list}"/>
<jvmarg value="-Dmodule.version=${module.version}"/>
</java>

<parallel threadcount="4" failonany="true">
Expand Down
2 changes: 2 additions & 0 deletions doc/notes/3.3.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ This build includes the following changes:
- Core: Implemented overflow protection in text encoding methods.
- Core: When LWJGL fails to resolve native libraries, it will now attempt to report native JAR files in the classpath with mismatching platform/architecture. (#587)
- Core: The `SharedLibraryLoader` now prefers to extract natives to the working directory, over the user's home directory.
- Core: Added version information to module descriptors. (#685)
* The LWJGL version/build used will now be included in stacktraces of modular applications.
- docs: The javadoc of callback classes/interfaces now includes a link to the corresponding `invoke` method, for better IDE navigation.
- macOS: Shared libraries are now built with Xcode 11.3 (up from 10.0)
- GLFW: Added overrides for internally loaded shared libraries.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,11 @@ public void close() throws IOException {
}

public static void main(String[] args) throws IOException {
if (args.length == 1) {
generateJavaModuleInfoClasses(args[0]);
} else if (args.length == 2) {
generateNativeModuleInfoClasses(args[0], args[1]);
String moduleNameList = System.getProperty("module.name.list");
if (moduleNameList != null) {
generateJavaModuleInfoClasses(moduleNameList);
} else {
throw new IllegalArgumentException("Usage: ModuleInfoGen <module.list> OR <module source name> <module release name>");
generateNativeModuleInfoClasses();
}
}

Expand Down Expand Up @@ -82,7 +81,7 @@ private static class Module implements Comparable<Module> {
return name;
}

private void compile(ModuleInfoGen gen) {
private void compile(ModuleInfoGen gen, String moduleVersion) {
String modulePath = dependencies.stream()
.filter(it -> !it.missing)
.map(it -> "bin/classes/lwjgl/" + it.name)
Expand All @@ -98,6 +97,7 @@ private void compile(ModuleInfoGen gen) {

gen.compile(
name,
moduleVersion,
info,
modulePath,
Paths.get("modules", "lwjgl", name, "src", "main", "java"),
Expand Down Expand Up @@ -141,8 +141,9 @@ private static void generateJavaModuleInfoClasses(String moduleNameList) throws
topologicalSort(modules);

// Compile module-info classes
String moduleVersion = System.getProperty("module.version");
for (Module module : modules) {
module.compile(gen);
module.compile(gen, moduleVersion);
}

// Move module-info classes to <module>/META-INF/versions/9
Expand All @@ -160,28 +161,37 @@ private static void generateJavaModuleInfoClasses(String moduleNameList) throws
}
}

private static void generateNativeModuleInfoClasses(String moduleNameSource, String moduleNameRelease) throws IOException {
private static void generateNativeModuleInfoClasses() throws IOException {
String moduleNameSource = System.getProperty("module.name.source");
String moduleNameRelease = System.getProperty("module.name.release");
if (moduleNameSource == null || moduleNameRelease == null) {
throw new IllegalStateException("Module source & release names must be specified.");
}

Path root = Paths.get("bin", "RELEASE", moduleNameRelease, "native");

Module module = parseModuleInfo(Files.readAllBytes(Paths.get("modules", "lwjgl", moduleNameSource, "src", "main", "resources", "module-info.java")));
String moduleNative = module.nameJava + ".natives";
Module module = parseModuleInfo(Files.readAllBytes(Paths.get("modules", "lwjgl", moduleNameSource, "src", "main", "resources", "module-info.java")));

String moduleNative = module.nameJava + ".natives";
String moduleVersion = System.getProperty("module.version");

try (ModuleInfoGen gen = new ModuleInfoGen()) {
try (Stream<Path> platforms = Files.list(root)) {
platforms
.filter(it -> Files.isDirectory(it))
.filter(Files::isDirectory)
.forEach(platform -> {
try {
try (Stream<Path> architectures = Files.list(platform)) {
architectures
.filter(it -> Files.isDirectory(it))
.filter(Files::isDirectory)
.forEach(architecture -> {
String nativePackage = platform.getFileName().toString() + '.' + architecture.getFileName() + '.' + module.nameJava;

Path outputPath = architecture.resolve(METAINF);

gen.compile(
moduleNative,
moduleVersion,
"module " + moduleNative + " {\n" +
" requires transitive " + module.nameJava + ";\n" +
"\n" +
Expand Down Expand Up @@ -312,6 +322,7 @@ private static void push(List<Module> stack, Module module) {

private void compile(
String module,
String moduleVersion,
String moduleInfo,
String modulePath,
Path sourcePath,
Expand All @@ -337,6 +348,10 @@ private void compile(
options.add("--module-path");
options.add(modulePath);
}
if (moduleVersion != null) {
options.add("--module-version");
options.add(moduleVersion);
}
options.add("-d");
options.add(outputPath.toString());

Expand Down
3 changes: 2 additions & 1 deletion modules/lwjgl/core/src/main/java/org/lwjgl/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ private Version() {
}

public static void main(String[] args) {
System.out.println(getVersion());
System.out.println(version);
System.err.println(version.substring(0, version.indexOf(' ')));
}

/** Returns the LWJGL version. */
Expand Down

0 comments on commit cef7b03

Please sign in to comment.