From ac20a10e714ac1dda47aa0f1441e1c74720a3a20 Mon Sep 17 00:00:00 2001 From: Manfred Endres <2523575+Larusso@users.noreply.github.com> Date: Thu, 24 Jun 2021 14:05:43 +0200 Subject: [PATCH] Fix default environment for Unity invocation (#102) Description =========== This patch sets the default environment used to call Unity to `System.env`. It is possible to append values to this default env or reset it completely. Unity needs the `HOME` variable by default and maybe some more. Changes ======= * ![FIX] default environment for Unity invocation --- .../unity/UnityTaskIntegrationSpec.groovy | 26 ++++++++++++++++--- .../wooga/gradle/unity/UnityPlugin.groovy | 1 + 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/integrationTest/groovy/wooga/gradle/unity/UnityTaskIntegrationSpec.groovy b/src/integrationTest/groovy/wooga/gradle/unity/UnityTaskIntegrationSpec.groovy index 4e4c9a70..e0a8c607 100644 --- a/src/integrationTest/groovy/wooga/gradle/unity/UnityTaskIntegrationSpec.groovy +++ b/src/integrationTest/groovy/wooga/gradle/unity/UnityTaskIntegrationSpec.groovy @@ -225,10 +225,22 @@ abstract class UnityTaskIntegrationSpec extends UnityIntegr @Unroll def "set environment variable #rawValue for task exec"() { - given: + given: "some clean environment variables" + def envNames = System.getenv().keySet().toArray() + environmentVariables.clear(*envNames) + + and: "a test value in system env" + initialValue.each { key, value -> + environmentVariables.set(key, value) + } + + and: "an overridden environment" appendToSubjectTask("$method($value)") addProviderQueryTask("custom", "${subjectUnderTestName}.environment", ".get()") + and: "some values in the user environment" + environmentVariables.set("USER_A", "foo") + when: def result = runTasksSuccessfully(subjectUnderTestName, "custom") @@ -246,13 +258,21 @@ abstract class UnityTaskIntegrationSpec extends UnityIntegr "environment" | true | ["A": true] "environment" | false | ["A": false] + initialValue = ["B": "5", "C" : "7"] method = (useSetter) ? "set${property.capitalize()}" : "${property}.set" value = wrapValueBasedOnType(rawValue, Map) } def "adds environment for task exec"() { - given: - appendToSubjectTask("environment.set(${wrapValueBasedOnType(initialValue, Map)})") + given: "some clean environment variables" + def envNames = System.getenv().keySet().toArray() + environmentVariables.clear(*envNames) + + and: "a test value in system env" + initialValue.each { key, value -> + environmentVariables.set(key, value) + } + appendToSubjectTask("$method(${wrapValueBasedOnType(rawValue, Map)})") addProviderQueryTask("custom", "${subjectUnderTestName}.environment", ".get().sort()") diff --git a/src/main/groovy/wooga/gradle/unity/UnityPlugin.groovy b/src/main/groovy/wooga/gradle/unity/UnityPlugin.groovy index ec84b81b..7e63717b 100644 --- a/src/main/groovy/wooga/gradle/unity/UnityPlugin.groovy +++ b/src/main/groovy/wooga/gradle/unity/UnityPlugin.groovy @@ -153,6 +153,7 @@ class UnityPlugin implements Plugin { t.unityLogFile.convention(extension.logsDir.file(project.provider { t.logCategory.get().isEmpty() ? "${t.name}.log" : "${t.logCategory.get()}/${t.name}.log" })) + t.environment.putAll(project.provider({System.getenv()})) } }