ToolEnvironment.cpp 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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. // before resource system exists so use rapidjson directly
  23. #include <rapidjson/document.h>
  24. #include <rapidjson/prettywriter.h>
  25. #include <rapidjson/filestream.h>
  26. #include <Atomic/IO/Log.h>
  27. #include <Atomic/IO/FileSystem.h>
  28. #include <Atomic/IO/File.h>
  29. #include "ToolEnvironment.h"
  30. using namespace rapidjson;
  31. namespace ToolCore
  32. {
  33. bool ToolEnvironment::bootstrapping_ = false;
  34. ToolEnvironment::ToolEnvironment(Context* context) : Object(context),
  35. cli_(false),
  36. toolPrefs_(new ToolPrefs(context))
  37. {
  38. }
  39. ToolEnvironment::~ToolEnvironment()
  40. {
  41. }
  42. bool ToolEnvironment::InitFromDistribution()
  43. {
  44. toolPrefs_->Load();
  45. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  46. #ifdef ATOMIC_PLATFORM_WINDOWS
  47. editorBinary_ = fileSystem->GetProgramDir() + "AtomicEditor.exe";
  48. String resourcesDir = fileSystem->GetProgramDir() + "Resources/";
  49. playerBinary_ = resourcesDir + "ToolData/Deployment/Windows/x64/AtomicPlayer.exe";
  50. #elif ATOMIC_PLATFORM_LINUX
  51. editorBinary_ = fileSystem->GetProgramDir() + "AtomicEditor";
  52. String resourcesDir = fileSystem->GetProgramDir() + "Resources/";
  53. playerBinary_ = resourcesDir + "ToolData/Deployment/Linux/AtomicPlayer";
  54. #else
  55. editorBinary_ = fileSystem->GetProgramDir() + "AtomicEditor";
  56. String resourcesDir = GetPath(RemoveTrailingSlash(fileSystem->GetProgramDir())) + "Resources/";
  57. playerAppFolder_ = resourcesDir + "ToolData/Deployment/MacOS/AtomicPlayer.app/";
  58. #endif
  59. resourceCoreDataDir_ = resourcesDir + "CoreData";
  60. resourcePlayerDataDir_ = resourcesDir + "PlayerData";
  61. toolDataDir_ = resourcesDir + "ToolData/";
  62. // AtomicNET
  63. #ifdef ATOMIC_DEBUG
  64. String config = "Debug";
  65. #else
  66. String config = "Release";
  67. #endif
  68. atomicNETRootDir_ = resourcesDir + "ToolData/AtomicNET/";
  69. atomicNETCoreAssemblyDir_ = atomicNETRootDir_ + config + "/";
  70. #ifdef ATOMIC_PLATFORM_OSX
  71. monoExecutableDir_ = "/Library/Frameworks/Mono.framework/Versions/Current/Commands/";
  72. atomicNETNuGetBinary_ = monoExecutableDir_ + "nuget";
  73. #endif
  74. return true;
  75. }
  76. bool ToolEnvironment::Initialize(bool cli)
  77. {
  78. bool result = true;
  79. cli_ = cli;
  80. toolPrefs_->Load();
  81. #ifdef ATOMIC_DEV_BUILD
  82. SetRootSourceDir(ATOMIC_ROOT_SOURCE_DIR);
  83. SetRootBuildDir(ATOMIC_ROOT_BUILD_DIR, true);
  84. #else
  85. if (!bootstrapping_)
  86. {
  87. result = InitFromDistribution();
  88. }
  89. else
  90. {
  91. SetRootSourceDir(ATOMIC_ROOT_SOURCE_DIR);
  92. SetRootBuildDir(ATOMIC_ROOT_BUILD_DIR, true);
  93. }
  94. #endif
  95. return result;
  96. }
  97. void ToolEnvironment::SetRootSourceDir(const String& sourceDir)
  98. {
  99. rootSourceDir_ = AddTrailingSlash(sourceDir);
  100. resourceCoreDataDir_ = rootSourceDir_ + "Resources/CoreData";
  101. resourcePlayerDataDir_ = rootSourceDir_ + "Resources/PlayerData";
  102. resourceEditorDataDir_ = rootSourceDir_ + "Resources/EditorData";
  103. toolDataDir_ = rootSourceDir_ + "Data/AtomicEditor/";
  104. // AtomicNET
  105. #ifdef ATOMIC_DEBUG
  106. String config = "Debug";
  107. #else
  108. String config = "Release";
  109. #endif
  110. atomicNETRootDir_ = rootSourceDir_ + "Artifacts/AtomicNET/";
  111. atomicNETCoreAssemblyDir_ = rootSourceDir_ + "Artifacts/AtomicNET/" + config + "/";
  112. #if defined ATOMIC_PLATFORM_WINDOWS || defined ATOMIC_PLATFORM_LINUX
  113. atomicNETNuGetBinary_ = ToString("%sBuild/Managed/nuget/nuget.exe", rootSourceDir_.CString());
  114. #endif
  115. #ifdef ATOMIC_PLATFORM_OSX
  116. monoExecutableDir_ = "/Library/Frameworks/Mono.framework/Versions/Current/Commands/";
  117. atomicNETNuGetBinary_ = monoExecutableDir_ + "nuget";
  118. #endif
  119. }
  120. void ToolEnvironment::SetRootBuildDir(const String& buildDir, bool setBinaryPaths)
  121. {
  122. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  123. rootBuildDir_ = AddTrailingSlash(buildDir);
  124. if (setBinaryPaths)
  125. {
  126. #ifdef ATOMIC_PLATFORM_WINDOWS
  127. #ifdef _DEBUG
  128. playerBinary_ = rootBuildDir_ + "Source/AtomicPlayer/Application/Debug/AtomicPlayer.exe";
  129. editorBinary_ = rootBuildDir_ + "Source/AtomicEditor/Debug/AtomicEditor.exe";
  130. #else
  131. playerBinary_ = rootBuildDir_ + "Source/AtomicPlayer/Application/Release/AtomicPlayer.exe";
  132. editorBinary_ = rootBuildDir_ + "Source/AtomicEditor/Release/AtomicEditor.exe";
  133. #endif
  134. // some build tools like ninja don't use Release/Debug folders
  135. if (!fileSystem->FileExists(playerBinary_))
  136. playerBinary_ = rootBuildDir_ + "Source/AtomicPlayer/Application/AtomicPlayer.exe";
  137. if (!fileSystem->FileExists(editorBinary_))
  138. editorBinary_ = rootBuildDir_ + "Source/AtomicEditor/AtomicEditor.exe";
  139. playerAppFolder_ = rootSourceDir_ + "Data/AtomicEditor/Deployment/MacOS/AtomicPlayer.app";
  140. #elif ATOMIC_PLATFORM_OSX
  141. #ifdef ATOMIC_XCODE
  142. playerBinary_ = rootBuildDir_ + "Source/AtomicPlayer/" + CMAKE_INTDIR + "/AtomicPlayer.app/Contents/MacOS/AtomicPlayer";
  143. editorBinary_ = rootBuildDir_ + "Source/AtomicEditor/" + CMAKE_INTDIR + "/AtomicEditor.app/Contents/MacOS/AtomicEditor";
  144. #else
  145. playerBinary_ = rootBuildDir_ + "Source/AtomicPlayer/Application/AtomicPlayer.app/Contents/MacOS/AtomicPlayer";
  146. playerAppFolder_ = rootBuildDir_ + "Source/AtomicPlayer/Application/AtomicPlayer.app/";
  147. editorBinary_ = rootBuildDir_ + "Source/AtomicEditor/AtomicEditor.app/Contents/MacOS/AtomicEditor";
  148. #endif
  149. #else
  150. playerBinary_ = rootBuildDir_ + "Source/AtomicPlayer/Application/AtomicPlayer";
  151. editorBinary_ = rootBuildDir_ + "Source/AtomicEditor/AtomicEditor";
  152. #endif
  153. }
  154. }
  155. String ToolEnvironment::GetIOSDeployBinary()
  156. {
  157. return GetToolDataDir() + "Deployment/IOS/ios-deploy/ios-deploy";
  158. }
  159. void ToolEnvironment::Dump()
  160. {
  161. ATOMIC_LOGINFOF("Root Source Dir: %s", rootSourceDir_.CString());
  162. ATOMIC_LOGINFOF("Root Build Dir: %s", rootBuildDir_.CString());
  163. ATOMIC_LOGINFOF("Core Resource Dir: %s", resourceCoreDataDir_.CString());
  164. ATOMIC_LOGINFOF("Player Resource Dir: %s", resourcePlayerDataDir_.CString());
  165. ATOMIC_LOGINFOF("Editor Resource Dir: %s", resourceEditorDataDir_.CString());
  166. ATOMIC_LOGINFOF("Editor Binary: %s", editorBinary_.CString());
  167. ATOMIC_LOGINFOF("Player Binary: %s", playerBinary_.CString());
  168. ATOMIC_LOGINFOF("Tool Binary: %s", toolBinary_.CString());
  169. ATOMIC_LOGINFOF("Tool Data Dir: %s", toolDataDir_.CString());
  170. ATOMIC_LOGINFOF("Deployment Data Dir: %s", deploymentDataDir_.CString());
  171. }
  172. }