applicationManager.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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. #pragma once
  9. #if !defined(Q_MOC_RUN)
  10. #include <AzToolsFramework/Application/ToolsApplication.h>
  11. #include <AzToolsFramework/Asset/AssetSeedManager.h>
  12. #include <AzToolsFramework/Asset/AssetBundler.h>
  13. #include <AzToolsFramework/Asset/AssetUtils.h>
  14. #include <AzCore/std/string/string.h>
  15. #include <AzCore/std/containers/vector.h>
  16. #include <AzCore/Debug/TraceMessageBus.h>
  17. #include <AzCore/std/smart_ptr/unique_ptr.h>
  18. #include <AzToolsFramework/API/EditorAssetSystemAPI.h>
  19. #include <source/utils/utils.h>
  20. #include <AzToolsFramework/AssetCatalog/PlatformAddressedAssetCatalogManager.h>
  21. #endif
  22. namespace AssetBundler
  23. {
  24. struct SeedsParams
  25. {
  26. AZ_CLASS_ALLOCATOR(SeedsParams, AZ::SystemAllocator);
  27. FilePath m_seedListFile;
  28. AZStd::vector<AZStd::string> m_addSeedList;
  29. AZStd::vector<AZStd::string> m_removeSeedList;
  30. bool m_addPlatformToAllSeeds = false;
  31. bool m_removePlatformFromAllSeeds = false;
  32. bool m_updateSeedPathHint = false;
  33. bool m_removeSeedPathHint = false;
  34. bool m_ignoreFileCase = false;
  35. bool m_save = false;
  36. bool m_print = false;
  37. AzFramework::PlatformFlags m_platformFlags = AzFramework::PlatformFlags::Platform_NONE;
  38. FilePath m_assetCatalogFile;
  39. };
  40. struct AssetListsParams
  41. {
  42. AZ_CLASS_ALLOCATOR(AssetListsParams, AZ::SystemAllocator);
  43. FilePath m_assetListFile;
  44. AZStd::vector<FilePath> m_seedListFiles;
  45. AZStd::vector<AZStd::string> m_addSeedList;
  46. AZStd::vector<AZStd::string> m_skipList;
  47. bool m_addDefaultSeedListFiles = false;
  48. bool m_print = false;
  49. bool m_dryRun = false;
  50. bool m_generateDebugFile = false;
  51. bool m_allowOverwrites = false;
  52. AzFramework::PlatformFlags m_platformFlags = AzFramework::PlatformFlags::Platform_NONE;
  53. FilePath m_assetCatalogFile;
  54. };
  55. enum ComparisonRulesStepAction
  56. {
  57. Add,
  58. AddToEnd,
  59. Remove,
  60. Move,
  61. Edit,
  62. Default,
  63. };
  64. struct ComparisonRulesParams
  65. {
  66. AZ_CLASS_ALLOCATOR(ComparisonRulesParams, AZ::SystemAllocator);
  67. AZStd::vector<AzToolsFramework::AssetFileInfoListComparison::ComparisonType> m_comparisonTypeList;
  68. AZStd::vector<AZStd::string> m_filePatternList;
  69. AZStd::vector<AzToolsFramework::AssetFileInfoListComparison::FilePatternType> m_filePatternTypeList;
  70. AZStd::vector<AZStd::string> m_tokenNamesList;
  71. AZStd::vector<AZStd::string> m_firstInputList;
  72. AZStd::vector<AZStd::string> m_secondInputList;
  73. FilePath m_comparisonRulesFile;
  74. ComparisonRulesStepAction m_comparisonRulesStepAction = ComparisonRulesStepAction::Default;
  75. size_t m_initialLine = 0;
  76. size_t m_destinationLine = 0;
  77. unsigned int m_intersectionCount = 0;
  78. bool m_print = false;
  79. };
  80. struct ComparisonParams
  81. {
  82. AZ_CLASS_ALLOCATOR(ComparisonParams, AZ::SystemAllocator);
  83. // Comparison input/output
  84. AZStd::vector<AZStd::string> m_firstCompareFile;
  85. AZStd::vector<AZStd::string> m_secondCompareFile;
  86. AZStd::vector<AZStd::string> m_outputs;
  87. AZStd::vector<AZStd::string> m_printComparisons;
  88. bool m_printLast = false;
  89. bool m_allowOverwrites = false;
  90. AzFramework::PlatformFlags m_platformFlags = AzFramework::PlatformFlags::Platform_NONE;
  91. // Comparison definitions
  92. FilePath m_comparisonRulesFile;
  93. ComparisonRulesParams m_comparisonRulesParams;
  94. };
  95. struct BundleSettingsParams
  96. {
  97. AZ_CLASS_ALLOCATOR(BundleSettingsParams, AZ::SystemAllocator);
  98. FilePath m_bundleSettingsFile;
  99. FilePath m_assetListFile;
  100. FilePath m_outputBundlePath;
  101. int m_bundleVersion = -1;
  102. int m_maxBundleSizeInMB = -1;
  103. bool m_print = false;
  104. AzFramework::PlatformFlags m_platformFlags = AzFramework::PlatformFlags::Platform_NONE;
  105. };
  106. struct BundlesParams
  107. {
  108. AZ_CLASS_ALLOCATOR(BundlesParams, AZ::SystemAllocator);
  109. FilePath m_bundleSettingsFile;
  110. FilePath m_assetListFile;
  111. FilePath m_outputBundlePath;
  112. int m_bundleVersion = -1;
  113. int m_maxBundleSizeInMB = -1;
  114. AzFramework::PlatformFlags m_platformFlags = AzFramework::PlatformFlags::Platform_NONE;
  115. bool m_allowOverwrites = false;
  116. };
  117. typedef AZStd::vector<BundlesParams> BundlesParamsList;
  118. struct BundleSeedParams
  119. {
  120. AZ_CLASS_ALLOCATOR(BundleSeedParams, AZ::SystemAllocator);
  121. AZStd::vector<AZStd::string> m_addSeedList;
  122. BundlesParams m_bundleParams;
  123. };
  124. class ApplicationManager
  125. : public QObject
  126. , public AZ::Debug::TraceMessageBus::Handler
  127. , public AzToolsFramework::ToolsApplication
  128. {
  129. Q_OBJECT
  130. public:
  131. AZ_CLASS_ALLOCATOR(ApplicationManager, AZ::SystemAllocator)
  132. ApplicationManager(int* argc, char*** argv, QObject* parent = nullptr);
  133. ApplicationManager(int* argc, char*** argv, QObject* parent, AZ::ComponentApplicationSettings componentAppSettings);
  134. ApplicationManager(int* argc, char*** argv, AZ::ComponentApplicationSettings componentAppSettings);
  135. virtual ~ApplicationManager();
  136. virtual bool Init();
  137. void DestroyApplication();
  138. virtual bool Run();
  139. ////////////////////////////////////////////////////////////////////////////////////////////
  140. // AzFramework::Application overrides
  141. AZ::ComponentTypeList GetRequiredSystemComponents() const override;
  142. ////////////////////////////////////////////////////////////////////////////////////////////
  143. ////////////////////////////////////////////////////////////////////////////////////////////
  144. // TraceMessageBus Interface
  145. bool OnPreError(const char* window, const char* fileName, int line, const char* func, const char* message) override;
  146. bool OnPreWarning(const char* window, const char* fileName, int line, const char* func, const char* message) override;
  147. bool OnPrintf(const char* window, const char* message) override;
  148. ////////////////////////////////////////////////////////////////////////////////////////////
  149. AZStd::string GetCurrentProjectName() { return m_currentProjectName; }
  150. AZStd::vector<AzFramework::GemInfo> GetGemInfoList() { return m_gemInfoList; }
  151. protected:
  152. ////////////////////////////////////////////////////////////////////////////////////////////
  153. // AzFramework::Application overrides
  154. void SetSettingsRegistrySpecializations(AZ::SettingsRegistryInterface::Specializations& specializations) override;
  155. ////////////////////////////////////////////////////////////////////////////////////////////
  156. ////////////////////////////////////////////////////////////////////////////////////////////
  157. // Get Generic Command Info
  158. CommandType GetCommandType(const AzFramework::CommandLine* parser, bool suppressErrors);
  159. bool ShouldPrintHelp(const AzFramework::CommandLine* parser);
  160. bool ShouldPrintVerbose(const AzFramework::CommandLine* parser);
  161. void InitArgValidationLists();
  162. ////////////////////////////////////////////////////////////////////////////////////////////
  163. ////////////////////////////////////////////////////////////////////////////////////////////
  164. // Store Detailed Command Info and Validate parser input (command correctness)
  165. AZ::Outcome<SeedsParams, AZStd::string> ParseSeedsCommandData(const AzFramework::CommandLine* parser);
  166. AZ::Outcome<AssetListsParams, AZStd::string> ParseAssetListsCommandData(const AzFramework::CommandLine* parser);
  167. AZ::Outcome<ComparisonRulesParams, AZStd::string> ParseComparisonRulesCommandData(const AzFramework::CommandLine* parser);
  168. AZ::Outcome<ComparisonParams, AZStd::string> ParseCompareCommandData(const AzFramework::CommandLine* parser);
  169. AZ::Outcome<BundleSettingsParams, AZStd::string> ParseBundleSettingsCommandData(const AzFramework::CommandLine* parser);
  170. AZ::Outcome<BundlesParamsList, AZStd::string> ParseBundlesCommandData(const AzFramework::CommandLine* parser);
  171. AZ::Outcome<BundleSeedParams, AZStd::string> ParseBundleSeedCommandData(const AzFramework::CommandLine* parser);
  172. AZ::Outcome<void, AZStd::string> ValidateInputArgs(const AzFramework::CommandLine* parser, const AZStd::vector<const char*>& validArgList);
  173. AZ::Outcome<AZStd::string, AZStd::string> GetFilePathArg(const AzFramework::CommandLine* parser, const char* argName, const char* subCommandName, bool isRequired = false);
  174. template <typename T>
  175. AZ::Outcome<AZStd::vector<T>, AZStd::string> GetArgsList(const AzFramework::CommandLine* parser, const char* argName, const char* subCommandName, bool isRequired = false);
  176. AZ::Outcome<AzFramework::PlatformFlags, AZStd::string> GetPlatformArg(const AzFramework::CommandLine* parser);
  177. AzFramework::PlatformFlags GetInputPlatformFlagsOrEnabledPlatformFlags(AzFramework::PlatformFlags inputPlatformFlags);
  178. AZStd::vector<AZStd::string> GetAddSeedArgList(const AzFramework::CommandLine* parser);
  179. AZStd::vector<AZStd::string> GetSkipArgList(const AzFramework::CommandLine* parser);
  180. ////////////////////////////////////////////////////////////////////////////////////////////
  181. ////////////////////////////////////////////////////////////////////////////////////////////
  182. // Run Commands and Validate param data (value correctness)
  183. bool RunSeedsCommands(const AZ::Outcome<SeedsParams, AZStd::string>& paramsOutcome);
  184. bool RunAssetListsCommands(const AZ::Outcome<AssetListsParams, AZStd::string>& paramsOutcome);
  185. bool RunComparisonRulesCommands(const AZ::Outcome<ComparisonRulesParams, AZStd::string>& paramsOutcome);
  186. bool RunCompareCommand(const AZ::Outcome<ComparisonParams, AZStd::string>& paramsOutcome);
  187. bool RunBundleSettingsCommands(const AZ::Outcome<BundleSettingsParams, AZStd::string>& paramsOutcome);
  188. bool RunBundlesCommands(const AZ::Outcome<BundlesParamsList, AZStd::string>& paramsOutcome);
  189. bool RunBundleSeedCommands(const AZ::Outcome<BundleSeedParams, AZStd::string>& paramsOutcome);
  190. ////////////////////////////////////////////////////////////////////////////////////////////
  191. ////////////////////////////////////////////////////////////////////////////////////////////
  192. // Helpers
  193. AZ::Outcome<void, AZStd::string> InitAssetCatalog(AzFramework::PlatformFlags platforms, const AZStd::string& assetCatalogFile = AZStd::string());
  194. //! Given a gem seed file, validates whether the seed file is valid for the current project
  195. //! and platform flags specified before loading the file from disk.
  196. //! Does not do any validation on non gem seed files.
  197. AZ::Outcome<void, AZStd::string> LoadSeedListFile(const AZStd::string& seedListFileAbsolutePath, AzFramework::PlatformFlags platformFlags);
  198. AZ::Outcome<void, AZStd::string> LoadProjectDependenciesFile(AzFramework::PlatformFlags platformFlags);
  199. void PrintSeedList(const AZStd::string& seedListFileAbsolutePath);
  200. bool RunPlatformSpecificAssetListCommands(const AssetListsParams& params, AzFramework::PlatformFlags platformFlags);
  201. void PrintAssetLists(const AssetListsParams& params,
  202. const AZStd::fixed_vector<AzFramework::PlatformId, AzFramework::PlatformId::NumPlatformIds>& platformIds,
  203. bool printExistingFiles,
  204. const AZStd::unordered_set<AZ::Data::AssetId>& exclusionList,
  205. const AZStd::vector<AZStd::string>& wildcardPatternExclusionList);
  206. AZStd::vector<FilePath> GetAllPlatformSpecificFilesOnDisk(const FilePath& platformIndependentFilePath, AzFramework::PlatformFlags platformFlags = AzFramework::PlatformFlags::Platform_NONE);
  207. AZ::Outcome<void, AZStd::string> ApplyBundleSettingsOverrides(
  208. AzToolsFramework::AssetBundleSettings& bundleSettings,
  209. const AZStd::string& assetListFilePath,
  210. const AZStd::string& outputBundleFilePath,
  211. int bundleVersion,
  212. int maxBundleSize);
  213. AZ::Outcome<void, AZStd::string> ParseComparisonTypesAndPatterns(const AzFramework::CommandLine* parser, ComparisonRulesParams& params);
  214. AZ::Outcome<void, AZStd::string> ParseComparisonTypesAndPatternsForEditCommand(const AzFramework::CommandLine* parser, ComparisonRulesParams& params);
  215. AZ::Outcome<void, AZStd::string> ParseComparisonRulesFirstAndSecondInputArgs(const AzFramework::CommandLine* parser, ComparisonRulesParams& params);
  216. AZ::Outcome<BundlesParamsList, AZStd::string> ParseBundleSettingsAndOverrides(const AzFramework::CommandLine* parser, const char* commandName);
  217. bool ConvertRulesParamsToComparisonData(const ComparisonRulesParams& params, AzToolsFramework::AssetFileInfoListComparison& assetListComparison, size_t startingIndex);
  218. bool EditComparisonData(const ComparisonRulesParams& params, AzToolsFramework::AssetFileInfoListComparison& assetListComparison, size_t index);
  219. void PrintComparisonRules(const AzToolsFramework::AssetFileInfoListComparison& assetListComparison, const AZStd::string& comparisonRulesAbsoluteFilePath);
  220. bool IsDefaultToken(const AZStd::string& pathOrToken);
  221. void PrintComparisonAssetList(const AzToolsFramework::AssetFileInfoList& infoList, const AZStd::string& resultName);
  222. void AddPlatformToAllComparisonParams(ComparisonParams& params, const AZStd::string& platformName);
  223. void AddPlatformToComparisonParam(AZStd::string& inOut, const AZStd::string& platformName);
  224. //! Error message to display when neither of two optional arguments was found
  225. static AZStd::string GetBinaryArgOptionFailure(const char* arg1, const char* arg2);
  226. bool SeedsOperationRequiresCatalog(const SeedsParams& params);
  227. ////////////////////////////////////////////////////////////////////////////////////////////
  228. ////////////////////////////////////////////////////////////////////////////////////////////
  229. // Output Help Text
  230. void OutputHelp(CommandType commandType);
  231. void OutputHelpSeeds();
  232. void OutputHelpAssetLists();
  233. void OutputHelpComparisonRules();
  234. void OutputHelpCompare();
  235. void OutputHelpBundleSettings();
  236. void OutputHelpBundles();
  237. void OutputHelpBundleSeed();
  238. ////////////////////////////////////////////////////////////////////////////////////////////
  239. AZStd::unique_ptr<AzToolsFramework::AssetSeedManager> m_assetSeedManager;
  240. AZStd::unique_ptr<AzToolsFramework::PlatformAddressedAssetCatalogManager> m_platformCatalogManager;
  241. AZStd::vector<AzFramework::GemInfo> m_gemInfoList;
  242. bool m_showVerboseOutput = false;
  243. AZStd::string m_currentProjectName;
  244. CommandType m_commandType = CommandType::Invalid;
  245. AZStd::vector<const char*> m_allSeedsArgs;
  246. AZStd::vector<const char*> m_allAssetListsArgs;
  247. AZStd::vector<const char*> m_allComparisonRulesArgs;
  248. AZStd::vector<const char*> m_allCompareArgs;
  249. AZStd::vector<const char*> m_allBundleSettingsArgs;
  250. AZStd::vector<const char*> m_allBundlesArgs;
  251. AZStd::vector<const char*> m_allBundleSeedArgs;
  252. };
  253. }