Skip to content

Commit

Permalink
Simpler, better fix for the generateSolution issue [ATLAS-1772] (#197)
Browse files Browse the repository at this point in the history
## Description
Current generateSolution fix leaves a file behind in the project, which
polutes the git, and potentially may add an extra script to the game. As
this script is present when the solution is generated, its added to the
solution as well, which can generate issues when the added script is
removed in the cleanup task. As we need the rider extension anyway, its
a better solution to just call it directly to generate a solution.

## Changes
* ![IMPROVE] generateSolution doesn't need to inject a script anymore
* ![FIX] solutions generated with `generateSolution` task fails in
dotnet builds

[NEW]:      https://resources.atlas.wooga.com/icons/icon_new.svg "New"
[ADD]:      https://resources.atlas.wooga.com/icons/icon_add.svg "Add"
[IMPROVE]: https://resources.atlas.wooga.com/icons/icon_improve.svg
"Improve"
[CHANGE]: https://resources.atlas.wooga.com/icons/icon_change.svg
"Change"
[FIX]:      https://resources.atlas.wooga.com/icons/icon_fix.svg "Fix"
[UPDATE]: https://resources.atlas.wooga.com/icons/icon_update.svg
"Update"

[BREAK]: https://resources.atlas.wooga.com/icons/icon_break.svg "Remove"
[REMOVE]: https://resources.atlas.wooga.com/icons/icon_remove.svg
"Remove"
[IOS]:      https://resources.atlas.wooga.com/icons/icon_iOS.svg "iOS"
[ANDROID]: https://resources.atlas.wooga.com/icons/icon_android.svg
"Android"
[WEBGL]: https://resources.atlas.wooga.com/icons/icon_webGL.svg "WebGL"
[GRADLE]: https://resources.atlas.wooga.com/icons/icon_gradle.svg
"GRADLE"
[UNITY]: https://resources.atlas.wooga.com/icons/icon_unity.svg "Unity"
[LINUX]: https://resources.atlas.wooga.com/icons/icon_linux.svg "Linux"
[WIN]: https://resources.atlas.wooga.com/icons/icon_windows.svg
"Windows"
[MACOS]:    https://resources.atlas.wooga.com/icons/icon_iOS.svg "macOS"
  • Loading branch information
Joaquimmnetto authored Apr 25, 2024
1 parent 0b2b025 commit 41a480f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,27 @@ class GenerateSolutionTaskIntegrationSpec extends UnityTaskIntegrationSpec<Gener
@UnityInstallation(version = "2019.4.24f1", cleanup = false)
def "generates .sln file when running generateSolution task for unity 2019.4"(Installation unity) {
given: "an unity3D project"
def project_path = "build/test_project"
buildFile << """
unity {
unityPath = ${wrapValueBasedOnType(unity.executable, File)}
projectDirectory = file("${projectDir.absolutePath}")
}
tasks.withType(wooga.gradle.unity.UnityTask).configureEach {
createProject = "${projectDir.absolutePath}"
buildTarget = "Android"
}
"""
appendToSubjectTask("""createProject = "${project_path}" """,
"""buildTarget = "Android" """)
assert !projectDir.list().any{ it.endsWith(".sln") }


when:"generateSolution task is called"
def result = runTasksSuccessfully(subjectUnderTestName)
def result = runTasks(subjectUnderTestName)

then:"solution file is generated"
projectDir.list().any{ it.endsWith(".sln") }
result.standardOutput.contains("Starting process 'command '${unity.getExecutable().getPath()}'")
result.wasExecuted(":_${subjectUnderTestName}_cleanup")
fileExists(project_path)
fileExists(project_path, "test_project.sln")
!fileExists(project_path, "Assets/SolutionGenerator.cs")
!fileExists(project_path, "Assets/SolutionGenerator.cs.meta")
result.standardOutput.contains("-executeMethod")
result.standardOutput.contains("UnityEditor.SyncVS.SyncSolution")
}


Expand All @@ -70,20 +72,22 @@ class GenerateSolutionTaskIntegrationSpec extends UnityTaskIntegrationSpec<Gener
buildFile << """
unity {
unityPath = ${wrapValueBasedOnType(unity.executable, File)}
projectDirectory = file("${projectDir.absolutePath}")
}
tasks.withType(wooga.gradle.unity.UnityTask).configureEach {
createProject = "${projectDir.absolutePath}"
buildTarget = "Android"
}
"""
appendToSubjectTask("""createProject = "${projectDir.absolutePath}" """,
"""buildTarget = "Android" """)
assert !projectDir.list().any{ it.endsWith(".sln") }

when:"generateSolution task is called"
def result = runTasks(subjectUnderTestName)

then:"solution file is generated"
result.standardOutput.contains("Starting process 'command '${unity.getExecutable().getPath()}'")
projectDir.list().any{ it.endsWith(".sln") }
result.wasExecuted(":_${subjectUnderTestName}_cleanup")
!fileExists(projectDir.absolutePath, "Assets/SolutionGenerator.cs")
!fileExists(projectDir.absolutePath, "Assets/SolutionGenerator.cs.meta")

result.standardOutput.contains("Starting process 'command '${unity.getExecutable().getPath()}'")
result.standardOutput.contains("-executeMethod")
result.standardOutput.contains("Packages.Rider.Editor.RiderScriptEditor.SyncSolution")
}
}
44 changes: 3 additions & 41 deletions src/main/groovy/wooga/gradle/unity/tasks/GenerateSolution.groovy
Original file line number Diff line number Diff line change
@@ -1,53 +1,15 @@
package wooga.gradle.unity.tasks

import org.gradle.api.file.Directory
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.provider.Provider
import org.gradle.api.tasks.InputDirectory
import org.gradle.api.tasks.Optional
import wooga.gradle.unity.UnityTask

class GenerateSolution extends ExecuteCsharpScript {
private final DirectoryProperty assetsDir = objects.directoryProperty()

@InputDirectory
@Optional
DirectoryProperty getAssetsDir() {
return assetsDir
}

void setAssetsDir(Provider<Directory> assetsDir) {
this.assetsDir.set(assetsDir)
}

void setAssetsDir(Directory assetsDir) {
this.assetsDir.set(assetsDir)
}

void setAssetsDir(File assetsDir) {
this.assetsDir.set(assetsDir)
}
class GenerateSolution extends UnityTask {

GenerateSolution() {
outputs.upToDateWhen { false }

// Not the usual approach we take. Usually we would like to put the default in the plugin conventions and such, but this
// task seems to be designed to be independent from plugin configuration, so we still apply plugin configuration,
// but we set __sensible defaults__.
// This runs before the config block in the plugin, so it can and will be overwritten by plugin configuration when the plugin is applied as well
this.assetsDir.convention(this.projectDirectory.dir("Assets").map {it.asFile.mkdirs();return it})

def defaultScript = this.assetsDir
.map { it.file("SolutionGenerator.cs") }
.map { script ->
script.asFile.text = GenerateSolution.classLoader.getResourceAsStream("DefaultSolutionGenerator.cs").text
script.asFile.deleteOnExit()
return script
}
this.sourceScript.convention(defaultScript)
this.destinationScript.convention(this.sourceScript)
this.executeMethod.set(project.provider {
unityVersion.majorVersion >= 2022?
"Wooga.UnityPlugin.DefaultSolutionGenerator.GenerateSolution" :
"Packages.Rider.Editor.RiderScriptEditor.SyncSolution" :
"UnityEditor.SyncVS.SyncSolution"
})

Expand Down

0 comments on commit 41a480f

Please sign in to comment.