BsBuildManager.cpp 4.1 KB

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