BsBuildManager.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "Build/BsBuildManager.h"
  4. #include "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"bsfMono",
  66. u8"RenderBeast", u8"SBansheeEngine", u8"mono-2.0-sgen", u8"nvtt" };
  67. switch (type)
  68. {
  69. case PlatformType::Windows:
  70. {
  71. for (auto& lib : libs)
  72. lib.setExtension(lib.getExtension() + ".dll");
  73. }
  74. default:
  75. break;
  76. }
  77. return libs;
  78. }
  79. Path BuildManager::getBuildFolder(BuildFolder folder, PlatformType platform) const
  80. {
  81. // Use Data folder as an anchor to find where the root is
  82. Path sourceRoot = Paths::getDataPath();
  83. UINT32 numDataDirs = Paths::FRAMEWORK_DATA_PATH.getNumDirectories();
  84. if (Paths::FRAMEWORK_DATA_PATH.isFile())
  85. numDataDirs++;
  86. for (UINT32 i = 0; i < numDataDirs; i++)
  87. sourceRoot.makeParent();
  88. switch (folder)
  89. {
  90. case BuildFolder::SourceRoot:
  91. return sourceRoot;
  92. case BuildFolder::DestinationRoot:
  93. {
  94. switch (platform)
  95. {
  96. case PlatformType::Windows:
  97. return gEditorApplication().getProjectPath() + BUILD_FOLDER_NAME + u8"Windows";
  98. default:
  99. break;
  100. }
  101. return gEditorApplication().getProjectPath() + BUILD_FOLDER_NAME;
  102. }
  103. case BuildFolder::NativeBinaries:
  104. {
  105. Path binariesPath = Paths::getBinariesPath();
  106. return binariesPath.makeRelative(sourceRoot);
  107. }
  108. case BuildFolder::BansheeDebugAssemblies:
  109. return Paths::DEBUG_ASSEMBLY_PATH;
  110. case BuildFolder::BansheeReleaseAssemblies:
  111. return Paths::RELEASE_ASSEMBLY_PATH;
  112. case BuildFolder::Data:
  113. return Paths::FRAMEWORK_DATA_PATH;
  114. }
  115. return Path::BLANK;
  116. }
  117. Path BuildManager::getMainExecutable(PlatformType type) const
  118. {
  119. switch (type)
  120. {
  121. case PlatformType::Windows:
  122. {
  123. Path output = gEditorApplication().getDataPath() + "Binaries/Win64/Game.exe";
  124. return output;
  125. }
  126. default:
  127. break;
  128. }
  129. return Path::BLANK;
  130. }
  131. String BuildManager::getDefines(PlatformType type) const
  132. {
  133. return getPlatformInfo(type)->defines;
  134. }
  135. void BuildManager::clear()
  136. {
  137. mBuildData = nullptr;
  138. }
  139. void BuildManager::save(const Path& outFile)
  140. {
  141. FileEncoder fe(outFile);
  142. fe.encode(mBuildData.get());
  143. }
  144. void BuildManager::load(const Path& inFile)
  145. {
  146. if (FileSystem::exists(inFile))
  147. {
  148. FileDecoder fd(inFile);
  149. mBuildData = std::static_pointer_cast<BuildData>(fd.decode());
  150. }
  151. if (mBuildData == nullptr)
  152. mBuildData = bs_shared_ptr_new<BuildData>();
  153. }
  154. }