From e2098d244c208935c7b64bc94af006fa5a8cae43 Mon Sep 17 00:00:00 2001 From: Jeff Campbell Date: Sun, 4 Jul 2021 22:50:47 -0400 Subject: [PATCH 1/3] Fixed platform-specific path issues * Modified WriteToDiskPostProcessor so that it will replace any inapropriate path characters per-platform with the correct ones * Modified GenerateOptions and ConfigOptions so that the case-sensitive plugin folder name is used and removed any platform-specific path characters * Added helper methods for determining current operating system --- .../WriteToDiskPostProcessor.cs | 20 +++++++++++- .../Genesis.Plugin/Tools/OperatingSystem.cs | 12 +++++++ .../Tools/OperatingSystemTools.cs | 31 +++++++++++++++++++ ExternalApp/Genesis/Options/ConfigOptions.cs | 6 ++-- .../Genesis/Options/GenerateOptions.cs | 2 +- 5 files changed, 66 insertions(+), 5 deletions(-) create mode 100644 ExternalApp/Genesis.Plugin/Tools/OperatingSystem.cs create mode 100644 ExternalApp/Genesis.Plugin/Tools/OperatingSystemTools.cs diff --git a/ExternalApp/Genesis.Core.Plugin/PostProcessors/WriteToDiskPostProcessor.cs b/ExternalApp/Genesis.Core.Plugin/PostProcessors/WriteToDiskPostProcessor.cs index 7945abd..f70a6d4 100644 --- a/ExternalApp/Genesis.Core.Plugin/PostProcessors/WriteToDiskPostProcessor.cs +++ b/ExternalApp/Genesis.Core.Plugin/PostProcessors/WriteToDiskPostProcessor.cs @@ -23,11 +23,16 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +using System; using System.IO; +using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; using Genesis.Plugin; using Genesis.Shared; +using Serilog; +using Serilog.Core; +using OperatingSystem = Genesis.Plugin.OperatingSystem; namespace Genesis.Core.Plugin { @@ -54,10 +59,23 @@ public void Configure(IGenesisConfig genesisConfig) public CodeGenFile[] PostProcess(CodeGenFile[] files) { + var logger = Log.Logger.ForContext(); var basePath = _targetDirectoryConfig.TargetDirectory + Path.DirectorySeparatorChar; + + // Get the path-specific slash characters that should be replaced if encountered. + var replaceSlash = OperatingSystemTools.GetOperatingSystem() switch + { + OperatingSystem.macOS => "\\", + OperatingSystem.Linux => "\\", + OperatingSystem.Windows => "/", + _ => throw new ArgumentException(nameof(OSPlatform)) + }; + var pathDirectorySeparatorStr = Path.DirectorySeparatorChar.ToString(); + Parallel.ForEach(files, (codeGenFile, state) => { - var path = basePath + codeGenFile.FileName; + var path = Path.GetFullPath(Path.Combine(basePath, codeGenFile.FileName)) + .Replace(replaceSlash, pathDirectorySeparatorStr); var directoryName = Path.GetDirectoryName(path); if (!Directory.Exists(directoryName)) { diff --git a/ExternalApp/Genesis.Plugin/Tools/OperatingSystem.cs b/ExternalApp/Genesis.Plugin/Tools/OperatingSystem.cs new file mode 100644 index 0000000..131db94 --- /dev/null +++ b/ExternalApp/Genesis.Plugin/Tools/OperatingSystem.cs @@ -0,0 +1,12 @@ +namespace Genesis.Plugin +{ + /// + /// Represents distinct supported flavors of operating systems. + /// + public enum OperatingSystem + { + Windows = 0, + macOS = 1, + Linux = 2 + } +} diff --git a/ExternalApp/Genesis.Plugin/Tools/OperatingSystemTools.cs b/ExternalApp/Genesis.Plugin/Tools/OperatingSystemTools.cs new file mode 100644 index 0000000..f99a97d --- /dev/null +++ b/ExternalApp/Genesis.Plugin/Tools/OperatingSystemTools.cs @@ -0,0 +1,31 @@ +using System; +using System.Runtime.InteropServices; + +namespace Genesis.Plugin +{ + /// + /// Helper methods for dealing with operating systems. + /// + public class OperatingSystemTools + { + public static OperatingSystem GetOperatingSystem() + { + if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + { + return OperatingSystem.macOS; + } + + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + return OperatingSystem.Linux; + } + + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + return OperatingSystem.Windows; + } + + throw new Exception("Cannot determine operating system!"); + } + } +} diff --git a/ExternalApp/Genesis/Options/ConfigOptions.cs b/ExternalApp/Genesis/Options/ConfigOptions.cs index 97adc1f..4922ae6 100644 --- a/ExternalApp/Genesis/Options/ConfigOptions.cs +++ b/ExternalApp/Genesis/Options/ConfigOptions.cs @@ -37,20 +37,20 @@ internal sealed class ConfigOptions longName:"create", SetName = "create", HelpText = "Specifies that a config file should be created and populated with all settings from " + - "availables plugins.")] + "available plugins.")] public bool DoCreate { get; set; } [Option( longName: "output-path", SetName = "create", HelpText = "The output file path where this config should be written", - Default = "./new_config.json")] + Default = "new_config.json")] public string CreatePath { get; set; } [Option( "plugin-path", HelpText = "The path to the plugin folder.", - Default = "./plugins")] + Default = "Plugins")] public string PluginPath { get; set; } [Option( diff --git a/ExternalApp/Genesis/Options/GenerateOptions.cs b/ExternalApp/Genesis/Options/GenerateOptions.cs index 3c38dca..a76ec9c 100644 --- a/ExternalApp/Genesis/Options/GenerateOptions.cs +++ b/ExternalApp/Genesis/Options/GenerateOptions.cs @@ -66,7 +66,7 @@ internal sealed class GenerateOptions [Option( "plugin-path", HelpText = "The path to the plugin folder.", - Default = "./plugins")] + Default = "Plugins")] public string PluginPath { get; set; } [Option( From 7e36d6985672f21425838e41c931e58f612a9f1a Mon Sep 17 00:00:00 2001 From: Jeff Campbell Date: Sun, 4 Jul 2021 22:51:03 -0400 Subject: [PATCH 2/3] Updated example content to exclude versioned header --- Unity/Assets/ExampleContent/GenesisSettings.asset | 5 ++--- .../Scripts/Generated/Factory/ArchetypeIDToGameObject.cs | 9 --------- .../Generated/Factory/ArchetypeIDToGameObjectArray.cs | 9 --------- .../Generated/Factory/ArchetypeIDToListGameObject.cs | 9 --------- .../Scripts/Generated/Factory/ArchetypeIDToSprite.cs | 9 --------- .../Scripts/Generated/Factory/ItemTypeToGameObject.cs | 9 --------- .../Generated/Factory/ItemTypeToGameObjectArray.cs | 9 --------- .../Generated/Factory/ItemTypeToListGameObject.cs | 9 --------- .../Scripts/Generated/Factory/ItemTypeToSprite.cs | 9 --------- 9 files changed, 2 insertions(+), 75 deletions(-) diff --git a/Unity/Assets/ExampleContent/GenesisSettings.asset b/Unity/Assets/ExampleContent/GenesisSettings.asset index c380739..e5db9f6 100644 --- a/Unity/Assets/ExampleContent/GenesisSettings.asset +++ b/Unity/Assets/ExampleContent/GenesisSettings.asset @@ -51,9 +51,8 @@ MonoBehaviour: - key: Genesis.CodeGenerators value: Genesis.Unity.Factory.Plugin.ScriptableFactoryCodeGenerator - key: Genesis.PostProcessors - value: Genesis.Core.Plugin.AddFileHeaderPostProcessor, Genesis.Core.Plugin.CleanTargetDirectoryPostProcessor, - Genesis.Core.Plugin.NewLinePostProcessor, Genesis.Core.Plugin.MergeFilesPostProcessor, - Genesis.Core.Plugin.WriteToDiskPostProcessor + value: Genesis.Core.Plugin.CleanTargetDirectoryPostProcessor, Genesis.Core.Plugin.NewLinePostProcessor, + Genesis.Core.Plugin.MergeFilesPostProcessor, Genesis.Core.Plugin.WriteToDiskPostProcessor - key: Genesis.DoUseWhiteListedAssemblies value: false - key: Genesis.WhiteListedAssemblies diff --git a/Unity/Assets/ExampleContent/Scripts/Generated/Factory/ArchetypeIDToGameObject.cs b/Unity/Assets/ExampleContent/Scripts/Generated/Factory/ArchetypeIDToGameObject.cs index edad58e..d4305d9 100644 --- a/Unity/Assets/ExampleContent/Scripts/Generated/Factory/ArchetypeIDToGameObject.cs +++ b/Unity/Assets/ExampleContent/Scripts/Generated/Factory/ArchetypeIDToGameObject.cs @@ -1,12 +1,3 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool (Genesis v2.0.4.0). -// -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ using System; using System.Collections.Generic; diff --git a/Unity/Assets/ExampleContent/Scripts/Generated/Factory/ArchetypeIDToGameObjectArray.cs b/Unity/Assets/ExampleContent/Scripts/Generated/Factory/ArchetypeIDToGameObjectArray.cs index 0efbbf5..7c446c4 100644 --- a/Unity/Assets/ExampleContent/Scripts/Generated/Factory/ArchetypeIDToGameObjectArray.cs +++ b/Unity/Assets/ExampleContent/Scripts/Generated/Factory/ArchetypeIDToGameObjectArray.cs @@ -1,12 +1,3 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool (Genesis v2.0.4.0). -// -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ using System; using System.Collections.Generic; diff --git a/Unity/Assets/ExampleContent/Scripts/Generated/Factory/ArchetypeIDToListGameObject.cs b/Unity/Assets/ExampleContent/Scripts/Generated/Factory/ArchetypeIDToListGameObject.cs index 0927e0f..f84ad09 100644 --- a/Unity/Assets/ExampleContent/Scripts/Generated/Factory/ArchetypeIDToListGameObject.cs +++ b/Unity/Assets/ExampleContent/Scripts/Generated/Factory/ArchetypeIDToListGameObject.cs @@ -1,12 +1,3 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool (Genesis v2.0.4.0). -// -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ using System; using System.Collections.Generic; diff --git a/Unity/Assets/ExampleContent/Scripts/Generated/Factory/ArchetypeIDToSprite.cs b/Unity/Assets/ExampleContent/Scripts/Generated/Factory/ArchetypeIDToSprite.cs index 022c696..1b87b09 100644 --- a/Unity/Assets/ExampleContent/Scripts/Generated/Factory/ArchetypeIDToSprite.cs +++ b/Unity/Assets/ExampleContent/Scripts/Generated/Factory/ArchetypeIDToSprite.cs @@ -1,12 +1,3 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool (Genesis v2.0.4.0). -// -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ using System; using System.Collections.Generic; diff --git a/Unity/Assets/ExampleContent/Scripts/Generated/Factory/ItemTypeToGameObject.cs b/Unity/Assets/ExampleContent/Scripts/Generated/Factory/ItemTypeToGameObject.cs index 686fa14..7b93fe3 100644 --- a/Unity/Assets/ExampleContent/Scripts/Generated/Factory/ItemTypeToGameObject.cs +++ b/Unity/Assets/ExampleContent/Scripts/Generated/Factory/ItemTypeToGameObject.cs @@ -1,12 +1,3 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool (Genesis v2.0.4.0). -// -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ using System; using System.Collections.Generic; diff --git a/Unity/Assets/ExampleContent/Scripts/Generated/Factory/ItemTypeToGameObjectArray.cs b/Unity/Assets/ExampleContent/Scripts/Generated/Factory/ItemTypeToGameObjectArray.cs index 8ef82b1..53bcfdc 100644 --- a/Unity/Assets/ExampleContent/Scripts/Generated/Factory/ItemTypeToGameObjectArray.cs +++ b/Unity/Assets/ExampleContent/Scripts/Generated/Factory/ItemTypeToGameObjectArray.cs @@ -1,12 +1,3 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool (Genesis v2.0.4.0). -// -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ using System; using System.Collections.Generic; diff --git a/Unity/Assets/ExampleContent/Scripts/Generated/Factory/ItemTypeToListGameObject.cs b/Unity/Assets/ExampleContent/Scripts/Generated/Factory/ItemTypeToListGameObject.cs index 5719897..7ccbcf6 100644 --- a/Unity/Assets/ExampleContent/Scripts/Generated/Factory/ItemTypeToListGameObject.cs +++ b/Unity/Assets/ExampleContent/Scripts/Generated/Factory/ItemTypeToListGameObject.cs @@ -1,12 +1,3 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool (Genesis v2.0.4.0). -// -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ using System; using System.Collections.Generic; diff --git a/Unity/Assets/ExampleContent/Scripts/Generated/Factory/ItemTypeToSprite.cs b/Unity/Assets/ExampleContent/Scripts/Generated/Factory/ItemTypeToSprite.cs index ff60abc..2846e53 100644 --- a/Unity/Assets/ExampleContent/Scripts/Generated/Factory/ItemTypeToSprite.cs +++ b/Unity/Assets/ExampleContent/Scripts/Generated/Factory/ItemTypeToSprite.cs @@ -1,12 +1,3 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool (Genesis v2.0.4.0). -// -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ using System; using System.Collections.Generic; From 71a8e144f366beb33ca0e3852d44f303bcc8062f Mon Sep 17 00:00:00 2001 From: Jeff Campbell Date: Sun, 4 Jul 2021 22:58:00 -0400 Subject: [PATCH 3/3] Updated changelog for v2.3.2 --- CHANGELOG.MD | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.MD b/CHANGELOG.MD index f27905e..379453b 100644 --- a/CHANGELOG.MD +++ b/CHANGELOG.MD @@ -5,6 +5,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Releases] +### [2.3.2] - 2021-07-04 +#### Fixed +These issues should help resolve any operating system path issues that caused either plugins to fail to be discovered or files to be written incorrectly. +* Modified `WriteToDiskPostProcessor` so that it will replace any inapropriate path characters per-platform with the correct ones. +* Modified `GenerateOptions` and `ConfigOptions` for the Genesis.CLI so that the case-sensitive "plugins" folder name is used and removed any platform-specific path characters. +* Added `OperatingSystemTools` helper methods for determining current operating system + ### [2.3.1] - 2021-07-01 #### Changed * Modified `GetAttributes` and `HasAttributes` extension methods with optional bool parameter `canInherit` so that a user can check to see if a `ITypeSymbol` is decorated with an matching attribute or base type name.