NETCmd.cpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. #include <Atomic/Core/Context.h>
  23. #include <Atomic/Core/StringUtils.h>
  24. #include <Atomic/IO/Log.h>
  25. #include <Atomic/IO/File.h>
  26. #include <Atomic/IO/FileSystem.h>
  27. #include <Atomic/IPC/IPC.h>
  28. #include <Atomic/IPC/IPCEvents.h>
  29. #include <Atomic/IPC/IPCBroker.h>
  30. #include "../ToolSystem.h"
  31. #include "../ToolEnvironment.h"
  32. #include "NETCmd.h"
  33. #include "../NETTools/AtomicNETService.h"
  34. #include "../NETTools/NETBuildSystem.h"
  35. #include "../NETTools/NETProjectGen.h"
  36. namespace ToolCore
  37. {
  38. NETCmd::NETCmd(Context* context) : Command(context)
  39. {
  40. }
  41. NETCmd::~NETCmd()
  42. {
  43. }
  44. bool NETCmd::Parse(const Vector<String>& arguments, unsigned startIndex, String& errorMsg)
  45. {
  46. String argument = arguments[startIndex].ToLower();
  47. command_ = startIndex + 1 < arguments.Size() ? arguments[startIndex + 1].ToLower() : String::EMPTY;
  48. if (argument != "net")
  49. {
  50. errorMsg = "Unable to parse net command";
  51. return false;
  52. }
  53. if (command_ == "genproject")
  54. {
  55. projectFile_ = startIndex + 2 < arguments.Size() ? arguments[startIndex + 2] : String::EMPTY;
  56. scriptPlatform_ = startIndex + 3 < arguments.Size() ? arguments[startIndex + 3] : String::EMPTY;
  57. if (!projectFile_.Length())
  58. {
  59. errorMsg = "Unable to parse project file";
  60. return false;
  61. }
  62. if (!scriptPlatform_.Length())
  63. {
  64. errorMsg = "Unable to parse script platform";
  65. return false;
  66. }
  67. }
  68. else if (command_ == "parse")
  69. {
  70. assemblyPath_ = startIndex + 2 < arguments.Size() ? arguments[startIndex + 2] : String::EMPTY;
  71. bool exists = false;
  72. if (assemblyPath_.Length())
  73. {
  74. FileSystem* fs = GetSubsystem<FileSystem>();
  75. exists = fs->FileExists(assemblyPath_);
  76. }
  77. if (!exists)
  78. {
  79. errorMsg = ToString("Assembly file not found: %s", assemblyPath_.CString());
  80. return false;
  81. }
  82. return true;
  83. }
  84. else if (command_ == "compile")
  85. {
  86. solutionPath_ = startIndex + 2 < arguments.Size() ? arguments[startIndex + 2] : String::EMPTY;
  87. platform_ = startIndex + 3 < arguments.Size() ? arguments[startIndex + 3] : String::EMPTY;
  88. configuration_ = startIndex + 4 < arguments.Size() ? arguments[startIndex + 4] : "Release";
  89. bool exists = false;
  90. if (solutionPath_.Length())
  91. {
  92. FileSystem* fs = GetSubsystem<FileSystem>();
  93. exists = fs->FileExists(solutionPath_);
  94. }
  95. if (!exists)
  96. {
  97. errorMsg = ToString("Solution file not found: %s", solutionPath_.CString());
  98. return false;
  99. }
  100. if (!platform_.Length())
  101. {
  102. errorMsg = "Platform not specified";
  103. return false;
  104. }
  105. return true;
  106. }
  107. else
  108. {
  109. errorMsg = "Unknown net command";
  110. return false;
  111. }
  112. return true;
  113. }
  114. void NETCmd::HandleNETBuildResult(StringHash eventType, VariantMap& eventData)
  115. {
  116. using namespace NETBuildResult;
  117. if (eventData[P_SUCCESS].GetBool())
  118. {
  119. LOGINFOF("NETBuild Success for solution: %s", solutionPath_.CString());
  120. Finished();
  121. }
  122. else
  123. {
  124. const String& errorText = eventData[P_ERRORTEXT].GetString();
  125. LOGERRORF("\n%s\n", errorText.CString());
  126. Error(ToString("NETBuild Error for solution: %s", solutionPath_.CString()));
  127. Finished();
  128. }
  129. }
  130. void NETCmd::Run()
  131. {
  132. if (command_ == "parse")
  133. {
  134. // start the NETService, which means we also need IPC
  135. IPC* ipc = new IPC(context_);
  136. context_->RegisterSubsystem(ipc);
  137. netService_ = new AtomicNETService(context_);
  138. context_->RegisterSubsystem(netService_);
  139. /*
  140. VariantMap cmd;
  141. cmd["command"] = "parse";
  142. cmd["assemblyPath"] = assemblyPath_;
  143. netService_->QueueCommand(cmd);
  144. cmd.Clear();
  145. cmd["command"] = "exit";
  146. netService_->QueueCommand(cmd);
  147. */
  148. if (!netService_->Start())
  149. {
  150. Error("Unable to start AtomicNETService");
  151. Finished();
  152. }
  153. }
  154. else if (command_ == "compile")
  155. {
  156. NETBuildSystem* buildSystem = new NETBuildSystem(context_);
  157. context_->RegisterSubsystem(buildSystem);
  158. NETBuild* build = buildSystem->Build(solutionPath_, platform_, configuration_);
  159. if (!build)
  160. {
  161. Error("Unable to start build");
  162. Finished();
  163. return;
  164. }
  165. build->SubscribeToEvent(E_NETBUILDRESULT, HANDLER(NETCmd, HandleNETBuildResult));
  166. }
  167. else if (command_ == "genproject")
  168. {
  169. SharedPtr<NETProjectGen> gen(new NETProjectGen(context_));
  170. gen->SetScriptPlatform(scriptPlatform_);
  171. gen->LoadProject(projectFile_);
  172. gen->Generate();
  173. Finished();
  174. }
  175. }
  176. }