BuildMac.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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/IO/FileSystem.h>
  23. #include <Atomic/Resource/ResourceCache.h>
  24. #include "../ToolSystem.h"
  25. #include "../ToolEnvironment.h"
  26. #include "../Project/Project.h"
  27. #include "../Assets/AssetDatabase.h"
  28. #include "BuildEvents.h"
  29. #include "BuildSystem.h"
  30. #include "BuildMac.h"
  31. namespace ToolCore
  32. {
  33. BuildMac::BuildMac(Context * context, Project *project) : BuildBase(context, project, PLATFORMID_MAC)
  34. {
  35. }
  36. BuildMac::~BuildMac()
  37. {
  38. }
  39. void BuildMac::Initialize()
  40. {
  41. ToolSystem* tsystem = GetSubsystem<ToolSystem>();
  42. Project* project = tsystem->GetProject();
  43. Vector<String> defaultResourcePaths;
  44. GetDefaultResourcePaths(defaultResourcePaths);
  45. String projectResources = project->GetResourcePath();
  46. for (unsigned i = 0; i < defaultResourcePaths.Size(); i++)
  47. {
  48. AddResourceDir(defaultResourcePaths[i]);
  49. }
  50. // TODO: smart filtering of cache
  51. AddResourceDir(project->GetProjectPath() + "Cache/");
  52. AddResourceDir(projectResources);
  53. BuildResourceEntries();
  54. }
  55. bool BuildMac::CheckIncludeResourceFile(const String& resourceDir, const String& fileName)
  56. {
  57. // #623 BEGIN TODO: Skip files that have a converted version in the cache
  58. AssetDatabase* db = GetSubsystem<AssetDatabase>();
  59. String cachePath = db->GetCachePath();
  60. if (resourceDir != cachePath)
  61. {
  62. String ext = GetExtension(fileName);
  63. if (ext == ".jpg" || ext == ".png" || ext == ".tga")
  64. {
  65. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  66. String compressedPath = cachePath + "DDS/" + fileName + ".dds";
  67. if (fileSystem->FileExists(compressedPath))
  68. return false;
  69. }
  70. }
  71. // #623 END TODO
  72. return BuildBase::CheckIncludeResourceFile(resourceDir, fileName);
  73. }
  74. void BuildMac::Build(const String& buildPath)
  75. {
  76. ToolEnvironment* tenv = GetSubsystem<ToolEnvironment>();
  77. buildPath_ = AddTrailingSlash(buildPath) + GetBuildSubfolder();
  78. BuildLog("Starting Mac Deployment");
  79. Initialize();
  80. BuildSystem* buildSystem = GetSubsystem<BuildSystem>();
  81. if (!BuildClean(buildPath_))
  82. return;
  83. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  84. String appSrcPath = tenv->GetPlayerAppFolder();
  85. if (!BuildCreateDirectory(buildPath_))
  86. return;
  87. buildPath_ += "/AtomicPlayer.app";
  88. if (!BuildCreateDirectory(buildPath_))
  89. return;
  90. if (!BuildCreateDirectory(buildPath_ + "/Contents"))
  91. return;
  92. if (!BuildCreateDirectory(buildPath_ + "/Contents/MacOS"))
  93. return;
  94. if (!BuildCreateDirectory(buildPath_ + "/Contents/Resources"))
  95. return;
  96. String resourcePackagePath = buildPath_ + "/Contents/Resources/AtomicResources" + PAK_EXTENSION;
  97. GenerateResourcePackage(resourcePackagePath);
  98. if (!BuildCopyFile(appSrcPath + "/Contents/Resources/Atomic.icns", buildPath_ + "/Contents/Resources/Atomic.icns"))
  99. return;
  100. if (!BuildCopyFile(appSrcPath + "/Contents/Info.plist", buildPath_ + "/Contents/Info.plist"))
  101. return;
  102. if (!BuildCopyFile(appSrcPath + "/Contents/MacOS/AtomicPlayer", buildPath_ + "/Contents/MacOS/AtomicPlayer"))
  103. return;
  104. #ifdef ATOMIC_PLATFORM_OSX
  105. Vector<String> args;
  106. args.Push("+x");
  107. args.Push(buildPath_ + "/Contents/MacOS/AtomicPlayer");
  108. fileSystem->SystemRun("chmod", args);
  109. #endif
  110. BuildLog("Mac Deployment Complete");
  111. buildPath_ = buildPath + "/Mac-Build";
  112. buildSystem->BuildComplete(PLATFORMID_MAC, buildPath_);
  113. }
  114. }