[GRADLE-2461] Daemon fails on < Win 7 if PATH env var is not set Created: 04/Sep/12 Updated: 04/Jan/13 Resolved: 06/Sep/12 |
|
Status: | Resolved |
Project: | Gradle |
Affects Version/s: | None |
Fix Version/s: | 1.3-rc-1 |
Type: | Improvement | ||
Reporter: | Gradle Forums | Assignee: | Unassigned |
Resolution: | Fixed | Votes: | 0 |
Description |
The daemon forces the PATH env var to be set. The following is an indicative trace:
Caused by: org.gradle.internal.nativeplatform.NativeIntegrationException: Could not set environment variable 'PATH'. errno: 203
at org.gradle.internal.nativeplatform.jna.WindowsProcessEnvironment.setNativeEnvironmentVariable(WindowsProcessEnvironment.java:33)
at org.gradle.internal.nativeplatform.jna.WindowsProcessEnvironment.removeNativeEnvironmentVariable(WindowsProcessEnvironment.java:38)
at org.gradle.internal.nativeplatform.jna.AbstractProcessEnvironment.removeEnvironmentVariable(AbstractProcessEnvironment.java:43)
at org.gradle.internal.nativeplatform.jna.AbstractProcessEnvironment.maybeSetEnvironment(AbstractProcessEnvironment.java:34)
at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:56)
at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
The line in question is: boolean retval = kernel32.SetEnvironmentVariable(name, value == null ? null : value); The problem appears to be that on early windows versions, passing a null value to this for an env var that is not set causing a 203 error code (ERROR_ENVVAR_NOT_FOUND) to be returned. I found this issue reported in the ruby project: http://bugs.ruby-lang.org/issues/3825 Their solution was to ignore this particular error code when returned by this method. |
Comments |
Comment by Fadeev Alexandr [ 04/Sep/12 ] |
This patch solves the problem (tested in Windows XP SP3): diff --git a/subprojects/native/src/main/java/org/gradle/internal/nativeplatform/jna/WindowsProcessEnvironment.java b/subprojects/native/src/main/java/org/gradle/internal/nativeplatform/jna/WindowsProcessEnvironment.java index 87162dc..b2f77b8 100755 --- a/subprojects/native/src/main/java/org/gradle/internal/nativeplatform/jna/WindowsProcessEnvironment.java +++ b/subprojects/native/src/main/java/org/gradle/internal/nativeplatform/jna/WindowsProcessEnvironment.java @@ -29,7 +29,7 @@ public class WindowsProcessEnvironment extends AbstractProcessEnvironment { public void setNativeEnvironmentVariable(String name, String value) { boolean retval = kernel32.SetEnvironmentVariable(name, value == null ? null : value); - if (!retval) { + if (!retval && (kernel32.GetLastError() != 203/*ERROR_ENVVAR_NOT_FOUND*/)) { throw new NativeIntegrationException(String.format("Could not set environment variable '%s'. errno: %d", name, kernel32.GetLastError())); } } P.S.: Like in issue reported in the ruby project: http://bugs.ruby-lang.org/issues/3825 |
Comment by Fadeev Alexandr [ 04/Sep/12 ] |
...I pulled the request with this bug fix |
Comment by Szczepan Faber [ 04/Sep/12 ] |
Thanks a lot for the pull request! Can you tell me how to reproduce the issue? I have win XP SP3 vm, I got rid of 'PATH' variable via the system properties. The variable is gone, echo %PATH% shows '%PATH%' and not an empty string. I can run gradle build (the latest master), I've tried gradlew buildComparison:integTest |
Comment by Fadeev Alexandr [ 04/Sep/12 ] |
My steps are: |
Comment by Fadeev Alexandr [ 05/Sep/12 ] |
Microsoft Windows XP Professional, Version 5.1.2600 Service Pack 3 Build 2600 |
Comment by Luke Daley [ 05/Sep/12 ] |
There is a pull request for this: https://github.com/gradle/gradle/pull/98 |
Comment by Szczepan Faber [ 05/Sep/12 ] |
I wasn't able to reproduce it. We could either: 1. trust the pull request I'm inclined to go for option 1 as this looks reasonable to me. Adam, if you're monitoring this thread - speak up. |
Comment by Fadeev Alexandr [ 06/Sep/12 ] |
So, what was decision finally made? Option #2 "put more effort in reproducing"? |
Comment by Luke Daley [ 06/Sep/12 ] |
Pulled. Thanks for the contribution. |