Refactored build scripts and removed unused dependencies

- Added the following Gradle tasks:
  - buildLocal (alias for build)
  - buildCrossPlatform (builds with all natives)
  - packageDebian
  - packageWindows
- Gradle no longer downloads or packages natives for wrong platforms
(unless buildCrossPlatform or require*Dependencies is run)
- Gradle should no longer complain about deprecated features
- buildPackages.sh is now a lot more robust
- Removed the following dependencies:
  - Apache Commons Math
  - Everything in LWJGL except OpenGL/AL, GLFW, STB and core
This commit is contained in:
OLEGSHA 2021-01-08 00:33:53 +03:00
parent eb82c96390
commit e389d2ad67
3 changed files with 358 additions and 105 deletions

View File

@ -1,31 +1,90 @@
/*
* build.gradle for Progressia
*/
plugins { plugins {
// Apply the java-library plugin to add support for Java Library // Apply the java-library plugin to add support for Java Library
id 'java-library' id 'java-library'
/*
* Uncomment the following line to enable the Eclipse plugin.
* This is only necessary if you don't use Buildship plugin from the IDE
*/
//id 'eclipse'
} }
java {
/*
* We're Java 8 for now.
* Why? As of 2020, most users have Oracle Java, which only supports Java 8.
*/
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
compileJava {
/*
* We want to compile for Java 8.
* If we are using JDK 8, no further action is required.
* However, on JDK 9 and later versions, '--release' option is required,
* which is missing on JDK 8.
*/
if (JavaVersion.current() != JavaVersion.VERSION_1_8) {
options.compilerArgs.addAll(['--release', '8'])
}
}
/*
* Dependencies
*/
repositories { repositories {
mavenCentral() mavenCentral()
jcenter() jcenter()
maven { url 'http://windcorp.ru/./maven' } /*
* Specify Windcorp Maven repository
* Currently used by:
* - ru.windcorp.fork.io.github.java-graphics:glm:1.0.1
*/
maven { url 'https://windcorp.ru/./maven' }
} }
dependencies { dependencies {
implementation 'org.apache.commons:commons-math3:3.6.1' // Google Guava
// A generic utilities library
implementation 'com.google.guava:guava:30.0-jre' implementation 'com.google.guava:guava:30.0-jre'
// Trove4j
// Provides optimized Collections for primitive types
implementation 'net.sf.trove4j:trove4j:3.0.3' implementation 'net.sf.trove4j:trove4j:3.0.3'
// java-graphics
// A GLM (OpenGL Mathematics) port to Java
// Unfortunately, Maven Central Repository provides an outdated version of this library, which contains several critical bugs
implementation 'ru.windcorp.fork.io.github.java-graphics:glm:1.0.1' implementation 'ru.windcorp.fork.io.github.java-graphics:glm:1.0.1'
// log4j // Log4j
// A logging library
implementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.13.3' implementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.13.3'
implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.13.3' implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.13.3'
// JUnit
// A unit-testing library
testImplementation 'junit:junit:4.12' testImplementation 'junit:junit:4.12'
// See also LWJGL dependencies below // See LWJGL dependencies below
} }
/*
* Progressia uses the following LWJGL libraries:
* - Core libraries
* - OpenGL
* - OpenAL
* - GLFW
* - STB
*/
/* /*
* LWJGL * LWJGL
* (auto-generated script) * (auto-generated script)
@ -55,94 +114,169 @@ dependencies {
implementation platform("org.lwjgl:lwjgl-bom:$lwjglVersion") implementation platform("org.lwjgl:lwjgl-bom:$lwjglVersion")
implementation "org.lwjgl:lwjgl" implementation "org.lwjgl:lwjgl"
implementation "org.lwjgl:lwjgl-assimp"
implementation "org.lwjgl:lwjgl-bgfx"
implementation "org.lwjgl:lwjgl-glfw" implementation "org.lwjgl:lwjgl-glfw"
implementation "org.lwjgl:lwjgl-nanovg"
implementation "org.lwjgl:lwjgl-nuklear"
implementation "org.lwjgl:lwjgl-openal" implementation "org.lwjgl:lwjgl-openal"
implementation "org.lwjgl:lwjgl-opengl" implementation "org.lwjgl:lwjgl-opengl"
implementation "org.lwjgl:lwjgl-par"
implementation "org.lwjgl:lwjgl-stb" implementation "org.lwjgl:lwjgl-stb"
implementation "org.lwjgl:lwjgl-vulkan"
runtimeOnly "org.lwjgl:lwjgl::$lwjglNatives" // Not adding runtimeOnly native libraries because natives are handled by addNativeDependencies
runtimeOnly "org.lwjgl:lwjgl-assimp::$lwjglNatives"
runtimeOnly "org.lwjgl:lwjgl-bgfx::$lwjglNatives"
runtimeOnly "org.lwjgl:lwjgl-glfw::$lwjglNatives"
runtimeOnly "org.lwjgl:lwjgl-nanovg::$lwjglNatives"
runtimeOnly "org.lwjgl:lwjgl-nuklear::$lwjglNatives"
runtimeOnly "org.lwjgl:lwjgl-openal::$lwjglNatives"
runtimeOnly "org.lwjgl:lwjgl-opengl::$lwjglNatives"
runtimeOnly "org.lwjgl:lwjgl-par::$lwjglNatives"
runtimeOnly "org.lwjgl:lwjgl-stb::$lwjglNatives"
if (lwjglNatives == "natives-macos") runtimeOnly "org.lwjgl:lwjgl-vulkan::$lwjglNatives"
} }
// LWJGL END // LWJGL END
configurations { /*
packageOnly * Tasks
packageLibraries.extendsFrom runtimeClasspath */
packageLibraries.extendsFrom packageOnly
}
dependencies { /*
def archs = ['natives-linux', 'natives-linux-arm64', 'natives-linux-arm32', 'natives-macos', 'natives-windows', 'natives-windows-x86'] * Additional native libraries specification
*/
archs.each { arch -> project.ext.platforms = new ArrayList<>()
packageOnly "org.lwjgl:lwjgl::$arch"
packageOnly "org.lwjgl:lwjgl-assimp::$arch" task addNativeDependencies {
packageOnly "org.lwjgl:lwjgl-bgfx::$arch" doFirst {
packageOnly "org.lwjgl:lwjgl-glfw::$arch" def archs = project.ext.platforms
packageOnly "org.lwjgl:lwjgl-nanovg::$arch"
packageOnly "org.lwjgl:lwjgl-nuklear::$arch" switch (archs.size()) {
packageOnly "org.lwjgl:lwjgl-openal::$arch" case 0:
packageOnly "org.lwjgl:lwjgl-opengl::$arch" println "Adding LWJGL native dependencies for local platform only:\n\t$lwjglNatives"
packageOnly "org.lwjgl:lwjgl-par::$arch" archs.add project.ext.lwjglNatives
packageOnly "org.lwjgl:lwjgl-stb::$arch" break
case 1:
println "Adding LWJGL native dependencies for platform\n\t" + archs.get(0)
break
default:
println "Adding LWJGL native dependencies for platforms:\n\t" + archs.join("\n\t")
} }
packageOnly "org.lwjgl:lwjgl-vulkan::natives-macos" dependencies {
archs.each { arch ->
runtimeOnly "org.lwjgl:lwjgl::$arch"
runtimeOnly "org.lwjgl:lwjgl-glfw::$arch"
runtimeOnly "org.lwjgl:lwjgl-openal::$arch"
runtimeOnly "org.lwjgl:lwjgl-opengl::$arch"
runtimeOnly "org.lwjgl:lwjgl-stb::$arch"
}
}
}
} }
jar { compileJava.mustRunAfter addNativeDependencies // Make sure runtimeOnly has not been resolved
task requireLinuxDependencies {
description 'Adds linux, linux-arm64 and linux-arm32 native libraries to built artifacts.'
doFirst {
project.ext.platforms.addAll(['natives-linux', 'natives-linux-arm64', 'natives-linux-arm32'])
}
}
task requireWindowsDependencies {
description 'Adds windows and windows-x86 native libraries to built artifacts.'
doFirst {
project.ext.platforms.addAll(['natives-windows', 'natives-windows-x86'])
}
}
task requireMacOSDependencies {
description 'Adds macos native libraries to built artifacts.'
doFirst {
project.ext.platforms.addAll(['natives-macos'])
}
}
def dependencySpecificationTasks = tasks.findAll { task -> task.name.startsWith('require') && task.name.endsWith('Dependencies') }
task requireCrossPlatformDependencies {
description 'Adds native libraries for all available platforms to built artifacts.'
dependsOn dependencySpecificationTasks
}
addNativeDependencies.mustRunAfter dependencySpecificationTasks
/*
* Manifest specification
*/
task specifyLocalManifest {
dependsOn addNativeDependencies // Make sure all native dependencies are specified
doFirst {
jar {
manifest { manifest {
attributes( attributes(
"Main-Class": "ru.windcorp.progressia.client.ProgressiaClientMain", "Main-Class": "ru.windcorp.progressia.client.ProgressiaClientMain",
"Class-Path": configurations.packageLibraries.collect { "lib/" + it.getName() }.join(' ') "Class-Path": configurations.runtimeClasspath.collect { "lib/" + it.getName() } .join(' ')
) )
} }
}
}
} }
build.dependsOn specifyLocalManifest
/* /*
* Copies runtime dependencies to a prespecified location so they can be packaged properly. * Library export
*/ */
task copyLibs(type: Copy) { task copyLibs(type: Copy) {
into "${libsDir}/lib" mustRunAfter addNativeDependencies
into libsDirectory.get().getAsFile().getPath() + "/lib"
from configurations.runtimeClasspath from configurations.runtimeClasspath
} }
build.dependsOn(copyLibs) build.dependsOn(copyLibs)
task copyLibsForPackaging(type: Copy) { /*
into "${libsDir}/lib" * Packaging
from configurations.packageLibraries */
}
task createPackages(type: Exec) { task packageDebian(type: Exec) {
commandLine './buildPackages.sh' description 'Builds the project and creates a Debain package.'
} group 'Progressia'
java { dependsOn build
sourceCompatibility = JavaVersion.VERSION_1_8 dependsOn requireLinuxDependencies
targetCompatibility = JavaVersion.VERSION_1_8
}
compileJava { commandLine './buildPackages.sh', 'debian'
if (JavaVersion.current() != JavaVersion.VERSION_1_8) {
options.compilerArgs.addAll(['--release', '8']) doLast {
println "Debian package available in build_packages/"
} }
} }
createPackages.dependsOn(build) task packageWindows(type: Exec) {
createPackages.dependsOn(copyLibsForPackaging) description 'Builds the project and creates a Windows installer.'
group 'Progressia'
dependsOn build
dependsOn requireWindowsDependencies
commandLine './buildPackages.sh', 'windows'
doLast {
println "Windows installer available in build_packages/"
}
}
task buildCrossPlatform {
description 'Builds the project including native libraries for all available platforms.'
group 'Progressia'
dependsOn requireCrossPlatformDependencies
dependsOn build
doLast {
println "Native libraries for all platforms have been added"
}
}
task buildLocal {
description "Builds the project including only native libraries for current platform ($lwjglNatives)."
group 'Progressia'
dependsOn build
doLast {
println "Native libraries only for platform $lwjglNatives have been added"
}
}

View File

@ -1,38 +1,159 @@
#!/bin/bash #!/bin/bash
lst="nsis" echoerr() { echo "$@" 1>&2; }
user=`whoami` buildDebianPackage() {
dpkg -l 2>/dev/null > ls.tmp # Commands that must be available to execute this action
requiredCommands='dpkg-deb fakeroot'
for items in $lst # Version that the package will receive
do version='0.1_all'
cmd=$(grep "\ $items\ " ls.tmp)
if [ $? == 0 ] directory="build_packages/DEB/progressia-$version"
then
echo "$items installed!" # .deb control file that must be present
echo "Building..." configurationFile="$directory/DEBIAN/control"
outputFile="build_packages/DEB/progressia-$version.deb"
echo "Checking environment to build Debian package"
for item in $requiredCommands; do
if command -v "$item" &> /dev/null; then
echo "- $item found"
else else
echo "Package $items not found! Please install $items." echoerr "Command $item not found, cannot package"
rm ls.tmp exit 100
exit 1
fi fi
done done
rm ls.tmp
cd build_packages/DEB/progressia-0.1_all/ if ! [ -r "$configurationFile" ]; then
mkdir -p home/$user/Progressia echoerr "$configurationFile is missing or not readable, cannot package"
exit 101
else
echo "- $configurationFile is present and readable"
fi
cd ../../.. echo "Environment OK; packaging Debian package"
exitCode=0
cp -r build/libs/lib build_packages/DEB/progressia-0.1_all/home/$user/Progressia/ {
cp build/libs/Progressia.jar build_packages/DEB/progressia-0.1_all/home/$user/Progressia/ user=`whoami`
cp -r build/libs/lib build_packages/NSIS homeDir="$directory/home/$user/Progressia/"
cp build/libs/Progressia.jar build_packages/NSIS
makensis build_packages/NSIS/ProgressiaInstaller.nsi mkdir -p "$homeDir" &&
mv build_packages/NSIS/ProgressiaInstaller.exe build_packages/Progressia.exe cp -r 'build/libs/lib' "$homeDir/lib" &&
fakeroot dpkg-deb --build build_packages/DEB/progressia-0.1_all cp 'build/libs/Progressia.jar' "$homeDir/Progressia.jar" &&
mv build_packages/DEB/progressia-0.1_all.deb build_packages/progressia-0.1_all.deb echo "------ DPKG-DEB ------" &&
echo "Build done!" fakeroot dpkg-deb --build "$directory" &&
echo "---- DPKG-DEB END ----" &&
mv "$outputFile" build_packages
} || {
echoerr "Could not create Debian package"
exitCode=1
}
{
if [ -d "$homeDir" ]; then
rm -r "$homeDir"
fi
echo "Cleaned up"
} || {
echoerr "Could not clean up after packaging Debian package"
exitCode=2
}
}
buildWindowsInstaller() {
# Commands that must be available to execute this action
requiredCommands='makensis'
# NSIS configuration file that must be present
configurationFile='build_packages/NSIS/ProgressiaInstaller.nsi'
# File that will be output
outputFile='build_packages/NSIS/ProgressiaInstaller.exe'
echo "Checking environment to build Windows installer"
for item in $requiredCommands; do
if command -v "$item" &> /dev/null; then
echo "- $item found"
else
echoerr "Command $item not found, cannot build"
exit 100
fi
done
if ! [ -r "$configurationFile" ]; then
echoerr "$configurationFile is missing or not readable, cannot build"
exit 101
else
echo "- $configurationFile is present and readable"
fi
echo "Environment OK; building Windows installer"
exitCode=0
{
cp -r 'build/libs/lib' 'build_packages/NSIS/lib' &&
cp 'build/libs/Progressia.jar' 'build_packages/NSIS/Progressia.jar' &&
echo "------ NSIS ------" &&
makensis "$configurationFile" &&
echo "---- NSIS END ----" &&
mv "$outputFile" build_packages
} || {
echoerr "Could not build Windows installer"
exitCode=1
}
{
if [ -d 'build_packages/NSIS/lib' ]; then
rm -r 'build_packages/NSIS/lib'
fi
if [ -e 'build_packages/NSIS/Progressia.jar' ]; then
rm 'build_packages/NSIS/Progressia.jar'
fi
echo "Cleaned up"
} || {
echoerr "Could not clean up after building Windows installer"
exitCode=2
}
exit "$exitCode"
}
printUsage() {
echoerr "Usage: $0 TARGET"
echoerr " where TARGET is 'debian' or 'windows'"
}
if [ -n "$2" ]; then
echoerr "Too many arguments."
printUsage
exit 202
fi
case "$1" in
"debian")
buildDebianPackage
;;
"windows")
buildWindowsInstaller
;;
"")
echoerr "No action specified"
printUsage
exit 200
;;
"--help" | "-help" | "help" | "?")
printUsage
;;
*)
echoerr "Unknown action '$1'"
printUsage
exit 201
;;
esac

View File

@ -1,13 +1,11 @@
package ru.windcorp.progressia.common.util; package ru.windcorp.progressia.common.util;
import org.apache.commons.math3.util.FastMath;
public class FloatMathUtils { public class FloatMathUtils {
public static final float PI_F = (float) Math.PI; public static final float PI_F = (float) Math.PI;
public static float floor(float x) { public static float floor(float x) {
return (float) FastMath.floor(x); return (float) Math.floor(x);
} }
public static float normalizeAngle(float a) { public static float normalizeAngle(float a) {