Changeset 82770 in webkit


Ignore:
Timestamp:
Apr 2, 2011 4:18:57 AM (13 years ago)
Author:
Patrick Gansterer
Message:

2011-04-02 Patrick Gansterer <Patrick Gansterer>

Reviewed by Eric Seidel.

Emulate shebang on Win32
https://bugs.webkit.org/show_bug.cgi?id=55927

Scripts on Windows work only if they are called with the explicit interpreter.
Read the first line of scripts to detect the correct executable.

  • Scripts/webkitpy/common/config/ports.py:
  • Scripts/webkitpy/common/system/executive.py: Added interpreter_for_script().
  • Scripts/webkitpy/common/system/executive_unittest.py:
Location:
trunk/Tools
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r82766 r82770  
     12011-04-02  Patrick Gansterer  <paroga@webkit.org>
     2
     3        Reviewed by Eric Seidel.
     4
     5        Emulate shebang on Win32
     6        https://bugs.webkit.org/show_bug.cgi?id=55927
     7
     8        Scripts on Windows work only if they are called with the explicit interpreter.
     9        Read the first line of scripts to detect the correct executable.
     10
     11        * Scripts/webkitpy/common/config/ports.py:
     12        * Scripts/webkitpy/common/system/executive.py: Added interpreter_for_script().
     13        * Scripts/webkitpy/common/system/executive_unittest.py:
     14
    1152011-04-01  Adam Barth  <abarth@webkit.org>
    216
  • trunk/Tools/Scripts/webkitpy/common/config/ports.py

    r80549 r82770  
    3131import os
    3232import platform
     33import sys
    3334
    3435from webkitpy.common.system.executive import Executive
     
    4445    @classmethod
    4546    def script_shell_command(cls, script_name):
    46         return [cls.script_path(script_name)]
     47        script_path = cls.script_path(script_name)
     48        # Win32 does not support shebang. We need to detect the interpreter ourself.
     49        if sys.platform == 'win32':
     50            interpreter = Executive.interpreter_for_script(script_path)
     51            if interpreter:
     52                return [interpreter, script_path]
     53        return [script_path]
    4754
    4855    @staticmethod
  • trunk/Tools/Scripts/webkitpy/common/system/executive.py

    r77745 r82770  
    4646
    4747from webkitpy.common.system.deprecated_logging import tee
     48from webkitpy.common.system.filesystem import FileSystem
    4849from webkitpy.python24 import versioning
    4950
     
    179180        # machines.
    180181        return 2
     182
     183    @staticmethod
     184    def interpreter_for_script(script_path, fs=FileSystem()):
     185        lines = fs.read_text_file(script_path).splitlines()
     186        if not len(lines):
     187            return None
     188        first_line = lines[0]
     189        if not first_line.startswith('#!'):
     190            return None
     191        if first_line.find('python') > -1:
     192            return sys.executable
     193        if first_line.find('perl') > -1:
     194            return 'perl'
     195        if first_line.find('ruby') > -1:
     196            return 'ruby'
     197        return None
    181198
    182199    def kill_process(self, pid):
  • trunk/Tools/Scripts/webkitpy/common/system/executive_unittest.py

    r80048 r82770  
    3535
    3636from webkitpy.common.system.executive import Executive, run_command, ScriptError
     37from webkitpy.common.system.filesystem_mock import MockFileSystem
    3738from webkitpy.test import cat, echo
    3839
     
    6566
    6667class ExecutiveTest(unittest.TestCase):
     68
     69    def assert_interpreter_for_content(self, intepreter, content):
     70        fs = MockFileSystem()
     71        file_path = None
     72        file_interpreter = None
     73
     74        tempfile, temp_name = fs.open_binary_tempfile('')
     75        tempfile.write(content)
     76        tempfile.close()
     77        file_interpreter = Executive.interpreter_for_script(temp_name, fs)
     78
     79        self.assertEqual(file_interpreter, intepreter)
     80
     81    def test_interpreter_for_script(self):
     82        self.assert_interpreter_for_content(None, '')
     83        self.assert_interpreter_for_content(None, 'abcd\nefgh\nijklm')
     84        self.assert_interpreter_for_content(None, '##/usr/bin/perl')
     85        self.assert_interpreter_for_content('perl', '#!/usr/bin/env perl')
     86        self.assert_interpreter_for_content('perl', '#!/usr/bin/env perl\nfirst\nsecond')
     87        self.assert_interpreter_for_content('perl', '#!/usr/bin/perl')
     88        self.assert_interpreter_for_content('perl', '#!/usr/bin/perl -w')
     89        self.assert_interpreter_for_content(sys.executable, '#!/usr/bin/env python')
     90        self.assert_interpreter_for_content(sys.executable, '#!/usr/bin/env python\nfirst\nsecond')
     91        self.assert_interpreter_for_content(sys.executable, '#!/usr/bin/python')
     92        self.assert_interpreter_for_content('ruby', '#!/usr/bin/env ruby')
     93        self.assert_interpreter_for_content('ruby', '#!/usr/bin/env ruby\nfirst\nsecond')
     94        self.assert_interpreter_for_content('ruby', '#!/usr/bin/ruby')
    6795
    6896    def test_run_command_with_bad_command(self):
Note: See TracChangeset for help on using the changeset viewer.