createplatformfiles.py 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #
  2. # Copyright (c) Contributors to the Open 3D Engine Project.
  3. # For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. #
  5. # SPDX-License-Identifier: Apache-2.0 OR MIT
  6. #
  7. #
  8. from __future__ import (absolute_import, division,
  9. print_function, unicode_literals)
  10. import sys
  11. import json
  12. import os
  13. import subprocess
  14. import argparse
  15. import pathlib
  16. fileContents = ""
  17. def getCopyright():
  18. return """#
  19. # Copyright (c) Contributors to the Open 3D Engine Project.
  20. # For complete copyright and license terms please see the LICENSE at the root of this distribution.
  21. #
  22. # SPDX-License-Identifier: Apache-2.0 OR MIT
  23. #
  24. #
  25. """
  26. def getPlatforms():
  27. return ['Android','iOS','Jasper','Linux','Mac','Provo','Salem','Windows']
  28. def isRestricted(platform):
  29. return platform in ['Jasper','Provo','Salem']
  30. def createEmptyPlatformFile(platform, rel_path, filename, dev_root, restricted_root):
  31. full_platform_filename = filename.replace("<platform>", platform.lower())
  32. if isRestricted(platform):
  33. full_platform_file_path = restricted_root / platform / rel_path
  34. else:
  35. full_platform_file_path = dev_root / rel_path / 'Platform' / platform
  36. full_platform_file_path.mkdir(parents=True, exist_ok=True)
  37. full_platform_file_path = (full_platform_file_path / full_platform_filename).resolve()
  38. alreadyExists = full_platform_file_path.exists()
  39. if alreadyExists:
  40. subprocess.run(['p4', 'edit', str(full_platform_file_path)])
  41. print(f'Creating {full_platform_file_path}')
  42. with open(full_platform_file_path, 'w') as destination_file:
  43. destination_file.write(getCopyright())
  44. if not alreadyExists:
  45. subprocess.run(['p4', 'add', str(full_platform_file_path)])
  46. def main():
  47. """script main function"""
  48. parser = argparse.ArgumentParser(description='This script generates an empty cmake file per platform at a given path\n'
  49. 'Output: will create Platform structure if not present, will create\n'
  50. ' Platform\<platform>\<filename>_<platformlowercase>.cmake\n'
  51. ' for each platform.',
  52. formatter_class=argparse.RawTextHelpFormatter)
  53. parser.add_argument('path', type=str, help='Path where the Platform folder is (without including the platform folder) relative to <dev_root>')
  54. parser.add_argument('filename', type=str, help='Pattern for the platform file (<platform> will be replaced by each platform), e.g. "platform_<platform>.cmake"')
  55. parser.add_argument('--dev-root', default=os.path.join(os.path.dirname(__file__), '..'), type=str, help='Override where the dev root is. If none is supplied, it will be auto-detected')
  56. parser.add_argument('--restricted-root', default='{dev_root}/restricted', type=str, help='Override where the restricted platform root is located. Defaults to <dev_root>/restricted')
  57. args = parser.parse_args()
  58. dev_root = pathlib.Path(args.dev_root).resolve()
  59. if not dev_root.exists():
  60. print(f'Dev root at {dev_root} does not exist')
  61. sys.exit(1)
  62. restricted_root = pathlib.Path(args.restricted_root.format(**locals())).resolve()
  63. os.chdir(dev_root)
  64. input_path = pathlib.Path(args.path).resolve()
  65. try:
  66. input_relpath = input_path.relative_to(dev_root)
  67. except ValueError:
  68. print(f'Input path, {input_path}, is not a child of dev root, {dev_root}')
  69. sys.exit(1)
  70. if not input_path.is_dir():
  71. print(f'Expected a valid path, got {input_path}')
  72. sys.exit(1)
  73. for platform in getPlatforms():
  74. createEmptyPlatformFile(platform, input_relpath, args.filename, dev_root, restricted_root)
  75. #entrypoint
  76. if __name__ == '__main__':
  77. main()