Skip to content

Commit

Permalink
Shell Script Generation setting was ignored by the extension.
Browse files Browse the repository at this point in the history
Also added a test to make sure it works properly.
  • Loading branch information
Martin Häusler committed Mar 18, 2024
1 parent c4e7ea5 commit 1e81fa6
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 36 deletions.
45 changes: 45 additions & 0 deletions src/integrationTest/kotlin/TestRunner.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,49 @@ class TestRunner {
output.assertContains("Godot information:","Header not printed")
output.assertContains("Current version: 3.5","Godot version not printed")
}

@ParameterizedTest
@ArgumentsSource(ScriptTypeArgumentProvider::class)
fun `can disable shell script generation`(postfix: String, @TempDir tempDir: File) {
"respectShellScriptGeneration".createBuildFile(postfix, tempDir)
//run the tasks we want
doRun(tempDir, listOf("tasks", "buildEnvironment"), "--stacktrace")

// The build file specifies NOT to generate the shell scripts.
// Check if the setting was respected and the files haven't been generated.
val allFiles = tempDir.listFiles() ?: emptyArray()
allFiles.assertFileNotPresent("editor.sh")
allFiles.assertFileNotPresent("editor.bat")
allFiles.assertFileNotPresent("game.sh")
allFiles.assertFileNotPresent("game.bat")
}

@ParameterizedTest
@ArgumentsSource(ScriptTypeArgumentProvider::class)
fun `shell scripts are generated by default`(postfix: String, @TempDir tempDir: File) {

"noconfig".createBuildFile(postfix, tempDir)
//run the tasks we want
doRun(tempDir, listOf("tasks", "buildEnvironment"), "--stacktrace")
// The build file specifies NOT to generate the shell scripts.
// Check if the setting was respected and the files haven't been generated.
val allFiles = tempDir.listFiles() ?: emptyArray()
allFiles.assertFileIsPresent("editor.sh")
allFiles.assertFileIsPresent("editor.bat")
allFiles.assertFileIsPresent("game.sh")
allFiles.assertFileIsPresent("game.bat")
}

private fun Array<out File>.assertFileIsPresent(fileName: String) {
assert(any { it.name == fileName }) {
"The file '${fileName}' does not exist even though it should exist."
}
}

private fun Array<out File>.assertFileNotPresent(fileName: String) {
assert(none { it.name == fileName }) {
"The file '${fileName}' exists even though it shouldn't exist."
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
plugins {
id 'io.github.frontrider.godle'
}

godle {
generateQuickstartScripts = false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
plugins {
id("io.github.frontrider.godle")
}

godle {
generateQuickstartScripts = false
}
41 changes: 5 additions & 36 deletions src/main/kotlin/initializers/initBaseGodot.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,32 +33,10 @@ internal fun Project.initBaseGodot() {
}
}
//create runner scripts
// Not in a task, to make it less cumbersome.
File(project.projectDir, "editor.sh").apply {
if (!exists()) {
writeText(
"#!/bin/sh \n./gradlew godotEditor"
)
}
}
File(project.projectDir, "editor.bat").apply {
if (!exists()) {
writeText(
"gradlew.bat godotEditor"
)
}
}
File(project.projectDir, "game.sh").apply {
if (!exists()) {
writeText(
"#!/bin/sh \n./gradlew godotRunGame"
)
}
}
File(project.projectDir, "game.bat").apply {
if (!exists()) {
writeText("call gradlew.bat godotRunGame")
}
if(extension.generateQuickstartScripts){
// create runner scripts
// Not in a task, to make it less cumbersome.
this.generateQuickstartScripts()
}

val storePath = "${extension.godotFolder}/"
Expand Down Expand Up @@ -166,16 +144,7 @@ internal fun Project.initBaseGodot() {
}
}

private fun Project.generateQuickstartScripts(extension: GodleExtension) {
//ignore the gradle wrapper's folder.
if (File(project.rootDir, "gradle/").exists()) {
val file = File(project.rootDir, "gradle/.gdignore")
if (!file.exists()) {
file.writeText("")
}
}
//create runner scripts
// Not in a task, to make it less cumbersome.
private fun Project.generateQuickstartScripts() {
File(project.rootDir, "editor.sh").apply {
if (!exists()) {
writeText(
Expand Down

0 comments on commit 1e81fa6

Please sign in to comment.