BuildCmd.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. //
  2. // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
  3. // LICENSE: Atomic Game Engine Editor and Tools EULA
  4. // Please see LICENSE_ATOMIC_EDITOR_AND_TOOLS.md in repository root for
  5. // license information: https://github.com/AtomicGameEngine/AtomicGameEngine
  6. //
  7. #include <Atomic/Core/StringUtils.h>
  8. #include <Atomic/IO/Log.h>
  9. #include <Atomic/IO/File.h>
  10. #include "../ToolSystem.h"
  11. #include "../Project/Project.h"
  12. #include "../Build/BuildEvents.h"
  13. #include "../Build/BuildSystem.h"
  14. #include "BuildCmd.h"
  15. #include <Poco/File.h>
  16. namespace ToolCore
  17. {
  18. BuildCmd::BuildCmd(Context* context) : Command(context)
  19. {
  20. }
  21. BuildCmd::~BuildCmd()
  22. {
  23. }
  24. bool BuildCmd::Parse(const Vector<String>& arguments, unsigned startIndex, String& errorMsg)
  25. {
  26. String argument = arguments[startIndex].ToLower();
  27. String value = startIndex + 1 < arguments.Size() ? arguments[startIndex + 1] : String::EMPTY;
  28. if (argument != "build")
  29. {
  30. errorMsg = "Unable to parse build command";
  31. return false;
  32. }
  33. if (!value.Length())
  34. {
  35. errorMsg = "Unable to parse build platform";
  36. return false;
  37. }
  38. buildPlatform_ = value.ToLower();
  39. return true;
  40. }
  41. void BuildCmd::HandleBuildComplete(StringHash eventType, VariantMap& eventData)
  42. {
  43. if (!eventData[BuildComplete::P_SUCCESS].GetBool())
  44. {
  45. Error("Build Failed");
  46. }
  47. else
  48. Finished();
  49. }
  50. void BuildCmd::Run()
  51. {
  52. LOGINFOF("Building project for: %s", buildPlatform_.CString());
  53. ToolSystem* tsystem = GetSubsystem<ToolSystem>();
  54. Project* project = tsystem->GetProject();
  55. Platform* platform = NULL;
  56. platform = tsystem->GetPlatformByName(buildPlatform_);
  57. if (!platform)
  58. {
  59. Error(ToString("Unknown build platform: %s", buildPlatform_.CString()));
  60. return;
  61. }
  62. if (!project->ContainsPlatform(platform->GetPlatformID()))
  63. {
  64. Error(ToString("Project does not contain platform: %s", buildPlatform_.CString()));
  65. return;
  66. }
  67. // create the build
  68. BuildBase* buildBase = platform->NewBuild(project);
  69. // add it to the build system
  70. BuildSystem* buildSystem = GetSubsystem<BuildSystem>();
  71. buildSystem->QueueBuild(buildBase);
  72. SubscribeToEvent(E_BUILDCOMPLETE, HANDLER(BuildCmd, HandleBuildComplete));
  73. // TODO: parallel/serial builds
  74. buildSystem->StartNextBuild();
  75. }
  76. }