PathDependencyManager.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. #include <AzCore/std/containers/vector.h>
  10. #include <AzCore/std/smart_ptr/shared_ptr.h>
  11. #include <AzCore/std/string/string.h>
  12. #include <AssetBuilderSDK/AssetBuilderSDK.h>
  13. #include <AzToolsFramework/AssetDatabase/AssetDatabaseConnection.h>
  14. #include <native/AssetManager/assetProcessorManager.h>
  15. class QString;
  16. namespace AssetProcessor
  17. {
  18. class PlatformConfiguration;
  19. class AssetDatabaseConnection;
  20. const char ExcludedDependenciesSymbol = ':';
  21. /// Handles resolving and saving product path dependencies
  22. class PathDependencyManager
  23. {
  24. public:
  25. // The two Ids needed for a ProductDependency entry, and platform. Used for saving ProductDependencies that are pending resolution
  26. struct DependencyProductIdInfo
  27. {
  28. AZ::s64 m_productId{};
  29. AZ::s64 m_productDependencyId{};
  30. AZStd::string m_platform;
  31. };
  32. using DependencyProductMap = AZStd::unordered_map<AZStd::string, AZStd::vector<DependencyProductIdInfo>>;
  33. PathDependencyManager(AZStd::shared_ptr<AssetDatabaseConnection> stateData, PlatformConfiguration* platformConfig);
  34. void QueueSourceForDependencyResolution(const AzToolsFramework::AssetDatabase::SourceDatabaseEntry& sourceEntry);
  35. void ProcessQueuedDependencyResolves();
  36. struct SearchEntry
  37. {
  38. SearchEntry(AZStd::string path, bool isSourcePath, const AzToolsFramework::AssetDatabase::SourceDatabaseEntry* sourceEntry, const AzToolsFramework::AssetDatabase::ProductDatabaseEntry* productEntry)
  39. : m_path(std::move(path)),
  40. m_isSourcePath(isSourcePath),
  41. m_sourceEntry(sourceEntry),
  42. m_productEntry(productEntry) {}
  43. AZStd::string m_path;
  44. bool m_isSourcePath;
  45. const AzToolsFramework::AssetDatabase::SourceDatabaseEntry* m_sourceEntry = nullptr;
  46. const AzToolsFramework::AssetDatabase::ProductDatabaseEntry* m_productEntry = nullptr;
  47. };
  48. /// This function is responsible for looking up existing, unresolved dependencies that the current asset satisfies.
  49. /// These can be dependencies on either the source asset or one of the product assets
  50. void RetryDeferredDependencies(const AzToolsFramework::AssetDatabase::SourceDatabaseEntry& sourceEntry, const AZStd::unordered_map<const SearchEntry*, AZStd::unordered_set<AzToolsFramework::AssetDatabase::ProductDependencyDatabaseEntry>>& matches, const AZStd::vector<AzToolsFramework::AssetDatabase::ProductDatabaseEntry>& products);
  51. /// This function is responsible for taking the path dependencies output by the current asset and trying to resolve them to AssetIds
  52. /// This does not look for dependencies that the current asset satisfies.
  53. void ResolveDependencies(AssetBuilderSDK::ProductPathDependencySet& pathDeps, AZStd::vector<AssetBuilderSDK::ProductDependency>& resolvedDeps, const AZStd::string& platform, const AZStd::string& productName);
  54. /// Saves a product's unresolved dependencies to the database
  55. void SaveUnresolvedDependenciesToDatabase(AssetBuilderSDK::ProductPathDependencySet& unresolvedDependencies, const AzToolsFramework::AssetDatabase::ProductDatabaseEntry& productEntry, const AZStd::string& platform);
  56. using DependencyResolvedCallback = AZStd::function<void(const AZ::Data::AssetId&, const AzToolsFramework::AssetDatabase::ProductDependencyDatabaseEntry&)>;
  57. void SetDependencyResolvedCallback(const DependencyResolvedCallback& callback);
  58. private:
  59. struct MapSet
  60. {
  61. DependencyProductMap m_sourcePathDependencyIds;
  62. DependencyProductMap m_productPathDependencyIds;
  63. DependencyProductMap m_wildcardSourcePathDependencyIds;
  64. DependencyProductMap m_wildcardProductPathDependencyIds;
  65. };
  66. MapSet PopulateExclusionMaps() const;
  67. void NotifyResolvedDependencies(const AzToolsFramework::AssetDatabase::ProductDependencyDatabaseEntryContainer& dependencyContainer) const;
  68. void SaveResolvedDependencies(const AzToolsFramework::AssetDatabase::SourceDatabaseEntry& sourceEntry, const MapSet& exclusionMaps, const AZStd::string& sourceNameWithScanFolder, const AZStd::unordered_set<AzToolsFramework::AssetDatabase::ProductDependencyDatabaseEntry>& dependencyEntries, AZStd::string_view matchedPath, bool isSourceDependency, const AzToolsFramework::AssetDatabase::ProductDatabaseEntryContainer& matchedProducts, AZStd::vector<AzToolsFramework::AssetDatabase::ProductDependencyDatabaseEntry>& dependencyContainer) const;
  69. static DependencyProductMap& SelectMap(MapSet& mapSet, bool wildcard, AzToolsFramework::AssetDatabase::ProductDependencyDatabaseEntry::DependencyType type);
  70. /// Returns false if a path contains wildcards, true otherwise
  71. static bool IsExactDependency(AZStd::string_view path);
  72. /// Prefixes the scanFolderId to the relativePath
  73. AZStd::string ToScanFolderPrefixedPath(int scanFolderId, const char* relativePath) const;
  74. /// Takes a path and breaks it into a database-prefixed relative path and scanFolder path
  75. /// This function can accept an absolute source path, an un-prefixed relative path, and a prefixed relative path
  76. /// The file returned will be the first one matched based on scanfolder priority
  77. bool ProcessInputPathToDatabasePathAndScanFolder(const char* dependencyPathSearch, QString& databaseName, QString& scanFolder) const;
  78. /// Gets any matched dependency exclusions
  79. /// @param sourceEntry source database entry corresponds to the newly finished product
  80. /// @param productEntry product database entry corresponds to the newly finished product
  81. /// @param excludedDependencies dependencies that should be ignored even if their file paths match any existing wildcard pattern
  82. /// @param dependencyType type of the dependencies we are handling
  83. /// @param exclusionMaps MapSet containing all the path dependency exclusions
  84. void GetMatchedExclusions(const AzToolsFramework::AssetDatabase::SourceDatabaseEntry& sourceEntry, const AzToolsFramework::AssetDatabase::ProductDatabaseEntry& productEntry,
  85. AZStd::vector<AZStd::pair<DependencyProductIdInfo, bool>>& excludedDependencies, AzToolsFramework::AssetDatabase::ProductDependencyDatabaseEntry::DependencyType dependencyType,
  86. const MapSet& exclusionMaps) const;
  87. AZStd::shared_ptr<AssetDatabaseConnection> m_stateData;
  88. PlatformConfiguration* m_platformConfig{};
  89. DependencyResolvedCallback m_dependencyResolvedCallback{};
  90. AZStd::vector<AzToolsFramework::AssetDatabase::SourceDatabaseEntry> m_queuedForResolve;
  91. };
  92. } // namespace AssetProcessor