Bug 55927 - Emulate shebang on Win32
Summary: Emulate shebang on Win32
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Tools / Tests (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Patrick R. Gansterer
URL:
Keywords:
Depends on: 55925
Blocks: 55811
  Show dependency treegraph
 
Reported: 2011-03-08 00:33 PST by Patrick R. Gansterer
Modified: 2011-04-02 04:19 PDT (History)
3 users (show)

See Also:


Attachments
Patch (1.67 KB, patch)
2011-03-08 00:41 PST, Patrick R. Gansterer
no flags Details | Formatted Diff | Diff
Patch (1.67 KB, patch)
2011-03-08 00:47 PST, Patrick R. Gansterer
no flags Details | Formatted Diff | Diff
Patch (6.96 KB, patch)
2011-03-30 13:12 PDT, Patrick R. Gansterer
no flags Details | Formatted Diff | Diff
Patch (4.70 KB, patch)
2011-03-30 14:51 PDT, Patrick R. Gansterer
no flags Details | Formatted Diff | Diff
Patch (5.40 KB, patch)
2011-04-02 03:04 PDT, Patrick R. Gansterer
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Patrick R. Gansterer 2011-03-08 00:33:29 PST
see patch
Comment 1 Patrick R. Gansterer 2011-03-08 00:41:27 PST
Created attachment 85031 [details]
Patch
Comment 2 Patrick R. Gansterer 2011-03-08 00:47:53 PST
Created attachment 85032 [details]
Patch
Comment 3 Adam Barth 2011-03-08 01:06:51 PST
Comment on attachment 85032 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=85032&action=review

> Tools/Scripts/webkitpy/common/config/ports.py:56
> +                if first_line.find("python") > -1:
> +                    return [sys.executable, script_file]
> +                if first_line.find("perl") > -1:
> +                    return ["perl", script_file]

Should we generate some kind of error if we can't figure out the right interpreter?
Comment 4 Patrick R. Gansterer 2011-03-08 01:12:50 PST
(In reply to comment #3)
> (From update of attachment 85032 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=85032&action=review
> 
> > Tools/Scripts/webkitpy/common/config/ports.py:56
> > +                if first_line.find("python") > -1:
> > +                    return [sys.executable, script_file]
> > +                if first_line.find("perl") > -1:
> > +                    return ["perl", script_file]
> 
> Should we generate some kind of error if we can't figure out the right interpreter?

Might be an option. At the moment we can pass a file with a file extention and no shebang to this function and windows can detect the correct interpreter via file extension. So it's not wrong all the time.
Comment 5 Eric Seidel (no email) 2011-03-08 08:38:55 PST
Comment on attachment 85032 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=85032&action=review

> Tools/Scripts/webkitpy/common/config/ports.py:55
> +            first_line = open(script_file, "r").readline()
> +            if first_line.startswith("#!"):
> +                if first_line.find("python") > -1:
> +                    return [sys.executable, script_file]
> +                if first_line.find("perl") > -1:

I would have split this off into a separate function (which would then be unit-testable).  Something like interpreter_for_script, or something.

In general this looks fine. I'm not sure how much this slows down execution.

I'm ready to r+ this with a unit test.  (See filesystem.py and filesystem_mock.py for how we do open and test open)
Comment 6 Dirk Pranke 2011-03-09 12:47:13 PST
Searching the first line using find() seems perhaps a bit dangerous to me. I'd be happier if we did some exact string matches instead. That way things like shebangs that reference python2.5 instead of python will fail in a more reliable manner.

Dunno how many different shebangs we have though, but it wouldn't be a bad thing to standardize on a couple ...
Comment 7 Dirk Pranke 2011-03-09 12:47:51 PST
Also, at some point you might want to handle ruby as well (thank you, pretty patch).
Comment 8 Patrick R. Gansterer 2011-03-30 13:12:24 PDT
Created attachment 87602 [details]
Patch
Comment 9 Dirk Pranke 2011-03-30 14:14:38 PDT
command_for_file() and and read_text_file_line() are too specialized to belong in the filesystem class. I would just use read_text_file().splitlines()[0] and a local function in config/ports.py. In the unlikely case that this turns out to be a performance problem, we can add something like open_binary_file_for_reading() that returns an Iterable that would be more generically useful.
Comment 10 Patrick R. Gansterer 2011-03-30 14:51:43 PDT
Created attachment 87621 [details]
Patch
Comment 11 Dirk Pranke 2011-03-30 15:23:13 PDT
Looks good, and is simpler than the last patch to boot. Thanks! (note that I am not actualy a reviewer so can't r+ it).
Comment 12 Eric Seidel (no email) 2011-03-30 21:24:50 PDT
Comment on attachment 87621 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=87621&action=review

This patch is great!

> Tools/Scripts/webkitpy/common/config/ports.py:47
> +    def interpreter_for_script(cls, script_path):

Maybe we should put this in executive.py?  It's a win32 feature, not releated to any specific webkit port.

> Tools/Scripts/webkitpy/common/config/ports.py:66
> +        # Win32 does not suppot shebang. We need to detect the interpreter ourself.

support
Comment 13 Eric Seidel (no email) 2011-03-30 21:26:20 PDT
Comment on attachment 87621 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=87621&action=review

>> Tools/Scripts/webkitpy/common/config/ports.py:47
>> +    def interpreter_for_script(cls, script_path):
> 
> Maybe we should put this in executive.py?  It's a win32 feature, not releated to any specific webkit port.

You should pass in a FileSystem for mocking.  Then your test doesn't need to even write out to disk if you use a MockFileSystem.

Please be sure to make that change before landing.
Comment 14 Patrick R. Gansterer 2011-04-02 03:04:16 PDT
Created attachment 87972 [details]
Patch
Comment 15 Patrick R. Gansterer 2011-04-02 04:19:21 PDT
Comment on attachment 87972 [details]
Patch

Clearing flags on attachment: 87972

Committed r82770: <http://trac.webkit.org/changeset/82770>
Comment 16 Patrick R. Gansterer 2011-04-02 04:19:31 PDT
All reviewed patches have been landed.  Closing bug.