BuildCmd.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. if (buildPlatform_ == "mac")
  50. platform = tsystem->GetPlatformByID(PLATFORMID_MAC);
  51. else if (buildPlatform_ == "web")
  52. platform = tsystem->GetPlatformByID(PLATFORMID_WEB);
  53. if (!platform)
  54. {
  55. Error(ToString("Unknown build platform: %s", buildPlatform_.CString()));
  56. return;
  57. }
  58. if (!project->ContainsPlatform(platform->GetPlatformID()))
  59. {
  60. Error(ToString("Project does not contain platform: %s", buildPlatform_.CString()));
  61. return;
  62. }
  63. // create the build
  64. BuildBase* buildBase = platform->NewBuild(project);
  65. // add it to the build system
  66. BuildSystem* buildSystem = GetSubsystem<BuildSystem>();
  67. buildSystem->QueueBuild(buildBase);
  68. SubscribeToEvent(E_BUILDCOMPLETE, HANDLER(BuildCmd, HandleBuildComplete));
  69. SubscribeToEvent(E_BUILDFAILED, HANDLER(BuildCmd, HandleBuildFailed));
  70. // TODO: parallel/serial builds
  71. buildSystem->StartNextBuild();
  72. }
  73. }