BuildVcpkg.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/usr/bin/env python3
  2. import os
  3. import subprocess
  4. import pathlib
  5. import sys
  6. def main() -> int:
  7. script_dir = pathlib.Path(__file__).parent.resolve()
  8. git_repo = "https://github.com/microsoft/vcpkg.git"
  9. git_rev = "533a5fda5c0646d1771345fb572e759283444d5f" # main on 2025-04-03
  10. build_dir = script_dir.parent / "Build"
  11. build_dir.mkdir(parents=True, exist_ok=True)
  12. vcpkg_checkout = build_dir / "vcpkg"
  13. if not vcpkg_checkout.is_dir():
  14. subprocess.check_call(args=["git", "clone", git_repo], cwd=build_dir)
  15. else:
  16. bootstrapped_vcpkg_version = subprocess.check_output(
  17. ["git", "-C", vcpkg_checkout, "rev-parse", "HEAD"]).strip().decode()
  18. if bootstrapped_vcpkg_version == git_rev:
  19. return 0
  20. print(f"Building vcpkg@{git_rev}")
  21. subprocess.check_call(args=["git", "fetch", "origin"], cwd=vcpkg_checkout)
  22. subprocess.check_call(args=["git", "checkout", git_rev], cwd=vcpkg_checkout)
  23. bootstrap_script = "bootstrap-vcpkg.bat" if os.name == 'nt' else "bootstrap-vcpkg.sh"
  24. subprocess.check_call(args=[vcpkg_checkout / bootstrap_script, "-disableMetrics"], cwd=vcpkg_checkout)
  25. return 0
  26. if __name__ == "__main__":
  27. sys.exit(main())