BuildCmd.cpp 2.1 KB

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