build_package_image.py 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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
  5. # of this distribution.
  6. #
  7. # SPDX-License-Identifier: Apache-2.0 OR MIT
  8. #
  9. #
  10. import argparse
  11. import functools
  12. import json
  13. import os
  14. import pathlib
  15. from pathlib import Path
  16. import shutil
  17. import subprocess
  18. from tempfile import TemporaryDirectory
  19. import sys
  20. sys.path.append(str(Path(__file__).parent.parent.parent / 'Scripts'))
  21. from builders.vcpkgbuilder import VcpkgBuilder
  22. import builders.monkeypatch_tempdir_cleanup
  23. class BlastBuilder(object):
  24. def __init__(self, workingDir: pathlib.Path, targetPlatform: str):
  25. self._workingDir = workingDir
  26. self._platform = targetPlatform
  27. self._env = dict(os.environ)
  28. self._env.update(
  29. PM_PACKAGES_ROOT=str(workingDir / 'packman-repo'),
  30. )
  31. self.check_call = functools.partial(subprocess.check_call,
  32. cwd=self.workingDir,
  33. env=self.env
  34. )
  35. @property
  36. def workingDir(self):
  37. return self._workingDir
  38. @property
  39. def platform(self):
  40. return self._platform
  41. @property
  42. def env(self):
  43. return self._env
  44. def clone(self, lockToCommit: str):
  45. if not (self.workingDir / '.git').exists():
  46. self.check_call(
  47. ['git', 'init',],
  48. )
  49. self.check_call(
  50. ['git', 'remote', 'add', 'origin', 'https://github.com/NVIDIAGameWorks/Blast.git',],
  51. )
  52. self.check_call(
  53. ['git', 'fetch', 'origin', '--depth=1', lockToCommit,],
  54. )
  55. self.check_call(
  56. ['git', 'checkout', lockToCommit,],
  57. )
  58. def build(self):
  59. cmake = str(self.workingDir / 'packman-repo/chk/cmake-x64/3.7.0/bin/cmake.exe')
  60. self.check_call(
  61. ['cmd.exe', '/C', 'generate_projects_vc15win64.bat'],
  62. )
  63. for config in ('debug', 'profile', 'release'):
  64. self.check_call(
  65. [cmake, '--build', str(self.workingDir / 'compiler' / 'vc15win64-cmake'), '--config', config, '--', '/m:2']
  66. )
  67. def copyBuildOutputTo(self, packageDir: pathlib.Path):
  68. if packageDir.exists():
  69. shutil.rmtree(packageDir)
  70. def ignoreFilter(dirname, filenames):
  71. """
  72. Describes files that are generated by the Blast build that are excluded from the resulting package
  73. """
  74. # These filenames are always ignored
  75. staticIgnores = [
  76. 'PhysXCommon_64.dll',
  77. 'PhysXCooking_64.dll',
  78. 'PhysXGpu_64.dll',
  79. 'PhysX_64.dll',
  80. 'ApexImporter_x64.exe',
  81. 'ApexImporter_x64.ilk',
  82. 'ApexImporter_x64.pdb',
  83. 'AuthoringTool_x64.exe',
  84. 'AuthoringTool_x64.ilk',
  85. 'AuthoringTool_x64.pdb',
  86. 'BlastPerfTests_x64.exe',
  87. 'BlastPerfTests_x64.ilk',
  88. 'BlastPerfTests_x64.pdb',
  89. 'BlastUnitTests_x64.exe',
  90. 'BlastUnitTests_x64.ilk',
  91. 'BlastUnitTests_x64.pdb',
  92. 'GFSDK_SSAO_D3D11.win64.dll',
  93. 'GFSDK_ShadowLib_DX11.win64.dll',
  94. 'LegacyConverter_x64.exe',
  95. 'LegacyConverter_x64.ilk',
  96. 'LegacyConverter_x64.pdb',
  97. 'SampleAssetViewer_x64.exe',
  98. 'SampleAssetViewer_x64.ilk',
  99. 'SampleAssetViewer_x64.pdb',
  100. 'd3dcompiler_47.dll',
  101. 'nvToolsExt64_1.dll',
  102. 'ApexImporter_x64.exp',
  103. 'ApexImporter_x64.lib',
  104. 'AuthoringTool_x64.exp',
  105. 'AuthoringTool_x64.lib',
  106. 'BlastPerfTests_x64.exp',
  107. 'BlastPerfTests_x64.lib',
  108. 'BlastUnitTests_x64.exp',
  109. 'BlastUnitTests_x64.lib',
  110. 'SampleAssetViewer_x64.exp',
  111. 'SampleAssetViewer_x64.lib',
  112. 'SampleBase_x64.lib',
  113. 'SampleBase_x64.pdb',
  114. ]
  115. relDir = Path(dirname).relative_to(self.workingDir)
  116. # For files coming from the sdk/ and shared/ directories, we only want to copy the headers.
  117. # Path.is_relative_to needs Python 3.9 or newer
  118. if relDir.is_relative_to('sdk/') or relDir.is_relative_to('shared/'):
  119. # We want to keep all directories, so don't add directories to the ignore list
  120. # We only want to keep .h and .inl files
  121. # Ignore all others
  122. return [fn for fn in filenames if (path := Path(fn)) and ((not (self.workingDir/relDir/path).is_dir()) and (path.suffix not in ('.h', '.inl')))] \
  123. + staticIgnores
  124. return staticIgnores
  125. for dirname in ('bin/vc15win64-cmake', 'lib/vc15win64-cmake', 'sdk', 'shared/utils'):
  126. shutil.copytree(
  127. src=self.workingDir / dirname,
  128. dst=packageDir / dirname,
  129. symlinks=True,
  130. ignore=ignoreFilter,
  131. )
  132. shutil.copy2(
  133. src=self.workingDir / 'license.txt',
  134. dst=packageDir / 'license.txt',
  135. )
  136. def writePackageInfoFile(self, packageDir: pathlib.Path, settings: dict):
  137. with (packageDir / 'PackageInfo.json').open('w') as fh:
  138. json.dump(settings, fh, indent=4)
  139. def main():
  140. parser = argparse.ArgumentParser()
  141. parser.add_argument(
  142. '--platform-name',
  143. dest='platformName',
  144. choices=['windows'],
  145. default=VcpkgBuilder.defaultPackagePlatformName(),
  146. )
  147. args = parser.parse_args()
  148. packageSystemDir = Path(__file__).resolve().parents[1]
  149. packageSourceDir = packageSystemDir / 'Blast'
  150. packageRoot = packageSystemDir / f'Blast-{args.platformName}'
  151. cmakeFindFile = packageSourceDir / f'FindBlast_{args.platformName}.cmake'
  152. if not cmakeFindFile.exists():
  153. cmakeFindFile = packageSourceDir / 'FindBlast.cmake'
  154. with TemporaryDirectory() as tempdir:
  155. tempdir = Path(tempdir)
  156. builder = BlastBuilder(workingDir=tempdir, targetPlatform=args.platformName)
  157. builder.clone('eb169fe87c9957d89e6132048317a5732299f6bf')
  158. builder.build()
  159. builder.copyBuildOutputTo(packageRoot/'Blast')
  160. # This version comes from running:
  161. # git clone https://github.com/NVIDIAGameWorks/Blast.git
  162. # git checkout eb169fe87c9957d89e6132048317a5732299f6bf
  163. # git describe
  164. # This yields v1.1.7_rc2-9-geb169fe, which describes commit eb169fe, which is 9 commits above the tag v1.1.7_rc2
  165. builder.writePackageInfoFile(
  166. packageRoot,
  167. settings={
  168. 'PackageName': f'Blast-v1.1.7_rc2-9-geb169fe-rev2-{args.platformName}',
  169. 'URL': 'https://github.com/NVIDIAGameWorks/Blast',
  170. 'License': 'custom',
  171. 'LicenseFile': 'Blast/license.txt',
  172. },
  173. )
  174. shutil.copy2(
  175. src=cmakeFindFile,
  176. dst=packageRoot / 'FindBlast.cmake'
  177. )
  178. if __name__ == '__main__':
  179. main()