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 +0,0 @@
# NOTE: Provided so ladybird.py can import the BuildVcpkg script as a module

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."

View file

@ -4,10 +4,9 @@ import json
import os
import pathlib
import subprocess
import sys
def main() -> int:
def build_vcpkg():
script_dir = pathlib.Path(__file__).parent.resolve()
with open(script_dir.parent / "vcpkg.json", "r") as vcpkg_json_file:
@ -28,7 +27,7 @@ def main() -> int:
)
if bootstrapped_vcpkg_version == git_rev:
return 0
return
print(f"Building vcpkg@{git_rev}")
@ -38,8 +37,10 @@ def main() -> int:
bootstrap_script = "bootstrap-vcpkg.bat" if os.name == "nt" else "bootstrap-vcpkg.sh"
subprocess.check_call(args=[vcpkg_checkout / bootstrap_script, "-disableMetrics"], cwd=vcpkg_checkout)
return 0
def main():
build_vcpkg()
if __name__ == "__main__":
sys.exit(main())
main()

View file

@ -1 +0,0 @@
# NOTE: Provided so ladybird.py can import the BuildVcpkg script as a module