Skip to content

Commit

Permalink
Add UBS 1.6 compatibility setup (#188)
Browse files Browse the repository at this point in the history
* Add UBS 1.6 compatibility setup

Description
===========

With UBS 1.6 and especially in combination with Unity > 2021 we have
to introduce some version specific changes.
The cli parameter `--version` is no longer valid and when provided in the
cli call to Unity will result in Unity printing its version.
So I renamed the cli flag to `--build-version` when UBS compatibility is set to
`v160`.

> Note:
> `--version` was already not working in UBS because of an issue with the used
> CLI parser. I kept the old behavior just to be compatible to the old version.

I also renamed `--version-code` to `--build-version-code`.

While touching things based on the UBS compatibility value I also changed
the default `exportMethod` value and `appConfigsDirectory`.

Changes
=======

* ![ADD] UBS 1.6 compatibility setup

* Refactor BuildEngineArgs
  • Loading branch information
Larusso authored Oct 20, 2022
1 parent c12c8c2 commit 436fbd8
Show file tree
Hide file tree
Showing 16 changed files with 230 additions and 152 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,18 @@ class UnityBuildPluginIntegrationSpec extends UnityIntegrationSpec {
@Shared
File appConfigsDir

@Shared
File appConfigsDir2

def setup() {
//create the default location for app configs
def assets = new File(projectDir, "Assets")
appConfigsDir = new File(assets, "UnifiedBuildSystem-Assets/AppConfigs")
appConfigsDir2 = new File(assets, "UnifiedBuildSystem-Assets/Configs")
appConfigsDir.mkdirs()
appConfigsDir2.mkdirs()

['ios_ci', 'android_ci', 'webGL_ci'].collect { createFile("${it}.asset", appConfigsDir) }.each {
['ios_ci', 'android_ci', 'webGL_ci'].collectMany { [createFile("${it}.asset", appConfigsDir), createFile("${it}.asset", appConfigsDir2)] }.each {
it << UNITY_ASSET_HEADER
it << "\n"
Yaml yaml = new Yaml()
Expand All @@ -56,12 +61,12 @@ class UnityBuildPluginIntegrationSpec extends UnityIntegrationSpec {
}

Yaml yaml = new Yaml()
def appconfig = createFile("custom.asset", appConfigsDir)
appconfig << UNITY_ASSET_HEADER
appconfig << "\n"
appconfig << yaml.dump(['MonoBehaviour': ['bundleId': 'net.wooga.test']])


[appConfigsDir, appConfigsDir2].each {
def appconfig = createFile("custom.asset", it)
appconfig << UNITY_ASSET_HEADER
appconfig << "\n"
appconfig << yaml.dump(['MonoBehaviour': ['bundleId': 'net.wooga.test']])
}
}

@Unroll
Expand Down Expand Up @@ -105,6 +110,7 @@ class UnityBuildPluginIntegrationSpec extends UnityIntegrationSpec {
"exportCustom" | "Wooga.UnifiedBuildSystem.Build.Export" | "${UnityCommandLineOption.buildTarget}" | null
"exportCustom" | "Wooga.UnifiedBuildSystem.Build.Export" | "${UnityCommandLineOption.buildTarget}" | UBSVersion.v100
"exportCustom" | "Wooga.UnifiedBuildSystem.Editor.BuildEngine.BuildFromEnvironment" | "${UnityCommandLineOption.buildTarget}" | UBSVersion.v120
"exportCustom" | "Wooga.UnifiedBuildSystem.Editor.BuildEngine.BuildFromEnvironment" | "${UnityCommandLineOption.buildTarget}" | UBSVersion.v160
}

String convertPropertyToEnvName(String property) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package wooga.gradle.build

import org.apache.commons.lang3.StringUtils
import org.yaml.snakeyaml.Yaml
import wooga.gradle.build.unity.UBSVersion
import wooga.gradle.build.unity.UnityBuildPlugin

import static com.wooga.gradle.PlatformUtils.escapedPath
Expand Down Expand Up @@ -58,6 +59,15 @@ abstract class UnityIntegrationSpec extends IntegrationSpec {
unityTestLocation
}

static wrapValueFallback = { Object rawValue, String type, Closure<String> fallback ->
switch (type) {
case UBSVersion.getSimpleName():
return "${UBSVersion.canonicalName}.${rawValue.toString()}".toString()
default:
return rawValue.toString()
}
}

File createAppConfig(String path) {
def appConfigsDir = new File(projectDir, path)
appConfigsDir.mkdirs()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import org.gradle.api.GradleException
import spock.lang.Shared
import spock.lang.Unroll
import wooga.gradle.build.UnityIntegrationSpec
import wooga.gradle.build.unity.UBSVersion

class UnityBuildPlayerIntegrationSpec extends UnityIntegrationSpec {

Expand Down Expand Up @@ -38,7 +39,7 @@ class UnityBuildPlayerIntegrationSpec extends UnityIntegrationSpec {
hasKeyValue("--version", version, customArgsParts)
hasKeyValue("--outputPath",
new File(projectDir, "build/export/${appConfigName}/project").path, customArgsParts)
if(argName == "configPath") {
if (argName == "configPath") {
hasKeyValue("-buildTarget", "android", customArgsParts)
}

Expand Down Expand Up @@ -91,4 +92,30 @@ class UnityBuildPlayerIntegrationSpec extends UnityIntegrationSpec {
def e = thrown(GradleException)
rootCause(e) instanceof IllegalArgumentException
}

@Unroll
def "property #property will be mapped to cli parameter #expectedParamter when UBSCompatibility is #compatibility"() {
buildFile << """
task("customExport", type: ${UnityBuildPlayer.class.name}) {
ubsCompatibilityVersion = ${wrapValueBasedOnType(compatibility, "UBSVersion", wrapValueFallback)}
appConfigFile = ${wrapValueBasedOnType("Assets/CustomConfigs/custom.asset", "File")}
${property} = ${wrapValueBasedOnType(expectedValue, "String")}
}
""".stripIndent()

when:
def result = runTasksSuccessfully("customExport")

then:
result.standardOutput.contains("${expectedParamter} ${expectedValue}")

where:
property | expectedParamter | expectedValue | compatibility
"version" | "--version" | "1.0.0" | UBSVersion.v100
"version" | "--version" | "2.0.0" | UBSVersion.v120
"version" | "--build-version" | "3.0.0" | UBSVersion.v160
"versionCode" | "--versionCode" | "1" | UBSVersion.v100
"versionCode" | "--versionCode" | "2" | UBSVersion.v120
"versionCode" | "--build-version-code" | "3" | UBSVersion.v160
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import spock.lang.Issue
import spock.lang.Shared
import spock.lang.Unroll
import wooga.gradle.build.UnityIntegrationSpec
import wooga.gradle.build.unity.UBSVersion
import wooga.gradle.build.unity.secrets.internal.EncryptionSpecHelper
import wooga.gradle.secrets.internal.SecretText
import wooga.gradle.secrets.internal.Secrets
Expand Down
4 changes: 2 additions & 2 deletions src/main/groovy/wooga/gradle/build/unity/UBSVersion.groovy
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package wooga.gradle.build.unity

enum UBSVersion {
v100, v120
}
v100, v120, v160
}
13 changes: 9 additions & 4 deletions src/main/groovy/wooga/gradle/build/unity/UnityBuildPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,11 @@ class UnityBuildPlugin implements Plugin<Project> {
}

static void configureExtension(UnityBuildPluginExtension extension, Project project) {
extension.ubsCompatibilityVersion.convention(UBSVersion.v100)
extension.exportMethodName.set(UnityBuildPluginConventions.EXPORT_METHOD_NAME.getStringValueProvider(project).orElse(extension.ubsCompatibilityVersion.map({
(it >= UBSVersion.v120) ? UnityBuildPluginConventions.EXPORT_METHOD_DEFAULT_VALUE_V2 : UnityBuildPluginConventions.EXPORT_METHOD_DEFAULT_VALUE_V1
})))

extension.exportMethodName.set(UnityBuildPluginConventions.EXPORT_METHOD_NAME.getStringValueProvider(project))
extension.defaultAppConfigName.set(UnityBuildPluginConventions.DEFAULT_APP_CONFIG_NAME.getStringValueProvider(project))
extension.commitHash.set(UnityBuildPluginConventions.BUILD_COMMIT_HASH.getStringValueProvider(project))
extension.toolsVersion.set(UnityBuildPluginConventions.BUILD_TOOLS_VERSION.getStringValueProvider(project))
Expand All @@ -80,7 +83,9 @@ class UnityBuildPlugin implements Plugin<Project> {
UnityPluginExtension unity = project.extensions.getByType(UnityPluginExtension)
extension.assetsDir.convention(unity.assetsDir)

extension.appConfigsDirectory.convention(extension.assetsDir.dir(UnityBuildPluginConventions.DEFAULT_APP_CONFIGS_DIRECTORY))
extension.appConfigsDirectory.convention(extension.assetsDir.dir(extension.ubsCompatibilityVersion.map({
(it >= UBSVersion.v120) ? UnityBuildPluginConventions.DEFAULT_APP_CONFIGS_DIRECTORY_V2 : UnityBuildPluginConventions.DEFAULT_APP_CONFIGS_DIRECTORY
})))
extension.exportInitScript.convention(UnityBuildPluginConventions.EXPORT_INIT_SCRIPT.getFileValueProvider(project))

extension.exportBuildDirBase.convention(UnityBuildPluginConventions.EXPORT_BUILD_DIR_BASE.getStringValueProvider(project).map({ new File(it) }))
Expand All @@ -91,7 +96,6 @@ class UnityBuildPlugin implements Plugin<Project> {
}

static void configureTasks(UnityBuildPluginExtension extension, Project project) {

def secretsExtension = project.extensions.getByType(SecretsPluginExtension.class)
def lifecycleExport = project.tasks.register("export") {
description = "export unity project"
Expand Down Expand Up @@ -181,6 +185,7 @@ class UnityBuildPlugin implements Plugin<Project> {
def config = new GenericUnityAssetFile(it.asFile)
return config["batchModeBuildTarget"]?.toString()?.toLowerCase()
}))
t.ubsCompatibilityVersion.convention(extension.ubsCompatibilityVersion)
}

project.tasks.withType(UnityBuildPlayer).configureEach { task ->
Expand Down Expand Up @@ -234,7 +239,7 @@ class UnityBuildPlugin implements Plugin<Project> {
}

TaskProvider<? extends Task> exportTask;
def ubsVersion = extension.ubsCompatibilityVersion.getOrElse(UBSVersion.v100)
def ubsVersion = extension.ubsCompatibilityVersion.get()
if (ubsVersion >= UBSVersion.v120) {
exportTask = project.tasks.register("export${baseName}", UnityBuildPlayer) {
UnityBuildPlayer t ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

package wooga.gradle.build.unity

import com.wooga.gradle.PropertyLookup

//import wooga.gradle.unity.utils.PropertyLookup
Expand All @@ -26,7 +27,10 @@ class UnityBuildPluginConventions {
/**
* Method used by the Unity editor application to start a build
*/
static final PropertyLookup EXPORT_METHOD_NAME = new PropertyLookup("UNITY_BUILD_EXPORT_METHOD_NAME", "unityBuild.exportMethodName", "Wooga.UnifiedBuildSystem.Build.Export")
static final PropertyLookup EXPORT_METHOD_NAME = new PropertyLookup("UNITY_BUILD_EXPORT_METHOD_NAME", "unityBuild.exportMethodName", null)

static final String EXPORT_METHOD_DEFAULT_VALUE_V1 = "Wooga.UnifiedBuildSystem.Build.Export"
static final String EXPORT_METHOD_DEFAULT_VALUE_V2 = "Wooga.UnifiedBuildSystem.Editor.Build.Export"

/**
* The name of the default AppConfig, the serialized configuration for the build
Expand Down Expand Up @@ -93,6 +97,7 @@ class UnityBuildPluginConventions {
* @see UnityBuildPluginExtension#getAppConfigsDirectory()
*/
static String DEFAULT_APP_CONFIGS_DIRECTORY = "UnifiedBuildSystem-Assets/AppConfigs"
static String DEFAULT_APP_CONFIGS_DIRECTORY_V2 = "UnifiedBuildSystem-Assets/Configs"

/**
* Default include pattern for app configs.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ import org.gradle.api.file.DirectoryProperty
import org.gradle.api.file.FileCollection
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.provider.Property
import wooga.gradle.build.unity.models.UBSCompatibility
import wooga.gradle.build.unity.models.UnityBuildSpec
import wooga.gradle.build.unity.models.VersionSpec

trait UnityBuildPluginExtension<T extends UnityBuildPluginExtension> extends UnityBuildSpec implements VersionSpec {
trait UnityBuildPluginExtension<T extends UnityBuildPluginExtension> extends UnityBuildSpec implements VersionSpec, UBSCompatibility {

private final DirectoryProperty appConfigsDirectory = objects.directoryProperty()

Expand All @@ -40,12 +41,6 @@ trait UnityBuildPluginExtension<T extends UnityBuildPluginExtension> extends Uni
outputDirectoryBase
}

private final Property<UBSVersion> ubsCompatibilityVersion = objects.property(UBSVersion)

Property<UBSVersion> getUbsCompatibilityVersion() {
ubsCompatibilityVersion
}

private final Property<String> defaultAppConfigName = objects.property(String)

Property<String> getDefaultAppConfigName() {
Expand Down

This file was deleted.

Loading

0 comments on commit 436fbd8

Please sign in to comment.