BuildBase.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
  2. // Please see LICENSE.md in repository root for license information
  3. // https://github.com/AtomicGameEngine/AtomicGameEngine
  4. #include <Atomic/IO/Log.h>
  5. #include <Atomic/IO/FileSystem.h>
  6. #include "../Subprocess/SubprocessSystem.h"
  7. #include "../Project/Project.h"
  8. #include "../ToolEnvironment.h"
  9. #include "BuildEvents.h"
  10. #include "BuildBase.h"
  11. #include "ResourcePackager.h"
  12. namespace ToolCore
  13. {
  14. BuildBase::BuildBase(Context * context, Project* project, PlatformID platform) : Object(context),
  15. platformID_(platform),
  16. containsMDL_(false)
  17. {
  18. if (UseResourcePackager())
  19. resourcePackager_ = new ResourcePackager(context, this);
  20. project_ = project;
  21. }
  22. BuildBase::~BuildBase()
  23. {
  24. for (unsigned i = 0; i < resourceEntries_.Size(); i++)
  25. {
  26. delete resourceEntries_[i];
  27. }
  28. }
  29. void BuildBase::BuildLog(const String& message)
  30. {
  31. buildLog_.Push(message);
  32. }
  33. void BuildBase::BuildWarn(const String& warning)
  34. {
  35. buildWarnings_.Push(warning);
  36. }
  37. void BuildBase::BuildError(const String& error)
  38. {
  39. buildErrors_.Push(error);
  40. }
  41. void BuildBase::SendBuildFailure(const String& message)
  42. {
  43. VariantMap buildError;
  44. buildError[BuildFailed::P_PLATFORMID] = platformID_;
  45. buildError[BuildFailed::P_MESSAGE] = message;
  46. SendEvent(E_BUILDFAILED, buildError);
  47. }
  48. void BuildBase::HandleSubprocessOutputEvent(StringHash eventType, VariantMap& eventData)
  49. {
  50. // E_SUBPROCESSOUTPUT
  51. const String& text = eventData[SubprocessOutput::P_TEXT].GetString();
  52. // convert to a build output event and forward to subscribers
  53. VariantMap buildOutputData;
  54. buildOutputData[BuildOutput::P_TEXT] = text;
  55. SendEvent(E_BUILDOUTPUT, buildOutputData);
  56. }
  57. void BuildBase::GetDefaultResourcePaths(Vector<String>& paths)
  58. {
  59. paths.Clear();
  60. ToolEnvironment* tenv = GetSubsystem<ToolEnvironment>();
  61. paths.Push(AddTrailingSlash(tenv->GetCoreDataDir()));
  62. paths.Push(AddTrailingSlash(tenv->GetPlayerDataDir()));
  63. }
  64. void BuildBase::ScanResourceDirectory(const String& resourceDir)
  65. {
  66. Vector<String> fileNames;
  67. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  68. fileSystem->ScanDir(fileNames, resourceDir, "*.*", SCAN_FILES, true);
  69. for (unsigned i = 0; i < fileNames.Size(); i++)
  70. {
  71. const String& filename = fileNames[i];
  72. for (unsigned j = 0; j < resourceEntries_.Size(); j++)
  73. {
  74. const BuildResourceEntry* entry = resourceEntries_[j];
  75. if (entry->packagePath_ == filename)
  76. {
  77. BuildWarn(ToString("Resource Path: %s already exists", filename.CString()));
  78. continue;
  79. }
  80. }
  81. // TODO: Add additional filters
  82. if (GetExtension(filename) == ".psd")
  83. continue;
  84. BuildResourceEntry* newEntry = new BuildResourceEntry;
  85. // BEGIN LICENSE MANAGEMENT
  86. if (GetExtension(filename) == ".mdl")
  87. {
  88. containsMDL_ = true;
  89. }
  90. // END LICENSE MANAGEMENT
  91. newEntry->absolutePath_ = resourceDir + filename;
  92. newEntry->resourceDir_ = resourceDir;
  93. if (resourceDir.EndsWith("/Cache/"))
  94. newEntry->packagePath_ = "Cache/" + filename;
  95. else
  96. newEntry->packagePath_ = filename;
  97. resourceEntries_.Push(newEntry);
  98. //LOGINFOF("Adding resource: %s : %s", newEntry->absolutePath_.CString(), newEntry->packagePath_.CString());
  99. }
  100. }
  101. void BuildBase::BuildResourceEntries()
  102. {
  103. for (unsigned i = 0; i < resourceDirs_.Size(); i++)
  104. {
  105. ScanResourceDirectory(resourceDirs_[i]);
  106. }
  107. if (resourcePackager_.NotNull())
  108. {
  109. for (unsigned i = 0; i < resourceEntries_.Size(); i++)
  110. {
  111. BuildResourceEntry* entry = resourceEntries_[i];
  112. resourcePackager_->AddResourceEntry(entry);
  113. }
  114. }
  115. }
  116. void BuildBase::GenerateResourcePackage(const String& resourcePackagePath)
  117. {
  118. resourcePackager_->GeneratePackage(resourcePackagePath);
  119. }
  120. void BuildBase::AddResourceDir(const String& dir)
  121. {
  122. assert(!resourceDirs_.Contains(dir));
  123. resourceDirs_.Push(dir);
  124. }
  125. }