/* * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or * its licensors. * * For complete copyright and license terms please see the LICENSE at the root of this * distribution (the "License"). All use of this software is governed by the License, * or, if provided, by the license below or the license accompanying this file. Do not * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * */ #pragma once #include #include #include #include #include #include #include #include #include #include #include #include namespace AssetBundler { struct SeedsParams { AZ_CLASS_ALLOCATOR(SeedsParams, AZ::SystemAllocator, 0); FilePath m_seedListFile; AZStd::vector m_addSeedList; AZStd::vector m_removeSeedList; bool m_addPlatformToAllSeeds = false; bool m_removePlatformFromAllSeeds = false; bool m_updateSeedPathHint = false; bool m_removeSeedPathHint = false; bool m_ignoreFileCase = false; bool m_save = false; bool m_print = false; AzFramework::PlatformFlags m_platformFlags = AzFramework::PlatformFlags::Platform_NONE; FilePath m_assetCatalogFile; }; struct AssetListsParams { AZ_CLASS_ALLOCATOR(AssetListsParams, AZ::SystemAllocator, 0); FilePath m_assetListFile; AZStd::vector m_seedListFiles; AZStd::vector m_addSeedList; AZStd::vector m_skipList; bool m_addDefaultSeedListFiles = false; bool m_print = false; bool m_dryRun = false; bool m_generateDebugFile = false; bool m_allowOverwrites = false; AzFramework::PlatformFlags m_platformFlags = AzFramework::PlatformFlags::Platform_NONE; FilePath m_assetCatalogFile; }; enum ComparisonRulesStepAction { Add, AddToEnd, Remove, Move, Edit, Default, }; struct ComparisonRulesParams { AZ_CLASS_ALLOCATOR(ComparisonRulesParams, AZ::SystemAllocator, 0); AZStd::vector m_comparisonTypeList; AZStd::vector m_filePatternList; AZStd::vector m_filePatternTypeList; AZStd::vector m_tokenNamesList; AZStd::vector m_firstInputList; AZStd::vector m_secondInputList; FilePath m_comparisonRulesFile; ComparisonRulesStepAction m_comparisonRulesStepAction = ComparisonRulesStepAction::Default; size_t m_initialLine = 0; size_t m_destinationLine = 0; unsigned int m_intersectionCount = 0; bool m_print = false; }; struct ComparisonParams { AZ_CLASS_ALLOCATOR(ComparisonParams, AZ::SystemAllocator, 0); // Comparison input/output AZStd::vector m_firstCompareFile; AZStd::vector m_secondCompareFile; AZStd::vector m_outputs; AZStd::vector m_printComparisons; bool m_printLast = false; bool m_allowOverwrites = false; AzFramework::PlatformFlags m_platformFlags = AzFramework::PlatformFlags::Platform_NONE; // Comparison definitions FilePath m_comparisonRulesFile; ComparisonRulesParams m_comparisonRulesParams; }; struct BundleSettingsParams { AZ_CLASS_ALLOCATOR(BundleSettingsParams, AZ::SystemAllocator, 0); FilePath m_bundleSettingsFile; FilePath m_assetListFile; FilePath m_outputBundlePath; int m_bundleVersion = -1; int m_maxBundleSizeInMB = -1; bool m_print = false; AzFramework::PlatformFlags m_platformFlags = AzFramework::PlatformFlags::Platform_NONE; }; struct BundlesParams { AZ_CLASS_ALLOCATOR(BundlesParams, AZ::SystemAllocator, 0); FilePath m_bundleSettingsFile; FilePath m_assetListFile; FilePath m_outputBundlePath; int m_bundleVersion = -1; int m_maxBundleSizeInMB = -1; AzFramework::PlatformFlags m_platformFlags = AzFramework::PlatformFlags::Platform_NONE; bool m_allowOverwrites = false; }; typedef AZStd::vector BundlesParamsList; struct BundleSeedParams { AZ_CLASS_ALLOCATOR(BundleSeedParams, AZ::SystemAllocator, 0); AZStd::vector m_addSeedList; BundlesParams m_bundleParams; }; class ApplicationManager : public AZ::Debug::TraceMessageBus::Handler , public AzToolsFramework::ToolsApplication { public: explicit ApplicationManager(int* argc, char*** argv); ~ApplicationManager(); void Init(); void DestroyApplication(); bool Run(); //////////////////////////////////////////////////////////////////////////////////////////// // AzFramework::Application overrides AZ::ComponentTypeList GetRequiredSystemComponents() const override; //////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////// // TraceMessageBus Interface bool OnPreError(const char* window, const char* fileName, int line, const char* func, const char* message) override; bool OnPreWarning(const char* window, const char* fileName, int line, const char* func, const char* message) override; bool OnPrintf(const char* window, const char* message) override; //////////////////////////////////////////////////////////////////////////////////////////// AZStd::string GetCurrentProjectName() { return m_currentProjectName; } AZStd::vector GetGemInfoList() { return m_gemInfoList; } protected: //////////////////////////////////////////////////////////////////////////////////////////// // Get Generic Command Info CommandType GetCommandType(const AzFramework::CommandLine* parser, bool suppressErrors); bool ShouldPrintHelp(const AzFramework::CommandLine* parser); bool ShouldPrintVerbose(const AzFramework::CommandLine* parser); void InitArgValidationLists(); //////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////// // Store Detailed Command Info and Validate parser input (command correctness) AZ::Outcome ParseSeedsCommandData(const AzFramework::CommandLine* parser); AZ::Outcome ParseAssetListsCommandData(const AzFramework::CommandLine* parser); AZ::Outcome ParseComparisonRulesCommandData(const AzFramework::CommandLine* parser); AZ::Outcome ParseCompareCommandData(const AzFramework::CommandLine* parser); AZ::Outcome ParseBundleSettingsCommandData(const AzFramework::CommandLine* parser); AZ::Outcome ParseBundlesCommandData(const AzFramework::CommandLine* parser); AZ::Outcome ParseBundleSeedCommandData(const AzFramework::CommandLine* parser); AZ::Outcome ValidateInputArgs(const AzFramework::CommandLine* parser, const AZStd::vector& validArgList); AZ::Outcome GetFilePathArg(const AzFramework::CommandLine* parser, const char* argName, const char* subCommandName, bool isRequired = false); template AZ::Outcome, AZStd::string> GetArgsList(const AzFramework::CommandLine* parser, const char* argName, const char* subCommandName, bool isRequired = false); AZ::Outcome GetPlatformArg(const AzFramework::CommandLine* parser); AzFramework::PlatformFlags GetInputPlatformFlagsOrEnabledPlatformFlags(AzFramework::PlatformFlags inputPlatformFlags); AZStd::vector GetAddSeedArgList(const AzFramework::CommandLine* parser); AZStd::vector GetSkipArgList(const AzFramework::CommandLine* parser); //////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////// // Run Commands and Validate param data (value correctness) bool RunSeedsCommands(const AZ::Outcome& paramsOutcome); bool RunAssetListsCommands(const AZ::Outcome& paramsOutcome); bool RunComparisonRulesCommands(const AZ::Outcome& paramsOutcome); bool RunCompareCommand(const AZ::Outcome& paramsOutcome); bool RunBundleSettingsCommands(const AZ::Outcome& paramsOutcome); bool RunBundlesCommands(const AZ::Outcome& paramsOutcome); bool RunBundleSeedCommands(const AZ::Outcome& paramsOutcome); //////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////// // Helpers AZ::Outcome InitAssetCatalog(AzFramework::PlatformFlags platforms, const AZStd::string& assetCatalogFile = AZStd::string()); //! Given a gem seed file, validates whether the seed file is valid for the current project //! and platform flags specified before loading the file from disk. //! Does not do any validation on non gem seed files. AZ::Outcome LoadSeedListFile(const AZStd::string& seedListFileAbsolutePath, AzFramework::PlatformFlags platformFlags); AZ::Outcome LoadProjectDependenciesFile(AzFramework::PlatformFlags platformFlags); void PrintSeedList(const AZStd::string& seedListFileAbsolutePath); bool RunPlatformSpecificAssetListCommands(const AssetListsParams& params, AzFramework::PlatformFlags platformFlags); void PrintAssetLists(const AssetListsParams& params, const AZStd::vector& platformIds, bool printExistingFiles, const AZStd::unordered_set& exclusionList, const AZStd::vector& wildcardPatternExclusionList); AZStd::vector GetAllPlatformSpecificFilesOnDisk(const FilePath& platformIndependentFilePath, AzFramework::PlatformFlags platformFlags = AzFramework::PlatformFlags::Platform_NONE); AZ::Outcome ApplyBundleSettingsOverrides( AzToolsFramework::AssetBundleSettings& bundleSettings, const AZStd::string& assetListFilePath, const AZStd::string& outputBundleFilePath, int bundleVersion, int maxBundleSize); AZ::Outcome ParseComparisonTypesAndPatterns(const AzFramework::CommandLine* parser, ComparisonRulesParams& params); AZ::Outcome ParseComparisonTypesAndPatternsForEditCommand(const AzFramework::CommandLine* parser, ComparisonRulesParams& params); AZ::Outcome ParseComparisonRulesFirstAndSecondInputArgs(const AzFramework::CommandLine* parser, ComparisonRulesParams& params); AZ::Outcome ParseBundleSettingsAndOverrides(const AzFramework::CommandLine* parser, const char* commandName); bool ConvertRulesParamsToComparisonData(const ComparisonRulesParams& params, AzToolsFramework::AssetFileInfoListComparison& assetListComparison, size_t startingIndex); bool EditComparisonData(const ComparisonRulesParams& params, AzToolsFramework::AssetFileInfoListComparison& assetListComparison, size_t index); void PrintComparisonRules(const AzToolsFramework::AssetFileInfoListComparison& assetListComparison, const AZStd::string& comparisonRulesAbsoluteFilePath); bool IsDefaultToken(const AZStd::string& pathOrToken); void PrintComparisonAssetList(const AzToolsFramework::AssetFileInfoList& infoList, const AZStd::string& resultName); void AddPlatformToAllComparisonParams(ComparisonParams& params, const AZStd::string& platformName); void AddPlatformToComparisonParam(AZStd::string& inOut, const AZStd::string& platformName); //! Error message to display when neither of two optional arguments was found static AZStd::string GetBinaryArgOptionFailure(const char* arg1, const char* arg2); bool SeedsOperationRequiresCatalog(const SeedsParams& params); //////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////// // Output Help Text void OutputHelp(CommandType commandType); void OutputHelpSeeds(); void OutputHelpAssetLists(); void OutputHelpComparisonRules(); void OutputHelpCompare(); void OutputHelpBundleSettings(); void OutputHelpBundles(); void OutputHelpBundleSeed(); //////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////// // Metrics void InitMetrics(); void ShutDownMetrics(); void SendErrorMetricEvent(const char *errorMessage) const; void AddFlagAttribute(const char* key, bool flagValue) const; void AddMetric(const char* metricName, double metricValue) const; //////////////////////////////////////////////////////////////////////////////////////////// AZStd::unique_ptr m_assetSeedManager; AZStd::unique_ptr m_platformCatalogManager; LyMetricIdType m_assetBundlerMetricId; AZStd::vector m_gemInfoList; bool m_showVerboseOutput = false; AZStd::string m_currentProjectName; CommandType m_commandType = CommandType::Invalid; AZStd::vector m_allSeedsArgs; AZStd::vector m_allAssetListsArgs; AZStd::vector m_allComparisonRulesArgs; AZStd::vector m_allCompareArgs; AZStd::vector m_allBundleSettingsArgs; AZStd::vector m_allBundlesArgs; AZStd::vector m_allBundleSeedArgs; }; }