From ce7b69ff313fccd2e22e1ef86ec6dd15539c67e7 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Thu, 23 Apr 2026 10:10:23 -0400 Subject: [PATCH] Meta: Move utility scripts to a subfolder The idea is that scripts directly under Meta are meant to be run by people. Scripts that are only imported or run by other scripts are moved to a subdirectory. --- .github/actions/setup/action.yml | 2 +- Documentation/BuildInstructionsLadybird.md | 2 +- Meta/CMake/gui_framework.cmake | 2 +- Meta/Generators/generate_ipc_definitions.py | 8 ++++++-- Meta/Generators/string_hash.py | 19 ------------------- Meta/Lagom/BuildFuzzers.sh | 2 +- Meta/Linters/lint_clang_format.py | 8 ++++---- Meta/Linters/lint_ipc.py | 4 ++-- Meta/{ => Utils}/build_vcpkg.py | 10 ++++++---- Meta/{ => Utils}/find_compiler.py | 6 +++--- Meta/{ => Utils}/find_compiler.sh | 0 Meta/{ => Utils}/host_platform.py | 0 Meta/{Generators => Utils}/lexer.py | 0 Meta/{ => Utils}/shell_include.sh | 0 Meta/{ => Utils}/utils.py | 18 +++++++++++++++++- Meta/WPT.sh | 2 +- Meta/ladybird.py | 16 ++++++++-------- 17 files changed, 51 insertions(+), 48 deletions(-) delete mode 100644 Meta/Generators/string_hash.py rename Meta/{ => Utils}/build_vcpkg.py (86%) rename Meta/{ => Utils}/find_compiler.py (98%) rename Meta/{ => Utils}/find_compiler.sh (100%) rename Meta/{ => Utils}/host_platform.py (100%) rename Meta/{Generators => Utils}/lexer.py (100%) rename Meta/{ => Utils}/shell_include.sh (100%) rename Meta/{ => Utils}/utils.py (72%) diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml index e1335b5ff0..70b3ade510 100644 --- a/.github/actions/setup/action.yml +++ b/.github/actions/setup/action.yml @@ -223,7 +223,7 @@ runs: - name: 'Install vcpkg' if: ${{ inputs.type == 'build' }} shell: bash - run: ./Meta/build_vcpkg.py + run: ./Meta/Utils/build_vcpkg.py - name: 'Export installed versions' id: 'export-versions' diff --git a/Documentation/BuildInstructionsLadybird.md b/Documentation/BuildInstructionsLadybird.md index 125f9b4da6..748cc65d33 100644 --- a/Documentation/BuildInstructionsLadybird.md +++ b/Documentation/BuildInstructionsLadybird.md @@ -7,7 +7,7 @@ Qt6 development packages, nasm, additional build tools, and a C++23 capable comp A Rust toolchain is also required. You can install it via [rustup](https://rustup.rs/). We currently use gcc-14 and clang-21 in our CI pipeline. If these versions are not available on your system, see -[`Meta/find_compiler.py`](../Meta/find_compiler.py) for the minimum compatible version. +[`find_compiler.py`](../Meta/Utils/find_compiler.py) for the minimum compatible version. CMake 3.30 or newer must be available in $PATH. diff --git a/Meta/CMake/gui_framework.cmake b/Meta/CMake/gui_framework.cmake index 5890e48407..2b2c066c58 100644 --- a/Meta/CMake/gui_framework.cmake +++ b/Meta/CMake/gui_framework.cmake @@ -1,4 +1,4 @@ -# Keep the lists here in sync with Meta/host_platform.py +# Keep the lists here in sync with Meta/Utils/host_platform.py if (ANDROID OR VCPKG_TARGET_ANDROID) set(_possible_guis "Android") set(_default_gui "Android") diff --git a/Meta/Generators/generate_ipc_definitions.py b/Meta/Generators/generate_ipc_definitions.py index b1316165ff..e60d5638f0 100644 --- a/Meta/Generators/generate_ipc_definitions.py +++ b/Meta/Generators/generate_ipc_definitions.py @@ -7,14 +7,18 @@ import argparse +import sys from dataclasses import dataclass from dataclasses import field +from pathlib import Path from typing import List from typing import TextIO -from lexer import Lexer -from string_hash import string_hash +sys.path.append(str(Path(__file__).resolve().parent.parent)) + +from Utils.lexer import Lexer +from Utils.utils import string_hash PRIMITIVE_TYPES = { "i8", diff --git a/Meta/Generators/string_hash.py b/Meta/Generators/string_hash.py deleted file mode 100644 index ba69a20cb6..0000000000 --- a/Meta/Generators/string_hash.py +++ /dev/null @@ -1,19 +0,0 @@ -# Copyright (c) 2026-present, the Ladybird developers. -# -# SPDX-License-Identifier: BSD-2-Clause - - -def string_hash(string: str) -> int: - """Port of AK::string_hash that produces the same u32 value.""" - h = 0 - - for ch in string: - h = (h + ord(ch)) & 0xFFFFFFFF - h = (h + (h << 10)) & 0xFFFFFFFF - h ^= h >> 6 - - h = (h + (h << 3)) & 0xFFFFFFFF - h ^= h >> 11 - h = (h + (h << 15)) & 0xFFFFFFFF - - return h diff --git a/Meta/Lagom/BuildFuzzers.sh b/Meta/Lagom/BuildFuzzers.sh index 5a8873051b..2ea7680ee1 100755 --- a/Meta/Lagom/BuildFuzzers.sh +++ b/Meta/Lagom/BuildFuzzers.sh @@ -25,7 +25,7 @@ fi # FIXME: Replace these CMake invocations with a CMake superbuild? echo "Building Lagom Tools..." -. "../find_compiler.sh" +. "../Utils/find_compiler.sh" pick_host_compiler --clang-only cmake -S ../.. -GNinja --preset=Distribution -B Build/tools \ diff --git a/Meta/Linters/lint_clang_format.py b/Meta/Linters/lint_clang_format.py index 3daabe6259..fcf5e290e5 100755 --- a/Meta/Linters/lint_clang_format.py +++ b/Meta/Linters/lint_clang_format.py @@ -13,11 +13,11 @@ from pathlib import Path from typing import List from typing import Optional -sys.path.append(str(Path(__file__).resolve().parent.parent.parent)) +sys.path.append(str(Path(__file__).resolve().parent.parent)) -from Meta.host_platform import HostSystem -from Meta.host_platform import Platform -from Meta.utils import run_command +from Utils.host_platform import HostSystem +from Utils.host_platform import Platform +from Utils.utils import run_command CLANG_FORMAT_MAJOR_VERSION = 21 CLANG_FORMAT_EXECUTABLE = "clang-format" diff --git a/Meta/Linters/lint_ipc.py b/Meta/Linters/lint_ipc.py index 82077402b7..1506c5ad39 100755 --- a/Meta/Linters/lint_ipc.py +++ b/Meta/Linters/lint_ipc.py @@ -13,9 +13,9 @@ from pathlib import Path from typing import Dict from typing import List -sys.path.append(str(Path(__file__).resolve().parent.parent.parent)) +sys.path.append(str(Path(__file__).resolve().parent.parent)) -from Meta.Generators.string_hash import string_hash +from Utils.utils import string_hash ENDPOINT_PREFIX = "endpoint " diff --git a/Meta/build_vcpkg.py b/Meta/Utils/build_vcpkg.py similarity index 86% rename from Meta/build_vcpkg.py rename to Meta/Utils/build_vcpkg.py index d08b71870c..3cc999c396 100755 --- a/Meta/build_vcpkg.py +++ b/Meta/Utils/build_vcpkg.py @@ -10,11 +10,13 @@ import pathlib import subprocess import sys -LADYBIRD_SOURCE_DIR = pathlib.Path(__file__).resolve().parent.parent -sys.path.append(str(LADYBIRD_SOURCE_DIR)) +META_SOURCE_DIR = pathlib.Path(__file__).resolve().parent.parent +LADYBIRD_SOURCE_DIR = META_SOURCE_DIR.parent -from Meta.host_platform import HostSystem # noqa: E402 -from Meta.host_platform import Platform # noqa: E402 +sys.path.append(str(META_SOURCE_DIR)) + +from Utils.host_platform import HostSystem # noqa: E402 +from Utils.host_platform import Platform # noqa: E402 def build_vcpkg(): diff --git a/Meta/find_compiler.py b/Meta/Utils/find_compiler.py similarity index 98% rename from Meta/find_compiler.py rename to Meta/Utils/find_compiler.py index 1b33f00904..8c201b59a0 100755 --- a/Meta/find_compiler.py +++ b/Meta/Utils/find_compiler.py @@ -14,9 +14,9 @@ from typing import Optional sys.path.append(str(Path(__file__).resolve().parent.parent)) -from Meta.host_platform import HostSystem -from Meta.host_platform import Platform -from Meta.utils import run_command +from Utils.host_platform import HostSystem +from Utils.host_platform import Platform +from Utils.utils import run_command CLANG_MINIMUM_VERSION = 19 GCC_MINIMUM_VERSION = 14 diff --git a/Meta/find_compiler.sh b/Meta/Utils/find_compiler.sh similarity index 100% rename from Meta/find_compiler.sh rename to Meta/Utils/find_compiler.sh diff --git a/Meta/host_platform.py b/Meta/Utils/host_platform.py similarity index 100% rename from Meta/host_platform.py rename to Meta/Utils/host_platform.py diff --git a/Meta/Generators/lexer.py b/Meta/Utils/lexer.py similarity index 100% rename from Meta/Generators/lexer.py rename to Meta/Utils/lexer.py diff --git a/Meta/shell_include.sh b/Meta/Utils/shell_include.sh similarity index 100% rename from Meta/shell_include.sh rename to Meta/Utils/shell_include.sh diff --git a/Meta/utils.py b/Meta/Utils/utils.py similarity index 72% rename from Meta/utils.py rename to Meta/Utils/utils.py index 6f0f2be261..91cbd19410 100644 --- a/Meta/utils.py +++ b/Meta/Utils/utils.py @@ -1,4 +1,4 @@ -# Copyright (c) 2025, Tim Flynn +# Copyright (c) 2025-2026, Tim Flynn # # SPDX-License-Identifier: BSD-2-Clause @@ -41,3 +41,19 @@ def run_command( return output.strip() return None + + +def string_hash(string: str) -> int: + """Port of AK::string_hash that produces the same u32 value.""" + h = 0 + + for ch in string: + h = (h + ord(ch)) & 0xFFFFFFFF + h = (h + (h << 10)) & 0xFFFFFFFF + h ^= h >> 6 + + h = (h + (h << 3)) & 0xFFFFFFFF + h ^= h >> 11 + h = (h + (h << 15)) & 0xFFFFFFFF + + return h diff --git a/Meta/WPT.sh b/Meta/WPT.sh index 1e5607df7e..e5649eaddc 100755 --- a/Meta/WPT.sh +++ b/Meta/WPT.sh @@ -5,7 +5,7 @@ set -e DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" # shellcheck source=/dev/null -. "${DIR}/shell_include.sh" +. "${DIR}/Utils/shell_include.sh" ensure_ladybird_source_dir diff --git a/Meta/ladybird.py b/Meta/ladybird.py index ce94a98bf8..98221464c3 100755 --- a/Meta/ladybird.py +++ b/Meta/ladybird.py @@ -15,15 +15,15 @@ import sys from pathlib import Path from typing import Optional -sys.path.append(str(Path(__file__).resolve().parent.parent)) +sys.path.append(str(Path(__file__).resolve().parent)) -from Meta.build_vcpkg import build_vcpkg -from Meta.find_compiler import pick_host_compiler -from Meta.host_platform import GUIFramework -from Meta.host_platform import HostArchitecture -from Meta.host_platform import HostSystem -from Meta.host_platform import Platform -from Meta.utils import run_command +from Utils.build_vcpkg import build_vcpkg +from Utils.find_compiler import pick_host_compiler +from Utils.host_platform import GUIFramework +from Utils.host_platform import HostArchitecture +from Utils.host_platform import HostSystem +from Utils.host_platform import Platform +from Utils.utils import run_command def main():