BsBuildManager.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "BsBuildManager.h"
  4. #include "BsBuildDataRTTI.h"
  5. #include "BsFileSerializer.h"
  6. #include "BsFileSystem.h"
  7. #include "BsEditorApplication.h"
  8. namespace BansheeEngine
  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 WString BuildManager::BUILD_FOLDER_NAME = L"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<WString> BuildManager::getFrameworkAssemblies(PlatformType type) const
  54. {
  55. switch (type)
  56. {
  57. case PlatformType::Windows:
  58. default:
  59. return { L"mscorlib", L"System", L"System.Core" };
  60. }
  61. }
  62. Vector<Path> BuildManager::getNativeBinaries(PlatformType type) const
  63. {
  64. Vector<Path> libs = { L"BansheeEngine", L"BansheeCore", L"BansheeUtility",
  65. L"BansheeD3D11RenderAPI", L"BansheeGLRenderAPI", L"BansheeMono", L"BansheeOISInput",
  66. L"RenderBeast", L"SBansheeEngine", L"BansheeOIS", L"mono-2.0", L"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::getRuntimeDataPath();
  83. sourceRoot.makeAbsolute(FileSystem::getWorkingDirectoryPath());
  84. UINT32 numDataDirs = Paths::RUNTIME_DATA_PATH.getNumDirectories();
  85. if (Paths::RUNTIME_DATA_PATH.isFile())
  86. numDataDirs++;
  87. for (UINT32 i = 0; i < numDataDirs; i++)
  88. sourceRoot.makeParent();
  89. switch (folder)
  90. {
  91. case BuildFolder::SourceRoot:
  92. return sourceRoot;
  93. case BuildFolder::DestinationRoot:
  94. {
  95. switch (platform)
  96. {
  97. case PlatformType::Windows:
  98. return gEditorApplication().getProjectPath() + BUILD_FOLDER_NAME + L"Windows";
  99. default:
  100. break;
  101. }
  102. return gEditorApplication().getProjectPath() + BUILD_FOLDER_NAME;
  103. }
  104. case BuildFolder::NativeBinaries:
  105. {
  106. Path binariesPath = FileSystem::getWorkingDirectoryPath();
  107. return binariesPath.makeRelative(sourceRoot);
  108. }
  109. case BuildFolder::BansheeDebugAssemblies:
  110. return Paths::DEBUG_ASSEMBLY_PATH;
  111. case BuildFolder::BansheeReleaseAssemblies:
  112. return Paths::RELEASE_ASSEMBLY_PATH;
  113. case BuildFolder::Data:
  114. return Paths::ENGINE_DATA_PATH;
  115. }
  116. return Path::BLANK;
  117. }
  118. Path BuildManager::getMainExecutable(PlatformType type) const
  119. {
  120. switch (type)
  121. {
  122. case PlatformType::Windows:
  123. {
  124. Path output = Paths::getRuntimeDataPath() + "Binaries\\Win64\\Game.exe";
  125. output.makeAbsolute(FileSystem::getWorkingDirectoryPath());
  126. return output;
  127. }
  128. default:
  129. break;
  130. }
  131. return Path::BLANK;
  132. }
  133. WString BuildManager::getDefines(PlatformType type) const
  134. {
  135. return getPlatformInfo(type)->defines;
  136. }
  137. void BuildManager::clear()
  138. {
  139. mBuildData = nullptr;
  140. }
  141. void BuildManager::save(const Path& outFile)
  142. {
  143. FileEncoder fe(outFile);
  144. fe.encode(mBuildData.get());
  145. }
  146. void BuildManager::load(const Path& inFile)
  147. {
  148. if (FileSystem::exists(inFile))
  149. {
  150. FileDecoder fd(inFile);
  151. mBuildData = std::static_pointer_cast<BuildData>(fd.decode());
  152. }
  153. if (mBuildData == nullptr)
  154. mBuildData = bs_shared_ptr_new<BuildData>();
  155. }
  156. }