Skip to content
This repository was archived by the owner on Jun 19, 2024. It is now read-only.

Commit ba320e8

Browse files
authored
Merge pull request #28 from LabyMod/cleanup
Cleanup
2 parents d415dd8 + e7a8d7c commit ba320e8

File tree

27 files changed

+907
-366
lines changed

27 files changed

+907
-366
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ jobs:
9292
run: "chmod +x gradlew"
9393
- name: Build base with gradle
9494
run: "./gradlew -PCI=true -PnativeBinaryExternalDir=native-binaries ultralight-java-base:build"
95-
- name: Build lwjgl3-opengl with gradle
96-
run: "./gradlew -PCI=true -PnativeBinaryExternalDir=native-binaries ultralight-java-lwjgl3-opengl:build"
95+
- name: Build lwjgl3-opengl example with gradle
96+
run: "./gradlew -PCI=true -PnativeBinaryExternalDir=native-binaries example:lwjgl3-opengl:build"
9797
- name: Check license
9898
run: "./gradlew licenseCheck"
9999
- name: Deploy to OSSHR

ci.gradle

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,77 @@
11
import org.apache.tools.ant.taskdefs.condition.Os
22

3+
// This is the directory the library headers will be generated in
34
ext.generatedHeadersDir = new File(buildDir, "generatedHeaders")
45
if(!ext.generatedHeadersDir.exists() && !ext.generatedHeadersDir.mkdirs()) {
56
throw new GradleException("Failed to create directory ${ext.generatedHeadersDir.absolutePath}")
67
}
78

9+
// This is the directory where the native binaries can be found after compilation
810
ext.nativeBinariesDir = new File(buildDir, "nativeBinaries")
911
if(!ext.nativeBinariesDir.exists() && !ext.nativeBinariesDir.mkdirs()) {
1012
throw new GradleException("Failed to create directory ${ext.nativeBinariesDir.absolutePath}")
1113
}
1214

15+
// Properties determining the build type
1316
def isExternalBuild = false
1417
def ciBuild = project.hasProperty("CI") && Boolean.parseBoolean(project.property("CI").toString())
1518

1619
if(!project.hasProperty("nativeBinaryExternalDir")) {
17-
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
20+
// The binaries will possibly be need to be built locally
21+
if(Os.isFamily(Os.FAMILY_WINDOWS)) {
1822
// WARNING, this assumes CMake uses visual studio
1923
// For GCC or Clang the output should be $nativeBinariesDir/libultralight-java.dll
2024
ext.nativeBinaries = Arrays.asList(new File(nativeBinariesDir, "Debug/ultralight-java.dll"))
21-
} else if (Os.isFamily(Os.FAMILY_MAC)) {
25+
} else if(Os.isFamily(Os.FAMILY_MAC)) {
2226
ext.nativeBinaries = Arrays.asList(new File(nativeBinariesDir, "libultralight-java.dylib"))
23-
} else if (Os.isFamily(Os.FAMILY_UNIX)) {
27+
} else if(Os.isFamily(Os.FAMILY_UNIX)) {
2428
ext.nativeBinaries = Arrays.asList(new File(nativeBinariesDir, "libultralight-java.so"))
2529
} else {
26-
if (!project.hasProperty("nativeBinaryLibrary")) {
30+
if(!project.hasProperty("nativeBinaryLibrary")) {
31+
// Unknown OS and missing binary, bail out
2732
throw new GradleException("Unable to determine native output library, " +
2833
"pass -PnativeBinaryLibrary=/path/to/native/binary to gradle")
2934
} else {
35+
// Unknown OS but the user specified the output binary
3036
ext.nativeBinaries = [new File(project.property("nativeBinaryLibrary").toString())]
3137
}
3238
}
3339
} else {
40+
// The binaries have been built by an external process and can be used now
3441
def nativeBinaryExternalDir = file(project.property("nativeBinaryExternalDir").toString())
3542
if(!nativeBinaryExternalDir.exists()) {
43+
// The directory where the binaries are supposed to be is missing, bail out
3644
throw new GradleException("nativeBinaryExternalDir ${nativeBinaryExternalDir.absolutePath} does not exist")
3745
}
3846

3947
ext.nativeBinaries = new ArrayList<File>()
4048

49+
// Collect all native binaries built externally
4150
for(def file in nativeBinaryExternalDir.listFiles()) {
4251
println "Found native binary ${file.absolutePath}"
4352
ext.nativeBinaries.add(file)
4453
}
4554

55+
// Flag the build
4656
isExternalBuild = true
4757
}
4858

4959
project(":ultralight-java-base").afterEvaluate { javaProject ->
5060
project(":ultralight-java-native").afterEvaluate { nativeProject ->
5161
if(!isExternalBuild) {
62+
// If the binaries have not been built externally, building the java project requires
63+
// building OS dependent binary locally
5264
javaProject.tasks["processResources"].dependsOn(nativeProject.tasks["build"])
5365
}
5466
}
5567
}
5668

69+
/**
70+
* Helper function to retrieve the file extensions from a file.
71+
*
72+
* @param file The file to retrieve the extension from
73+
* @return The extension of the file, or an empty string, if the file does not have an extension
74+
*/
5775
static def getExtension(File file) {
5876
String fileName = file.getName()
5977

@@ -64,16 +82,30 @@ static def getExtension(File file) {
6482
}
6583
}
6684

85+
/**
86+
* Helper function to retrieve the absolute path of a file without its extension.
87+
*
88+
* @param file The file to retrieve the path from
89+
* @return The absolute path of the file without its extension, or the path itself,
90+
* if the file does not have an extension
91+
*/
6792
static def getPathWithoutExtension(File file) {
68-
String fileName = file.getAbsolutePath()
93+
String path = file.getAbsolutePath()
6994

70-
if(fileName.lastIndexOf(".") != -1 && fileName.lastIndexOf(".") != 0) {
71-
return fileName.substring(0, fileName.lastIndexOf("."))
95+
if(path.lastIndexOf(".") != -1 && path.lastIndexOf(".") != 0) {
96+
return path.substring(0, path.lastIndexOf("."))
7297
} else {
73-
return ""
98+
return path
7499
}
75100
}
76101

102+
/**
103+
* Processes a binary file by calculating its new path and moving it if desired.
104+
*
105+
* @param binary The binary to process
106+
* @param doMove If {@code true}, the file will be moved to the new path
107+
* @return The new file of the binary
108+
*/
77109
def processBinary(File binary, boolean doMove) {
78110
String extension = getExtension(binary)
79111
String path = getPathWithoutExtension(binary)
@@ -89,12 +121,16 @@ def processBinary(File binary, boolean doMove) {
89121
}
90122

91123
if(ciBuild) {
124+
// We are running a CI build
92125
def ciDir = file("ci")
93126
if(!ciDir.exists() && !ciDir.mkdirs()) {
127+
// Failed to create a necessary directory, bail out
94128
throw new GradleException("Failed to create directory ${ciDir.absolutePath}")
95129
}
96130

97131
new File(ciDir, "binaries").withWriter {
132+
// Write a file with paths to the native binaries, required by our script
133+
// at .github/workflows/ci.yml to create an archive with natives
98134
for(File binary in ext.nativeBinaries) {
99135
it.write(processBinary(binary, false).absolutePath)
100136
}
@@ -104,13 +140,15 @@ if(ciBuild) {
104140

105141
task moveNativeBinaries {
106142
doLast {
107-
for (File binary in binaries) {
143+
for(File binary in binaries) {
144+
// Move the binaries to their new locations
108145
processBinary(binary, true)
109146
}
110147
}
111148
}
112149

113150
project(":ultralight-java-native").afterEvaluate { nativeProject ->
151+
// Make sure the binaries are moved after the build
114152
nativeProject.tasks["build"].finalizedBy(moveNativeBinaries)
115153
}
116154
}
Lines changed: 73 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -1,101 +1,73 @@
1-
import org.apache.tools.ant.taskdefs.condition.Os
2-
3-
plugins {
4-
id 'java-library'
5-
id 'maven-publish'
6-
}
7-
8-
group 'com.labymedia'
9-
10-
def lwjglClassifier = {
11-
if(Os.isFamily(Os.FAMILY_WINDOWS)) {
12-
return "natives-windows"
13-
} else if(Os.isFamily(Os.FAMILY_MAC)) {
14-
return "natives-macos"
15-
} else if(Os.isFamily(Os.FAMILY_UNIX)) {
16-
return "natives-linux"
17-
} else {
18-
throw new UnsupportedOperationException("This OS is not supported")
19-
}
20-
}
21-
22-
repositories {
23-
mavenCentral()
24-
}
25-
26-
dependencies {
27-
implementation group: 'org.lwjgl', name: 'lwjgl', version: '3.2.2'
28-
runtimeOnly group: 'org.lwjgl', name: 'lwjgl', version: '3.2.2', classifier: lwjglClassifier()
29-
30-
implementation group: 'org.lwjgl', name: 'lwjgl-opengl', version: '3.2.2'
31-
runtimeOnly group: 'org.lwjgl', name: 'lwjgl-opengl', version: '3.2.2', classifier: lwjglClassifier()
32-
33-
implementation project(':ultralight-java-base')
34-
implementation project(':ultralight-java-databind')
35-
36-
testImplementation group: 'org.lwjgl', name: 'lwjgl-glfw', version: '3.2.2'
37-
testRuntimeOnly group: 'org.lwjgl', name: 'lwjgl-glfw', version: '3.2.2', classifier: lwjglClassifier()
38-
}
39-
40-
tasks.test.enabled = false
41-
42-
def runDir = file("run")
43-
if(!runDir.exists() && !runDir.mkdirs()) {
44-
throw new GradleException("Failed to create run directory")
45-
}
46-
47-
def ultralightOsIdentifier = {
48-
def bitName = (System.getProperty("os.arch", "?").contains("64") ||
49-
System.getProperty("sun.arch.data.model", "?").contains("64")) ? "64" : "32"
50-
51-
if(Os.isFamily(Os.FAMILY_WINDOWS)) {
52-
return "win-x" + bitName
53-
} else if(Os.isFamily(Os.FAMILY_MAC)) {
54-
return "mac-x" + bitName
55-
} else if(Os.isFamily(Os.FAMILY_UNIX)) {
56-
return "linux-x" + bitName
57-
} else {
58-
throw new UnsupportedOperationException("This OS is not supported")
59-
}
60-
}
61-
62-
task copyTestResources(type: Copy) {
63-
from new File(project(':ultralight-java-native').buildDir, "cmake-gen-${ultralightOsIdentifier()}/3rdparty/ultralight-${ultralightOsIdentifier()}/bin")
64-
include "**/*.dll", "**/*.so", "**/*.dylib", "resources/*"
65-
into runDir
66-
}
67-
68-
task runTest(type: JavaExec, dependsOn: [copyTestResources]) {
69-
classpath sourceSets.test.runtimeClasspath
70-
main "com.labymedia.ultralight.lwjgl3.opengl.TestRunner"
71-
jvmArgs "-Xmx5M"
72-
workingDir file("run")
73-
}
74-
75-
task exportTestCommandLine {
76-
doLast {
77-
println tasks.runTest.commandLine.join(" ")
78-
}
79-
}
80-
81-
task testJar(type: Jar) {
82-
sourceSets.test.runtimeClasspath.each {
83-
def target = file(it)
84-
85-
if(!target.exists()) {
86-
return
87-
}
88-
89-
if(target.isDirectory()) {
90-
from(fileTree(it))
91-
} else {
92-
from(zipTree(it))
93-
}
94-
}
95-
96-
manifest {
97-
attributes(
98-
"Main-Class": "com.labymedia.ultralight.lwjgl3.opengl.TestRunner"
99-
)
100-
}
101-
}
1+
import org.apache.tools.ant.taskdefs.condition.Os
2+
3+
plugins {
4+
id 'application'
5+
}
6+
7+
group 'com.labymedia'
8+
9+
def lwjglClassifier = {
10+
if(Os.isFamily(Os.FAMILY_WINDOWS)) {
11+
return "natives-windows"
12+
} else if(Os.isFamily(Os.FAMILY_MAC)) {
13+
return "natives-macos"
14+
} else if(Os.isFamily(Os.FAMILY_UNIX)) {
15+
return "natives-linux"
16+
} else {
17+
throw new UnsupportedOperationException("This OS is not supported")
18+
}
19+
}
20+
21+
repositories {
22+
mavenCentral()
23+
}
24+
25+
dependencies {
26+
implementation group: 'org.lwjgl', name: 'lwjgl', version: '3.2.2'
27+
runtimeOnly group: 'org.lwjgl', name: 'lwjgl', version: '3.2.2', classifier: lwjglClassifier()
28+
29+
implementation group: 'org.lwjgl', name: 'lwjgl-opengl', version: '3.2.2'
30+
runtimeOnly group: 'org.lwjgl', name: 'lwjgl-opengl', version: '3.2.2', classifier: lwjglClassifier()
31+
32+
implementation project(':ultralight-java-base')
33+
implementation project(':ultralight-java-databind')
34+
35+
implementation group: 'org.lwjgl', name: 'lwjgl-glfw', version: '3.2.2'
36+
runtimeOnly group: 'org.lwjgl', name: 'lwjgl-glfw', version: '3.2.2', classifier: lwjglClassifier()
37+
}
38+
39+
def runDir = file("run")
40+
if(!runDir.exists() && !runDir.mkdirs()) {
41+
throw new GradleException("Failed to create run directory")
42+
}
43+
44+
def ultralightOsIdentifier = {
45+
def bitName = (System.getProperty("os.arch", "?").contains("64") ||
46+
System.getProperty("sun.arch.data.model", "?").contains("64")) ? "64" : "32"
47+
48+
if(Os.isFamily(Os.FAMILY_WINDOWS)) {
49+
return "win-x" + bitName
50+
} else if(Os.isFamily(Os.FAMILY_MAC)) {
51+
return "mac-x" + bitName
52+
} else if(Os.isFamily(Os.FAMILY_UNIX)) {
53+
return "linux-x" + bitName
54+
} else {
55+
throw new UnsupportedOperationException("This OS is not supported")
56+
}
57+
}
58+
59+
application {
60+
mainClassName = "com.labymedia.ultralight.lwjgl3.opengl.ExampleMain"
61+
}
62+
63+
run {
64+
workingDir runDir
65+
}
66+
67+
task copyResources(type: Copy) {
68+
from new File(project(':ultralight-java-native').buildDir, "cmake-gen-${ultralightOsIdentifier()}/3rdparty/ultralight-${ultralightOsIdentifier()}/bin")
69+
include "**/*.dll", "**/*.so", "**/*.dylib", "resources/*"
70+
into runDir
71+
}
72+
73+
run.dependsOn copyResources

0 commit comments

Comments
 (0)