[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:
1) Clone sources from github (03 Sep 2012)
2) Run 'gradlew.bat build'
3) When it come to buildCompare tests they fail. System environment variable PATH is not empty and I don't touch it. The issue is that the function setEnvironmentVariable sets the contents of the specified environment
variable for the current process and has no effect on the system
environment variables. PATH for that test process is not set, and some windows versions return 203 error with these conditions. May be it's depends on kernel32.dll version, where the function is defined. Tomorrow I can say you my kernel32 version (on my another computer).

Comment by Fadeev Alexandr [ 05/Sep/12 ]

Microsoft Windows XP Professional, Version 5.1.2600 Service Pack 3 Build 2600
kernel32.dll 5.1.2600.5512

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
2. put more effort in reproducing

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.

Generated at Wed Jun 30 12:22:33 CDT 2021 using Jira 8.4.2#804003-sha1:d21414fc212e3af190e92c2d2ac41299b89402cf.