BuilderConfigurationManager.cpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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 "BuilderConfigurationManager.h"
  9. #include <QFile>
  10. #include <QSettings>
  11. namespace AssetProcessor
  12. {
  13. BuilderConfigurationManager::BuilderConfigurationManager()
  14. {
  15. BuilderConfigurationRequestBus::Handler::BusConnect();
  16. }
  17. BuilderConfigurationManager::~BuilderConfigurationManager()
  18. {
  19. BuilderConfigurationRequestBus::Handler::BusDisconnect();
  20. }
  21. bool BuilderConfigurationManager::LoadConfiguration(const AZStd::string& configFile)
  22. {
  23. if (!QFile::exists(configFile.c_str()))
  24. {
  25. AZ_Warning("BuilderConfiguration", false, "Couldn't load builder configuration file at %s", configFile.c_str());
  26. return false;
  27. }
  28. QSettings loader(configFile.c_str(), QSettings::IniFormat);
  29. QStringList groups = loader.childGroups();
  30. for (QString group : groups)
  31. {
  32. const char JobGroupKey[] = "Job ";
  33. if (group.startsWith(JobGroupKey, Qt::CaseInsensitive))
  34. {
  35. loader.beginGroup(group);
  36. AZStd::string jobName = group.mid(static_cast<int>(strlen(JobGroupKey))).toStdString().c_str(); // Job name is after "job "
  37. ParamMap thisMap;
  38. for (const auto& thisKey : loader.allKeys())
  39. {
  40. thisMap[thisKey.toUtf8().data()] = loader.value(thisKey);
  41. }
  42. m_jobSettings[jobName] = thisMap;
  43. loader.endGroup();
  44. }
  45. const char BuilderGroupKey[] = "Builder ";
  46. if (group.startsWith(BuilderGroupKey, Qt::CaseInsensitive))
  47. {
  48. loader.beginGroup(group);
  49. AZStd::string builderName = group.mid(static_cast<int>(strlen(BuilderGroupKey))).toStdString().c_str(); // Builder name is after "Builder"
  50. ParamMap thisMap;
  51. for (const auto& thisKey : loader.allKeys())
  52. {
  53. thisMap[AZStd::string(thisKey.toUtf8().data())] = QVariant(loader.value(thisKey));
  54. }
  55. m_builderSettings[builderName] = thisMap;
  56. loader.endGroup();
  57. }
  58. }
  59. m_loaded = true;
  60. return true;
  61. }
  62. bool BuilderConfigurationManager::UpdateJobDescriptor(const AZStd::string& jobKey, AssetBuilderSDK::JobDescriptor& jobDesc)
  63. {
  64. auto jobEntry = m_jobSettings.find(jobKey);
  65. if (jobEntry == m_jobSettings.end())
  66. {
  67. return false;
  68. }
  69. const auto& paramMap = jobEntry->second;
  70. auto thisParam = paramMap.find("fingerprint");
  71. if (thisParam != paramMap.end())
  72. {
  73. jobDesc.m_additionalFingerprintInfo = thisParam->second.toString().toStdString().c_str();
  74. }
  75. thisParam = paramMap.find("checkServer");
  76. if (thisParam != paramMap.end())
  77. {
  78. jobDesc.m_checkServer = thisParam->second.toBool();
  79. }
  80. thisParam = paramMap.find("critical");
  81. if (thisParam != paramMap.end())
  82. {
  83. jobDesc.m_critical = thisParam->second.toBool();;
  84. }
  85. thisParam = paramMap.find("priority");
  86. if (thisParam != paramMap.end())
  87. {
  88. jobDesc.m_priority = thisParam->second.toInt();
  89. }
  90. thisParam = paramMap.find("checkExclusiveLock");
  91. if (thisParam != paramMap.end())
  92. {
  93. jobDesc.m_checkExclusiveLock = thisParam->second.toBool();
  94. }
  95. thisParam = paramMap.find("params");
  96. if (thisParam != paramMap.end())
  97. {
  98. QString patternString = thisParam->second.type() == QVariant::StringList ? thisParam->second.toStringList().join(",") : thisParam->second.toString();
  99. if (patternString.length())
  100. {
  101. jobDesc.m_jobParameters.clear();
  102. QStringList paramList = patternString.split(",");
  103. for (const auto& stringParam : paramList)
  104. {
  105. QStringList paramVals = stringParam.split("=");
  106. jobDesc.m_jobParameters[AZ_CRC(paramVals[0].toUtf8().data())] = paramVals.size() > 1 ? paramVals[1].toUtf8().data() : "";
  107. }
  108. }
  109. }
  110. return true;
  111. }
  112. bool BuilderConfigurationManager::UpdateBuilderDescriptor(const AZStd::string& builderName, AssetBuilderSDK::AssetBuilderDesc& builderDesc)
  113. {
  114. auto builderEntry = m_builderSettings.find(builderName);
  115. if (builderEntry == m_builderSettings.end())
  116. {
  117. return false;
  118. }
  119. const auto& paramMap = builderEntry->second;
  120. auto paramEntry = paramMap.find("fingerprint");
  121. if (paramEntry != paramMap.end())
  122. {
  123. builderDesc.m_analysisFingerprint = paramEntry->second.toString().toStdString().c_str();
  124. }
  125. paramEntry = paramMap.find("version");
  126. if (paramEntry != paramMap.end())
  127. {
  128. builderDesc.m_version = paramEntry->second.toInt();
  129. }
  130. paramEntry = paramMap.find("flags");
  131. if (paramEntry != paramMap.end())
  132. {
  133. builderDesc.m_flags = static_cast<AZ::u8>(paramEntry->second.toInt());
  134. }
  135. paramEntry = builderEntry->second.find("patterns");
  136. if (paramEntry != paramMap.end())
  137. {
  138. QString patternString = paramEntry->second.type() == QVariant::StringList ? paramEntry->second.toStringList().join(",") : paramEntry->second.toString();
  139. if (patternString.length())
  140. {
  141. builderDesc.m_patterns.clear();
  142. QStringList paramList = patternString.split(",");
  143. for (const auto& thisParam : paramList)
  144. {
  145. AssetBuilderSDK::AssetBuilderPattern thisPattern;
  146. QStringList paramVals = thisParam.split("=");
  147. thisPattern.m_pattern = paramVals[0].toUtf8().data();
  148. if (paramVals.length() > 1 && (paramVals[1] == "1" || paramVals[1].compare("regex", Qt::CaseInsensitive)))
  149. {
  150. thisPattern.m_type = AssetBuilderSDK::AssetBuilderPattern::Regex;
  151. }
  152. else
  153. {
  154. thisPattern.m_type = AssetBuilderSDK::AssetBuilderPattern::Wildcard;
  155. }
  156. builderDesc.m_patterns.emplace_back(AZStd::move(thisPattern));
  157. }
  158. }
  159. }
  160. return true;
  161. }
  162. } // namespace AssetProcessor