NETCmd.cpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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/NETProjectGen.h"
  35. #include "../NETTools/NETCompile.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. configuration_ = startIndex + 3 < arguments.Size() ? arguments[startIndex + 3] : "Release";
  88. bool exists = false;
  89. if (solutionPath_.Length())
  90. {
  91. FileSystem* fs = GetSubsystem<FileSystem>();
  92. exists = fs->FileExists(solutionPath_);
  93. }
  94. if (!exists)
  95. {
  96. errorMsg = ToString("Solution file not found: %s", solutionPath_.CString());
  97. return false;
  98. }
  99. return true;
  100. }
  101. else
  102. {
  103. errorMsg = "Unknown net command";
  104. return false;
  105. }
  106. return true;
  107. }
  108. void NETCmd::HandleNETCompileResult(StringHash eventType, VariantMap& eventData)
  109. {
  110. using namespace NETCompilerResult;
  111. if (eventData[P_SUCCESS].GetBool())
  112. {
  113. LOGINFOF("NETCompile Success for solution: %s", solutionPath_.CString());
  114. Finished();
  115. }
  116. else
  117. {
  118. const String& errorText = eventData[P_ERRORTEXT].GetString();
  119. LOGERRORF("\n%s\n", errorText.CString());
  120. Error(ToString("NETCompile Error for solution: %s", solutionPath_.CString()));
  121. Finished();
  122. }
  123. }
  124. void NETCmd::Run()
  125. {
  126. if (command_ == "parse")
  127. {
  128. // start the NETService, which means we also need IPC
  129. IPC* ipc = new IPC(context_);
  130. context_->RegisterSubsystem(ipc);
  131. netService_ = new AtomicNETService(context_);
  132. context_->RegisterSubsystem(netService_);
  133. /*
  134. VariantMap cmd;
  135. cmd["command"] = "parse";
  136. cmd["assemblyPath"] = assemblyPath_;
  137. netService_->QueueCommand(cmd);
  138. cmd.Clear();
  139. cmd["command"] = "exit";
  140. netService_->QueueCommand(cmd);
  141. */
  142. if (!netService_->Start())
  143. {
  144. Error("Unable to start AtomicNETService");
  145. Finished();
  146. }
  147. }
  148. else if (command_ == "compile")
  149. {
  150. compiler_ = new NETCompile(context_);
  151. SubscribeToEvent(E_NETCOMPILERESULT, HANDLER(NETCmd, HandleNETCompileResult));
  152. compiler_->Compile(solutionPath_, configuration_);
  153. }
  154. else if (command_ == "genproject")
  155. {
  156. SharedPtr<NETProjectGen> gen(new NETProjectGen(context_));
  157. gen->SetScriptPlatform(scriptPlatform_);
  158. gen->LoadProject(projectFile_);
  159. gen->Generate();
  160. Finished();
  161. }
  162. }
  163. }