build_package_image.py 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/usr/bin/env python3
  2. #
  3. # Copyright (c) Contributors to the Open 3D Engine Project.
  4. # For complete copyright and license terms please see the LICENSE at the root of this distribution.
  5. #
  6. # SPDX-License-Identifier: Apache-2.0 OR MIT
  7. #
  8. #
  9. from pathlib import Path
  10. from tempfile import TemporaryDirectory
  11. import argparse
  12. import shutil
  13. import sys
  14. sys.path.append(str(Path(__file__).parent.parent.parent / 'Scripts'))
  15. from builders.vcpkgbuilder import VcpkgBuilder
  16. import builders.monkeypatch_tempdir_cleanup
  17. def main():
  18. parser = argparse.ArgumentParser()
  19. parser.add_argument(
  20. '--platform-name',
  21. dest='platformName',
  22. choices=['windows', 'mac', 'linux'],
  23. default=VcpkgBuilder.defaultPackagePlatformName(),
  24. )
  25. args = parser.parse_args()
  26. packageSystemDir = Path(__file__).resolve().parents[1]
  27. packageSourceDir = packageSystemDir / 'poly2tri'
  28. outputDir = packageSystemDir / f'poly2tri-{args.platformName}'
  29. cmakeFindFile = packageSourceDir / f'Findpoly2tri_{args.platformName}.cmake'
  30. if not cmakeFindFile.exists():
  31. cmakeFindFile = packageSourceDir / 'Findpoly2tri.cmake'
  32. # vcpkg uses https://github.com/greenm01/poly2tri repo (88de490), but we need
  33. # the more recent version from https://github.com/jhasse/poly2tri repo (7f0487a),
  34. # patching vcpkg to build jhasse version.
  35. buildJhasseRepoPatch = (packageSourceDir / 'build-poly2tri-jhasse-repo.patch')
  36. with TemporaryDirectory() as tempdir:
  37. tempdir = Path(tempdir)
  38. builder = VcpkgBuilder(
  39. packageName='poly2tri',
  40. portName='poly2tri',
  41. vcpkgDir=tempdir,
  42. targetPlatform=args.platformName,
  43. static=True
  44. )
  45. builder.cloneVcpkg('751fc199af8d33eb300af5edbd9e3b77c48f0bca')
  46. builder.patch(buildJhasseRepoPatch)
  47. builder.bootstrap()
  48. builder.build()
  49. builder.copyBuildOutputTo(
  50. outputDir,
  51. extraFiles={
  52. next(builder.vcpkgDir.glob(f'buildtrees/poly2tri/src/*/LICENSE')): outputDir / builder.packageName / 'LICENSE',
  53. next(builder.vcpkgDir.glob(f'buildtrees/poly2tri/src/*/README.md')): outputDir / builder.packageName / 'README.md',
  54. },
  55. subdir='poly2tri'
  56. )
  57. # vcpkg's commit 751fc19 uses poly2tri's commit 7f0487a (after patch)
  58. builder.writePackageInfoFile(
  59. outputDir,
  60. settings={
  61. 'PackageName': f'poly2tri-7f0487a-rev1-{args.platformName}',
  62. 'URL': 'https://github.com/jhasse/poly2tri',
  63. 'License': 'BSD-3-Clause',
  64. 'LicenseFile': 'poly2tri/LICENSE'
  65. },
  66. )
  67. shutil.copy2(
  68. src=cmakeFindFile,
  69. dst=outputDir / 'Findpoly2tri.cmake'
  70. )
  71. if __name__ == '__main__':
  72. main()