diff --git a/src/Generator/Diagnostics.cs b/src/Generator/Diagnostics.cs index 3aa6d5ca..bb152415 100644 --- a/src/Generator/Diagnostics.cs +++ b/src/Generator/Diagnostics.cs @@ -6,7 +6,8 @@ namespace CppSharp { AmbiguousOverload, InvalidOperatorOverload, - SymbolNotFound + SymbolNotFound, + FileGenerated, } public enum DiagnosticKind diff --git a/src/Generator/Driver.cs b/src/Generator/Driver.cs index 1d014400..94e43b38 100644 --- a/src/Generator/Driver.cs +++ b/src/Generator/Driver.cs @@ -259,6 +259,6 @@ namespace CppSharp public string Assembly; public string IncludePrefix; public bool WriteOnlyWhenChanged; - + public Func GenerateName; } } \ No newline at end of file diff --git a/src/Generator/Generators/CLI/CLIGenerator.cs b/src/Generator/Generators/CLI/CLIGenerator.cs index 313cdb67..c0143233 100644 --- a/src/Generator/Generators/CLI/CLIGenerator.cs +++ b/src/Generator/Generators/CLI/CLIGenerator.cs @@ -1,6 +1,5 @@ using System; using System.IO; -using CppSharp.Types; namespace CppSharp.Generators.CLI { @@ -18,27 +17,22 @@ namespace CppSharp.Generators.CLI void WriteTemplate(TextTemplate template) { - var file = Path.GetFileNameWithoutExtension(template.TranslationUnit.FileName) - + Driver.Options.WrapperSuffix + "." - + template.FileExtension; - - var path = Path.Combine(Driver.Options.OutputDir, file); - var fullPath = Path.GetFullPath(path); + var path = GetOutputPath(template.TranslationUnit) + + "." + template.FileExtension; template.Generate(); - - Console.WriteLine(" Generated '" + file + "'."); - - var str = template.ToString(); + var text = template.ToString(); if(Driver.Options.WriteOnlyWhenChanged) { - var updated = fileHashes.UpdateHash(path, str.GetHashCode()); - if(File.Exists(fullPath) && !updated) + var updated = fileHashes.UpdateHash(path, text.GetHashCode()); + if (File.Exists(path) && !updated) return; - } + } - File.WriteAllText(fullPath,str); + Driver.Diagnostics.EmitMessage(DiagnosticId.FileGenerated, + " Generated '{0}'.", Path.GetFileName(path)); + File.WriteAllText(path, text); } public override bool Generate(TranslationUnit unit) diff --git a/src/Generator/Generators/CLI/CLISourcesTemplate.cs b/src/Generator/Generators/CLI/CLISourcesTemplate.cs index 4d84f2a3..31c8bbda 100644 --- a/src/Generator/Generators/CLI/CLISourcesTemplate.cs +++ b/src/Generator/Generators/CLI/CLISourcesTemplate.cs @@ -19,9 +19,12 @@ namespace CppSharp.Generators.CLI { GenerateStart(); - WriteLine("#include \"{0}{1}.h\"", - TranslationUnit.FileNameWithoutExtension, - Options.WrapperSuffix); + var file = Path.GetFileNameWithoutExtension(TranslationUnit.FileName); + + if (Driver.Options.GenerateName != null) + file = Driver.Options.GenerateName(TranslationUnit); + + WriteLine("#include \"{0}{1}.h\"", file); GenerateForwardReferenceHeaders(); diff --git a/src/Generator/Generators/CSharp/CSharpGenerator.cs b/src/Generator/Generators/CSharp/CSharpGenerator.cs index f7a53677..9125ccb1 100644 --- a/src/Generator/Generators/CSharp/CSharpGenerator.cs +++ b/src/Generator/Generators/CSharp/CSharpGenerator.cs @@ -1,6 +1,5 @@ using System; using System.IO; -using CppSharp.Types; namespace CppSharp.Generators.CSharp { @@ -16,16 +15,14 @@ namespace CppSharp.Generators.CSharp void WriteTemplate(TextTemplate template) { - var file = Path.GetFileNameWithoutExtension(template.TranslationUnit.FileName) - + Driver.Options.WrapperSuffix + "." - + template.FileExtension; - - var path = Path.Combine(Driver.Options.OutputDir, file); + var path = GetOutputPath(template.TranslationUnit) + + "." + template.FileExtension; template.Generate(); - Console.WriteLine(" Generated '" + file + "'."); - File.WriteAllText(Path.GetFullPath(path), template.ToString()); + File.WriteAllText(path, template.ToString()); + Driver.Diagnostics.EmitMessage(DiagnosticId.FileGenerated, + " Generated '{0}'.", Path.GetFileName(path)); } public override bool Generate(TranslationUnit unit) diff --git a/src/Generator/Generators/Generator.cs b/src/Generator/Generators/Generator.cs index 404bda74..bd6747ca 100644 --- a/src/Generator/Generators/Generator.cs +++ b/src/Generator/Generators/Generator.cs @@ -1,4 +1,6 @@ -namespace CppSharp.Generators +using System.IO; + +namespace CppSharp.Generators { public enum LanguageGeneratorKind { @@ -21,5 +23,16 @@ } public abstract bool Generate(TranslationUnit unit); + + public string GetOutputPath(TranslationUnit unit) + { + var file = unit.FileNameWithoutExtension; + + if (Driver.Options.GenerateName != null) + file = Driver.Options.GenerateName(unit); + + var path = Path.Combine(Driver.Options.OutputDir, file); + return Path.GetFullPath(path); + } } } \ No newline at end of file