Bug 53822

Summary: test-webkitpy crashes with a WindowsError when run under Win32 Python
Product: WebKit Reporter: Tony Chang <tony>
Component: Tools / TestsAssignee: Tony Chang <tony>
Status: REOPENED ---    
Severity: Normal CC: abarth, aroben, commit-queue, eric, evan, webkit.review.bot
Priority: P2 Keywords: PlatformOnly
Version: 528+ (Nightly build)   
Hardware: PC   
OS: Windows XP   
Bug Depends on: 53854    
Bug Blocks: 48728, 55811    
Attachments:
Description Flags
Patch none

Description Tony Chang 2011-02-04 15:56:59 PST
get test-webkitpy running on win32 python
Comment 1 Tony Chang 2011-02-04 15:59:05 PST
Created attachment 81312 [details]
Patch
Comment 2 Tony Chang 2011-02-04 15:59:34 PST
For reference, here's the current bot output:
http://build.webkit.org/builders/Chromium%20Win%20Release%20%28Tests%29/builds/8789/steps/webkitpy-test/logs/stdio
Comment 3 Eric Seidel (no email) 2011-02-04 16:12:30 PST
Comment on attachment 81312 [details]
Patch

I guess.  Shell is *evil*.  I suspect this will cause other troubles.
Comment 4 Eric Seidel (no email) 2011-02-04 16:13:31 PST
Comment on attachment 81312 [details]
Patch

Should we do our own path resolution instead?  I feel like at some other point I needed/wanted a "which" command written in python.  I guess if we don't use a shell, we won't get the environment in which PATH is defined anyway.
Comment 5 Evan Martin 2011-02-04 16:27:03 PST
FWIW, I would guess eseidel's dislike of going through a shell because of quoting issues, but on on Windows the low-level process creation API takes a string so you need to get quoting right anyway (http://msdn.microsoft.com/en-us/library/ms682425%28VS.85%29.aspx).  Python implicitly converts the array of args to a quoted command line for you on Windows.  Passing shell=True on Windows is pretty standard in Python code I see, though I admit it's all within a small circle of people.
Comment 6 Tony Chang 2011-02-04 16:30:25 PST
Mid-air conflict while I was writing pretty much what Evan wrote.

The only thing I have to add is that since we expect subprocess.Popen to include the environment on other platforms, it seems to be semantically consistent to for us to use shell=True on Windows.  Although in practice, maybe we don't need the environment to be copied to subprocesses.

*shrug*
Comment 7 Eric Seidel (no email) 2011-02-04 16:35:14 PST
We've talked about creating our own POpen subclass to fix some of the popen bugs we work-around in Executive.   This might be further (mild) motivation for such.
Comment 8 Adam Roben (:aroben) 2011-02-04 17:22:14 PST
I don't remember running into this problem back when I was working on getting test-webkitpy working with Win32 Python. But test-webkitpy has undoubtedly changed since then.
Comment 9 Adam Roben (:aroben) 2011-02-04 17:23:49 PST
The subprocess docs say this:

The only reason you would need to specify shell=True on Windows is where the command you wish to execute is actually built in to the shell, eg dir, copy. You don’t need shell=True to run a batch file, nor to run a console-based executable.

http://docs.python.org/library/subprocess.html#using-the-subprocess-module

So…are the docs wrong? Is there some other reason you'd have to pass shell=True on Windows?
Comment 10 WebKit Commit Bot 2011-02-04 18:39:14 PST
Comment on attachment 81312 [details]
Patch

Clearing flags on attachment: 81312

Committed r77720: <http://trac.webkit.org/changeset/77720>
Comment 11 WebKit Commit Bot 2011-02-04 18:39:20 PST
All reviewed patches have been landed.  Closing bug.
Comment 12 WebKit Commit Bot 2011-02-04 19:18:37 PST
The commit-queue encountered the following flaky tests while processing attachment 81312 [details]:

http/tests/websocket/tests/send-throw.html bug 53834 (author: abarth@webkit.org)
The commit-queue is continuing to process your patch.
Comment 13 WebKit Review Bot 2011-02-04 19:43:24 PST
http://trac.webkit.org/changeset/77720 might have broken GTK Linux 64-bit Debug
Comment 14 Tony Chang 2011-02-07 09:22:11 PST
(In reply to comment #9)
> The subprocess docs say this:
> 
> The only reason you would need to specify shell=True on Windows is where the command you wish to execute is actually built in to the shell, eg dir, copy. You don’t need shell=True to run a batch file, nor to run a console-based executable.
> 
> http://docs.python.org/library/subprocess.html#using-the-subprocess-module
> 
> So…are the docs wrong? Is there some other reason you'd have to pass shell=True on Windows?

The docs are correct, it just doesn't enumerate all the reasons to use the shell on Windows.  We needed it to search the path for things like 'svn' or 'ruby'.  Here's the python bug tracking the difference:
  http://bugs.python.org/issue8557

Anyway, this was rolled out because when shell=True and the command isn't found, we raise ScriptError rather then OSError.
Comment 15 Eric Seidel (no email) 2011-02-07 12:44:10 PST
ScriptError was originally creaed as part of scm.py to indicate when git/svn returned non-zero.

These days it's used for more than that I fear.

But still we should return OSError when  we can't find a command instead of ScriptError.
Comment 16 Tony Chang 2011-02-07 14:10:26 PST
(In reply to comment #15)

> But still we should return OSError when  we can't find a command instead of ScriptError.

Hmm, I'm not sure how to do this.  The return code is 1, but that doesn't always mean that the command wasn't found.  I could search the command output to see if the command wasn't found, but I suspect for non-English versions of Windows, the text will differ.

Eric's original suggestion of writing our own path resolution is possible (it's a cross product of PATH and PATHEXT), but I worry that we'll get it wrong.  E.g., is it possible for other environment variables to be in %PATH%?  What are the rules for case insensitivity?