| #!/usr/bin/env python3 |
| |
| # Copyright (C) 2026 Apple Inc. All rights reserved. |
| # |
| # Redistribution and use in source and binary forms, with or without |
| # modification, are permitted provided that the following conditions |
| # are met: |
| # |
| # 1. Redistributions of source code must retain the above copyright |
| # notice, this list of conditions and the following disclaimer. |
| # 2. Redistributions in binary form must reproduce the above copyright |
| # notice, this list of conditions and the following disclaimer in the |
| # documentation and/or other materials provided with the distribution. |
| # 3. Neither the name of Apple Inc. ("Apple") nor the names of |
| # its contributors may be used to endorse or promote products derived |
| # from this software without specific prior written permission. |
| # |
| # THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY |
| # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| # DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
| # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| |
| # Watches Source/WebInspectorUI/ for changes and automatically rebuilds. |
| # Requires `entr` to be installed (e.g., `brew install entr`). |
| |
| import argparse |
| import os |
| import shutil |
| import subprocess |
| import sys |
| |
| SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) |
| WEBKIT_ROOT = os.path.normpath(os.path.join(SCRIPT_DIR, '..', '..')) |
| INSPECTOR_DIR = os.path.join(WEBKIT_ROOT, 'Source', 'WebInspectorUI') |
| WATCH_EXTENSIONS = ('.js', '.css', '.html', '.svg', '.png') |
| |
| |
| def webkit_configuration(): |
| """Read the configuration set by set-webkit-configuration via webkitdirs.pm.""" |
| try: |
| output = subprocess.check_output( |
| ['perl', '-I', SCRIPT_DIR, '-Mwebkitdirs', '-e', 'print configuration()'], |
| stderr=subprocess.DEVNULL) |
| return output.decode().strip().lower() |
| except subprocess.CalledProcessError: |
| return 'release' |
| |
| |
| def main(): |
| parser = argparse.ArgumentParser( |
| description='Watch Source/WebInspectorUI/ for changes and rebuild automatically.') |
| parser.add_argument('--debug', action='store_const', const='debug', dest='configuration', |
| help='Build in debug mode') |
| parser.add_argument('--release', action='store_const', const='release', dest='configuration', |
| help='Build in release mode') |
| parser.add_argument('target', nargs='?', default=None, |
| help='Make target (e.g., "release", "debug"). ' |
| 'Defaults to the configuration from set-webkit-configuration.') |
| args = parser.parse_args() |
| |
| if not shutil.which('entr'): |
| print('Error: `entr` is not installed.', file=sys.stderr) |
| print('Install it with: brew install entr', file=sys.stderr) |
| sys.exit(1) |
| |
| if not os.path.isdir(INSPECTOR_DIR): |
| print('Error: {} directory not found.'.format(INSPECTOR_DIR), file=sys.stderr) |
| sys.exit(1) |
| |
| make_target = args.target or args.configuration or webkit_configuration() |
| make_cmd = ['make', '-C', INSPECTOR_DIR, make_target] |
| |
| find_cmd = ['find', '-E', INSPECTOR_DIR, '-regex', r'.*\.({})'.format('|'.join( |
| ext.lstrip('.') for ext in WATCH_EXTENSIONS))] |
| |
| print('Watching {} for changes...'.format(os.path.relpath(INSPECTOR_DIR, WEBKIT_ROOT))) |
| print('Build command: {}'.format(' '.join(make_cmd))) |
| print('Press Ctrl+C to stop.\n') |
| |
| find_proc = subprocess.Popen(find_cmd, stdout=subprocess.PIPE) |
| try: |
| sys.exit(subprocess.call(['entr'] + make_cmd, stdin=find_proc.stdout)) |
| except KeyboardInterrupt: |
| sys.exit(0) |
| finally: |
| find_proc.stdout.close() |
| find_proc.wait() |
| |
| |
| if __name__ == '__main__': |
| main() |