RESOLVED FIXED 55927
Emulate shebang on Win32
https://bugs.webkit.org/show_bug.cgi?id=55927
Summary Emulate shebang on Win32
Patrick R. Gansterer
Reported 2011-03-08 00:33:29 PST
see patch
Attachments
Patch (1.67 KB, patch)
2011-03-08 00:41 PST, Patrick R. Gansterer
no flags
Patch (1.67 KB, patch)
2011-03-08 00:47 PST, Patrick R. Gansterer
no flags
Patch (6.96 KB, patch)
2011-03-30 13:12 PDT, Patrick R. Gansterer
no flags
Patch (4.70 KB, patch)
2011-03-30 14:51 PDT, Patrick R. Gansterer
no flags
Patch (5.40 KB, patch)
2011-04-02 03:04 PDT, Patrick R. Gansterer
no flags
Patrick R. Gansterer
Comment 1 2011-03-08 00:41:27 PST
Patrick R. Gansterer
Comment 2 2011-03-08 00:47:53 PST
Adam Barth
Comment 3 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?
Patrick R. Gansterer
Comment 4 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.
Eric Seidel (no email)
Comment 5 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)
Dirk Pranke
Comment 6 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 ...
Dirk Pranke
Comment 7 2011-03-09 12:47:51 PST
Also, at some point you might want to handle ruby as well (thank you, pretty patch).
Patrick R. Gansterer
Comment 8 2011-03-30 13:12:24 PDT
Dirk Pranke
Comment 9 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.
Patrick R. Gansterer
Comment 10 2011-03-30 14:51:43 PDT
Dirk Pranke
Comment 11 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).
Eric Seidel (no email)
Comment 12 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
Eric Seidel (no email)
Comment 13 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.
Patrick R. Gansterer
Comment 14 2011-04-02 03:04:16 PDT
Patrick R. Gansterer
Comment 15 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>
Patrick R. Gansterer
Comment 16 2011-04-02 04:19:31 PDT
All reviewed patches have been landed. Closing bug.
Note You need to log in before you can comment on or make changes to this bug.