Browse Source

Support compile on save for C# when not using VS, mono environment cleanups

Josh Engebretson 9 years ago
parent
commit
6bceb75dd8

+ 28 - 4
Script/AtomicEditor/hostExtensions/languageExtensions/CSharpLanguageExtension.ts

@@ -60,11 +60,17 @@ export default class CSharpLanguageExtension implements Editor.HostExtensions.Re
 
 
         if (this.isNETProject && !this.menuCreated) {
         if (this.isNETProject && !this.menuCreated) {
 
 
+            const isCompileOnSave = this.serviceRegistry.projectServices.getUserPreference(this.name, "CompileOnSave", false);
+
             // Build the menu - First build up an empty menu then manually add the items so we can have reference to them
             // Build the menu - First build up an empty menu then manually add the items so we can have reference to them
             const menu = this.serviceRegistry.uiServices.createPluginMenuItemSource("AtomicNET", {});
             const menu = this.serviceRegistry.uiServices.createPluginMenuItemSource("AtomicNET", {});
             menu.addItem(new Atomic.UIMenuItem("Open Solution", `${this.name}.opensolution`));
             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("Compile Project", `${this.name}.compileproject`));
             menu.addItem(new Atomic.UIMenuItem("Generate Solution", `${this.name}.generatesolution`));
             menu.addItem(new Atomic.UIMenuItem("Generate Solution", `${this.name}.generatesolution`));
+
+            this.compileOnSaveMenuItem = new Atomic.UIMenuItem(`Compile on Save: ${isCompileOnSave ? "On" : "Off"}`, `${this.name}.compileonsave`);
+            menu.addItem(this.compileOnSaveMenuItem);
+
             this.menuCreated = true;
             this.menuCreated = true;
         }
         }
 
 
@@ -119,12 +125,24 @@ export default class CSharpLanguageExtension implements Editor.HostExtensions.Re
     */
     */
     save(ev: Editor.EditorEvents.SaveResourceEvent) {
     save(ev: Editor.EditorEvents.SaveResourceEvent) {
 
 
+        if (Atomic.getExtension(ev.path) != ".cs") {
+            return;
+        }
+
         // let's check to see if we have created a csharp file
         // let's check to see if we have created a csharp file
         if (!this.isNETProject) {
         if (!this.isNETProject) {
-            if (Atomic.getExtension(ev.path) == ".cs") {
-                this.isNETProject = true;
-            }
+            this.isNETProject = true;
         }
         }
+
+        const isCompileOnSave = this.serviceRegistry.projectServices.getUserPreference(this.name, "CompileOnSave", false);
+
+        if (isCompileOnSave && ToolCore.netProjectSystem) {
+
+            // for now, only support compile on save when not using VS
+            if (!ToolCore.netProjectSystem.visualStudioAvailable)
+                ToolCore.netProjectSystem.buildAtomicProject();
+        }
+
     }
     }
 
 
     /*** ProjectService implementation ****/
     /*** ProjectService implementation ****/
@@ -183,7 +201,13 @@ export default class CSharpLanguageExtension implements Editor.HostExtensions.Re
                 case "generatesolution":
                 case "generatesolution":
                     this.generateSolution();
                     this.generateSolution();
                     return true;
                     return true;
-
+                case "compileonsave":
+                    let isCompileOnSave = this.serviceRegistry.projectServices.getUserPreference(this.name, "CompileOnSave", false);
+                    // Toggle
+                    isCompileOnSave = !isCompileOnSave;
+                    this.serviceRegistry.projectServices.setUserPreference(this.name, "CompileOnSave", isCompileOnSave);
+                    this.compileOnSaveMenuItem.string = `Compile on Save: ${isCompileOnSave ? "On" : "Off"}`;
+                    return true;
             }
             }
         }
         }
     }
     }

+ 5 - 0
Script/AtomicNET/AtomicNET/Core/Constants.cs

@@ -7,7 +7,12 @@ namespace AtomicEngine
 
 
     public static partial class Constants
     public static partial class Constants
     {
     {
+
+#if __MonoCS__
+        public const string LIBNAME = "AtomicNETNative";
+#else
         public const string LIBNAME = "AtomicNETNative.dll";
         public const string LIBNAME = "AtomicNETNative.dll";
+#endif
 
 
     }
     }
 
 

+ 1 - 1
Source/AtomicEditor/EditorMode/AEEditorMode.cpp

@@ -186,7 +186,7 @@ bool EditorMode::PlayProject(String addArgs, bool debug)
 #ifndef ATOMIC_PLATFORM_WINDOWS
 #ifndef ATOMIC_PLATFORM_WINDOWS
 
 
     vargs.Insert(0, playerBinary);
     vargs.Insert(0, playerBinary);
-    playerBinary = "/Library/Frameworks/Mono.framework/Versions/Current/Commands/mono64";
+    playerBinary = tenv->GetMonoExecutableDir() + "mono64";
 
 
 #endif
 #endif
 
 

+ 0 - 3
Source/AtomicNET/NETNative/NETServiceApplication.cpp

@@ -51,9 +51,6 @@ namespace Atomic
         // NETService is always headless
         // NETService is always headless
         engineParameters_["Headless"] = true;
         engineParameters_["Headless"] = true;
 
 
-        // FIXME AtomicNET:
-        // engineParameters_["ResourcePrefixPaths"] = "C:/Dev/atomic/AtomicGameEngine/Resources/";
-
         FileSystem* filesystem = GetSubsystem<FileSystem>();
         FileSystem* filesystem = GetSubsystem<FileSystem>();
         engineParameters_.InsertNew("LogName", filesystem->GetAppPreferencesDir("AtomicEditor", "Logs") + "NETServiceApplication.log");
         engineParameters_.InsertNew("LogName", filesystem->GetAppPreferencesDir("AtomicEditor", "Logs") + "NETServiceApplication.log");
 
 

+ 6 - 17
Source/ToolCore/NETTools/AtomicNETService.cpp

@@ -54,30 +54,19 @@ namespace ToolCore
     {
     {
         // TODO: Needs to handle deployed tooling, release builds
         // TODO: Needs to handle deployed tooling, release builds
 
 
-        execPath = String::EMPTY;
-        args.Clear();
-
-#ifdef ATOMIC_PLATFORM_WINDOWS
-
         ToolEnvironment* tenv = GetSubsystem<ToolEnvironment>();
         ToolEnvironment* tenv = GetSubsystem<ToolEnvironment>();
 
 
-#ifdef _DEBUG
+        execPath = String::EMPTY;
+        args.Clear();
 
 
-        String config = "Debug";
-#else
-        String config = "Release";
-#endif
+#ifdef ATOMIC_PLATFORM_WINDOWS        
 
 
         execPath = tenv->GetAtomicNETCoreAssemblyDir() + "/AtomicNETService.exe";
         execPath = tenv->GetAtomicNETCoreAssemblyDir() + "/AtomicNETService.exe";
 
 
-#elif ATOMIC_PLATFORM_OSX
-
-        execPath = "/usr/local/share/dotnet/dotnet";
+#elif defined ATOMIC_PLATFORM_OSX
 
 
-        args.Push("exec");
-        args.Push("--additionalprobingpath");
-        args.Push("/Users/josh/.nuget/packages");
-        args.Push("/Users/josh/Dev/atomic/AtomicGameEngine/Script/AtomicNET/AtomicNETService/bin/Debug/netcoreapp1.0/AtomicNETService.exe");
+        execPath = tenv->GetMonoExecutableDir() + "mono64";
+        args.Push(tenv->GetAtomicNETCoreAssemblyDir() + "AtomicNETService.exe");
 
 
 #endif
 #endif
 
 

+ 4 - 2
Source/ToolCore/NETTools/NETBuildSystem.cpp

@@ -290,12 +290,14 @@ namespace ToolCore
             String cmd = "bash";
             String cmd = "bash";
             args.Push("-c");
             args.Push("-c");
 
 
+            String xbuildBinary = tenv->GetMonoExecutableDir() + "xbuild";
+
             if (requiresNuGet)
             if (requiresNuGet)
             {
             {
-                compile += ToString("/Library/Frameworks/Mono.framework/Versions/Current/Commands/nuget restore \"%s\" && ", solutionPath.CString());
+                compile += ToString("\"%s\" restore \"%s\" && ", nugetBinary.CString(), solutionPath.CString());
             }
             }
 
 
-            compile += ToString("/Library/Frameworks/Mono.framework/Versions/Current/Commands/xbuild \"%s\" /p:Configuration=%s /p:Platform=\"Any CPU\"", solutionPath.CString(), configuration.CString());
+            compile += ToString("\"%s\" \"%s\" /p:Configuration=%s /p:Platform=\"Any CPU\"", xbuildBinary.CString(), solutionPath.CString(), configuration.CString());
 
 
             args.Push(compile);
             args.Push(compile);
 
 

+ 16 - 2
Source/ToolCore/ToolEnvironment.cpp

@@ -76,13 +76,18 @@ bool ToolEnvironment::InitFromPackage()
 
 
     // AtomicNET
     // AtomicNET
 
 
-    // atomicNETNuGetBinary_ = ToString("%sBuild/Managed/nuget/nuget.exe", rootSourceDir_.CString());
+    // atomicNETNuGetBinary_ = ToString("%sBuild/Managed/nuget/nuget.exe", rootSourceDir_.CString());       
 
 
     atomicNETRootDir_ = resourcesDir + "ToolData/AtomicNET/";
     atomicNETRootDir_ = resourcesDir + "ToolData/AtomicNET/";
     atomicNETCoreAssemblyDir_ = atomicNETRootDir_ + "Release/";
     atomicNETCoreAssemblyDir_ = atomicNETRootDir_ + "Release/";
     atomicNETManagedPlayerBinary_ = atomicNETCoreAssemblyDir_ + "AtomicPlayer.exe";
     atomicNETManagedPlayerBinary_ = atomicNETCoreAssemblyDir_ + "AtomicPlayer.exe";
     atomicNETManagedIPCPlayerBinary_ = atomicNETCoreAssemblyDir_ + "AtomicIPCPlayer.exe";
     atomicNETManagedIPCPlayerBinary_ = atomicNETCoreAssemblyDir_ + "AtomicIPCPlayer.exe";
 
 
+#ifdef ATOMIC_PLATFORM_OSX
+    monoExecutableDir_ = "/Library/Frameworks/Mono.framework/Versions/Current/Commands/";
+    atomicNETNuGetBinary_ = monoExecutableDir_ + "nuget";
+#endif
+
     return true;
     return true;
 }
 }
 
 
@@ -175,13 +180,22 @@ void ToolEnvironment::SetRootSourceDir(const String& sourceDir)
     String config = "Release";
     String config = "Release";
 #endif
 #endif
 
 
-    atomicNETNuGetBinary_ = ToString("%sBuild/Managed/nuget/nuget.exe", rootSourceDir_.CString());
+
 
 
     atomicNETRootDir_ = rootSourceDir_ + "Artifacts/AtomicNET/";
     atomicNETRootDir_ = rootSourceDir_ + "Artifacts/AtomicNET/";
     atomicNETCoreAssemblyDir_ = rootSourceDir_ + "Artifacts/AtomicNET/" + config + "/";
     atomicNETCoreAssemblyDir_ = rootSourceDir_ + "Artifacts/AtomicNET/" + config + "/";
     atomicNETManagedPlayerBinary_ = atomicNETCoreAssemblyDir_ + "AtomicPlayer.exe";
     atomicNETManagedPlayerBinary_ = atomicNETCoreAssemblyDir_ + "AtomicPlayer.exe";
     atomicNETManagedIPCPlayerBinary_ = atomicNETCoreAssemblyDir_ + "AtomicIPCPlayer.exe";
     atomicNETManagedIPCPlayerBinary_ = atomicNETCoreAssemblyDir_ + "AtomicIPCPlayer.exe";
 
 
+#ifdef ATOMIC_PLATFORM_WINDOWS
+    atomicNETNuGetBinary_ = ToString("%sBuild/Managed/nuget/nuget.exe", rootSourceDir_.CString());
+#endif
+
+#ifdef ATOMIC_PLATFORM_OSX
+    monoExecutableDir_ = "/Library/Frameworks/Mono.framework/Versions/Current/Commands/";
+    atomicNETNuGetBinary_ = monoExecutableDir_ + "nuget";
+#endif
+
 }
 }
 
 
 void ToolEnvironment::SetRootBuildDir(const String& buildDir, bool setBinaryPaths)
 void ToolEnvironment::SetRootBuildDir(const String& buildDir, bool setBinaryPaths)

+ 4 - 0
Source/ToolCore/ToolEnvironment.h

@@ -87,6 +87,9 @@ public:
     const String& GetAtomicNETManagedPlayerBinary() { return atomicNETManagedPlayerBinary_; }
     const String& GetAtomicNETManagedPlayerBinary() { return atomicNETManagedPlayerBinary_; }
     const String& GetAtomicNETManagedIPCPlayerBinary() { return atomicNETManagedIPCPlayerBinary_; }
     const String& GetAtomicNETManagedIPCPlayerBinary() { return atomicNETManagedIPCPlayerBinary_; }
 
 
+    const String& GetMonoExecutableDir() { return monoExecutableDir_; }
+
+
 
 
     // OSX
     // OSX
     const String& GetPlayerAppFolder() { return playerAppFolder_; }
     const String& GetPlayerAppFolder() { return playerAppFolder_; }
@@ -147,6 +150,7 @@ private:
     String atomicNETNuGetBinary_;
     String atomicNETNuGetBinary_;
     String atomicNETManagedPlayerBinary_;
     String atomicNETManagedPlayerBinary_;
     String atomicNETManagedIPCPlayerBinary_;
     String atomicNETManagedIPCPlayerBinary_;
+    String monoExecutableDir_;
 
 
     SharedPtr<ToolPrefs> toolPrefs_;
     SharedPtr<ToolPrefs> toolPrefs_;
 };
 };