BuildWindows.cpp 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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/FileSystem.h>
  24. #include <Atomic/Resource/ResourceCache.h>
  25. #include "../ToolSystem.h"
  26. #include "../ToolEnvironment.h"
  27. #include "../Project/Project.h"
  28. #include "BuildWindows.h"
  29. #include "BuildSystem.h"
  30. #include "BuildEvents.h"
  31. namespace ToolCore
  32. {
  33. BuildWindows::BuildWindows(Context * context, Project *project) : BuildBase(context, project, PLATFORMID_WINDOWS)
  34. {
  35. }
  36. BuildWindows::~BuildWindows()
  37. {
  38. }
  39. void BuildWindows::Initialize()
  40. {
  41. ToolSystem* tsystem = GetSubsystem<ToolSystem>();
  42. Project* project = tsystem->GetProject();
  43. Vector<String> defaultResourcePaths;
  44. GetDefaultResourcePaths(defaultResourcePaths);
  45. for (unsigned i = 0; i < defaultResourcePaths.Size(); i++)
  46. {
  47. AddResourceDir(defaultResourcePaths[i]);
  48. }
  49. AddResourceDir(project->GetProjectPath() + "Cache/");
  50. BuildResourceEntries();
  51. String projectResources = project->GetResourcePath();
  52. BuildProjectResourceEntries();
  53. // TODO: smart filtering of cache
  54. //AddResourceDir(projectResources);
  55. //BuildResourceEntries();
  56. }
  57. void BuildWindows::BuildAtomicNET()
  58. {
  59. // AtomicNET
  60. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  61. ToolEnvironment* tenv = GetSubsystem<ToolEnvironment>();
  62. ToolSystem* tsystem = GetSubsystem<ToolSystem>();
  63. Project* project = tsystem->GetProject();
  64. String projectResources = project->GetResourcePath();
  65. String assembliesPath = projectResources + "Assemblies/";
  66. // if no assemblies path, no need to install AtomicNET
  67. if (!fileSystem->DirExists(assembliesPath))
  68. return;
  69. Vector<String> results;
  70. fileSystem->ScanDir(results, assembliesPath, "*.dll", SCAN_FILES, true);
  71. // if no assembiles in Assemblies path, no need to install AtomicNET
  72. if (!results.Size())
  73. return;
  74. BuildLog("Building AtomicNET");
  75. fileSystem->CreateDir(buildPath_ + "/AtomicPlayer_Resources/AtomicNET");
  76. fileSystem->CreateDir(buildPath_ + "/AtomicPlayer_Resources/AtomicNET/Atomic");
  77. fileSystem->CreateDir(buildPath_ + "/AtomicPlayer_Resources/AtomicNET/Atomic/Assemblies");
  78. fileSystem->CopyDir(tenv->GetNETCoreCLRAbsPath(), buildPath_ + "/AtomicPlayer_Resources/AtomicNET/CoreCLR");
  79. fileSystem->CopyDir(tenv->GetNETTPAPaths(), buildPath_ + "/AtomicPlayer_Resources/AtomicNET/Atomic/TPA");
  80. // Atomic Assemblies
  81. const String& assemblyLoadPaths = tenv->GetNETAssemblyLoadPaths();
  82. Vector<String> paths = assemblyLoadPaths.Split(';');
  83. for (unsigned i = 0; i < paths.Size(); i++)
  84. {
  85. Vector<String> loadResults;
  86. fileSystem->ScanDir(loadResults, paths[i], "*.dll", SCAN_FILES, true);
  87. for (unsigned j = 0; j < loadResults.Size(); j++)
  88. {
  89. String pathName, fileName, ext;
  90. SplitPath(loadResults[j], pathName, fileName, ext);
  91. if (fileName != "AtomicNETEngine")
  92. continue;
  93. fileSystem->Copy(paths[i] + "/" + loadResults[j], ToString("%s/AtomicPlayer_Resources/AtomicNET/Atomic/Assemblies/%s.dll", buildPath_.CString(), fileName.CString()));
  94. }
  95. }
  96. // Project assemblied
  97. for (unsigned i = 0; i < results.Size(); i++)
  98. {
  99. String pathName, fileName, ext;
  100. SplitPath(results[i], pathName, fileName, ext);
  101. fileSystem->Copy(assembliesPath + results[i], ToString("%s/AtomicPlayer_Resources/AtomicNET/Atomic/Assemblies/%s.dll", buildPath_.CString(), fileName.CString()));
  102. }
  103. }
  104. void BuildWindows::Build(const String& buildPath)
  105. {
  106. ToolEnvironment* tenv = GetSubsystem<ToolEnvironment>();
  107. buildPath_ = AddTrailingSlash(buildPath) + GetBuildSubfolder();
  108. BuildLog("Starting Windows Deployment");
  109. Initialize();
  110. if (!BuildClean(buildPath_))
  111. return;
  112. BuildSystem* buildSystem = GetSubsystem<BuildSystem>();
  113. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  114. String rootSourceDir = tenv->GetRootSourceDir();
  115. String playerBinary = tenv->GetPlayerBinary();
  116. String d3d9dll = GetPath(playerBinary) + "/D3DCompiler_47.dll";
  117. if (!BuildCreateDirectory(buildPath_))
  118. return;
  119. if (!BuildCreateDirectory(buildPath_ + "/AtomicPlayer_Resources"))
  120. return;
  121. String resourcePackagePath = buildPath_ + "/AtomicPlayer_Resources/AtomicResources" + PAK_EXTENSION;
  122. GenerateResourcePackage(resourcePackagePath);
  123. if (buildFailed_)
  124. return;
  125. if (!BuildCreateDirectory(buildPath_ + "/Settings"))
  126. return;
  127. String engineJSON(GetSettingsDirectory() + "/Engine.json");
  128. if (fileSystem->FileExists(engineJSON))
  129. {
  130. if (!BuildCopyFile(engineJSON, buildPath_ + "/Settings/Engine.json"))
  131. return;
  132. }
  133. if (!BuildCopyFile(playerBinary, buildPath_ + "/AtomicPlayer.exe"))
  134. return;
  135. if (!BuildCopyFile(d3d9dll, buildPath_ + "/D3DCompiler_47.dll"))
  136. return;
  137. BuildAtomicNET();
  138. BuildLog("Windows Deployment Complete");
  139. buildSystem->BuildComplete(PLATFORMID_WINDOWS, buildPath_);
  140. }
  141. }