PlatformConfiguration.cpp 88 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080
  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. #include "native/utilities/PlatformConfiguration.h"
  9. #include "native/AssetManager/FileStateCache.h"
  10. #include "native/assetprocessor.h"
  11. #include <QDirIterator>
  12. #include <AzCore/Component/ComponentApplicationBus.h>
  13. #include <AzCore/Settings/SettingsRegistryMergeUtils.h>
  14. #include <AzCore/Settings/SettingsRegistryVisitorUtils.h>
  15. #include <AzCore/Serialization/Json/JsonUtils.h>
  16. #include <AzCore/Utils/Utils.h>
  17. #include <AzFramework/API/ApplicationAPI.h>
  18. #include <AzFramework/Gem/GemInfo.h>
  19. #include <AzToolsFramework/Asset/AssetUtils.h>
  20. #include <AzCore/Serialization/SerializeContext.h>
  21. #include <AzToolsFramework/Metadata/MetadataManager.h>
  22. namespace AssetProcessor
  23. {
  24. struct AssetImporterPathsVisitor
  25. : AZ::SettingsRegistryInterface::Visitor
  26. {
  27. AssetImporterPathsVisitor(AZ::SettingsRegistryInterface* settingsRegistry, AZStd::vector<AZStd::string>& supportedExtension)
  28. : m_settingsRegistry(settingsRegistry)
  29. , m_supportedFileExtensions(supportedExtension)
  30. {
  31. }
  32. using AZ::SettingsRegistryInterface::Visitor::Visit;
  33. void Visit(const AZ::SettingsRegistryInterface::VisitArgs&, AZStd::string_view value) override
  34. {
  35. if (auto found = value.find('.'); found != AZStd::string::npos)
  36. {
  37. m_supportedFileExtensions.emplace_back(value.substr(found + 1));
  38. }
  39. else
  40. {
  41. m_supportedFileExtensions.emplace_back(value);
  42. }
  43. }
  44. AZ::SettingsRegistryInterface* m_settingsRegistry;
  45. AZStd::vector<AZStd::string> m_supportedFileExtensions;
  46. };
  47. //! Visitor for reading the "/Amazon/AssetProcessor/Settings/ScanFolder *" entries from the Settings Registry
  48. //! Expects the key to path to the visitor to be "/Amazon/AssetProcessor/Settings"
  49. struct ScanFolderVisitor
  50. : AZ::SettingsRegistryVisitorUtils::ObjectVisitor
  51. {
  52. using AZ::SettingsRegistryInterface::Visitor::Visit;
  53. AZ::SettingsRegistryInterface::VisitResponse Visit(const AZ::SettingsRegistryInterface::VisitArgs& visitArgs) override;
  54. struct ScanFolderInfo
  55. {
  56. AZStd::string m_scanFolderIdentifier;
  57. AZStd::string m_scanFolderDisplayName;
  58. AZ::IO::Path m_watchPath{ AZ::IO::PosixPathSeparator };
  59. AZStd::vector<AZStd::string> m_includeIdentifiers;
  60. AZStd::vector<AZStd::string> m_excludeIdentifiers;
  61. int m_scanOrder{};
  62. bool m_isRecursive{};
  63. };
  64. AZStd::vector<ScanFolderInfo> m_scanFolderInfos;
  65. };
  66. struct ExcludeVisitor
  67. : AZ::SettingsRegistryVisitorUtils::ObjectVisitor
  68. {
  69. using AZ::SettingsRegistryInterface::Visitor::Visit;
  70. AZ::SettingsRegistryInterface::VisitResponse Visit(const AZ::SettingsRegistryInterface::VisitArgs& visitArgs) override;
  71. AZStd::vector<ExcludeAssetRecognizer> m_excludeAssetRecognizers;
  72. };
  73. struct SimpleJobVisitor
  74. : AZ::SettingsRegistryVisitorUtils::ObjectVisitor
  75. {
  76. SimpleJobVisitor(const AZStd::vector<AssetBuilderSDK::PlatformInfo>& enabledPlatforms)
  77. : m_enabledPlatforms(enabledPlatforms)
  78. {
  79. }
  80. using AZ::SettingsRegistryInterface::Visitor::Visit;
  81. AZ::SettingsRegistryInterface::VisitResponse Visit(const AZ::SettingsRegistryInterface::VisitArgs& visitArgs) override;
  82. struct SimpleJobAssetRecognizer
  83. {
  84. AssetRecognizer m_recognizer;
  85. AZStd::string m_defaultParams;
  86. bool m_ignore{};
  87. };
  88. AZStd::vector<SimpleJobAssetRecognizer> m_assetRecognizers;
  89. private:
  90. void ApplyParamsOverrides(const AZ::SettingsRegistryInterface::VisitArgs& visitArgs,
  91. SimpleJobAssetRecognizer& assetRecognizer);
  92. const AZStd::vector<AssetBuilderSDK::PlatformInfo>& m_enabledPlatforms;
  93. };
  94. //! This vistor reads in the Asset Cache Server configuration elements from the settings registry
  95. struct ACSVisitor
  96. : AZ::SettingsRegistryVisitorUtils::ObjectVisitor
  97. {
  98. using AZ::SettingsRegistryInterface::Visitor::Visit;
  99. AZ::SettingsRegistryInterface::VisitResponse Visit(const AZ::SettingsRegistryInterface::VisitArgs& visitArgs) override;
  100. AZStd::vector<AssetRecognizer> m_assetRecognizers;
  101. };
  102. struct PlatformsInfoVisitor
  103. : AZ::SettingsRegistryVisitorUtils::ObjectVisitor
  104. {
  105. using AZ::SettingsRegistryInterface::Visitor::Visit;
  106. AZ::SettingsRegistryInterface::VisitResponse Visit(const AZ::SettingsRegistryInterface::VisitArgs& visitArgs) override
  107. {
  108. // Visit any each "Platform *" field that is a direct child of the object at the AssetProcessorSettingsKey
  109. constexpr AZStd::string_view PlatformInfoPrefix = "Platform ";
  110. if (!visitArgs.m_fieldName.starts_with(PlatformInfoPrefix))
  111. {
  112. return AZ::SettingsRegistryInterface::VisitResponse::Skip;
  113. }
  114. // Retrieve the platform name from the rest of valueName portion of the key "Platform (.*)"
  115. AZStd::string platformIdentifier = visitArgs.m_fieldName.substr(PlatformInfoPrefix.size());
  116. // Lowercase the platformIdentifier
  117. AZStd::to_lower(platformIdentifier.begin(), platformIdentifier.end());
  118. // Look up the "tags" field that is child of the "Platform (.*)" field
  119. using FixedValueString = AZ::SettingsRegistryInterface::FixedValueString;
  120. const auto tagKeyPath = FixedValueString(visitArgs.m_jsonKeyPath) + "/tags";
  121. if (AZStd::string tagValue; visitArgs.m_registry.Get(tagValue, tagKeyPath))
  122. {
  123. AZStd::unordered_set<AZStd::string> platformTags;
  124. auto JoinTags = [&platformTags](AZStd::string_view token)
  125. {
  126. AZStd::string cleanedTag{ token };
  127. AZStd::to_lower(cleanedTag.begin(), cleanedTag.end());
  128. platformTags.insert(AZStd::move(cleanedTag));
  129. };
  130. AZ::StringFunc::TokenizeVisitor(tagValue, JoinTags, ',');
  131. m_platformInfos.emplace_back(platformIdentifier, platformTags);
  132. }
  133. return AZ::SettingsRegistryInterface::VisitResponse::Skip;
  134. }
  135. AZStd::vector<AssetBuilderSDK::PlatformInfo> m_platformInfos;
  136. };
  137. struct MetaDataTypesVisitor
  138. : AZ::SettingsRegistryInterface::Visitor
  139. {
  140. using AZ::SettingsRegistryInterface::Visitor::Visit;
  141. void Visit(const AZ::SettingsRegistryInterface::VisitArgs& visitArgs, AZStd::string_view value) override
  142. {
  143. m_metaDataTypes.push_back({ AZ::IO::PathView(visitArgs.m_fieldName, AZ::IO::PosixPathSeparator).LexicallyNormal().String(), value });
  144. }
  145. struct MetaDataType
  146. {
  147. AZStd::string m_fileType;
  148. AZStd::string m_extensionType;
  149. };
  150. AZStd::vector<MetaDataType> m_metaDataTypes;
  151. };
  152. AZ::SettingsRegistryInterface::VisitResponse ScanFolderVisitor::Visit(const AZ::SettingsRegistryInterface::VisitArgs& visitArgs)
  153. {
  154. constexpr AZStd::string_view ScanFolderInfoPrefix = "ScanFolder ";
  155. // Check if a "ScanFolder *" element is being traversed
  156. if (!visitArgs.m_fieldName.starts_with(ScanFolderInfoPrefix))
  157. {
  158. return AZ::SettingsRegistryInterface::VisitResponse::Skip;
  159. }
  160. AZStd::string_view currentScanFolderIdentifier = visitArgs.m_fieldName.substr(ScanFolderInfoPrefix.size());
  161. ScanFolderInfo& scanFolderInfo = m_scanFolderInfos.emplace_back();
  162. scanFolderInfo.m_scanFolderIdentifier = currentScanFolderIdentifier;
  163. scanFolderInfo.m_scanFolderDisplayName = currentScanFolderIdentifier;
  164. using FixedValueString = AZ::SettingsRegistryInterface::FixedValueString;
  165. if (AZ::s64 value;
  166. visitArgs.m_registry.Get(value, FixedValueString(visitArgs.m_jsonKeyPath) + "/recursive"))
  167. {
  168. scanFolderInfo.m_isRecursive = value != 0;
  169. }
  170. if (AZ::s64 value;
  171. visitArgs.m_registry.Get(value, FixedValueString(visitArgs.m_jsonKeyPath) + "/order"))
  172. {
  173. scanFolderInfo.m_scanOrder = static_cast<int>(value);
  174. }
  175. if (AZStd::string value;
  176. visitArgs.m_registry.Get(value, FixedValueString(visitArgs.m_jsonKeyPath) + "/watch"))
  177. {
  178. scanFolderInfo.m_watchPath = value;
  179. }
  180. if (AZStd::string value;
  181. visitArgs.m_registry.Get(value, FixedValueString(visitArgs.m_jsonKeyPath) + "/display")
  182. && !value.empty())
  183. {
  184. scanFolderInfo.m_scanFolderDisplayName = value;
  185. }
  186. if (AZStd::string value;
  187. visitArgs.m_registry.Get(value, FixedValueString(visitArgs.m_jsonKeyPath) + "/include"))
  188. {
  189. auto JoinTags = [&scanFolderInfo](AZStd::string_view token)
  190. {
  191. scanFolderInfo.m_includeIdentifiers.push_back(token);
  192. };
  193. AZ::StringFunc::TokenizeVisitor(value, JoinTags, ',');
  194. }
  195. if (AZStd::string value;
  196. visitArgs.m_registry.Get(value, FixedValueString(visitArgs.m_jsonKeyPath) + "/exclude"))
  197. {
  198. auto JoinTags = [&scanFolderInfo](AZStd::string_view token)
  199. {
  200. scanFolderInfo.m_excludeIdentifiers.push_back(token);
  201. };
  202. AZ::StringFunc::TokenizeVisitor(value, JoinTags, ',');
  203. }
  204. return AZ::SettingsRegistryInterface::VisitResponse::Skip;
  205. }
  206. AZ::SettingsRegistryInterface::VisitResponse ExcludeVisitor::Visit(const AZ::SettingsRegistryInterface::VisitArgs& visitArgs)
  207. {
  208. constexpr AZStd::string_view ExcludeNamePrefix = "Exclude ";
  209. if (!visitArgs.m_fieldName.starts_with(ExcludeNamePrefix))
  210. {
  211. return AZ::SettingsRegistryInterface::VisitResponse::Skip;
  212. }
  213. AZStd::string_view excludeName = visitArgs.m_fieldName.substr(ExcludeNamePrefix.size());
  214. ExcludeAssetRecognizer& excludeAssetRecognizer = m_excludeAssetRecognizers.emplace_back();
  215. excludeAssetRecognizer.m_name = QString::fromUtf8(excludeName.data(), aznumeric_cast<int>(excludeName.size()));
  216. // The "pattern" and "glob" entries were previously parsed by QSettings which un-escapes the values
  217. // To compensate for it the AssetProcessorPlatformConfig.ini was escaping the
  218. // backslash character used to escape other characters, therefore causing a "double escape"
  219. // situation
  220. auto UnescapePattern = [](AZStd::string_view pattern)
  221. {
  222. constexpr AZStd::string_view backslashEscape = R"(\\)";
  223. AZStd::string unescapedResult;
  224. while (!pattern.empty())
  225. {
  226. size_t pos = pattern.find(backslashEscape);
  227. if (pos != AZStd::string_view::npos)
  228. {
  229. unescapedResult += pattern.substr(0, pos);
  230. unescapedResult += '\\';
  231. // Move the pattern string after the double backslash characters
  232. pattern = pattern.substr(pos + backslashEscape.size());
  233. }
  234. else
  235. {
  236. unescapedResult += pattern;
  237. pattern = {};
  238. }
  239. }
  240. return unescapedResult;
  241. };
  242. using FixedValueString = AZ::SettingsRegistryInterface::FixedValueString;
  243. if (AZStd::string value;
  244. visitArgs.m_registry.Get(value, FixedValueString(visitArgs.m_jsonKeyPath) + "/pattern"))
  245. {
  246. if (!value.empty())
  247. {
  248. const auto patternType = AssetBuilderSDK::AssetBuilderPattern::Regex;
  249. excludeAssetRecognizer.m_patternMatcher = AssetBuilderSDK::FilePatternMatcher(UnescapePattern(value), patternType);
  250. }
  251. }
  252. if (AZStd::string value;
  253. visitArgs.m_registry.Get(value, FixedValueString(visitArgs.m_jsonKeyPath) + "/glob"))
  254. {
  255. if (!excludeAssetRecognizer.m_patternMatcher.IsValid())
  256. {
  257. const auto patternType = AssetBuilderSDK::AssetBuilderPattern::Wildcard;
  258. excludeAssetRecognizer.m_patternMatcher = AssetBuilderSDK::FilePatternMatcher(UnescapePattern(value), patternType);
  259. }
  260. }
  261. return AZ::SettingsRegistryInterface::VisitResponse::Skip;
  262. }
  263. AZ::SettingsRegistryInterface::VisitResponse SimpleJobVisitor::Visit(const AZ::SettingsRegistryInterface::VisitArgs& visitArgs)
  264. {
  265. constexpr AZStd::string_view RCNamePrefix = "RC "; // RC = Resource Compiler
  266. constexpr AZStd::string_view SJNamePrefix = "SJ "; // SJ = Simple Job
  267. if (!visitArgs.m_fieldName.starts_with(RCNamePrefix) && !visitArgs.m_fieldName.starts_with(SJNamePrefix))
  268. {
  269. return AZ::SettingsRegistryInterface::VisitResponse::Skip;
  270. }
  271. AZStd::string_view sjNameView = visitArgs.m_fieldName.starts_with(SJNamePrefix)
  272. ? visitArgs.m_fieldName.substr(SJNamePrefix.size())
  273. : visitArgs.m_fieldName.substr(RCNamePrefix.size());
  274. auto& assetRecognizer = m_assetRecognizers.emplace_back();
  275. assetRecognizer.m_recognizer.m_name = sjNameView;
  276. using FixedValueString = AZ::SettingsRegistryInterface::FixedValueString;
  277. if (bool value;
  278. visitArgs.m_registry.Get(value, FixedValueString(visitArgs.m_jsonKeyPath) + "/ignore"))
  279. {
  280. assetRecognizer.m_ignore = value;
  281. }
  282. if (bool value;
  283. visitArgs.m_registry.Get(value, FixedValueString(visitArgs.m_jsonKeyPath) + "/lockSource"))
  284. {
  285. assetRecognizer.m_recognizer.m_testLockSource = value;
  286. }
  287. if (bool value;
  288. visitArgs.m_registry.Get(value, FixedValueString(visitArgs.m_jsonKeyPath) + "/critical"))
  289. {
  290. assetRecognizer.m_recognizer.m_isCritical = value;
  291. }
  292. if (bool value;
  293. visitArgs.m_registry.Get(value, FixedValueString(visitArgs.m_jsonKeyPath) + "/checkServer"))
  294. {
  295. assetRecognizer.m_recognizer.m_checkServer = value;
  296. }
  297. if (bool value;
  298. visitArgs.m_registry.Get(value, FixedValueString(visitArgs.m_jsonKeyPath) + "/supportsCreateJobs"))
  299. {
  300. assetRecognizer.m_recognizer.m_supportsCreateJobs = value;
  301. }
  302. if (bool value;
  303. visitArgs.m_registry.Get(value, FixedValueString(visitArgs.m_jsonKeyPath) + "/outputProductDependencies"))
  304. {
  305. assetRecognizer.m_recognizer.m_outputProductDependencies = value;
  306. }
  307. if (AZ::s64 value;
  308. visitArgs.m_registry.Get(value, FixedValueString(visitArgs.m_jsonKeyPath) + "/priority"))
  309. {
  310. assetRecognizer.m_recognizer.m_priority = static_cast<int>(value);
  311. }
  312. // The "pattern" and "glob" entries were previously parsed by QSettings which un-escapes the values
  313. // To compensate for it the AssetProcessorPlatformConfig.ini was escaping the
  314. // backslash character used to escape other characters, therefore causing a "double escape"
  315. // situation
  316. auto UnescapePattern = [](AZStd::string_view pattern)
  317. {
  318. constexpr AZStd::string_view backslashEscape = R"(\\)";
  319. AZStd::string unescapedResult;
  320. while (!pattern.empty())
  321. {
  322. size_t pos = pattern.find(backslashEscape);
  323. if (pos != AZStd::string_view::npos)
  324. {
  325. unescapedResult += pattern.substr(0, pos);
  326. unescapedResult += '\\';
  327. // Move the pattern string after the double backslash characters
  328. pattern = pattern.substr(pos + backslashEscape.size());
  329. }
  330. else
  331. {
  332. unescapedResult += pattern;
  333. pattern = {};
  334. }
  335. }
  336. return unescapedResult;
  337. };
  338. if (AZStd::string value;
  339. visitArgs.m_registry.Get(value, FixedValueString(visitArgs.m_jsonKeyPath) + "/pattern"))
  340. {
  341. if (!value.empty())
  342. {
  343. const auto patternType = AssetBuilderSDK::AssetBuilderPattern::Regex;
  344. assetRecognizer.m_recognizer.m_patternMatcher = AssetBuilderSDK::FilePatternMatcher(UnescapePattern(value), patternType);
  345. }
  346. }
  347. if (AZStd::string value;
  348. visitArgs.m_registry.Get(value, FixedValueString(visitArgs.m_jsonKeyPath) + "/glob"))
  349. {
  350. // Add the glob pattern if it the matter matcher doesn't already contain a valid regex pattern
  351. if (!assetRecognizer.m_recognizer.m_patternMatcher.IsValid())
  352. {
  353. const auto patternType = AssetBuilderSDK::AssetBuilderPattern::Wildcard;
  354. assetRecognizer.m_recognizer.m_patternMatcher = AssetBuilderSDK::FilePatternMatcher(UnescapePattern(value), patternType);
  355. }
  356. }
  357. if (AZStd::string value;
  358. visitArgs.m_registry.Get(value, FixedValueString(visitArgs.m_jsonKeyPath) + "/version"))
  359. {
  360. assetRecognizer.m_recognizer.m_version = value;
  361. }
  362. if (AZStd::string value;
  363. visitArgs.m_registry.Get(value, FixedValueString(visitArgs.m_jsonKeyPath) + "/productAssetType"))
  364. {
  365. if (!value.empty())
  366. {
  367. AZ::Uuid productAssetType{ value.data(), value.size() };
  368. if (!productAssetType.IsNull())
  369. {
  370. assetRecognizer.m_recognizer.m_productAssetType = productAssetType;
  371. }
  372. }
  373. }
  374. if (AZStd::string value;
  375. visitArgs.m_registry.Get(value, FixedValueString(visitArgs.m_jsonKeyPath) + "/params"))
  376. {
  377. assetRecognizer.m_defaultParams = value;
  378. }
  379. ApplyParamsOverrides(visitArgs, assetRecognizer);
  380. return AZ::SettingsRegistryInterface::VisitResponse::Skip;
  381. }
  382. void SimpleJobVisitor::ApplyParamsOverrides(const AZ::SettingsRegistryInterface::VisitArgs& visitArgs, SimpleJobAssetRecognizer& assetRecognizer)
  383. {
  384. /* so in this particular case we want to end up with an AssetPlatformSpec struct that
  385. has only got the platforms that 'matter' in it
  386. so for example, if you have the following enabled platforms
  387. [Platform PC]
  388. tags=blah
  389. [Platform Mac]
  390. tags=whatever
  391. [Platform android]
  392. tags=mobile
  393. and you encounter a recognizer like:
  394. [SJ blahblah]
  395. pattern=whatever
  396. params=abc
  397. mac=skip
  398. mobile=hijklmnop
  399. android=1234
  400. then the outcome should be a recognizer which has:
  401. pattern=whatever
  402. pc=abc -- no tags or platforms matched but we do have a default params
  403. android=1234 -- because even though it matched the mobile tag, platforms explicitly specified take precedence
  404. (and no mac) -- because it matched a skip rule
  405. So the strategy will be to read the default params
  406. - if present, we pre-populate all the platforms with it
  407. - If missing, we pre-populate nothing
  408. Then loop over the other params and
  409. if the key matches a tag, if it does we add/change that platform
  410. (if its 'skip' we remove it)
  411. if the key matches a platform, if it does we add/change that platform
  412. (if its 'skip' we remove it)
  413. */
  414. for (const AssetBuilderSDK::PlatformInfo& platform : m_enabledPlatforms)
  415. {
  416. // Exclude the common platform from the internal copy builder, we don't support it as an output for assets currently
  417. if(platform.m_identifier == AssetBuilderSDK::CommonPlatformName)
  418. {
  419. continue;
  420. }
  421. AZStd::string_view currentParams = assetRecognizer.m_defaultParams;
  422. // The "/Amazon/AssetProcessor/Settings/SJ */<platform>" entry will be queried
  423. AZ::IO::Path overrideParamsKey = AZ::IO::Path(AZ::IO::PosixPathSeparator);
  424. overrideParamsKey /= visitArgs.m_jsonKeyPath;
  425. overrideParamsKey /= platform.m_identifier;
  426. AZ::SettingsRegistryInterface::FixedValueString overrideParamsValue;
  427. // Check if the enabled platform identifier matches a key within the "SJ *" object
  428. if (visitArgs.m_registry.Get(overrideParamsValue, overrideParamsKey.Native()))
  429. {
  430. currentParams = overrideParamsValue;
  431. }
  432. else
  433. {
  434. // otherwise check for tags associated with the platform
  435. for (const AZStd::string& tag : platform.m_tags)
  436. {
  437. overrideParamsKey.ReplaceFilename(AZ::IO::PathView(tag));
  438. if (visitArgs.m_registry.Get(overrideParamsValue, overrideParamsKey.Native()))
  439. {
  440. // if we get here it means we found a tag that applies to this platform
  441. currentParams = overrideParamsValue;
  442. break;
  443. }
  444. }
  445. }
  446. // now generate a platform spec as long as we're not skipping
  447. if (!AZ::StringFunc::Equal(currentParams, "skip"))
  448. {
  449. assetRecognizer.m_recognizer.m_platformSpecs[platform.m_identifier] = AssetInternalSpec::Copy;
  450. }
  451. }
  452. }
  453. AZ::SettingsRegistryInterface::VisitResponse ACSVisitor::Visit(const AZ::SettingsRegistryInterface::VisitArgs& visitArgs)
  454. {
  455. constexpr AZStd::string_view ACSNamePrefix = "ACS ";
  456. if (!visitArgs.m_fieldName.starts_with(ACSNamePrefix))
  457. {
  458. return AZ::SettingsRegistryInterface::VisitResponse::Skip;
  459. }
  460. AZStd::string name = visitArgs.m_fieldName.substr(ACSNamePrefix.size());
  461. AssetRecognizer& assetRecognizer = m_assetRecognizers.emplace_back();
  462. assetRecognizer.m_name = name;
  463. using FixedValueString = AZ::SettingsRegistryInterface::FixedValueString;
  464. if (bool value;
  465. visitArgs.m_registry.Get(value, FixedValueString(visitArgs.m_jsonKeyPath) + "/lockSource"))
  466. {
  467. assetRecognizer.m_testLockSource = value;
  468. }
  469. if (bool value;
  470. visitArgs.m_registry.Get(value, FixedValueString(visitArgs.m_jsonKeyPath) + "/critical"))
  471. {
  472. assetRecognizer.m_isCritical = value;
  473. }
  474. if (bool value;
  475. visitArgs.m_registry.Get(value, FixedValueString(visitArgs.m_jsonKeyPath) + "/checkServer"))
  476. {
  477. assetRecognizer.m_checkServer = value;
  478. }
  479. if (bool value;
  480. visitArgs.m_registry.Get(value, FixedValueString(visitArgs.m_jsonKeyPath) + "/supportsCreateJobs"))
  481. {
  482. assetRecognizer.m_supportsCreateJobs = value;
  483. }
  484. if (bool value;
  485. visitArgs.m_registry.Get(value, FixedValueString(visitArgs.m_jsonKeyPath) + "/outputProductDependencies"))
  486. {
  487. assetRecognizer.m_outputProductDependencies = value;
  488. }
  489. if (AZ::s64 value;
  490. visitArgs.m_registry.Get(value, FixedValueString(visitArgs.m_jsonKeyPath) + "/priority"))
  491. {
  492. assetRecognizer.m_priority = aznumeric_cast<int>(value);
  493. }
  494. // The "pattern" and "glob" entries were previously parsed by QSettings which un-escapes the values
  495. // To compensate for it the AssetProcessorPlatformConfig.ini was escaping the
  496. // backslash character used to escape other characters, therefore causing a "double escape"
  497. // situation
  498. auto UnescapePattern = [](AZStd::string_view pattern)
  499. {
  500. constexpr AZStd::string_view backslashEscape = R"(\\)";
  501. AZStd::string unescapedResult;
  502. while (!pattern.empty())
  503. {
  504. size_t pos = pattern.find(backslashEscape);
  505. if (pos != AZStd::string_view::npos)
  506. {
  507. unescapedResult += pattern.substr(0, pos);
  508. unescapedResult += '\\';
  509. // Move the pattern string after the double backslash characters
  510. pattern = pattern.substr(pos + backslashEscape.size());
  511. }
  512. else
  513. {
  514. unescapedResult += pattern;
  515. pattern = {};
  516. }
  517. }
  518. return unescapedResult;
  519. };
  520. if (AZStd::string value;
  521. visitArgs.m_registry.Get(value, FixedValueString(visitArgs.m_jsonKeyPath) + "/pattern"))
  522. {
  523. if (!value.empty())
  524. {
  525. const auto patternType = AssetBuilderSDK::AssetBuilderPattern::Regex;
  526. assetRecognizer.m_patternMatcher = AssetBuilderSDK::FilePatternMatcher(UnescapePattern(value), patternType);
  527. }
  528. }
  529. if (AZStd::string value;
  530. visitArgs.m_registry.Get(value, FixedValueString(visitArgs.m_jsonKeyPath) + "/glob"))
  531. {
  532. // Add the glob pattern if it the matter matcher doesn't already contain a valid regex pattern
  533. if (!assetRecognizer.m_patternMatcher.IsValid())
  534. {
  535. const auto patternType = AssetBuilderSDK::AssetBuilderPattern::Wildcard;
  536. assetRecognizer.m_patternMatcher = AssetBuilderSDK::FilePatternMatcher(UnescapePattern(value), patternType);
  537. }
  538. }
  539. if (AZStd::string value;
  540. visitArgs.m_registry.Get(value, FixedValueString(visitArgs.m_jsonKeyPath) + "/version"))
  541. {
  542. assetRecognizer.m_version = value;
  543. }
  544. if (AZStd::string value;
  545. visitArgs.m_registry.Get(value, FixedValueString(visitArgs.m_jsonKeyPath) + "/productAssetType"))
  546. {
  547. if (!value.empty())
  548. {
  549. AZ::Uuid productAssetType{ value.data(), value.size() };
  550. if (!productAssetType.IsNull())
  551. {
  552. assetRecognizer.m_productAssetType = productAssetType;
  553. }
  554. }
  555. }
  556. return AZ::SettingsRegistryInterface::VisitResponse::Skip;
  557. }
  558. const char AssetConfigPlatformDir[] = "AssetProcessorConfig/";
  559. const char AssetProcessorPlatformConfigFileName[] = "AssetProcessorPlatformConfig.ini";
  560. constexpr const char* ProjectScanFolderKey = "Project/Assets";
  561. constexpr const char* GemStartingPriorityOrderKey = "/GemScanFolderStartingPriorityOrder";
  562. constexpr const char* ProjectRelativeGemPriorityKey = "/ProjectRelativeGemsScanFolderPriority";
  563. PlatformConfiguration::PlatformConfiguration(QObject* pParent)
  564. : QObject(pParent)
  565. {
  566. }
  567. bool PlatformConfiguration::AddPlatformConfigFilePaths(AZStd::vector<AZ::IO::Path>& configFilePaths)
  568. {
  569. auto settingsRegistry = AZ::SettingsRegistry::Get();
  570. if (settingsRegistry == nullptr)
  571. {
  572. AZ_Error(AssetProcessor::ConsoleChannel, false, "Global Settings Registry is not available, the "
  573. "Engine Root folder cannot be queried")
  574. return false;
  575. }
  576. AZ::IO::FixedMaxPath engineRoot;
  577. if (!settingsRegistry->Get(engineRoot.Native(), AZ::SettingsRegistryMergeUtils::FilePathKey_EngineRootFolder))
  578. {
  579. AZ_Error(AssetProcessor::ConsoleChannel, false, "Unable to find Engine Root in Settings Registry");
  580. return false;
  581. }
  582. return AzToolsFramework::AssetUtils::AddPlatformConfigFilePaths(engineRoot.Native(), configFilePaths);
  583. }
  584. bool PlatformConfiguration::InitializeFromConfigFiles(const QString& absoluteSystemRoot, const QString& absoluteAssetRoot,
  585. const QString& projectPath, bool addPlatformConfigs, bool addGemsConfigs)
  586. {
  587. // this function may look strange, but the point here is that each section in the config file
  588. // can depend on entries from the prior section, but also, each section can be overridden by
  589. // the other config files.
  590. // so we have to read each section one at a time, in order of config file priority (most important one last)
  591. static const char ScanFolderOption[] = "scanfolders";
  592. const AzFramework::CommandLine* commandLine = nullptr;
  593. AzFramework::ApplicationRequests::Bus::BroadcastResult(commandLine, &AzFramework::ApplicationRequests::GetCommandLine);
  594. const bool scanFolderOverride = commandLine ? commandLine->HasSwitch(ScanFolderOption) : false;
  595. static const char NoConfigScanFolderOption[] = "noConfigScanFolders";
  596. const bool noConfigScanFolders = commandLine ? commandLine->HasSwitch(NoConfigScanFolderOption) : false;
  597. static const char NoGemScanFolderOption[] = "noGemScanFolders";
  598. const bool noGemScanFolders = commandLine ? commandLine->HasSwitch(NoGemScanFolderOption) : false;
  599. static const char ScanFolderPatternOption[] = "scanfolderpattern";
  600. QStringList scanFolderPatterns;
  601. if (commandLine && commandLine->HasSwitch(ScanFolderPatternOption))
  602. {
  603. for (size_t idx = 0; idx < commandLine->GetNumSwitchValues(ScanFolderPatternOption); idx++)
  604. {
  605. scanFolderPatterns.push_back(commandLine->GetSwitchValue(ScanFolderPatternOption, idx).c_str());
  606. }
  607. }
  608. auto settingsRegistry = AZ::SettingsRegistry::Get();
  609. if (settingsRegistry == nullptr)
  610. {
  611. AZ_Error(AssetProcessor::ConsoleChannel, false, "There is no Global Settings Registry set."
  612. " Unable to merge AssetProcessor config files(*.ini) and Asset processor settings registry files(*.setreg)");
  613. return false;
  614. }
  615. AZStd::vector<AZ::IO::Path> configFiles = AzToolsFramework::AssetUtils::GetConfigFiles(absoluteSystemRoot.toUtf8().constData(),
  616. projectPath.toUtf8().constData(),
  617. addPlatformConfigs, addGemsConfigs && !noGemScanFolders, settingsRegistry);
  618. // First Merge all Engine, Gem and Project specific AssetProcessor*Config.setreg/.inifiles
  619. for (const AZ::IO::Path& configFile : configFiles)
  620. {
  621. if (AZ::IO::SystemFile::Exists(configFile.c_str()))
  622. {
  623. MergeConfigFileToSettingsRegistry(*settingsRegistry, configFile);
  624. }
  625. }
  626. // Merge the Command Line to the Settings Registry after merging the AssetProcessor*Config.setreg/ini files
  627. // to allow the command line to override the settings
  628. #if defined(AZ_DEBUG_BUILD) || defined(AZ_PROFILE_BUILD)
  629. if (commandLine)
  630. {
  631. AZ::SettingsRegistryMergeUtils::MergeSettingsToRegistry_CommandLine(*settingsRegistry, *commandLine, {});
  632. }
  633. #endif
  634. // first, read the platform informations.
  635. ReadPlatformInfosFromSettingsRegistry();
  636. // now read which platforms are currently enabled - this may alter the platform infos array and eradicate
  637. // the ones that are not suitable and currently enabled, leaving only the ones enabled either on command line
  638. // or config files.
  639. // the command line can always takes precedence - but can only turn on and off platforms, it cannot describe them.
  640. PopulateEnabledPlatforms();
  641. FinalizeEnabledPlatforms();
  642. if(!m_enabledPlatforms.empty())
  643. {
  644. // Add the common platform if we have some other platforms enabled. For now, this is only intended for intermediate assets
  645. // So we don't want to enable it unless at least one actual platform is available, to avoid hiding an error state of no real platforms being active
  646. EnableCommonPlatform();
  647. }
  648. if (scanFolderOverride)
  649. {
  650. AZStd::vector<AssetBuilderSDK::PlatformInfo> platforms;
  651. PopulatePlatformsForScanFolder(platforms);
  652. for (size_t idx = 0; idx < commandLine->GetNumSwitchValues(ScanFolderOption); idx++)
  653. {
  654. QString scanFolder{ commandLine->GetSwitchValue(ScanFolderOption, idx).c_str() };
  655. scanFolder = AssetUtilities::NormalizeFilePath(scanFolder);
  656. AddScanFolder(ScanFolderInfo(
  657. scanFolder,
  658. AZStd::string::format("ScanFolderParam %zu", idx).c_str(),
  659. AZStd::string::format("SF%zu", idx).c_str(),
  660. false,
  661. true,
  662. platforms,
  663. aznumeric_caster(idx),
  664. /*scanFolderId*/ 0,
  665. true));
  666. }
  667. }
  668. // Then read recognizers (which depend on platforms)
  669. if (!ReadRecognizersFromSettingsRegistry(absoluteAssetRoot, noConfigScanFolders, scanFolderPatterns))
  670. {
  671. if (m_fatalError.empty())
  672. {
  673. m_fatalError = "Unable to read recognizers specified in the configuration files during load. Please check the Asset Processor platform ini files for errors.";
  674. }
  675. return IsValid();
  676. }
  677. if(!m_scanFolders.empty())
  678. {
  679. // Enable the intermediate scanfolder if we have some other scanfolders. Since this is hardcoded we don't want to hide an error state
  680. // where no other scanfolders are enabled besides this one. It wouldn't make sense for the intermediate scanfolder to be the only enabled scanfolder
  681. AddIntermediateScanFolder();
  682. }
  683. if (!noGemScanFolders && addGemsConfigs)
  684. {
  685. if (settingsRegistry == nullptr || !AzFramework::GetGemsInfo(m_gemInfoList, *settingsRegistry))
  686. {
  687. AZ_Error(AssetProcessor::ConsoleChannel, false, "Unable to Get Gems Info for the project (%s).", projectPath.toUtf8().constData());
  688. return false;
  689. }
  690. // now add all the scan folders of gems.
  691. AddGemScanFolders(m_gemInfoList);
  692. }
  693. // Then read metadata (which depends on scan folders)
  694. ReadMetaDataFromSettingsRegistry();
  695. // at this point there should be at least some watch folders besides gems.
  696. if (m_scanFolders.empty())
  697. {
  698. m_fatalError = "Unable to find any scan folders specified in the configuration files during load. Please check the Asset Processor platform ini files for errors.";
  699. return IsValid();
  700. }
  701. return IsValid();
  702. }
  703. void PlatformConfiguration::PopulateEnabledPlatforms()
  704. {
  705. // if there are no platform informations inside the ini file, there's no point in proceeding
  706. // since we are unaware of the existence of the platform at all
  707. if (m_enabledPlatforms.empty())
  708. {
  709. AZ_Warning(AssetProcessor::ConsoleChannel, false, "There are no \"%s/Platform xxxxxx\" entries present in the settings registry. We cannot proceed.",
  710. AssetProcessorSettingsKey);
  711. return;
  712. }
  713. // the command line can always takes precedence - but can only turn on and off platforms, it cannot describe them.
  714. QStringList commandLinePlatforms = AssetUtilities::ReadPlatformsFromCommandLine();
  715. if (!commandLinePlatforms.isEmpty())
  716. {
  717. // command line overrides everything.
  718. m_tempEnabledPlatforms.clear();
  719. for (const QString& platformFromCommandLine : commandLinePlatforms)
  720. {
  721. QString platform = platformFromCommandLine.toLower().trimmed();
  722. if (!platform.isEmpty())
  723. {
  724. AZStd::string platformOverride{ platform.toUtf8().data() };
  725. if (auto foundIt = AZStd::find(m_tempEnabledPlatforms.begin(), m_tempEnabledPlatforms.end(), platformOverride);
  726. foundIt == m_tempEnabledPlatforms.end())
  727. {
  728. m_tempEnabledPlatforms.push_back(AZStd::move(platformOverride));
  729. }
  730. }
  731. }
  732. return; // command line wins!
  733. }
  734. // command line isn't active, read from settings registry instead.
  735. auto settingsRegistry = AZ::SettingsRegistry::Get();
  736. if (settingsRegistry == nullptr)
  737. {
  738. AZ_Error(AssetProcessor::ConsoleChannel, false, R"(Global Settings Registry is not available, unable to read the "%s/Platforms")"
  739. " settings paths", AssetProcessorSettingsKey);
  740. return;
  741. }
  742. AZStd::vector<AZStd::string> enabledPlatforms;
  743. AzToolsFramework::AssetUtils::ReadEnabledPlatformsFromSettingsRegistry(*settingsRegistry, enabledPlatforms);
  744. m_tempEnabledPlatforms.insert(m_tempEnabledPlatforms.end(), AZStd::make_move_iterator(enabledPlatforms.begin()),
  745. AZStd::make_move_iterator(enabledPlatforms.end()));
  746. }
  747. void PlatformConfiguration::FinalizeEnabledPlatforms()
  748. {
  749. #if defined(AZ_ENABLE_TRACING)
  750. // verify command line platforms are valid:
  751. for (const auto& enabledPlatformFromConfigs : m_tempEnabledPlatforms)
  752. {
  753. bool found = false;
  754. for (const AssetBuilderSDK::PlatformInfo& platformInfo : m_enabledPlatforms)
  755. {
  756. if (platformInfo.m_identifier == enabledPlatformFromConfigs)
  757. {
  758. found = true;
  759. break;
  760. }
  761. }
  762. if (!found)
  763. {
  764. m_fatalError = AZStd::string::format(R"(The list of enabled platforms in the settings registry does not contain platform "%s")"
  765. " entries - check command line and settings registry files for errors!", enabledPlatformFromConfigs.c_str());
  766. return;
  767. }
  768. }
  769. #endif // defined(AZ_ENABLE_TRACING)
  770. // over here, we want to eliminate any platforms in the m_enabledPlatforms array that are not in the m_tempEnabledPlatforms
  771. for (int enabledPlatformIdx = static_cast<int>(m_enabledPlatforms.size() - 1); enabledPlatformIdx >= 0; --enabledPlatformIdx)
  772. {
  773. const AssetBuilderSDK::PlatformInfo& platformInfo = m_enabledPlatforms[enabledPlatformIdx];
  774. if (auto foundIt = AZStd::find(m_tempEnabledPlatforms.begin(), m_tempEnabledPlatforms.end(), platformInfo.m_identifier);
  775. foundIt == m_tempEnabledPlatforms.end())
  776. {
  777. m_enabledPlatforms.erase(m_enabledPlatforms.cbegin() + enabledPlatformIdx);
  778. }
  779. }
  780. if (m_enabledPlatforms.empty())
  781. {
  782. AZ_Warning(AssetProcessor::ConsoleChannel, false, "There are no \"%s/Platform xxxxxx\" entry present in the settings registry. We cannot proceed.",
  783. AssetProcessorSettingsKey);
  784. return;
  785. }
  786. m_tempEnabledPlatforms.clear();
  787. }
  788. void PlatformConfiguration::ReadPlatformInfosFromSettingsRegistry()
  789. {
  790. auto settingsRegistry = AZ::SettingsRegistry::Get();
  791. if (settingsRegistry == nullptr)
  792. {
  793. AZ_Error(AssetProcessor::ConsoleChannel, false, R"(Global Settings Registry is not available, unable to read the "%s/Platform *")"
  794. " settings paths", AssetProcessorSettingsKey);
  795. return;
  796. }
  797. PlatformsInfoVisitor visitor;
  798. settingsRegistry->Visit(visitor, AssetProcessorSettingsKey);
  799. for (const AssetBuilderSDK::PlatformInfo& platformInfo : visitor.m_platformInfos)
  800. {
  801. EnablePlatform(platformInfo, true);
  802. }
  803. }
  804. void PlatformConfiguration::ReadEnabledPlatformsFromSettingsRegistry()
  805. {
  806. auto settingsRegistry = AZ::SettingsRegistry::Get();
  807. if (settingsRegistry == nullptr)
  808. {
  809. AZ_Error(AssetProcessor::ConsoleChannel, false, R"(Global Settings Registry is not available, unable to read the "%s/Platforms")"
  810. " settings paths", AssetProcessorSettingsKey);
  811. return;
  812. }
  813. AzToolsFramework::AssetUtils::ReadEnabledPlatformsFromSettingsRegistry(*settingsRegistry, m_tempEnabledPlatforms);
  814. }
  815. void PlatformConfiguration::PopulatePlatformsForScanFolder(AZStd::vector<AssetBuilderSDK::PlatformInfo>& platformsList, QStringList includeTagsList, QStringList excludeTagsList)
  816. {
  817. if (includeTagsList.isEmpty())
  818. {
  819. // Add all enabled platforms
  820. for (const AssetBuilderSDK::PlatformInfo& platform : m_enabledPlatforms)
  821. {
  822. if(platform.m_identifier == AssetBuilderSDK::CommonPlatformName)
  823. {
  824. // The common platform is not included in any scanfolder to avoid builders by-default producing jobs for it
  825. continue;
  826. }
  827. if (AZStd::find(platformsList.begin(), platformsList.end(), platform) == platformsList.end())
  828. {
  829. platformsList.push_back(platform);
  830. }
  831. }
  832. }
  833. else
  834. {
  835. for (QString identifier : includeTagsList)
  836. {
  837. for (const AssetBuilderSDK::PlatformInfo& platform : m_enabledPlatforms)
  838. {
  839. if(platform.m_identifier == AssetBuilderSDK::CommonPlatformName)
  840. {
  841. // The common platform is not included in any scanfolder to avoid builders by-default producing jobs for it
  842. continue;
  843. }
  844. bool addPlatform = (QString::compare(identifier, platform.m_identifier.c_str(), Qt::CaseInsensitive) == 0) ||
  845. platform.m_tags.find(identifier.toLower().toUtf8().data()) != platform.m_tags.end();
  846. if (addPlatform)
  847. {
  848. if (AZStd::find(platformsList.begin(), platformsList.end(), platform) == platformsList.end())
  849. {
  850. platformsList.push_back(platform);
  851. }
  852. }
  853. }
  854. }
  855. }
  856. for (QString identifier : excludeTagsList)
  857. {
  858. for (const AssetBuilderSDK::PlatformInfo& platform : m_enabledPlatforms)
  859. {
  860. bool removePlatform = (QString::compare(identifier, platform.m_identifier.c_str(), Qt::CaseInsensitive) == 0) ||
  861. platform.m_tags.find(identifier.toLower().toUtf8().data()) != platform.m_tags.end();
  862. if (removePlatform)
  863. {
  864. platformsList.erase(AZStd::remove(platformsList.begin(), platformsList.end(), platform), platformsList.end());
  865. }
  866. }
  867. }
  868. }
  869. void PlatformConfiguration::CacheIntermediateAssetsScanFolderId() const
  870. {
  871. for (const auto& scanfolder : m_scanFolders)
  872. {
  873. if (scanfolder.GetPortableKey() == AssetProcessor::IntermediateAssetsFolderName)
  874. {
  875. m_intermediateAssetScanFolderId = scanfolder.ScanFolderID();
  876. return;
  877. }
  878. }
  879. AZ_Error(
  880. "PlatformConfiguration", false,
  881. "CacheIntermediateAssetsScanFolderId: Failed to find Intermediate Assets folder in scanfolder list");
  882. }
  883. AZStd::optional<AZ::s64> PlatformConfiguration::GetIntermediateAssetsScanFolderId() const
  884. {
  885. if (m_intermediateAssetScanFolderId >= 0)
  886. {
  887. return m_intermediateAssetScanFolderId;
  888. }
  889. return AZStd::nullopt;
  890. }
  891. // used to save our the AssetCacheServer settings to a remote location
  892. struct AssetCacheServerMatcher
  893. {
  894. AZ_CLASS_ALLOCATOR(AssetCacheServerMatcher, AZ::SystemAllocator);
  895. AZ_TYPE_INFO(AssetCacheServerMatcher, "{329A59C9-755E-4FA9-AADB-05C50AC62FD5}");
  896. static void Reflect(AZ::SerializeContext* serializeContext)
  897. {
  898. serializeContext->Class<AssetCacheServerMatcher>()->Version(0)
  899. ->Field("name", &AssetCacheServerMatcher::m_name)
  900. ->Field("glob", &AssetCacheServerMatcher::m_glob)
  901. ->Field("pattern", &AssetCacheServerMatcher::m_pattern)
  902. ->Field("productAssetType", &AssetCacheServerMatcher::m_productAssetType)
  903. ->Field("checkServer", &AssetCacheServerMatcher::m_checkServer);
  904. serializeContext->RegisterGenericType<AZStd::unordered_map<AZStd::string, AssetCacheServerMatcher>>();
  905. }
  906. AZStd::string m_name;
  907. AZStd::string m_glob;
  908. AZStd::string m_pattern;
  909. AZ::Uuid m_productAssetType = AZ::Uuid::CreateNull();
  910. bool m_checkServer = false;
  911. };
  912. bool PlatformConfiguration::ConvertToJson(const RecognizerContainer& recognizerContainer, AZStd::string& jsonText)
  913. {
  914. AZStd::unordered_map<AZStd::string, AssetCacheServerMatcher> assetCacheServerMatcherMap;
  915. for (const auto& recognizer : recognizerContainer)
  916. {
  917. AssetCacheServerMatcher matcher;
  918. matcher.m_name = recognizer.first;
  919. matcher.m_checkServer = recognizer.second.m_checkServer;
  920. matcher.m_productAssetType = recognizer.second.m_productAssetType;
  921. if (recognizer.second.m_patternMatcher.GetBuilderPattern().m_type == AssetBuilderSDK::AssetBuilderPattern::Wildcard)
  922. {
  923. matcher.m_glob = recognizer.second.m_patternMatcher.GetBuilderPattern().m_pattern;
  924. }
  925. else if (recognizer.second.m_patternMatcher.GetBuilderPattern().m_type == AssetBuilderSDK::AssetBuilderPattern::Regex)
  926. {
  927. matcher.m_pattern = recognizer.second.m_patternMatcher.GetBuilderPattern().m_pattern;
  928. }
  929. assetCacheServerMatcherMap.insert({"ACS " + matcher.m_name, matcher});
  930. }
  931. AZ::JsonSerializerSettings settings;
  932. AZ::ComponentApplicationBus::BroadcastResult(settings.m_serializeContext, &AZ::ComponentApplicationRequests::GetSerializeContext);
  933. settings.m_registrationContext = nullptr;
  934. rapidjson::Document jsonDocument;
  935. auto jsonResult = AZ::JsonSerialization::Store(jsonDocument, jsonDocument.GetAllocator(), assetCacheServerMatcherMap, settings);
  936. if (jsonResult.GetProcessing() == AZ::JsonSerializationResult::Processing::Halted)
  937. {
  938. return false;
  939. }
  940. auto saveToFileOutcome = AZ::JsonSerializationUtils::WriteJsonString(jsonDocument, jsonText);
  941. return saveToFileOutcome.IsSuccess();
  942. }
  943. bool PlatformConfiguration::ConvertFromJson(const AZStd::string& jsonText, RecognizerContainer& recognizerContainer)
  944. {
  945. rapidjson::Document assetCacheServerMatcherDoc;
  946. assetCacheServerMatcherDoc.Parse(jsonText.c_str());
  947. if (assetCacheServerMatcherDoc.HasParseError())
  948. {
  949. return false;
  950. }
  951. AZ::JsonDeserializerSettings settings;
  952. AZ::ComponentApplicationBus::BroadcastResult(settings.m_serializeContext, &AZ::ComponentApplicationRequests::GetSerializeContext);
  953. settings.m_registrationContext = nullptr;
  954. AZStd::unordered_map<AZStd::string, AssetCacheServerMatcher> assetCacheServerMatcherMap;
  955. auto resultCode = AZ::JsonSerialization::Load(assetCacheServerMatcherMap, assetCacheServerMatcherDoc, settings);
  956. if (!resultCode.HasDoneWork())
  957. {
  958. return false;
  959. }
  960. recognizerContainer.clear();
  961. for (const auto& matcher : assetCacheServerMatcherMap)
  962. {
  963. AssetRecognizer assetRecognizer;
  964. assetRecognizer.m_checkServer = matcher.second.m_checkServer;
  965. assetRecognizer.m_name = matcher.second.m_name;
  966. assetRecognizer.m_productAssetType = matcher.second.m_productAssetType;
  967. if (!matcher.second.m_glob.empty())
  968. {
  969. assetRecognizer.m_patternMatcher = { matcher.second.m_glob , AssetBuilderSDK::AssetBuilderPattern::Wildcard };
  970. }
  971. else if (!matcher.second.m_pattern.empty())
  972. {
  973. assetRecognizer.m_patternMatcher = { matcher.second.m_pattern , AssetBuilderSDK::AssetBuilderPattern::Regex };
  974. }
  975. recognizerContainer.insert({ "ACS " + matcher.second.m_name, assetRecognizer });
  976. }
  977. return !recognizerContainer.empty();
  978. }
  979. void PlatformConfiguration::Reflect(AZ::ReflectContext* context)
  980. {
  981. if (AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  982. {
  983. AssetCacheServerMatcher::Reflect(serializeContext);
  984. }
  985. }
  986. bool PlatformConfiguration::ReadRecognizersFromSettingsRegistry(const QString& assetRoot, bool skipScanFolders, QStringList scanFolderPatterns)
  987. {
  988. auto settingsRegistry = AZ::SettingsRegistry::Get();
  989. if (settingsRegistry == nullptr)
  990. {
  991. AZ_Error(AssetProcessor::ConsoleChannel, false, "Global Settings Registry is not set."
  992. " Unable to read recognizers Asset Processor Settings");
  993. return false;
  994. }
  995. AZ::IO::FixedMaxPath projectPath = AZ::Utils::GetProjectPath();
  996. AZ::IO::FixedMaxPathString projectName = AZ::Utils::GetProjectName();
  997. AZ::IO::FixedMaxPathString executableDirectory = AZ::Utils::GetExecutableDirectory();
  998. AZ::IO::FixedMaxPath engineRoot(AZ::IO::PosixPathSeparator);
  999. settingsRegistry->Get(engineRoot.Native(), AZ::SettingsRegistryMergeUtils::FilePathKey_EngineRootFolder);
  1000. engineRoot = engineRoot.LexicallyNormal(); // Normalize the path to use posix slashes
  1001. if (!skipScanFolders)
  1002. {
  1003. AZStd::unordered_map<AZStd::string, AZ::IO::Path> gemNameToPathMap;
  1004. auto MakeGemNameToPathMap = [&gemNameToPathMap, &projectPath, &engineRoot]
  1005. (AZStd::string_view gemName, AZ::IO::PathView gemPath)
  1006. {
  1007. AZ::IO::FixedMaxPath gemAbsPath = gemPath;
  1008. if (gemPath.IsRelative())
  1009. {
  1010. gemAbsPath = projectPath / gemPath;
  1011. if (!AZ::IO::SystemFile::Exists(gemAbsPath.c_str()))
  1012. {
  1013. gemAbsPath = engineRoot / gemPath;
  1014. }
  1015. // convert the relative path to an absolute path
  1016. if (!AZ::IO::SystemFile::Exists(gemAbsPath.c_str()))
  1017. {
  1018. if (auto gemAbsPathOpt = AZ::Utils::ConvertToAbsolutePath(gemPath.Native());
  1019. gemAbsPathOpt.has_value())
  1020. {
  1021. gemAbsPath = AZStd::move(*gemAbsPathOpt);
  1022. }
  1023. }
  1024. }
  1025. if (AZ::IO::SystemFile::Exists(gemAbsPath.c_str()))
  1026. {
  1027. gemNameToPathMap.try_emplace(AZStd::string::format("@GEMROOT:%.*s@", AZ_STRING_ARG(gemName)), gemAbsPath.AsPosix());
  1028. }
  1029. };
  1030. AZ::SettingsRegistryMergeUtils::VisitActiveGems(*settingsRegistry, MakeGemNameToPathMap);
  1031. ScanFolderVisitor visitor;
  1032. settingsRegistry->Visit(visitor, AssetProcessorSettingsKey);
  1033. for (auto& scanFolderEntry : visitor.m_scanFolderInfos)
  1034. {
  1035. if (scanFolderEntry.m_watchPath.empty())
  1036. {
  1037. continue;
  1038. }
  1039. auto scanFolderMatch = [watchFolderQt = QString::fromUtf8(scanFolderEntry.m_watchPath.c_str(),
  1040. aznumeric_cast<int>(scanFolderEntry.m_watchPath.Native().size()))](const QString& scanFolderPattern)
  1041. {
  1042. QRegExp nameMatch(scanFolderPattern, Qt::CaseInsensitive, QRegExp::Wildcard);
  1043. return nameMatch.exactMatch(watchFolderQt);
  1044. };
  1045. if (!scanFolderPatterns.empty() && AZStd::none_of(scanFolderPatterns.begin(), scanFolderPatterns.end(), scanFolderMatch))
  1046. {
  1047. // Continue to the next iteration if the watch folder doesn't match any of the supplied patterns
  1048. continue;
  1049. }
  1050. // Substitute macro values into the watch path and the scan folder display name
  1051. AZStd::string assetRootPath = assetRoot.toUtf8().data();
  1052. AZ::StringFunc::Replace(scanFolderEntry.m_watchPath.Native(), "@ROOT@", assetRootPath.c_str());
  1053. AZ::StringFunc::Replace(scanFolderEntry.m_watchPath.Native(), "@PROJECTROOT@", projectPath.c_str());
  1054. AZ::StringFunc::Replace(scanFolderEntry.m_watchPath.Native(), "@ENGINEROOT@", engineRoot.c_str());
  1055. AZ::StringFunc::Replace(scanFolderEntry.m_watchPath.Native(), "@EXEFOLDER@", executableDirectory.c_str());
  1056. // Normalize path make sure it is using posix slashes
  1057. scanFolderEntry.m_watchPath = scanFolderEntry.m_watchPath.LexicallyNormal();
  1058. AZ::StringFunc::Replace(scanFolderEntry.m_scanFolderDisplayName, "@ROOT@", assetRootPath.c_str());
  1059. AZ::StringFunc::Replace(scanFolderEntry.m_scanFolderDisplayName, "@PROJECTROOT@", projectPath.c_str());
  1060. AZ::StringFunc::Replace(scanFolderEntry.m_scanFolderDisplayName, "@PROJECTNAME@", projectName.c_str());
  1061. AZ::StringFunc::Replace(scanFolderEntry.m_scanFolderDisplayName, "@ENGINEROOT@", engineRoot.c_str());
  1062. // Substitute gem root path if applicable
  1063. if (scanFolderEntry.m_watchPath.Native().contains("@GEMROOT")
  1064. || scanFolderEntry.m_scanFolderDisplayName.contains("@GEMROOT"))
  1065. {
  1066. for (const auto& [gemAlias, gemPath] : gemNameToPathMap)
  1067. {
  1068. AZ::StringFunc::Replace(scanFolderEntry.m_watchPath.Native(), gemAlias.c_str(), gemPath.c_str());
  1069. AZ::StringFunc::Replace(scanFolderEntry.m_scanFolderDisplayName, gemAlias.c_str(), gemPath.c_str());
  1070. }
  1071. }
  1072. QStringList includeIdentifiers;
  1073. for (AZStd::string_view includeIdentifier : scanFolderEntry.m_includeIdentifiers)
  1074. {
  1075. includeIdentifiers.push_back(QString::fromUtf8(includeIdentifier.data(), aznumeric_cast<int>(includeIdentifier.size())));
  1076. }
  1077. QStringList excludeIdentifiers;
  1078. for (AZStd::string_view excludeIdentifier : scanFolderEntry.m_excludeIdentifiers)
  1079. {
  1080. excludeIdentifiers.push_back(QString::fromUtf8(excludeIdentifier.data(), aznumeric_cast<int>(excludeIdentifier.size())));
  1081. }
  1082. AZStd::vector<AssetBuilderSDK::PlatformInfo> platforms;
  1083. PopulatePlatformsForScanFolder(platforms, includeIdentifiers, excludeIdentifiers);
  1084. const bool isEngineRoot = scanFolderEntry.m_watchPath == engineRoot;
  1085. // If the scan folder happens to be the engine root, it is not recursive
  1086. scanFolderEntry.m_isRecursive = scanFolderEntry.m_isRecursive && !isEngineRoot;
  1087. // New assets can be saved in any scan folder defined except for the engine root.
  1088. const bool canSaveNewAssets = !isEngineRoot;
  1089. QString watchFolderPath = QString::fromUtf8(scanFolderEntry.m_watchPath.c_str(), static_cast<int>(scanFolderEntry.m_watchPath.Native().size()));
  1090. watchFolderPath = AssetUtilities::NormalizeDirectoryPath(watchFolderPath);
  1091. AddScanFolder(ScanFolderInfo(
  1092. watchFolderPath,
  1093. QString::fromUtf8(scanFolderEntry.m_scanFolderDisplayName.c_str(), aznumeric_cast<int>(scanFolderEntry.m_scanFolderDisplayName.size())),
  1094. QString::fromUtf8(scanFolderEntry.m_scanFolderIdentifier.c_str(), aznumeric_cast<int>(scanFolderEntry.m_scanFolderIdentifier.size())),
  1095. isEngineRoot,
  1096. scanFolderEntry.m_isRecursive,
  1097. platforms,
  1098. scanFolderEntry.m_scanOrder,
  1099. 0,
  1100. canSaveNewAssets
  1101. ));
  1102. }
  1103. }
  1104. ExcludeVisitor excludeVisitor;
  1105. settingsRegistry->Visit(excludeVisitor, AssetProcessorSettingsKey);
  1106. for (auto&& excludeRecognizer: excludeVisitor.m_excludeAssetRecognizers)
  1107. {
  1108. m_excludeAssetRecognizers[excludeRecognizer.m_name] = AZStd::move(excludeRecognizer);
  1109. }
  1110. SimpleJobVisitor simpleJobVisitor(m_enabledPlatforms);
  1111. settingsRegistry->Visit(simpleJobVisitor, AssetProcessorSettingsKey);
  1112. for (auto&& sjRecognizer : simpleJobVisitor.m_assetRecognizers)
  1113. {
  1114. if (!sjRecognizer.m_recognizer.m_platformSpecs.empty() && !sjRecognizer.m_ignore)
  1115. {
  1116. m_assetRecognizers[sjRecognizer.m_recognizer.m_name] = AZStd::move(sjRecognizer.m_recognizer);
  1117. }
  1118. }
  1119. ACSVisitor acsVistor;
  1120. settingsRegistry->Visit(acsVistor, AssetProcessorServerKey);
  1121. for (auto&& acsRecognizer : acsVistor.m_assetRecognizers)
  1122. {
  1123. m_assetCacheServerRecognizers[acsRecognizer.m_name] = AZStd::move(acsRecognizer);
  1124. }
  1125. return true;
  1126. }
  1127. void PlatformConfiguration::ReadMetaDataFromSettingsRegistry()
  1128. {
  1129. auto settingsRegistry = AZ::SettingsRegistry::Get();
  1130. if (settingsRegistry == nullptr)
  1131. {
  1132. AZ_Error(AssetProcessor::ConsoleChannel, false, "Global Settings Registry is not set."
  1133. " MetaDataTypes entries cannot be read from Asset Processor Settings");
  1134. return;
  1135. }
  1136. MetaDataTypesVisitor visitor;
  1137. settingsRegistry->Visit(visitor, AZ::SettingsRegistryInterface::FixedValueString(AssetProcessorSettingsKey) + "/MetaDataTypes");
  1138. using namespace AzToolsFramework::AssetUtils;
  1139. AZStd::vector<AZStd::string> supportedFileExtensions;
  1140. AssetImporterPathsVisitor assetImporterVisitor{ settingsRegistry, supportedFileExtensions };
  1141. settingsRegistry->Visit(assetImporterVisitor, AZ::SettingsRegistryInterface::FixedValueString(AssetImporterSettingsKey) + "/" + AssetImporterSupportedFileTypeKey);
  1142. for (auto& entry : assetImporterVisitor.m_supportedFileExtensions)
  1143. {
  1144. visitor.m_metaDataTypes.push_back({ AZStd::string::format("%s.assetinfo", entry.c_str()), entry });
  1145. }
  1146. AddMetaDataType(AzToolsFramework::MetadataManager::MetadataFileExtensionNoDot, "");
  1147. for (const auto& metaDataType : visitor.m_metaDataTypes)
  1148. {
  1149. QString fileType = AssetUtilities::NormalizeFilePath(QString::fromUtf8(metaDataType.m_fileType.c_str(),
  1150. aznumeric_cast<int>(metaDataType.m_fileType.size())));
  1151. auto extensionType = QString::fromUtf8(metaDataType.m_extensionType.c_str(),
  1152. aznumeric_cast<int>(metaDataType.m_extensionType.size()));
  1153. AddMetaDataType(fileType, extensionType);
  1154. // Check if the Metadata 'file type' is a real file
  1155. QString fullPath = FindFirstMatchingFile(fileType);
  1156. if (!fullPath.isEmpty())
  1157. {
  1158. m_metaDataRealFiles.insert(fileType.toLower());
  1159. }
  1160. }
  1161. }
  1162. int PlatformConfiguration::GetProjectScanFolderOrder() const
  1163. {
  1164. auto mainProjectScanFolder = FindScanFolder([](const AssetProcessor::ScanFolderInfo& scanFolderInfo) -> bool
  1165. {
  1166. return scanFolderInfo.GetPortableKey() == ProjectScanFolderKey;
  1167. });
  1168. if (mainProjectScanFolder)
  1169. {
  1170. return mainProjectScanFolder->GetOrder();
  1171. }
  1172. return 0;
  1173. }
  1174. bool PlatformConfiguration::MergeConfigFileToSettingsRegistry(AZ::SettingsRegistryInterface& settingsRegistry, const AZ::IO::PathView& configFile)
  1175. {
  1176. // If the config file is a settings registry file use the SettingsRegistryInterface MergeSettingsFile function
  1177. // otherwise use the SettingsRegistryMergeUtils MergeSettingsToRegistry_ConfigFile function to merge an INI-style
  1178. // file to the settings registry
  1179. if (configFile.Extension() == ".setreg")
  1180. {
  1181. return static_cast<bool>(settingsRegistry.MergeSettingsFile(configFile.Native(), AZ::SettingsRegistryInterface::Format::JsonMergePatch));
  1182. }
  1183. AZ::SettingsRegistryMergeUtils::ConfigParserSettings configParserSettings;
  1184. configParserSettings.m_registryRootPointerPath = AssetProcessorSettingsKey;
  1185. return AZ::SettingsRegistryMergeUtils::MergeSettingsToRegistry_ConfigFile(settingsRegistry, configFile.Native(), configParserSettings);
  1186. }
  1187. const AZStd::vector<AssetBuilderSDK::PlatformInfo>& PlatformConfiguration::GetEnabledPlatforms() const
  1188. {
  1189. return m_enabledPlatforms;
  1190. }
  1191. const AssetBuilderSDK::PlatformInfo* const PlatformConfiguration::GetPlatformByIdentifier(const char* identifier) const
  1192. {
  1193. for (const AssetBuilderSDK::PlatformInfo& platform : m_enabledPlatforms)
  1194. {
  1195. if (platform.m_identifier == identifier)
  1196. {
  1197. // this may seem odd - returning a pointer into a vector, but this vector is initialized once during startup and then remains static thereafter.
  1198. return &platform;
  1199. }
  1200. }
  1201. return nullptr;
  1202. }
  1203. QPair<QString, QString> PlatformConfiguration::GetMetaDataFileTypeAt(int pos) const
  1204. {
  1205. return m_metaDataFileTypes[pos];
  1206. }
  1207. bool PlatformConfiguration::IsMetaDataTypeRealFile(QString relativeName) const
  1208. {
  1209. return m_metaDataRealFiles.find(relativeName.toLower()) != m_metaDataRealFiles.end();
  1210. }
  1211. void PlatformConfiguration::EnablePlatform(const AssetBuilderSDK::PlatformInfo& platform, bool enable)
  1212. {
  1213. // remove it if present.
  1214. auto platformIt = std::find_if(m_enabledPlatforms.begin(), m_enabledPlatforms.end(), [&](const AssetBuilderSDK::PlatformInfo& info)
  1215. {
  1216. return info.m_identifier == platform.m_identifier;
  1217. });
  1218. if (platformIt != m_enabledPlatforms.end())
  1219. {
  1220. // already present - replace or remove it.
  1221. if (enable)
  1222. {
  1223. *platformIt = platform;
  1224. }
  1225. else
  1226. {
  1227. m_enabledPlatforms.erase(platformIt);
  1228. }
  1229. }
  1230. else
  1231. {
  1232. // it is not already present. we only add it if we're enabling.
  1233. // if we're disabling, there's nothing to do.
  1234. if (enable)
  1235. {
  1236. m_enabledPlatforms.push_back(platform);
  1237. }
  1238. }
  1239. }
  1240. bool PlatformConfiguration::GetMatchingRecognizers(QString fileName, RecognizerPointerContainer& output) const
  1241. {
  1242. bool foundAny = false;
  1243. if (IsFileExcluded(fileName))
  1244. {
  1245. //if the file is excluded than return false;
  1246. return false;
  1247. }
  1248. for (const auto& assetRecognizer : m_assetRecognizers)
  1249. {
  1250. const AssetRecognizer& recognizer = assetRecognizer.second;
  1251. if (recognizer.m_patternMatcher.MatchesPath(fileName.toUtf8().constData()))
  1252. {
  1253. // found a match
  1254. output.push_back(&recognizer);
  1255. foundAny = true;
  1256. }
  1257. }
  1258. return foundAny;
  1259. }
  1260. int PlatformConfiguration::GetScanFolderCount() const
  1261. {
  1262. return aznumeric_caster(m_scanFolders.size());
  1263. }
  1264. AZStd::vector<AzFramework::GemInfo> PlatformConfiguration::GetGemsInformation() const
  1265. {
  1266. return m_gemInfoList;
  1267. }
  1268. AssetProcessor::ScanFolderInfo& PlatformConfiguration::GetScanFolderAt(int index)
  1269. {
  1270. Q_ASSERT(index >= 0);
  1271. Q_ASSERT(index < m_scanFolders.size());
  1272. return m_scanFolders[index];
  1273. }
  1274. const AssetProcessor::ScanFolderInfo& PlatformConfiguration::GetScanFolderAt(int index) const
  1275. {
  1276. Q_ASSERT(index >= 0);
  1277. Q_ASSERT(index < m_scanFolders.size());
  1278. return m_scanFolders[index];
  1279. }
  1280. const AssetProcessor::ScanFolderInfo* PlatformConfiguration::FindScanFolder(
  1281. AZStd::function<bool(const AssetProcessor::ScanFolderInfo&)> predicate) const
  1282. {
  1283. auto resultIt = AZStd::ranges::find_if(m_scanFolders, predicate);
  1284. return resultIt != m_scanFolders.end() ? &(*resultIt) : nullptr;
  1285. }
  1286. const AssetProcessor::ScanFolderInfo* PlatformConfiguration::GetScanFolderById(AZ::s64 id) const
  1287. {
  1288. return FindScanFolder([id](const ScanFolderInfo& scanFolder)
  1289. {
  1290. return scanFolder.ScanFolderID() == id;
  1291. });
  1292. }
  1293. const AZ::s64 PlatformConfiguration::GetIntermediateAssetScanFolderId() const
  1294. {
  1295. return m_intermediateAssetScanFolderId;
  1296. }
  1297. void PlatformConfiguration::AddScanFolder(const AssetProcessor::ScanFolderInfo& source, bool isUnitTesting)
  1298. {
  1299. if (isUnitTesting)
  1300. {
  1301. //using a bool instead of using #define UNIT_TEST because the user can also run batch processing in unittest
  1302. m_scanFolders.push_back(source);
  1303. // since we're synthesizing folder adds, assign ascending folder ids if not provided.
  1304. if (source.ScanFolderID() == 0)
  1305. {
  1306. m_scanFolders.back().SetScanFolderID(m_scanFolders.size() - 1);
  1307. }
  1308. return;
  1309. }
  1310. // Find and remove any previous matching entry, last entry wins
  1311. auto it = std::find_if(m_scanFolders.begin(), m_scanFolders.end(), [&source](const ScanFolderInfo& info)
  1312. {
  1313. return info.GetPortableKey().toLower() == source.GetPortableKey().toLower();
  1314. });
  1315. if (it != m_scanFolders.end())
  1316. {
  1317. m_scanFolders.erase(it);
  1318. }
  1319. m_scanFolders.push_back(source);
  1320. std::stable_sort(m_scanFolders.begin(), m_scanFolders.end(), [](const ScanFolderInfo& a, const ScanFolderInfo& b)
  1321. {
  1322. return a.GetOrder() < b.GetOrder();
  1323. }
  1324. );
  1325. }
  1326. void PlatformConfiguration::AddRecognizer(const AssetRecognizer& source)
  1327. {
  1328. m_assetRecognizers.insert({source.m_name, source});
  1329. }
  1330. void PlatformConfiguration::RemoveRecognizer(QString name)
  1331. {
  1332. auto found = m_assetRecognizers.find(name.toUtf8().data());
  1333. m_assetRecognizers.erase(found);
  1334. }
  1335. void PlatformConfiguration::AddMetaDataType(const QString& type, const QString& extension)
  1336. {
  1337. QPair<QString, QString> key = qMakePair(type.toLower(), extension.toLower());
  1338. if (!m_metaDataFileTypes.contains(key))
  1339. {
  1340. m_metaDataFileTypes.push_back(key);
  1341. }
  1342. }
  1343. bool PlatformConfiguration::ConvertToRelativePath(QString fullFileName, QString& databaseSourceName, QString& scanFolderName) const
  1344. {
  1345. const ScanFolderInfo* info = GetScanFolderForFile(fullFileName);
  1346. if (info)
  1347. {
  1348. scanFolderName = info->ScanPath();
  1349. scanFolderName.replace(AZ_WRONG_DATABASE_SEPARATOR, AZ_CORRECT_DATABASE_SEPARATOR);
  1350. return ConvertToRelativePath(fullFileName, info, databaseSourceName);
  1351. }
  1352. // did not find it.
  1353. return false;
  1354. }
  1355. bool PlatformConfiguration::ConvertToRelativePath(const QString& fullFileName, const ScanFolderInfo* scanFolderInfo, QString& databaseSourceName)
  1356. {
  1357. if(!scanFolderInfo)
  1358. {
  1359. return false;
  1360. }
  1361. QString relPath; // empty string.
  1362. if (fullFileName.length() > scanFolderInfo->ScanPath().length())
  1363. {
  1364. relPath = fullFileName.right(fullFileName.length() - scanFolderInfo->ScanPath().length() - 1); // also eat the slash, hence -1
  1365. }
  1366. databaseSourceName = relPath;
  1367. databaseSourceName.replace(AZ_WRONG_DATABASE_SEPARATOR, AZ_CORRECT_DATABASE_SEPARATOR);
  1368. return true;
  1369. }
  1370. QString PlatformConfiguration::GetOverridingFile(QString relativeName, QString scanFolderName) const
  1371. {
  1372. for (int pathIdx = 0; pathIdx < m_scanFolders.size(); ++pathIdx)
  1373. {
  1374. AssetProcessor::ScanFolderInfo scanFolderInfo = m_scanFolders[pathIdx];
  1375. if (scanFolderName.compare(scanFolderInfo.ScanPath(), Qt::CaseInsensitive) == 0)
  1376. {
  1377. // we have found the actual folder containing the file we started with
  1378. // since all other folders "deeper" in the override vector are lower priority than this one
  1379. // (they are sorted in priority order, most priority first).
  1380. return QString();
  1381. }
  1382. QString tempRelativeName(relativeName);
  1383. if ((!scanFolderInfo.RecurseSubFolders()) && (tempRelativeName.contains('/')))
  1384. {
  1385. // the name is a deeper relative path, but we don't recurse this scan folder, so it can't win
  1386. continue;
  1387. }
  1388. // note that we only Update To Correct Case here, because this is one of the few situations where
  1389. // a file with the same relative path may be overridden but different case.
  1390. if (AssetUtilities::UpdateToCorrectCase(scanFolderInfo.ScanPath(), tempRelativeName))
  1391. {
  1392. // we have found a file in an earlier scan folder that would override this file
  1393. return QDir(scanFolderInfo.ScanPath()).absoluteFilePath(tempRelativeName);
  1394. }
  1395. }
  1396. // we found it nowhere.
  1397. return QString();
  1398. }
  1399. // This function is one of the most frequently called ones in the entire application
  1400. // and is invoked several times per file. It can frequently become a bottleneck, so
  1401. // avoid doing expensive operations here, especially memory or IO operations.
  1402. QString PlatformConfiguration::FindFirstMatchingFile(QString relativeName, bool skipIntermediateScanFolder, const ScanFolderInfo** outScanFolderInfo) const
  1403. {
  1404. if (relativeName.isEmpty())
  1405. {
  1406. return QString();
  1407. }
  1408. auto* fileStateInterface = AZ::Interface<AssetProcessor::IFileStateRequests>::Get();
  1409. // Only compute the intermediate assets folder path if we are going to search for and skip it.
  1410. if (skipIntermediateScanFolder)
  1411. {
  1412. if (m_intermediateAssetScanFolderId == -1)
  1413. {
  1414. CacheIntermediateAssetsScanFolderId();
  1415. }
  1416. }
  1417. QString absolutePath; // avoid allocating memory repeatedly here by reusing absolutePath each scan folder.
  1418. absolutePath.reserve(AZ_MAX_PATH_LEN);
  1419. QFileInfo details(relativeName); // note that this does not actually hit the actual storage medium until you query something
  1420. bool isAbsolute = details.isAbsolute(); // note that this looks at the file name string only, it does not hit storage.
  1421. for (int pathIdx = 0; pathIdx < m_scanFolders.size(); ++pathIdx)
  1422. {
  1423. const AssetProcessor::ScanFolderInfo& scanFolderInfo = m_scanFolders[pathIdx];
  1424. if ((skipIntermediateScanFolder) && (scanFolderInfo.ScanFolderID() == m_intermediateAssetScanFolderId))
  1425. {
  1426. // There's only 1 intermediate assets folder, if we've skipped it, theres no point continuing to check every folder afterwards
  1427. skipIntermediateScanFolder = false;
  1428. continue;
  1429. }
  1430. if ((!scanFolderInfo.RecurseSubFolders()) && (relativeName.contains('/')))
  1431. {
  1432. // the name is a deeper relative path, but we don't recurse this scan folder, so it can't win
  1433. continue;
  1434. }
  1435. if (isAbsolute)
  1436. {
  1437. if (!relativeName.startsWith(scanFolderInfo.ScanPath()))
  1438. {
  1439. continue; // its not this scanfolder.
  1440. }
  1441. absolutePath = relativeName;
  1442. }
  1443. else
  1444. {
  1445. // scanfolders are always absolute paths and already normalized. We can just concatenate.
  1446. // Do so with minimal allocation by using resize/append, instead of operator+
  1447. absolutePath.resize(0);
  1448. absolutePath.append(scanFolderInfo.ScanPath());
  1449. absolutePath.append('/');
  1450. absolutePath.append(relativeName);
  1451. }
  1452. AssetProcessor::FileStateInfo fileStateInfo;
  1453. if (fileStateInterface)
  1454. {
  1455. if (fileStateInterface->GetFileInfo(absolutePath, &fileStateInfo))
  1456. {
  1457. if (outScanFolderInfo)
  1458. {
  1459. *outScanFolderInfo = &scanFolderInfo;
  1460. }
  1461. return AssetUtilities::NormalizeFilePath(fileStateInfo.m_absolutePath);
  1462. }
  1463. }
  1464. }
  1465. return QString();
  1466. }
  1467. QStringList PlatformConfiguration::FindWildcardMatches(
  1468. const QString& sourceFolder,
  1469. QString relativeName,
  1470. bool includeFolders,
  1471. bool recursiveSearch) const
  1472. {
  1473. if (relativeName.isEmpty())
  1474. {
  1475. return QStringList();
  1476. }
  1477. QDir sourceFolderDir(sourceFolder);
  1478. QString posixRelativeName = QDir::fromNativeSeparators(relativeName);
  1479. QStringList returnList;
  1480. QRegExp nameMatch{ posixRelativeName, Qt::CaseInsensitive, QRegExp::Wildcard };
  1481. QDirIterator dirIterator(
  1482. sourceFolderDir.path(), QDir::AllEntries | QDir::NoSymLinks | QDir::NoDotAndDotDot,
  1483. recursiveSearch ? QDirIterator::Subdirectories : QDirIterator::NoIteratorFlags);
  1484. QStringList files;
  1485. while (dirIterator.hasNext())
  1486. {
  1487. dirIterator.next();
  1488. if (!includeFolders && !dirIterator.fileInfo().isFile())
  1489. {
  1490. continue;
  1491. }
  1492. QString pathMatch{ sourceFolderDir.relativeFilePath(dirIterator.filePath()) };
  1493. if (nameMatch.exactMatch(pathMatch))
  1494. {
  1495. returnList.append(QDir::fromNativeSeparators(dirIterator.filePath()));
  1496. }
  1497. }
  1498. return returnList;
  1499. }
  1500. QStringList PlatformConfiguration::FindWildcardMatches(
  1501. const QString& sourceFolder,
  1502. QString relativeName,
  1503. const AZStd::unordered_set<AZStd::string>& excludedFolders,
  1504. bool includeFolders,
  1505. bool recursiveSearch) const
  1506. {
  1507. if (relativeName.isEmpty())
  1508. {
  1509. return QStringList();
  1510. }
  1511. QDir sourceFolderDir(sourceFolder);
  1512. QString posixRelativeName = QDir::fromNativeSeparators(relativeName);
  1513. QStringList returnList;
  1514. QRegExp nameMatch{ posixRelativeName, Qt::CaseInsensitive, QRegExp::Wildcard };
  1515. AZStd::stack<QString> dirs;
  1516. dirs.push(sourceFolderDir.absolutePath());
  1517. while (!dirs.empty())
  1518. {
  1519. QString absolutePath = dirs.top();
  1520. dirs.pop();
  1521. if (excludedFolders.contains(absolutePath.toUtf8().constData()))
  1522. {
  1523. continue;
  1524. }
  1525. QDirIterator dirIterator(absolutePath, QDir::AllEntries | QDir::NoSymLinks | QDir::NoDotAndDotDot);
  1526. while (dirIterator.hasNext())
  1527. {
  1528. dirIterator.next();
  1529. if (!dirIterator.fileInfo().isFile())
  1530. {
  1531. if (recursiveSearch)
  1532. {
  1533. dirs.push(dirIterator.filePath());
  1534. }
  1535. if (!includeFolders)
  1536. {
  1537. continue;
  1538. }
  1539. }
  1540. QString pathMatch{ sourceFolderDir.relativeFilePath(dirIterator.filePath()) };
  1541. if (nameMatch.exactMatch(pathMatch))
  1542. {
  1543. returnList.append(QDir::fromNativeSeparators(dirIterator.filePath()));
  1544. }
  1545. }
  1546. }
  1547. return returnList;
  1548. }
  1549. const AssetProcessor::ScanFolderInfo* PlatformConfiguration::GetScanFolderForFile(const QString& fullFileName) const
  1550. {
  1551. QString normalized = AssetUtilities::NormalizeFilePath(fullFileName);
  1552. // first, check for an EXACT match. If there's an exact match, this must be the one returned!
  1553. // this is to catch the case where the actual path of a scan folder is fed in to this.
  1554. // because exact matches are preferred over less exact, we first check exact matches:
  1555. for (int pathIdx = 0; pathIdx < m_scanFolders.size(); ++pathIdx)
  1556. {
  1557. QString scanFolderName = m_scanFolders[pathIdx].ScanPath();
  1558. if (scanFolderName.length() == normalized.length())
  1559. {
  1560. if (normalized.compare(scanFolderName, Qt::CaseInsensitive) == 0)
  1561. {
  1562. // if its an exact match, we're basically done
  1563. return &m_scanFolders[pathIdx];
  1564. }
  1565. }
  1566. }
  1567. for (int pathIdx = 0; pathIdx < m_scanFolders.size(); ++pathIdx)
  1568. {
  1569. QString scanFolderName = m_scanFolders[pathIdx].ScanPath();
  1570. if (normalized.length() > scanFolderName.length())
  1571. {
  1572. if (normalized.startsWith(scanFolderName, Qt::CaseInsensitive))
  1573. {
  1574. QChar examineChar = normalized[scanFolderName.length()]; // it must be a slash or its just a scan folder that starts with the same thing by coincidence.
  1575. if (examineChar != QChar('/'))
  1576. {
  1577. continue;
  1578. }
  1579. QString relPath = normalized.right(normalized.length() - scanFolderName.length() - 1); // also eat the slash, hence -1
  1580. if (!m_scanFolders[pathIdx].RecurseSubFolders())
  1581. {
  1582. // we only allow things that are in the root for nonrecursive folders
  1583. if (relPath.contains('/'))
  1584. {
  1585. continue;
  1586. }
  1587. }
  1588. return &m_scanFolders[pathIdx];
  1589. }
  1590. }
  1591. }
  1592. return nullptr; // not found.
  1593. }
  1594. //! Given a scan folder path, get its complete info
  1595. const AssetProcessor::ScanFolderInfo* PlatformConfiguration::GetScanFolderByPath(const QString& scanFolderPath) const
  1596. {
  1597. return FindScanFolder([&scanFolderPath](const AssetProcessor::ScanFolderInfo& scanFolder)
  1598. {
  1599. return scanFolder.ScanPath() == scanFolderPath;
  1600. });
  1601. }
  1602. void PlatformConfiguration::EnableCommonPlatform()
  1603. {
  1604. EnablePlatform(AssetBuilderSDK::PlatformInfo{ AssetBuilderSDK::CommonPlatformName, AZStd::unordered_set<AZStd::string>{ "common" } });
  1605. }
  1606. void PlatformConfiguration::AddIntermediateScanFolder()
  1607. {
  1608. auto settingsRegistry = AZ::SettingsRegistry::Get();
  1609. AZ::SettingsRegistryInterface::FixedValueString cacheRootFolder;
  1610. settingsRegistry->Get(cacheRootFolder, AZ::SettingsRegistryMergeUtils::FilePathKey_CacheProjectRootFolder);
  1611. AZ::IO::Path scanfolderPath = cacheRootFolder.c_str();
  1612. scanfolderPath /= AssetProcessor::IntermediateAssetsFolderName;
  1613. AZStd::vector<AssetBuilderSDK::PlatformInfo> platforms;
  1614. PopulatePlatformsForScanFolder(platforms);
  1615. scanfolderPath = AssetUtilities::NormalizeDirectoryPath(QString::fromUtf8(scanfolderPath.c_str())).toUtf8().constData();
  1616. // By default the project scanfolder is recursive with an order of 0
  1617. // The intermediate assets folder needs to be higher priority since its a subfolder (otherwise GetScanFolderForFile won't pick the right scanfolder)
  1618. constexpr int order = -1;
  1619. AddScanFolder(ScanFolderInfo{
  1620. scanfolderPath.c_str(),
  1621. AssetProcessor::IntermediateAssetsFolderName,
  1622. AssetProcessor::IntermediateAssetsFolderName,
  1623. false,
  1624. true,
  1625. platforms,
  1626. order
  1627. });
  1628. }
  1629. void PlatformConfiguration::AddGemScanFolders(const AZStd::vector<AzFramework::GemInfo>& gemInfoList)
  1630. {
  1631. // If the gem is project-relative, make adjustments to its priority order based on registry settings:
  1632. // /Amazon/AssetProcessor/Settings/GemScanFolderStartingPriorityOrder
  1633. // /Amazon/AssetProcessor/Settings/ProjectRelativeGemsScanFolderPriority
  1634. // See <o3de-root>/Registry/AssetProcessorPlatformConfig.setreg for more information.
  1635. AZ::s64 gemStartingOrder = 100;
  1636. AZStd::string projectGemPrioritySetting{};
  1637. const AZ::IO::FixedMaxPath projectPath = AZ::Utils::GetProjectPath();
  1638. int pathCount = 0;
  1639. const int projectScanOrder = GetProjectScanFolderOrder();
  1640. if (auto const settingsRegistry = AZ::SettingsRegistry::Get(); settingsRegistry != nullptr)
  1641. {
  1642. settingsRegistry->Get(gemStartingOrder,
  1643. AZ::SettingsRegistryInterface::FixedValueString(AssetProcessorSettingsKey) + GemStartingPriorityOrderKey);
  1644. settingsRegistry->Get(projectGemPrioritySetting,
  1645. AZ::SettingsRegistryInterface::FixedValueString(AssetProcessorSettingsKey) + ProjectRelativeGemPriorityKey);
  1646. AZStd::to_lower(projectGemPrioritySetting.begin(), projectGemPrioritySetting.end());
  1647. }
  1648. auto GetGemFolderOrder = [&](bool isProjectRelativeGem) -> int
  1649. {
  1650. ++pathCount;
  1651. int currentGemOrder = aznumeric_cast<int>(gemStartingOrder) + pathCount;
  1652. if (isProjectRelativeGem)
  1653. {
  1654. if (projectGemPrioritySetting == "higher")
  1655. {
  1656. currentGemOrder = projectScanOrder - pathCount;
  1657. }
  1658. else if (projectGemPrioritySetting == "lower")
  1659. {
  1660. currentGemOrder = projectScanOrder + pathCount;
  1661. }
  1662. }
  1663. return currentGemOrder;
  1664. };
  1665. int gemOrder = aznumeric_cast<int>(gemStartingOrder);
  1666. AZStd::vector<AssetBuilderSDK::PlatformInfo> platforms;
  1667. PopulatePlatformsForScanFolder(platforms);
  1668. for (const AzFramework::GemInfo& gemElement : gemInfoList)
  1669. {
  1670. for (size_t sourcePathIndex{}; sourcePathIndex < gemElement.m_absoluteSourcePaths.size(); ++sourcePathIndex)
  1671. {
  1672. const AZ::IO::Path& absoluteSourcePath = gemElement.m_absoluteSourcePaths[sourcePathIndex];
  1673. QString gemAbsolutePath = QString::fromUtf8(absoluteSourcePath.c_str(), aznumeric_cast<int>(absoluteSourcePath.Native().size())); // this is an absolute path!
  1674. const bool isProjectGem = absoluteSourcePath.IsRelativeTo(projectPath);
  1675. // Append the index of the source path array element to make a unique portable key is created for each path of a gem
  1676. AZ::Uuid gemNameUuid = AZ::Uuid::CreateName((gemElement.m_gemName + AZStd::to_string(sourcePathIndex)).c_str());
  1677. QString gemNameAsUuid(gemNameUuid.ToFixedString().c_str());
  1678. QDir gemDir(gemAbsolutePath);
  1679. // The gems /Assets/ folders are always added to the watch list, we want the following params
  1680. // Watched folder: (absolute path to the gem /Assets/ folder) MUST BE CORRECT CASE
  1681. // Display name: "Gems/GemName/Assets" // uppercase, for human eyes
  1682. // portable Key: "gemassets-(UUID Of Gem)"
  1683. // Is Root: False
  1684. // Recursive: True
  1685. QString gemFolder = gemDir.absoluteFilePath(AzFramework::GemInfo::GetGemAssetFolder());
  1686. // note that we normalize this gem path with slashes so that there's nothing special about it compared to other scan folders
  1687. gemFolder = AssetUtilities::NormalizeDirectoryPath(gemFolder);
  1688. QString assetBrowserDisplayName = AzFramework::GemInfo::GetGemAssetFolder(); // Gems always use assets folder as their displayname...
  1689. QString portableKey = QString("gemassets-%1").arg(gemNameAsUuid);
  1690. bool isRoot = false;
  1691. bool isRecursive = true;
  1692. gemOrder = GetGemFolderOrder(isProjectGem);
  1693. AZ_TracePrintf(AssetProcessor::DebugChannel, "Adding GEM assets folder for monitoring / scanning: %s.\n", gemFolder.toUtf8().data());
  1694. AddScanFolder(ScanFolderInfo(
  1695. gemFolder,
  1696. assetBrowserDisplayName,
  1697. portableKey,
  1698. isRoot,
  1699. isRecursive,
  1700. platforms,
  1701. gemOrder,
  1702. /*scanFolderId*/ 0,
  1703. /*canSaveNewAssets*/ true)); // Users can create assets like slices in Gem asset folders.
  1704. // Now add another scan folder on Gem/GemName/Registry...
  1705. gemFolder = gemDir.absoluteFilePath(AzFramework::GemInfo::GetGemRegistryFolder());
  1706. gemFolder = AssetUtilities::NormalizeDirectoryPath(gemFolder);
  1707. assetBrowserDisplayName = AzFramework::GemInfo::GetGemRegistryFolder();
  1708. portableKey = QString("gemregistry-%1").arg(gemNameAsUuid);
  1709. gemOrder = GetGemFolderOrder(isProjectGem);
  1710. AZ_TracePrintf(AssetProcessor::DebugChannel, "Adding GEM registry folder for monitoring / scanning: %s.\n", gemFolder.toUtf8().data());
  1711. AddScanFolder(ScanFolderInfo(
  1712. gemFolder,
  1713. assetBrowserDisplayName,
  1714. portableKey,
  1715. isRoot,
  1716. isRecursive,
  1717. platforms,
  1718. gemOrder));
  1719. }
  1720. }
  1721. }
  1722. const RecognizerContainer& PlatformConfiguration::GetAssetRecognizerContainer() const
  1723. {
  1724. return m_assetRecognizers;
  1725. }
  1726. const RecognizerContainer& PlatformConfiguration::GetAssetCacheRecognizerContainer() const
  1727. {
  1728. return m_assetCacheServerRecognizers;
  1729. }
  1730. const ExcludeRecognizerContainer& PlatformConfiguration::GetExcludeAssetRecognizerContainer() const
  1731. {
  1732. return m_excludeAssetRecognizers;
  1733. }
  1734. bool PlatformConfiguration::AddAssetCacheRecognizerContainer(const RecognizerContainer& recognizerContainer)
  1735. {
  1736. bool addedEntries = false;
  1737. for (const auto& recognizer : recognizerContainer)
  1738. {
  1739. auto entryIter = m_assetCacheServerRecognizers.find(recognizer.first);
  1740. if (entryIter != m_assetCacheServerRecognizers.end())
  1741. {
  1742. m_assetCacheServerRecognizers.insert(recognizer);
  1743. addedEntries = true;
  1744. }
  1745. }
  1746. return addedEntries;
  1747. }
  1748. // AssetProcessor
  1749. void AssetProcessor::PlatformConfiguration::AddExcludeRecognizer(const ExcludeAssetRecognizer& recogniser)
  1750. {
  1751. m_excludeAssetRecognizers.insert(recogniser.m_name, recogniser);
  1752. }
  1753. void AssetProcessor::PlatformConfiguration::RemoveExcludeRecognizer(QString name)
  1754. {
  1755. auto found = m_excludeAssetRecognizers.find(name);
  1756. if (found != m_excludeAssetRecognizers.end())
  1757. {
  1758. m_excludeAssetRecognizers.erase(found);
  1759. }
  1760. }
  1761. bool AssetProcessor::PlatformConfiguration::IsFileExcluded(QString fileName) const
  1762. {
  1763. QString relPath, scanFolderName;
  1764. if (ConvertToRelativePath(fileName, relPath, scanFolderName))
  1765. {
  1766. return IsFileExcludedRelPath(relPath);
  1767. }
  1768. return false;
  1769. }
  1770. bool AssetProcessor::PlatformConfiguration::IsFileExcludedRelPath(QString relPath) const
  1771. {
  1772. AZ::IO::FixedMaxPathString encoded = relPath.toUtf8().constData();
  1773. for (const ExcludeAssetRecognizer& excludeRecognizer : m_excludeAssetRecognizers)
  1774. {
  1775. if (excludeRecognizer.m_patternMatcher.MatchesPath(encoded.c_str()))
  1776. {
  1777. return true;
  1778. }
  1779. }
  1780. return false;
  1781. }
  1782. bool AssetProcessor::PlatformConfiguration::IsValid() const
  1783. {
  1784. if (m_fatalError.empty())
  1785. {
  1786. if (m_enabledPlatforms.empty())
  1787. {
  1788. m_fatalError = "The configuration is invalid - no platforms appear to be enabled. Check to make sure that the AssetProcessorPlatformConfig.setreg file(s) are present and correct.";
  1789. }
  1790. else if (m_assetRecognizers.empty())
  1791. {
  1792. m_fatalError = "The configuration is invalid - no matching asset recognizers appear valid. Check to make sure that the AssetProcessorPlatformConfig.setreg file(s) are present and correct.";
  1793. }
  1794. else if (m_scanFolders.empty())
  1795. {
  1796. m_fatalError = "The configuration is invalid - no scan folders defined. Check to make sure that the AssetProcessorPlatformConfig.setreg file(s) are present and correct.";
  1797. }
  1798. }
  1799. if (!m_fatalError.empty())
  1800. {
  1801. AZ_Error(AssetProcessor::ConsoleChannel, false, "Error: %s", m_fatalError.c_str());
  1802. return false;
  1803. }
  1804. return true;
  1805. }
  1806. const AZStd::string& AssetProcessor::PlatformConfiguration::GetError() const
  1807. {
  1808. return m_fatalError;
  1809. }
  1810. } // namespace assetProcessor