build_package_image.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 os
  13. import subprocess
  14. import sys
  15. sys.path.append(str(Path(__file__).parent.parent.parent / 'Scripts'))
  16. from builders.vcpkgbuilder import VcpkgBuilder
  17. import builders.monkeypatch_tempdir_cleanup
  18. def main():
  19. parser = argparse.ArgumentParser()
  20. parser.add_argument(
  21. '--platform-name',
  22. dest='platformName',
  23. choices=['windows', 'android', 'mac', 'ios'],
  24. default=VcpkgBuilder.defaultPackagePlatformName(),
  25. )
  26. args = parser.parse_args()
  27. packageSystemDir = Path(__file__).resolve().parents[1]
  28. opensslPackageSourceDir = packageSystemDir / 'OpenSSL'
  29. outputDir = opensslPackageSourceDir / 'temp' / f'OpenSSL-{args.platformName}'
  30. opensslPatch = opensslPackageSourceDir / 'set_openssl_port_to_1_1_1_x.patch'
  31. enableStdioOnIOS = opensslPackageSourceDir / 'enable-stdio-on-iOS.patch'
  32. cmakeFindFile = opensslPackageSourceDir / 'FindOpenSSL.cmake.template'
  33. cmakeFindFileTemplate = cmakeFindFile.open().read()
  34. useStaticLibsForPlatform = {
  35. 'android': True,
  36. 'mac': True,
  37. 'ios': True,
  38. 'windows': True,
  39. }
  40. revisionForPlatform = {
  41. 'android': 'rev2',
  42. 'mac': 'rev1',
  43. 'ios': 'rev1',
  44. 'windows': 'rev1'
  45. }
  46. testScriptForPlatform = {
  47. 'android' : opensslPackageSourceDir / 'test_OpenSSL_android.cmd',
  48. 'mac' : opensslPackageSourceDir / 'test_OpenSSL_mac.sh',
  49. 'ios' : opensslPackageSourceDir / 'test_OpenSSL_ios.sh',
  50. 'windows' : opensslPackageSourceDir / 'test_OpenSSL_windows.cmd'
  51. }
  52. with TemporaryDirectory() as tempdir:
  53. tempdir = Path(tempdir)
  54. builder = VcpkgBuilder(packageName='OpenSSL', portName='openssl', vcpkgDir=tempdir, targetPlatform=args.platformName, static=useStaticLibsForPlatform[args.platformName])
  55. builder.deleteFolder(outputDir)
  56. builder.cloneVcpkg('b86c0c35b88e2bf3557ff49dc831689c2f085090')
  57. builder.bootstrap()
  58. builder.patch(opensslPatch)
  59. builder.patch(enableStdioOnIOS)
  60. builder.build()
  61. builder.copyBuildOutputTo(
  62. outputDir,
  63. extraFiles={
  64. next(builder.vcpkgDir.glob(f'buildtrees/openssl/{builder.triplet}-rel/**/LICENSE')): outputDir / builder.packageName / 'LICENSE',
  65. })
  66. revisionName = revisionForPlatform[args.platformName]
  67. builder.writePackageInfoFile(
  68. outputDir,
  69. settings={
  70. 'PackageName': f'OpenSSL-1.1.1o-{revisionName}-{args.platformName}',
  71. 'URL': 'https://github.com/openssl/openssl',
  72. 'License': 'OpenSSL',
  73. 'LicenseFile': 'OpenSSL/LICENSE'
  74. },
  75. )
  76. crypto_library_dependencies = ''
  77. if args.platformName == 'windows':
  78. crypto_library_dependencies = 'crypt32.lib ws2_32.lib'
  79. builder.writeCMakeFindFile(
  80. outputDir,
  81. template=cmakeFindFileTemplate,
  82. templateEnv={
  83. 'CRYPTO_LIBRARY_DEPENDENCIES':crypto_library_dependencies
  84. },
  85. )
  86. # now test the package, it will be in outputDir
  87. customEnviron = os.environ.copy()
  88. customEnviron["PACKAGE_ROOT"] = str(outputDir.resolve())
  89. scriptpath = testScriptForPlatform[args.platformName].resolve()
  90. cwdpath = opensslPackageSourceDir.resolve()
  91. print(f'Running test script "{scriptpath}" with package "{outputDir}" with cwd "{cwdpath}"')
  92. subprocess.check_call(
  93. [ str(scriptpath) ],
  94. cwd=str(cwdpath),
  95. env=customEnviron
  96. )
  97. if __name__ == '__main__':
  98. main()