From 401b3b42b9731e83c938f732ede8e458dee30162 Mon Sep 17 00:00:00 2001 From: Josh Engebretson Date: Fri, 9 Sep 2016 14:44:47 -0700 Subject: [PATCH] Support for Android platform on redistibutable editor builds: Build_AtomicEditor.bat --with-android --- Build/Scripts/BuildAndroid.js | 2 +- Build/Scripts/BuildWindows.js | 36 +++++++++++---- Build/Scripts/Windows/CompileAtomicEditor.bat | 1 - Build_AtomicEditor.bat | 30 ++++++++++++- .../CSharpLanguageExtension.ts | 14 ++++++ Source/ToolCore/Build/BuildBase.h | 3 ++ Source/ToolCore/Build/BuildWindows.cpp | 16 +++++-- Source/ToolCore/NETTools/NETProjectGen.cpp | 9 +++- Source/ToolCore/NETTools/NETProjectSystem.cpp | 44 +++++++++++++++++++ Source/ToolCore/NETTools/NETProjectSystem.h | 1 + 10 files changed, 139 insertions(+), 17 deletions(-) diff --git a/Build/Scripts/BuildAndroid.js b/Build/Scripts/BuildAndroid.js index d1ec920965..fa2af0e9ed 100644 --- a/Build/Scripts/BuildAndroid.js +++ b/Build/Scripts/BuildAndroid.js @@ -8,7 +8,7 @@ var buildDir = host.artifactsRoot + "Build/Android/"; namespace('build', function() { - task('android_player', ["build:atomiceditor"], { + task('android_native', { async: true }, function() { diff --git a/Build/Scripts/BuildWindows.js b/Build/Scripts/BuildWindows.js index 6f53313ec4..c2130b8ee9 100644 --- a/Build/Scripts/BuildWindows.js +++ b/Build/Scripts/BuildWindows.js @@ -11,7 +11,9 @@ namespace('build', function() { // Builds a standalone Atomic Editor, which can be distributed out of build tree task('atomiceditor', { async: true - }, function() { +}, function(android) { + + android = android == "android" ? true : false; // Clean build var cleanBuild = true; @@ -27,6 +29,17 @@ namespace('build', function() { // Build the AtomicEditor cmds.push(atomicRoot + "Build/Scripts/Windows/CompileAtomicEditor.bat"); + cmds.push(host.atomicTool + " net compile " + atomicRoot + "Script/AtomicNET/AtomicNETProject.json " + (android ? "ANDROID" : "WINDOWS") + " Release"); + + function copyAtomicNET() { + + fs.copySync(atomicRoot + "Artifacts/AtomicNET/Release", + editorAppFolder + "Resources/ToolData/AtomicNET/Release"); + + fs.copySync(atomicRoot + "Script/AtomicNET/AtomicProject.json", + editorAppFolder + "Resources/ToolData/AtomicNET/Build/Projects/AtomicProject.json"); + + } jake.exec(cmds, function() { @@ -56,17 +69,24 @@ namespace('build', function() { fs.copySync(buildDir + "Source/AtomicPlayer/Application/Release/D3DCompiler_47.dll", editorAppFolder + "Resources/ToolData/Deployment/Windows/x64/D3DCompiler_47.dll"); - // AtomicNET + if (android) { - fs.copySync(atomicRoot + "Artifacts/AtomicNET/Release", - editorAppFolder + "Resources/ToolData/AtomicNET/Release"); + var androidNativeTask = jake.Task['build:android_native']; - fs.copySync(atomicRoot + "Script/AtomicNET/AtomicProject.json", - editorAppFolder + "Resources/ToolData/AtomicNET/Build/Projects/AtomicProject.json"); + androidNativeTask.addListener('complete', function () { + copyAtomicNET(); + console.log("\nAtomic Editor build to ", editorAppFolder); + complete(); + }); - console.log("Atomic Editor build to ", editorAppFolder); + androidNativeTask.invoke(); - complete(); + } + else { + copyAtomicNET(); + console.log("\nAtomic Editor build to ", editorAppFolder); + complete(); + } }, { printStdout: true diff --git a/Build/Scripts/Windows/CompileAtomicEditor.bat b/Build/Scripts/Windows/CompileAtomicEditor.bat index d1b36b1a42..9ea8443801 100644 --- a/Build/Scripts/Windows/CompileAtomicEditor.bat +++ b/Build/Scripts/Windows/CompileAtomicEditor.bat @@ -1,4 +1,3 @@ call "%VS140COMNTOOLS%..\..\VC\bin\amd64\vcvars64.bat" cmake ..\\..\\..\\ -DATOMIC_DEV_BUILD=0 -G "Visual Studio 14 2015 Win64" msbuild /m Atomic.sln /t:AtomicEditor /t:AtomicPlayer /t:AtomicNETNative /p:Configuration=Release /p:Platform=x64 -msbuild Source/AtomicTool/GenerateAtomicNET.vcxproj /p:Configuration=Release /p:Platform=x64 diff --git a/Build_AtomicEditor.bat b/Build_AtomicEditor.bat index 0b5fe5247e..3477693c94 100644 --- a/Build_AtomicEditor.bat +++ b/Build_AtomicEditor.bat @@ -1,11 +1,37 @@ -@ECHO OFF +@echo OFF +setlocal enabledelayedexpansion + +set ATOMICEDITOR_BUILD_CMD=Build\Windows\node\node.exe Build\node_modules\jake\bin\cli.js -f ./Build/Scripts/Bootstrap.js build:atomiceditor + +for %%a in (%*) do ( + if /I "%%a"=="--with-android" (set ATOMICEDITOR_ANDROID=YES) +) + +:: If we're building in android support, make sure ANDROID_NDK is defined +if "%ATOMICEDITOR_ANDROID%" == "YES" ( + + if "%ANDROID_NDK%" == "" ( + @echo: + echo ANDROID_NDK not set, exiting + @echo: + exit /B + ) + + @echo: + echo Building Atomic Editor with Android support + @echo: + set ATOMICEDITOR_BUILD_CMD=!ATOMICEDITOR_BUILD_CMD!["android"] +) + @echo: @echo: ECHO Building Atomic Editor, this process will take a few minutes @echo: @echo: PAUSE -Build\Windows\node\node.exe Build\node_modules\jake\bin\cli.js -f ./Build/Scripts/Bootstrap.js build:atomiceditor +%ATOMICEDITOR_BUILD_CMD% @echo: @echo: PAUSE + +endlocal diff --git a/Script/AtomicEditor/hostExtensions/languageExtensions/CSharpLanguageExtension.ts b/Script/AtomicEditor/hostExtensions/languageExtensions/CSharpLanguageExtension.ts index 2c5243fd56..f335de9f09 100644 --- a/Script/AtomicEditor/hostExtensions/languageExtensions/CSharpLanguageExtension.ts +++ b/Script/AtomicEditor/hostExtensions/languageExtensions/CSharpLanguageExtension.ts @@ -67,6 +67,7 @@ export default class CSharpLanguageExtension implements Editor.HostExtensions.Re menu.addItem(new Atomic.UIMenuItem("Open Solution", `${this.name}.opensolution`)); menu.addItem(new Atomic.UIMenuItem("Compile Project", `${this.name}.compileproject`)); menu.addItem(new Atomic.UIMenuItem("Generate Solution", `${this.name}.generatesolution`)); + menu.addItem(new Atomic.UIMenuItem("Package Resources", `${this.name}.packageresources`)); this.compileOnSaveMenuItem = new Atomic.UIMenuItem(`Compile on Save: ${isCompileOnSave ? "On" : "Off"}`, `${this.name}.compileonsave`); menu.addItem(this.compileOnSaveMenuItem); @@ -201,6 +202,9 @@ export default class CSharpLanguageExtension implements Editor.HostExtensions.Re case "generatesolution": this.generateSolution(); return true; + case "packageresources": + this.packageResources(); + return true; case "compileonsave": let isCompileOnSave = this.serviceRegistry.projectServices.getUserPreference(this.name, "CompileOnSave", false); // Toggle @@ -243,5 +247,15 @@ export default class CSharpLanguageExtension implements Editor.HostExtensions.Re } + /** + * Generate Solution + */ + packageResources() { + + if (ToolCore.netProjectSystem) { + ToolCore.netProjectSystem.generateResourcePak(); + } + + } } diff --git a/Source/ToolCore/Build/BuildBase.h b/Source/ToolCore/Build/BuildBase.h index 9018ecccc7..d6766e7e4a 100644 --- a/Source/ToolCore/Build/BuildBase.h +++ b/Source/ToolCore/Build/BuildBase.h @@ -81,6 +81,9 @@ friend class AndroidProjectGenerator; bool GetResourcesOnly() const { return resourcesOnly_; } void SetResourcesOnly(bool resourcesOnly = true) { resourcesOnly_ = resourcesOnly; } + bool GetBuildFailed() const { return buildFailed_; } + const Vector& GetBuildErrors() const { return buildErrors_; } + protected: bool BuildClean(const String& path); diff --git a/Source/ToolCore/Build/BuildWindows.cpp b/Source/ToolCore/Build/BuildWindows.cpp index ba5ed44d99..4e0933038b 100644 --- a/Source/ToolCore/Build/BuildWindows.cpp +++ b/Source/ToolCore/Build/BuildWindows.cpp @@ -173,13 +173,16 @@ void BuildWindows::Build(const String& buildPath) ToolSystem* tsystem = GetSubsystem(); Project* project = tsystem->GetProject(); - buildPath_ = AddTrailingSlash(buildPath) + GetBuildSubfolder(); + buildPath_ = AddTrailingSlash(buildPath); + if (!resourcesOnly_) + buildPath_ += GetBuildSubfolder(); + BuildLog("Starting Windows Deployment"); Initialize(); - if (!BuildClean(buildPath_)) + if (!resourcesOnly_ && !BuildClean(buildPath_)) return; String rootSourceDir = tenv->GetRootSourceDir(); @@ -187,11 +190,18 @@ void BuildWindows::Build(const String& buildPath) if (!BuildCreateDirectory(buildPath_)) return; - if (!BuildCreateDirectory(buildPath_ + "/AtomicPlayer_Resources")) + if (!resourcesOnly_ && !BuildCreateDirectory(buildPath_ + "/AtomicPlayer_Resources")) return; String resourcePackagePath = buildPath_ + "/AtomicPlayer_Resources/AtomicResources" + PAK_EXTENSION; + + if (resourcesOnly_) + { + resourcePackagePath = buildPath_ + "/AtomicResources" + PAK_EXTENSION; + } + GenerateResourcePackage(resourcePackagePath); + if (buildFailed_) return; diff --git a/Source/ToolCore/NETTools/NETProjectGen.cpp b/Source/ToolCore/NETTools/NETProjectGen.cpp index e7876997a2..84f8afc8a9 100644 --- a/Source/ToolCore/NETTools/NETProjectGen.cpp +++ b/Source/ToolCore/NETTools/NETProjectGen.cpp @@ -219,20 +219,25 @@ namespace ToolCore { if (GetIsPCL()) { + ref = "AtomicNET"; platform = "Portable"; } else if (SupportsDesktop()) { + ref = "AtomicNET"; platform = "Desktop"; } else if (SupportsPlatform("android")) { + if (ref != "AtomicNET.Android.SDL") + ref = "AtomicNET"; + platform = "Android"; } if (platform.Length()) { - String atomicNETAssembly = tenv->GetAtomicNETCoreAssemblyDir() + ToString("%s/AtomicNET.dll", platform.CString(), ref.CString()); + String atomicNETAssembly = tenv->GetAtomicNETCoreAssemblyDir() + ToString("%s/%s.dll", platform.CString(), ref.CString()); xref = igroup.CreateChild("Reference"); xref.SetAttribute("Include", atomicNETAssembly); } @@ -617,7 +622,7 @@ namespace ToolCore #endif // TODO: more than armeabi-v7a (which this is) - String nativePath = AddTrailingSlash(tenv->GetAtomicNETRootDir()) + config + "/Android/Native/libAtomicNETNative.so"; + String nativePath = AddTrailingSlash(tenv->GetAtomicNETRootDir()) + config + "/Native/Android/libAtomicNETNative.so"; XMLElement nativeLibrary = projectRoot.CreateChild("ItemGroup").CreateChild("AndroidNativeLibrary"); nativeLibrary.SetAttribute("Include", nativePath); diff --git a/Source/ToolCore/NETTools/NETProjectSystem.cpp b/Source/ToolCore/NETTools/NETProjectSystem.cpp index eec641fb99..6f55d04780 100644 --- a/Source/ToolCore/NETTools/NETProjectSystem.cpp +++ b/Source/ToolCore/NETTools/NETProjectSystem.cpp @@ -35,6 +35,8 @@ #include "../Project/ProjectSettings.h" #include "../Project/ProjectEvents.h" +#include "../Build/BuildSystem.h" + #include "../Subprocess/SubprocessSystem.h" #include "NETProjectGen.h" @@ -199,6 +201,34 @@ namespace ToolCore } } + bool NETProjectSystem::GenerateResourcePak() + { + ToolSystem* tsystem = GetSubsystem(); + Project* project = tsystem->GetProject(); + BuildSystem* buildSystem = GetSubsystem(); + + // TODO: We just use WINDOWS platform for PAK generation for now + Platform* platform = tsystem->GetPlatformByName("WINDOWS"); + + buildSystem->SetBuildPath(project->GetProjectPath() + "AtomicNET/Resources/"); + + SharedPtr buildBase(platform->NewBuild(project)); + buildBase->SetResourcesOnly(true); + buildBase->SetVerbose(true); + buildSystem->QueueBuild(buildBase); + buildSystem->StartNextBuild(); + + if (buildBase->GetBuildFailed()) + { + const StringVector& errors = buildBase->GetBuildErrors(); + ATOMIC_LOGERRORF("NETProjectSystem::GenerateSolution - Unable to Build Resources.pak: %s", errors.Size() ? errors[0].CString() : "Unknown Error"); + return false; + } + + return true; + + } + bool NETProjectSystem::GenerateSolution() { ToolSystem* tsystem = GetSubsystem(); @@ -210,6 +240,20 @@ namespace ToolCore return false; } + // TODO: Generalize and move me + if (project->GetSupportsPlatform("android")) + { + FileSystem* fileSystem = GetSubsystem(); + + if (!fileSystem->FileExists(project->GetProjectPath() + "AtomicNET/Resources/AtomicResources.pak")) + { + if (!GenerateResourcePak()) + return false; + + } + + } + SharedPtr gen(new NETProjectGen(context_)); if (!gen->LoadAtomicProject(project->GetProjectPath())) diff --git a/Source/ToolCore/NETTools/NETProjectSystem.h b/Source/ToolCore/NETTools/NETProjectSystem.h index 2ea136c7a0..25233ffd0d 100644 --- a/Source/ToolCore/NETTools/NETProjectSystem.h +++ b/Source/ToolCore/NETTools/NETProjectSystem.h @@ -63,6 +63,7 @@ namespace ToolCore void OpenSourceFile(const String& sourceFilePath); bool GenerateSolution(); + bool GenerateResourcePak(); private: