mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-16 23:39:44 +00:00
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:
parent
8d4ac42205
commit
d00d49ba2f
Notes:
github-actions[bot]
2025-05-22 16:22:20 +00:00
Author: https://github.com/trflynn89
Commit: d00d49ba2f
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4844
4 changed files with 27 additions and 17 deletions
|
@ -1 +0,0 @@
|
||||||
# NOTE: Provided so ladybird.py can import the BuildVcpkg script as a module
|
|
|
@ -1,6 +1,7 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
|
import importlib.util
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
|
@ -9,11 +10,29 @@ import resource
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
import types
|
||||||
|
|
||||||
from enum import IntEnum
|
from enum import IntEnum
|
||||||
from pathlib import Path
|
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):
|
class HostArchitecture(IntEnum):
|
||||||
Unsupported = 0
|
Unsupported = 0
|
||||||
x86_64 = 1
|
x86_64 = 1
|
||||||
|
@ -200,7 +219,7 @@ def main():
|
||||||
build_main(build_dir, "install", args.args)
|
build_main(build_dir, "install", args.args)
|
||||||
elif args.command == "vcpkg":
|
elif args.command == "vcpkg":
|
||||||
configure_build_env(args.preset, args.cc, args.cxx)
|
configure_build_env(args.preset, args.cc, args.cxx)
|
||||||
build_vcpkg()
|
BuildVcpkg.build_vcpkg()
|
||||||
elif args.command == "clean":
|
elif args.command == "clean":
|
||||||
clean_main(args.preset, args.cc, args.cxx)
|
clean_main(args.preset, args.cc, args.cxx)
|
||||||
elif args.command == "rebuild":
|
elif args.command == "rebuild":
|
||||||
|
@ -215,7 +234,7 @@ def main():
|
||||||
|
|
||||||
def configure_main(platform: Platform, preset: str, cc: str, cxx: str) -> Path:
|
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)
|
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():
|
if build_preset_dir.joinpath("build.ninja").exists() or build_preset_dir.joinpath("ladybird.sln").exists():
|
||||||
return build_preset_dir
|
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
|
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():
|
def validate_cmake_version():
|
||||||
# FIXME: This 3.25+ CMake version check may not be needed anymore due to vcpkg downloading a newer 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."
|
cmake_install_message = "Please install CMake version 3.25 or newer."
|
||||||
|
|
|
@ -4,10 +4,9 @@ import json
|
||||||
import os
|
import os
|
||||||
import pathlib
|
import pathlib
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
|
||||||
|
|
||||||
|
|
||||||
def main() -> int:
|
def build_vcpkg():
|
||||||
script_dir = pathlib.Path(__file__).parent.resolve()
|
script_dir = pathlib.Path(__file__).parent.resolve()
|
||||||
|
|
||||||
with open(script_dir.parent / "vcpkg.json", "r") as vcpkg_json_file:
|
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:
|
if bootstrapped_vcpkg_version == git_rev:
|
||||||
return 0
|
return
|
||||||
|
|
||||||
print(f"Building vcpkg@{git_rev}")
|
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"
|
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)
|
subprocess.check_call(args=[vcpkg_checkout / bootstrap_script, "-disableMetrics"], cwd=vcpkg_checkout)
|
||||||
|
|
||||||
return 0
|
|
||||||
|
def main():
|
||||||
|
build_vcpkg()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
sys.exit(main())
|
main()
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
# NOTE: Provided so ladybird.py can import the BuildVcpkg script as a module
|
|
Loading…
Add table
Add a link
Reference in a new issue