| #!/usr/bin/env python3 | |
| # Copyright (C) 2024 Igalia S.L. | |
| # | |
| # This program is free software; you can redistribute it and/or | |
| # modify it under the terms of the GNU Lesser General Public | |
| # License as published by the Free Software Foundation; either | |
| # version 2.1 of the License, or (at your option) any later version. | |
| # | |
| # This program is distributed in the hope that it will be useful, | |
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| # Lesser General Public License for more details. | |
| # | |
| # You should have received a copy of the GNU Lesser General Public | |
| # License along with this program; if not, write to the | |
| # Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, | |
| # Boston, MA 02110-1301, USA. | |
| import sys | |
| import argparse | |
| import socket | |
| import errno | |
| from webkitpy.port.linux_container_sdk_utils import maybe_enter_webkit_container_sdk, maybe_use_container_sdk_root_dir | |
| maybe_enter_webkit_container_sdk() | |
| from webkitpy.common.host import Host | |
| from webkitpy.port import configuration_options, platform_options, factory | |
| from webkitcorepy.string_utils import decode | |
| maybe_use_container_sdk_root_dir() | |
| def system_has_ipv6(): | |
| if not socket.has_ipv6: | |
| return False | |
| try: | |
| with socket.socket(socket.AF_INET6, socket.SOCK_STREAM) as sock: | |
| sock.bind(("::1", 0)) | |
| return True | |
| except OSError as e: | |
| if e.errno in [errno.EADDRNOTAVAIL, errno.EAFNOSUPPORT]: | |
| return False | |
| if e.errno == errno.EADDRINUSE: | |
| return True | |
| raise | |
| def main(argv): | |
| option_parser = argparse.ArgumentParser('usage: %prog [options]') | |
| configuration = option_parser.add_mutually_exclusive_group(required=True) | |
| configuration.add_argument('--debug', action='store_const', const='Debug', dest='configuration', help='Use a Debug build') | |
| configuration.add_argument('--release', action='store_const', const='Release', dest='configuration', help='Use a Release build') | |
| platform = option_parser.add_mutually_exclusive_group(required=True) | |
| platform.add_argument('--gtk', action='store_const', dest='platform', const='gtk', help='Use the GTK WebKitWebDriver') | |
| platform.add_argument('--wpe', action='store_const', dest='platform', const='wpe', help='Use the WPE WPEWebDriver') | |
| option_parser.add_argument('-p', '--port', dest='port', type=int, required=True, help="Port number the driver will use") | |
| option_parser.add_argument('--host', dest='host', type=str, help="Host IP the driver will use, or either 'local' or 'all' (default: 'local')") | |
| options = option_parser.parse_args() | |
| webdriver_cmd_args = [f'--port={options.port}'] | |
| if options.host: | |
| webdriver_cmd_args.append(f'--host={options.host}') | |
| elif not system_has_ipv6(): | |
| # workaround https://gitlab.gnome.org/GNOME/libsoup/-/issues/172 | |
| webdriver_cmd_args.append(f'--host=127.0.0.1') | |
| port = factory.PortFactory(Host()).get(options.platform, options=options) | |
| return port.run_webdriver(webdriver_cmd_args) | |
| if __name__ == '__main__': | |
| sys.exit(main(sys.argv[1:])) |