BuildCmd.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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/StringUtils.h>
  23. #include <Atomic/IO/Log.h>
  24. #include <Atomic/IO/File.h>
  25. #include "../ToolSystem.h"
  26. #include "../Project/Project.h"
  27. #include "../Build/BuildEvents.h"
  28. #include "../Build/BuildSystem.h"
  29. #include "../Build/AssetBuildConfig.h"
  30. #include "BuildCmd.h"
  31. #include <Poco/File.h>
  32. namespace ToolCore
  33. {
  34. BuildCmd::BuildCmd(Context* context) :
  35. Command(context),
  36. autoLog_(false),
  37. verbose_(false)
  38. {
  39. }
  40. BuildCmd::~BuildCmd()
  41. {
  42. }
  43. bool BuildCmd::ParseInternal(const Vector<String>& arguments, unsigned startIndex, String& errorMsg)
  44. {
  45. String argument = arguments[startIndex].ToLower();
  46. String value = startIndex + 1 < arguments.Size() ? arguments[startIndex + 1] : String::EMPTY;
  47. if (argument != "build")
  48. {
  49. errorMsg = "Unable to parse build command";
  50. return false;
  51. }
  52. if (!value.Length())
  53. {
  54. errorMsg = "Unable to parse build platform";
  55. return false;
  56. }
  57. buildPlatform_ = value.ToLower();
  58. for (int i = startIndex + 2; i < arguments.Size(); ++i)
  59. {
  60. String option = arguments[i].ToLower();
  61. if (option == "-tag")
  62. {
  63. if (arguments.Size() == i + 1)
  64. {
  65. errorMsg = "Missing tag";
  66. return false;
  67. }
  68. }
  69. else if (option == "-autolog")
  70. {
  71. autoLog_ = true;
  72. }
  73. else if (option == "-verbose")
  74. {
  75. verbose_ = true;
  76. }
  77. }
  78. String tag = startIndex + 2 < arguments.Size() ? arguments[startIndex + 2] : String::EMPTY;
  79. assetsBuildTag_ = tag.ToLower();
  80. return true;
  81. }
  82. void BuildCmd::HandleBuildComplete(StringHash eventType, VariantMap& eventData)
  83. {
  84. if (!eventData[BuildComplete::P_SUCCESS].GetBool())
  85. {
  86. Error("Build Failed");
  87. }
  88. else
  89. Finished();
  90. }
  91. void BuildCmd::Run()
  92. {
  93. ATOMIC_LOGINFOF("Building project for: %s", buildPlatform_.CString());
  94. ToolSystem* tsystem = GetSubsystem<ToolSystem>();
  95. Project* project = tsystem->GetProject();
  96. Platform* platform = NULL;
  97. platform = tsystem->GetPlatformByName(buildPlatform_);
  98. if (!platform)
  99. {
  100. Error(ToString("Unknown build platform: %s", buildPlatform_.CString()));
  101. return;
  102. }
  103. // create the build
  104. BuildBase* buildBase = platform->NewBuild(project);
  105. if (!assetsBuildTag_.Empty())
  106. {
  107. buildBase->SetAssetBuildTag(assetsBuildTag_);
  108. }
  109. buildBase->SetAutoLog(autoLog_);
  110. buildBase->SetVerbose(verbose_);
  111. // add it to the build system
  112. BuildSystem* buildSystem = GetSubsystem<BuildSystem>();
  113. buildSystem->QueueBuild(buildBase);
  114. SubscribeToEvent(E_BUILDCOMPLETE, ATOMIC_HANDLER(BuildCmd, HandleBuildComplete));
  115. // TODO: parallel/serial builds
  116. buildSystem->StartNextBuild();
  117. }
  118. }