BuildBase.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. //
  2. // Copyright (c) 2014-2016 THUNDERBEAST GAMES LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #pragma once
  23. #include <Atomic/Core/Object.h>
  24. #include "BuildTypes.h"
  25. #include "../Platform/Platform.h"
  26. namespace Atomic
  27. {
  28. class File;
  29. }
  30. using namespace Atomic;
  31. namespace ToolCore
  32. {
  33. class ResourcePackager;
  34. class Project;
  35. class BuildBase : public Object
  36. {
  37. ATOMIC_OBJECT(BuildBase, Object);
  38. friend class AndroidProjectGenerator;
  39. public:
  40. BuildBase(Context* context, Project* project, PlatformID platform);
  41. virtual ~BuildBase();
  42. virtual void Build(const String& buildPath) = 0;
  43. // some platforms may want to do their own packaging of resources
  44. virtual bool UseResourcePackager() { return true; }
  45. virtual String GetBuildSubfolder() = 0;
  46. // add in search order, first added is first searched
  47. // will warn on name conflicts
  48. void AddResourceDir(const String& dir);
  49. void AddProjectResourceDir(const String& dir);
  50. void BuildLog(const String& message, bool sendEvent = true);
  51. void BuildWarn(const String& warning, bool sendEvent = true);
  52. void BuildError(const String& error, bool sendEvent = true);
  53. /// Fail the current build
  54. void FailBuild(const String& message);
  55. /// Converts subprocess output event to a buildoutput event
  56. void HandleSubprocessOutputEvent(StringHash eventType, VariantMap& eventData);
  57. /// Asset build tag used by the assetbuildconfig.json file to identify the assets to that should be include
  58. /// in the build. If no tag is specified, then all resources are included.
  59. void SetAssetBuildTag(const String assetBuildTag) { assetBuildTag_ = assetBuildTag; }
  60. void SetVerbose(bool verbose = true) { verbose_ = verbose; }
  61. bool GetResourcesOnly() const { return resourcesOnly_; }
  62. void SetResourcesOnly(bool resourcesOnly = true) { resourcesOnly_ = resourcesOnly; }
  63. bool GetBuildFailed() const { return buildFailed_; }
  64. const Vector<String>& GetBuildErrors() const { return buildErrors_; }
  65. void SetAutoLog(bool autoLog) { autoLog_ = autoLog; }
  66. protected:
  67. bool BuildClean(const String& path);
  68. bool BuildRemoveDirectory(const String& path);
  69. bool BuildCreateDirectory(const String& path);
  70. bool BuildCopyFile(const String& srcFileName, const String& destFileName);
  71. bool BuildCopyDir(const String& srcDir, const String& destDir);
  72. virtual bool CheckIncludeResourceFile(const String& resourceDir, const String& fileName);
  73. void GenerateResourcePackage(const String& resourcePackagePath);
  74. void BuildDefaultResourceEntries();
  75. void BuildProjectResourceEntries();
  76. void AddToResourcePackager(const String& filename, const String& resourceDir);
  77. void GetDefaultResourcePaths(Vector<String>& paths);
  78. String GetSettingsDirectory();
  79. String buildPath_;
  80. PODVector<BuildResourceEntry*> resourceEntries_;
  81. bool containsMDL_;
  82. bool buildFailed_;
  83. /// AssetBuildConfiguraton's asset build tag reference
  84. String assetBuildTag_;
  85. /// Pointer to a file used to capture the resources included in the build
  86. File *fileIncludedResourcesLog_;
  87. bool resourcesOnly_;
  88. bool verbose_;
  89. bool autoLog_;
  90. private:
  91. void BuildFilteredProjectResourceEntries();
  92. void BuildAllProjectResourceEntries();
  93. PlatformID platformID_;
  94. Vector<String> buildLog_;
  95. Vector<String> buildWarnings_;
  96. Vector<String> buildErrors_;
  97. SharedPtr<Project> project_;
  98. SharedPtr<ResourcePackager> resourcePackager_;
  99. Vector<String> resourceDirs_;
  100. Vector<String> projectResourceDir_;
  101. void ReadAssetBuildConfig();
  102. };
  103. }