BuildVcpkg.py 1.5 KB

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