BuildReleaseAuxiliaryContent.py 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. """
  2. All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
  3. its licensors.
  4. For complete copyright and license terms please see the LICENSE at the root of this
  5. distribution (the "License"). All use of this software is governed by the License,
  6. or, if provided, by the license below or the license accompanying this file. Do not
  7. remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. Config file for pytest & PythonTestTools. Warns user if the packaged Python is not
  10. being used.
  11. """
  12. import argparse
  13. import os
  14. import re
  15. import subprocess
  16. def printMessage(message):
  17. print(message)
  18. def getCurrentProject():
  19. bootstrap = open("bootstrap.cfg", "r")
  20. gameProjectRegex = re.compile("^sys_game_folder\s*=\s*(.*)")
  21. for line in bootstrap:
  22. gameFolderMatch = gameProjectRegex.match(line)
  23. if gameFolderMatch:
  24. return gameFolderMatch.group(1)
  25. return None
  26. def getCommandLineArgs():
  27. # Game project override is not taken because it's generally not safe to process assets for the non-active project. DLLs may be out of date.
  28. parser = argparse.ArgumentParser(
  29. description='Lumberyard game project release build automation tool, generates auxiliary content for the current game project specified in bootstrap.cfg'
  30. 'or --project override if provided.')
  31. parser.add_argument('--platforms', required=True,
  32. help='Required: The comma separated platform list to generate auxiliary content for.')
  33. parser.add_argument('--buildFolder', required=True,
  34. help='Required: The build folder for your engine, containing AssetProcessorBatch.exe')
  35. parser.add_argument('--recompress', action='store_true',
  36. help='If present, the ResourceCompiler (RC.exe) will decompress and compress back each PAK file found as they are transferred from the cache folder to the game_pc_pak folder.')
  37. parser.add_argument('--use_fastest', action='store_true',
  38. help='As each file is being added to its PAK file, they will be compressed across all available codecs (ZLIB, ZSTD and LZ4) and the one with the fastest decompression time will be chosen. The default is to always use ZLIB.')
  39. parser.add_argument('--skipAssetProcessing', action='store_true',
  40. help='If present, assetprocessorbatch will not be launched before creating the auxiliary content for the current game project specified in the bootstrap.cfg file. The default behavior of processing assets first helps you make sure your auxiliary content will always be generated from the most up to date data for your game.')
  41. parser.add_argument('--skiplevelPaks', action='store_true',
  42. help='If present, the ResourceCompiler (RC.exe) will skip putting any level related pak files for e.g level.pak and terraintexture.pak in the auxiliary contents. Consider using this option if your levels are being packaged through some other system, such as the AssetBundler.')
  43. parser.add_argument('--project', help='If present, project to use instead of the bootstrap project')
  44. return parser.parse_args()
  45. def subprocessWithPrint(command):
  46. printMessage(command)
  47. subprocess.check_call(command)
  48. def main():
  49. args = getCommandLineArgs()
  50. gameProject = args.project or getCurrentProject()
  51. if not gameProject:
  52. printMessage(
  53. "Game project could not be read from bootstrap.cfg, please verify it is set correctly and run this again.")
  54. return
  55. printMessage("Generating auxiliary content for project {} from build folder {} for platforms {}".format(gameProject,
  56. args.buildFolder,
  57. args.platforms))
  58. # Build paths to tools
  59. apBatchExe = os.path.join(args.buildFolder, "AssetProcessorBatch.exe")
  60. rcFolder = args.buildFolder
  61. rcExe = os.path.join(rcFolder, "rc.exe")
  62. rc_script_name = 'RCJob_Generic_MakeAuxiliaryContent.xml'
  63. rc_script_path = os.path.join(rcFolder, rc_script_name)
  64. this_script_folder = os.path.dirname(os.path.abspath(__file__))
  65. if not os.path.exists(rc_script_path):
  66. rc_script_path = os.path.join(this_script_folder, 'Code', 'Tools', 'rc', 'Config', 'rc',
  67. rc_script_name)
  68. if not os.path.exists(rc_script_path):
  69. printMessage(f"Could not find {rc_script_name} at {rcFolder} or {this_script_folder}")
  70. return
  71. # Make sure all assets are up to date.
  72. if not args.skipAssetProcessing:
  73. printMessage("Updating game assets")
  74. # Asset processor will read the current project from bootstrap.
  75. subprocessWithPrint("{} /platforms={}".format(apBatchExe, args.platforms))
  76. else:
  77. printMessage("Skipping asset processing")
  78. platformsSplit = args.platforms.split(',')
  79. for platform in platformsSplit:
  80. printMessage("Generating auxiliary content for platform {}".format(platform))
  81. # Call RC to generate the auxiliary content.
  82. recompressArg = 1 if args.recompress else 0
  83. useFastestArg = 1 if args.use_fastest else 0
  84. skiplevelPaksArg = 1 if args.skiplevelPaks else 0
  85. rc_cmd = f"{rcExe} /job={rc_script_path} /p={platform} /game={gameProject.lower()} " \
  86. f"/recompress={recompressArg}" \
  87. f" /use_fastest={useFastestArg} /skiplevelPaks={skiplevelPaksArg}"
  88. subprocessWithPrint(rc_cmd)
  89. if __name__ == "__main__":
  90. main()