BsBuildManager.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "Build/BsBuildManager.h"
  4. #include "Private/RTTI/BsBuildDataRTTI.h"
  5. #include "Serialization/BsFileSerializer.h"
  6. #include "FileSystem/BsFileSystem.h"
  7. #include "BsEditorApplication.h"
  8. namespace bs
  9. {
  10. BuildData::BuildData()
  11. :activePlatform(PlatformType::Windows)
  12. {
  13. platformData.resize((UINT32)PlatformType::Count);
  14. platformData[0] = bs_shared_ptr_new<WinPlatformInfo>();
  15. }
  16. RTTITypeBase* BuildData::getRTTIStatic()
  17. {
  18. return BuildDataRTTI::instance();
  19. }
  20. RTTITypeBase* BuildData::getRTTI() const
  21. {
  22. return BuildData::getRTTIStatic();
  23. }
  24. const char* BuildManager::BUILD_FOLDER_NAME = "Builds/";
  25. BuildManager::BuildManager()
  26. {
  27. mBuildData = bs_shared_ptr_new<BuildData>();
  28. }
  29. const Vector<PlatformType>& BuildManager::getAvailablePlatforms() const
  30. {
  31. static const Vector<PlatformType> PLATFORMS = { PlatformType::Windows };
  32. return PLATFORMS;
  33. }
  34. PlatformType BuildManager::getActivePlatform() const
  35. {
  36. return mBuildData->activePlatform;
  37. }
  38. void BuildManager::setActivePlatform(PlatformType type)
  39. {
  40. if ((UINT32)type < (UINT32)PlatformType::Count)
  41. mBuildData->activePlatform = type;
  42. }
  43. SPtr<PlatformInfo> BuildManager::getActivePlatformInfo() const
  44. {
  45. return mBuildData->platformData[(UINT32)mBuildData->activePlatform];
  46. }
  47. SPtr<PlatformInfo> BuildManager::getPlatformInfo(PlatformType type) const
  48. {
  49. if ((UINT32)type < (UINT32)mBuildData->platformData.size())
  50. return mBuildData->platformData[(UINT32)type];
  51. return nullptr;
  52. }
  53. Vector<String> BuildManager::getFrameworkAssemblies(PlatformType type) const
  54. {
  55. switch (type)
  56. {
  57. case PlatformType::Windows:
  58. default:
  59. return { u8"mscorlib", u8"System", u8"System.Core" };
  60. }
  61. }
  62. Vector<Path> BuildManager::getNativeBinaries(PlatformType type) const
  63. {
  64. Vector<Path> libs = { u8"bsfEngine", u8"bsfCore", u8"bsfUtility",
  65. u8"bsfD3D11RenderAPI", u8"bsfGLRenderAPI", u8"RenderBeast", u8"mono-2.0-sgen", u8"nvtt" };
  66. switch (type)
  67. {
  68. case PlatformType::Windows:
  69. {
  70. for (auto& lib : libs)
  71. lib.setExtension(lib.getExtension() + ".dll");
  72. }
  73. default:
  74. break;
  75. }
  76. return libs;
  77. }
  78. Path BuildManager::getBuildFolder(BuildFolder folder, PlatformType platform) const
  79. {
  80. // Use Data folder as an anchor to find where the root is
  81. Path sourceRoot = Paths::getDataPath();
  82. UINT32 numDataDirs = Paths::FRAMEWORK_DATA_PATH.getNumDirectories();
  83. if (Paths::FRAMEWORK_DATA_PATH.isFile())
  84. numDataDirs++;
  85. for (UINT32 i = 0; i < numDataDirs; i++)
  86. sourceRoot.makeParent();
  87. switch (folder)
  88. {
  89. case BuildFolder::SourceRoot:
  90. return sourceRoot;
  91. case BuildFolder::DestinationRoot:
  92. {
  93. switch (platform)
  94. {
  95. case PlatformType::Windows:
  96. return gEditorApplication().getProjectPath() + BUILD_FOLDER_NAME + u8"Windows";
  97. default:
  98. break;
  99. }
  100. return gEditorApplication().getProjectPath() + BUILD_FOLDER_NAME;
  101. }
  102. case BuildFolder::NativeBinaries:
  103. {
  104. Path binariesPath = Paths::getBinariesPath();
  105. return binariesPath.makeRelative(sourceRoot);
  106. }
  107. case BuildFolder::BansheeDebugAssemblies:
  108. return Paths::DEBUG_ASSEMBLY_PATH;
  109. case BuildFolder::BansheeReleaseAssemblies:
  110. return Paths::RELEASE_ASSEMBLY_PATH;
  111. case BuildFolder::Data:
  112. return Paths::FRAMEWORK_DATA_PATH;
  113. }
  114. return Path::BLANK;
  115. }
  116. Path BuildManager::getMainExecutable(PlatformType type) const
  117. {
  118. switch (type)
  119. {
  120. case PlatformType::Windows:
  121. {
  122. Path output = Paths::getEditorDataPath() + "Binaries/Win64/Game.exe";
  123. return output;
  124. }
  125. default:
  126. break;
  127. }
  128. return Path::BLANK;
  129. }
  130. String BuildManager::getDefines(PlatformType type) const
  131. {
  132. return getPlatformInfo(type)->defines;
  133. }
  134. void BuildManager::clear()
  135. {
  136. mBuildData = nullptr;
  137. }
  138. void BuildManager::save(const Path& outFile)
  139. {
  140. FileEncoder fe(outFile);
  141. fe.encode(mBuildData.get());
  142. }
  143. void BuildManager::load(const Path& inFile)
  144. {
  145. if (FileSystem::exists(inFile))
  146. {
  147. FileDecoder fd(inFile);
  148. mBuildData = std::static_pointer_cast<BuildData>(fd.decode());
  149. }
  150. if (mBuildData == nullptr)
  151. mBuildData = bs_shared_ptr_new<BuildData>();
  152. }
  153. }