BuildLinux.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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 <Poco/File.h>
  23. #include <Atomic/Core/StringUtils.h>
  24. #include <Atomic/IO/Log.h>
  25. #include <Atomic/IO/FileSystem.h>
  26. #include <Atomic/Resource/ResourceCache.h>
  27. #include "../ToolSystem.h"
  28. #include "../ToolEnvironment.h"
  29. #include "../Project/Project.h"
  30. #include "../Project/ProjectSettings.h"
  31. #include "../Assets/AssetDatabase.h"
  32. #include "BuildLinux.h"
  33. #include "BuildSystem.h"
  34. #include "BuildEvents.h"
  35. namespace ToolCore
  36. {
  37. BuildLinux::BuildLinux(Context * context, Project *project) : BuildBase(context, project, PLATFORMID_LINUX)
  38. {
  39. }
  40. BuildLinux::~BuildLinux()
  41. {
  42. }
  43. void BuildLinux::Initialize()
  44. {
  45. ToolSystem* tsystem = GetSubsystem<ToolSystem>();
  46. Project* project = tsystem->GetProject();
  47. Vector<String> defaultResourcePaths;
  48. GetDefaultResourcePaths(defaultResourcePaths);
  49. for (unsigned i = 0; i < defaultResourcePaths.Size(); i++)
  50. {
  51. AddResourceDir(defaultResourcePaths[i]);
  52. }
  53. BuildDefaultResourceEntries();
  54. // Include the project resources and cache separately
  55. AddProjectResourceDir(project->GetResourcePath());
  56. AssetDatabase* db = GetSubsystem<AssetDatabase>();
  57. String cachePath = db->GetCachePath();
  58. AddProjectResourceDir(cachePath);
  59. BuildProjectResourceEntries();
  60. }
  61. bool BuildLinux::CheckIncludeResourceFile(const String& resourceDir, const String& fileName)
  62. {
  63. // #623 BEGIN TODO: Skip files that have a converted version in the cache
  64. AssetDatabase* db = GetSubsystem<AssetDatabase>();
  65. String cachePath = db->GetCachePath();
  66. if (resourceDir != cachePath)
  67. {
  68. String ext = GetExtension(fileName);
  69. if (ext == ".jpg" || ext == ".png" || ext == ".tga")
  70. {
  71. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  72. String compressedPath = cachePath + "DDS/" + fileName + ".dds";
  73. if (fileSystem->FileExists(compressedPath))
  74. return false;
  75. }
  76. }
  77. // #623 END TODO
  78. return BuildBase::CheckIncludeResourceFile(resourceDir, fileName);
  79. }
  80. void BuildLinux::BuildNative(const String& buildPath)
  81. {
  82. BuildLog("Building Linux Application");
  83. ToolEnvironment* tenv = GetSubsystem<ToolEnvironment>();
  84. String playerBinary = tenv->GetPlayerBinary();
  85. if (!BuildCopyFile(playerBinary, buildPath_ + "/AtomicPlayer"))
  86. return;
  87. // to perpetuate the execute bits on the executable
  88. String copiedFile = buildPath_ + "/AtomicPlayer";
  89. Poco::File deploy(copiedFile.CString());
  90. if (deploy.exists())
  91. deploy.setExecutable(true);
  92. }
  93. void BuildLinux::Build(const String& buildPath)
  94. {
  95. BuildSystem* buildSystem = GetSubsystem<BuildSystem>();
  96. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  97. ToolEnvironment* tenv = GetSubsystem<ToolEnvironment>();
  98. ToolSystem* tsystem = GetSubsystem<ToolSystem>();
  99. Project* project = tsystem->GetProject();
  100. buildPath_ = AddTrailingSlash(buildPath);
  101. if (!resourcesOnly_)
  102. buildPath_ += GetBuildSubfolder();
  103. BuildLog("Starting Linux Deployment");
  104. Initialize();
  105. if (!resourcesOnly_ && !BuildClean(buildPath_))
  106. return;
  107. String rootSourceDir = tenv->GetRootSourceDir();
  108. if (!BuildCreateDirectory(buildPath_))
  109. return;
  110. if (!resourcesOnly_ && !BuildCreateDirectory(buildPath_ + "/AtomicPlayer_Resources"))
  111. return;
  112. String resourcePackagePath = buildPath_ + "/AtomicPlayer_Resources/AtomicResources" + PAK_EXTENSION;
  113. if (resourcesOnly_)
  114. {
  115. resourcePackagePath = buildPath_ + "/AtomicResources" + PAK_EXTENSION;
  116. }
  117. GenerateResourcePackage(resourcePackagePath);
  118. if (buildFailed_)
  119. return;
  120. if (resourcesOnly_)
  121. return;
  122. if (!BuildCreateDirectory(buildPath_ + "/Settings"))
  123. return;
  124. String engineJSON(GetSettingsDirectory() + "/Engine.json");
  125. if (fileSystem->FileExists(engineJSON))
  126. {
  127. if (!BuildCopyFile(engineJSON, buildPath_ + "/Settings/Engine.json"))
  128. return;
  129. }
  130. // TODO: only builds non-managed projects
  131. BuildNative(buildPath);
  132. BuildLog("Linux Deployment Complete");
  133. buildSystem->BuildComplete(PLATFORMID_LINUX, buildPath_);
  134. }
  135. }