Meta+Toolchain: Extract BuildVcpkg to an importable function

This lets ladybird.py import it properly, instead of invoking BuildVcpkg
main().
This commit is contained in:
Timothy Flynn 2025-05-22 10:59:56 -04:00 committed by Tim Flynn
commit d00d49ba2f
Notes: github-actions[bot] 2025-05-22 16:22:20 +00:00
4 changed files with 27 additions and 17 deletions

View file

@ -1,6 +1,7 @@
#!/usr/bin/env python3
import argparse
import importlib.util
import multiprocessing
import os
import platform
@ -9,11 +10,29 @@ import resource
import shutil
import subprocess
import sys
import types
from enum import IntEnum
from pathlib import Path
def import_module(module_path: Path) -> types.ModuleType:
spec = importlib.util.spec_from_file_location(module_path.stem, module_path)
if not spec or not spec.loader:
raise ModuleNotFoundError(f"Could not find module {module_path}")
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
return module
META_PATH = Path(__file__).parent
TOOLCHAIN_PATH = META_PATH.parent / "Toolchain"
BuildVcpkg = import_module(TOOLCHAIN_PATH / "BuildVcpkg.py")
class HostArchitecture(IntEnum):
Unsupported = 0
x86_64 = 1
@ -200,7 +219,7 @@ def main():
build_main(build_dir, "install", args.args)
elif args.command == "vcpkg":
configure_build_env(args.preset, args.cc, args.cxx)
build_vcpkg()
BuildVcpkg.build_vcpkg()
elif args.command == "clean":
clean_main(args.preset, args.cc, args.cxx)
elif args.command == "rebuild":
@ -215,7 +234,7 @@ def main():
def configure_main(platform: Platform, preset: str, cc: str, cxx: str) -> Path:
ladybird_source_dir, build_preset_dir, build_env_cmake_args = configure_build_env(preset, cc, cxx)
build_vcpkg()
BuildVcpkg.build_vcpkg()
if build_preset_dir.joinpath("build.ninja").exists() or build_preset_dir.joinpath("ladybird.sln").exists():
return build_preset_dir
@ -313,14 +332,6 @@ def configure_build_env(preset: str, cc: str, cxx: str) -> tuple[Path, Path, lis
return ladybird_source_dir, build_preset_dir, cmake_args
def build_vcpkg():
sys.path.append(str(Path(__file__).parent.joinpath("..", "Toolchain")))
# FIXME: Rename main() in BuildVcpkg.py to build_vcpkg() and call that from the scripts __main__
from BuildVcpkg import main as build_vcpkg # pyright: ignore
build_vcpkg()
def validate_cmake_version():
# FIXME: This 3.25+ CMake version check may not be needed anymore due to vcpkg downloading a newer version
cmake_install_message = "Please install CMake version 3.25 or newer."