From 66c7585d4925c1a71b307532bed1b044f77ab3c6 Mon Sep 17 00:00:00 2001 From: Stephen Shaw Date: Wed, 22 Apr 2020 20:38:00 -0600 Subject: [PATCH 1/5] Move sln to root making it easier to find --- .jenkins.groovy | 2 +- .jenkins.pullrequest.groovy | 2 +- src/Gir.sln => Gir.sln | 46 ++++++++++++++++++------------------- 3 files changed, 25 insertions(+), 25 deletions(-) rename src/Gir.sln => Gir.sln (82%) diff --git a/.jenkins.groovy b/.jenkins.groovy index 87eada7..eb72ed5 100644 --- a/.jenkins.groovy +++ b/.jenkins.groovy @@ -8,7 +8,7 @@ for (x in alltargets) { stage("Test on ${mainlabel}") { ws { git credentialsId: '56f5f1ca-b5a7-41b5-8318-c84dd4364e72', url: 'git://github.com/mono/gir-sharp.git' - chroot additionalPackages: 'ca-certificates-mono nuget msbuild mono-devel libgtk2.0-dev libgtk-3-dev', chrootName: "${mainlabel}-stable", command: "nuget restore src/Gir.sln && nuget install NUnit.ConsoleRunner -Version 3.8.0 -OutputDirectory testrunner && msbuild /p:Configuration=Release src/Gir.sln && mono ./testrunner/NUnit.ConsoleRunner.3.8.0/tools/nunit3-console.exe ./src/Gir.Tests/bin/Release/Gir.Tests.dll" + chroot additionalPackages: 'ca-certificates-mono nuget msbuild mono-devel libgtk2.0-dev libgtk-3-dev', chrootName: "${mainlabel}-stable", command: "nuget restore Gir.sln && nuget install NUnit.ConsoleRunner -Version 3.8.0 -OutputDirectory testrunner && msbuild /p:Configuration=Release Gir.sln && mono ./testrunner/NUnit.ConsoleRunner.3.8.0/tools/nunit3-console.exe ./src/Gir.Tests/bin/Release/Gir.Tests.dll" step([$class: 'XUnitPublisher', testTimeMargin: '3000', thresholdMode: 1, thresholds: [[$class: 'FailedThreshold', failureNewThreshold: '5', failureThreshold: '5', unstableNewThreshold: '1', unstableThreshold: '1'], [$class: 'SkippedThreshold', failureNewThreshold: '5', failureThreshold: '5', unstableNewThreshold: '1', unstableThreshold: '1']], tools: [[$class: 'NUnit3TestType', deleteOutputFiles: true, failIfNotNew: true, pattern: '**/TestResult.xml', skipNoTestFiles: true, stopProcessingIfError: true]]]) } } diff --git a/.jenkins.pullrequest.groovy b/.jenkins.pullrequest.groovy index c791d85..86eac9f 100644 --- a/.jenkins.pullrequest.groovy +++ b/.jenkins.pullrequest.groovy @@ -8,7 +8,7 @@ for (x in alltargets) { stage("Test on ${mainlabel}") { ws { checkout changelog: false, poll: false, scm: [$class: 'GitSCM', branches: [[name: "${sha1}"]], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[refspec: "+refs/pull/${ghprbPullId}/*:refs/remotes/origin/pr/${ghprbPullId}/*", url: 'git://github.com/mono/gir-sharp.git']]] - chroot additionalPackages: 'ca-certificates-mono nuget msbuild mono-devel libgtk2.0-dev libgtk-3-dev', chrootName: "${mainlabel}-stable", command: "nuget restore src/Gir.sln && nuget install NUnit.ConsoleRunner -Version 3.8.0 -OutputDirectory testrunner && msbuild /p:Configuration=Release src/Gir.sln && mono ./testrunner/NUnit.ConsoleRunner.3.8.0/tools/nunit3-console.exe ./src/Gir.Tests/bin/Release/Gir.Tests.dll" + chroot additionalPackages: 'ca-certificates-mono nuget msbuild mono-devel libgtk2.0-dev libgtk-3-dev', chrootName: "${mainlabel}-stable", command: "nuget restore Gir.sln && nuget install NUnit.ConsoleRunner -Version 3.8.0 -OutputDirectory testrunner && msbuild /p:Configuration=Release Gir.sln && mono ./testrunner/NUnit.ConsoleRunner.3.8.0/tools/nunit3-console.exe ./src/Gir.Tests/bin/Release/Gir.Tests.dll" step([$class: 'XUnitPublisher', testTimeMargin: '3000', thresholdMode: 1, thresholds: [[$class: 'FailedThreshold', failureNewThreshold: '5', failureThreshold: '5', unstableNewThreshold: '1', unstableThreshold: '1'], [$class: 'SkippedThreshold', failureNewThreshold: '5', failureThreshold: '5', unstableNewThreshold: '1', unstableThreshold: '1']], tools: [[$class: 'NUnit3TestType', deleteOutputFiles: true, failIfNotNew: true, pattern: '**/TestResult.xml', skipNoTestFiles: true, stopProcessingIfError: true]]]) } } diff --git a/src/Gir.sln b/Gir.sln similarity index 82% rename from src/Gir.sln rename to Gir.sln index b771726..95bc85a 100644 --- a/src/Gir.sln +++ b/Gir.sln @@ -1,23 +1,23 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2012 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gir", "Gir\Gir.csproj", "{D8FC3B49-B1A1-4DEB-8E76-EE537195AD38}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gir.Tests", "Gir.Tests\Gir.Tests.csproj", "{51FB7677-5684-4664-A59C-075CA6976F57}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|x86 = Debug|x86 - Release|x86 = Release|x86 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {D8FC3B49-B1A1-4DEB-8E76-EE537195AD38}.Debug|x86.ActiveCfg = Debug|x86 - {D8FC3B49-B1A1-4DEB-8E76-EE537195AD38}.Debug|x86.Build.0 = Debug|x86 - {D8FC3B49-B1A1-4DEB-8E76-EE537195AD38}.Release|x86.ActiveCfg = Release|x86 - {D8FC3B49-B1A1-4DEB-8E76-EE537195AD38}.Release|x86.Build.0 = Release|x86 - {51FB7677-5684-4664-A59C-075CA6976F57}.Debug|x86.ActiveCfg = Debug|Any CPU - {51FB7677-5684-4664-A59C-075CA6976F57}.Debug|x86.Build.0 = Debug|Any CPU - {51FB7677-5684-4664-A59C-075CA6976F57}.Release|x86.ActiveCfg = Release|Any CPU - {51FB7677-5684-4664-A59C-075CA6976F57}.Release|x86.Build.0 = Release|Any CPU - EndGlobalSection -EndGlobal + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gir", "src\Gir\Gir.csproj", "{D8FC3B49-B1A1-4DEB-8E76-EE537195AD38}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gir.Tests", "src\Gir.Tests\Gir.Tests.csproj", "{51FB7677-5684-4664-A59C-075CA6976F57}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x86 = Debug|x86 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {D8FC3B49-B1A1-4DEB-8E76-EE537195AD38}.Debug|x86.ActiveCfg = Debug|x86 + {D8FC3B49-B1A1-4DEB-8E76-EE537195AD38}.Debug|x86.Build.0 = Debug|x86 + {D8FC3B49-B1A1-4DEB-8E76-EE537195AD38}.Release|x86.ActiveCfg = Release|x86 + {D8FC3B49-B1A1-4DEB-8E76-EE537195AD38}.Release|x86.Build.0 = Release|x86 + {51FB7677-5684-4664-A59C-075CA6976F57}.Debug|x86.ActiveCfg = Debug|Any CPU + {51FB7677-5684-4664-A59C-075CA6976F57}.Debug|x86.Build.0 = Debug|Any CPU + {51FB7677-5684-4664-A59C-075CA6976F57}.Release|x86.ActiveCfg = Release|Any CPU + {51FB7677-5684-4664-A59C-075CA6976F57}.Release|x86.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal From 85016e64dd86ed54a0d302788ce158e42d78d35b Mon Sep 17 00:00:00 2001 From: Stephen Shaw Date: Wed, 22 Apr 2020 21:41:59 -0600 Subject: [PATCH 2/5] Move to new csproj format. Target net472 and netcoreapp3.0 --- Directory.Build.props | 16 ++++ Directory.Build.targets | 8 ++ Gir.sln | 19 +++-- src/Gir.Tests/Gir.Tests.csproj | 72 ++++------------ src/Gir/Gir.csproj | 128 ++--------------------------- src/Gir/Properties/AssemblyInfo.cs | 26 ------ 6 files changed, 57 insertions(+), 212 deletions(-) create mode 100644 Directory.Build.props create mode 100644 Directory.Build.targets delete mode 100644 src/Gir/Properties/AssemblyInfo.cs diff --git a/Directory.Build.props b/Directory.Build.props new file mode 100644 index 0000000..95e6b85 --- /dev/null +++ b/Directory.Build.props @@ -0,0 +1,16 @@ + + + latest + true + x86 + + + + + 1.0.0 + 1.0.0.0 + GirSharp + CSharp binding generator + Copyright (C) 2018-2020 Microsoft + + diff --git a/Directory.Build.targets b/Directory.Build.targets new file mode 100644 index 0000000..5823303 --- /dev/null +++ b/Directory.Build.targets @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/Gir.sln b/Gir.sln index 95bc85a..6dd975b 100644 --- a/Gir.sln +++ b/Gir.sln @@ -1,6 +1,7 @@ - Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2012 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30014.187 +MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gir", "src\Gir\Gir.csproj", "{D8FC3B49-B1A1-4DEB-8E76-EE537195AD38}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gir.Tests", "src\Gir.Tests\Gir.Tests.csproj", "{51FB7677-5684-4664-A59C-075CA6976F57}" @@ -11,13 +12,19 @@ Global Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {D8FC3B49-B1A1-4DEB-8E76-EE537195AD38}.Debug|x86.ActiveCfg = Debug|x86 - {D8FC3B49-B1A1-4DEB-8E76-EE537195AD38}.Debug|x86.Build.0 = Debug|x86 - {D8FC3B49-B1A1-4DEB-8E76-EE537195AD38}.Release|x86.ActiveCfg = Release|x86 - {D8FC3B49-B1A1-4DEB-8E76-EE537195AD38}.Release|x86.Build.0 = Release|x86 + {D8FC3B49-B1A1-4DEB-8E76-EE537195AD38}.Debug|x86.ActiveCfg = Debug|Any CPU + {D8FC3B49-B1A1-4DEB-8E76-EE537195AD38}.Debug|x86.Build.0 = Debug|Any CPU + {D8FC3B49-B1A1-4DEB-8E76-EE537195AD38}.Release|x86.ActiveCfg = Release|Any CPU + {D8FC3B49-B1A1-4DEB-8E76-EE537195AD38}.Release|x86.Build.0 = Release|Any CPU {51FB7677-5684-4664-A59C-075CA6976F57}.Debug|x86.ActiveCfg = Debug|Any CPU {51FB7677-5684-4664-A59C-075CA6976F57}.Debug|x86.Build.0 = Debug|Any CPU {51FB7677-5684-4664-A59C-075CA6976F57}.Release|x86.ActiveCfg = Release|Any CPU {51FB7677-5684-4664-A59C-075CA6976F57}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {13C16ACC-6523-43F7-8F15-9CA70BDF9E81} + EndGlobalSection EndGlobal diff --git a/src/Gir.Tests/Gir.Tests.csproj b/src/Gir.Tests/Gir.Tests.csproj index 254c644..ffce625 100644 --- a/src/Gir.Tests/Gir.Tests.csproj +++ b/src/Gir.Tests/Gir.Tests.csproj @@ -1,54 +1,9 @@ - - + + - Debug - AnyCPU - {51FB7677-5684-4664-A59C-075CA6976F57} - Library - Gir.Tests - Gir.Tests - v4.7 - - + netcoreapp3.0;net472 - - true - full - false - bin\Debug - DEBUG; - prompt - 4 - - - true - bin\Release - prompt - 4 - - - - - ..\..\..\..\..\..\..\Library\Frameworks\Mono.framework\Versions\5.13.0\lib\mono\4.7-api\System.Xml.dll - - - - - - - - - - - - - - - - - - - + Always @@ -195,6 +150,7 @@ Always + Always @@ -230,16 +186,18 @@ Always + - - {D8FC3B49-B1A1-4DEB-8E76-EE537195AD38} - Gir - + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + - - 3.10.1 - + - + \ No newline at end of file diff --git a/src/Gir/Gir.csproj b/src/Gir/Gir.csproj index 6a34997..de701eb 100644 --- a/src/Gir/Gir.csproj +++ b/src/Gir/Gir.csproj @@ -1,134 +1,16 @@ - + + - Debug - x86 - {D8FC3B49-B1A1-4DEB-8E76-EE537195AD38} + netcoreapp3.0;net472 Exe - Gir - Gir - v4.7 - - - true - full - false - bin\Debug - DEBUG; - prompt - 4 - true - true - x86 - - - true - bin\Release - prompt - 4 true - x86 - true - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - + \ No newline at end of file diff --git a/src/Gir/Properties/AssemblyInfo.cs b/src/Gir/Properties/AssemblyInfo.cs deleted file mode 100644 index 6c4ec38..0000000 --- a/src/Gir/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; - -// Information about this assembly is defined by the following attributes. -// Change them to the values specific to your project. - -[assembly: AssemblyTitle("Gir")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Microsoft")] -[assembly: AssemblyProduct("")] -[assembly: AssemblyCopyright("")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". -// The form "{Major}.{Minor}.*" will automatically update the build and revision, -// and "{Major}.{Minor}.{Build}.*" will update just the revision. - -[assembly: AssemblyVersion("1.0.*")] - -// The following attributes are used to specify the signing key for the assembly, -// if desired. See the Mono documentation for more information about signing. - -//[assembly: AssemblyDelaySign(false)] -//[assembly: AssemblyKeyFile("")] From d6443a4ea558f258c24a9c74a158591368be3b09 Mon Sep 17 00:00:00 2001 From: Stephen Shaw Date: Wed, 22 Apr 2020 21:57:41 -0600 Subject: [PATCH 3/5] Add disposing pattern to remove error (warningaserror?) --- src/Gir/Generation/IndentWriter.cs | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/Gir/Generation/IndentWriter.cs b/src/Gir/Generation/IndentWriter.cs index 1a1ae5d..1189bf1 100644 --- a/src/Gir/Generation/IndentWriter.cs +++ b/src/Gir/Generation/IndentWriter.cs @@ -1,10 +1,11 @@ -using System; +using System; using System.IO; namespace Gir { public class IndentWriter : IDisposable { + bool isDisposed; TextWriter writer; int indent; @@ -51,15 +52,27 @@ public IndentWriter (TextWriter tw) public void Dispose () { - if (writer != null) { - if (Options.WriteHeader) { - Unindent (); - WriteLine ("}"); - } + Dispose (true); + GC.SuppressFinalize (this); + } + + protected virtual void Dispose (bool disposing) + { + if (isDisposed) return; - writer?.Dispose (); - writer = null; + if (disposing) { + if (writer != null) { + if (Options.WriteHeader) { + Unindent (); + WriteLine ("}"); + } + + writer?.Dispose (); + writer = null; + } } + + isDisposed = true; } public IndentWriter WriteDocumentation (Documentation doc, string tag) From 6c1275a84a2ff0b66176ac19db9f80602ff317e6 Mon Sep 17 00:00:00 2001 From: Stephen Shaw Date: Wed, 22 Apr 2020 21:59:43 -0600 Subject: [PATCH 4/5] Using new using resource syntax --- src/Gir/Generation/Bitfield.cs | 21 +++++++------- src/Gir/Generation/Callback.cs | 46 +++++++++++++++---------------- src/Gir/Generation/Class.cs | 35 ++++++++++++----------- src/Gir/Generation/Enumeration.cs | 17 ++++++------ src/Gir/Generation/Interface.cs | 19 ++++++------- src/Gir/Generation/Record.cs | 23 ++++++++-------- src/Gir/Parser.cs | 18 ++++++------ 7 files changed, 85 insertions(+), 94 deletions(-) diff --git a/src/Gir/Generation/Bitfield.cs b/src/Gir/Generation/Bitfield.cs index 9417f76..d03264f 100644 --- a/src/Gir/Generation/Bitfield.cs +++ b/src/Gir/Generation/Bitfield.cs @@ -1,4 +1,4 @@ - + namespace Gir { public partial class Bitfield : IGeneratable, IDocumented, IEnumFormatter @@ -8,22 +8,21 @@ public string FormatValue (string value) int intValue = int.Parse (value); // Maybe pad with leading zeroes based on the value? - return string.Format ("0x{0:X}", intValue); + return $"0x{intValue:X}"; } public void Generate (GenerationOptions opts) { - using (var writer = this.GetWriter (opts)) { - this.GenerateDocumentation (writer); - writer.WriteLine ("[Flags]"); - writer.WriteLine ("public enum " + Name); - writer.WriteLine ("{"); + using var writer = this.GetWriter (opts); + this.GenerateDocumentation (writer); + writer.WriteLine ("[Flags]"); + writer.WriteLine ("public enum " + Name); + writer.WriteLine ("{"); - using (writer.Indent ()) { - this.GenerateMembers (writer); - } - writer.WriteLine ("}"); + using (writer.Indent ()) { + this.GenerateMembers (writer); } + writer.WriteLine ("}"); } } } diff --git a/src/Gir/Generation/Callback.cs b/src/Gir/Generation/Callback.cs index 8f7cb38..9b722de 100644 --- a/src/Gir/Generation/Callback.cs +++ b/src/Gir/Generation/Callback.cs @@ -5,37 +5,35 @@ public partial class Callback : IGeneratable, IMethodLike { public void Generate (GenerationOptions opts) { - using (var writer = this.GetWriter (opts)) - { - // TODO: Validation if we have an userdata parameter we can use so we can write this code. - // Otherwise, we need to generate code which uses a non-static callback. + using var writer = this.GetWriter (opts); + // TODO: Validation if we have an userdata parameter we can use so we can write this code. + // Otherwise, we need to generate code which uses a non-static callback. - var returnType = this.GetReturnCSharpType (writer); - var parameters = this.BuildParameters (opts, true); + var returnType = this.GetReturnCSharpType (writer); + var parameters = this.BuildParameters (opts, true); - // Public API delegate which uses managed types. - writer.WriteLine ("[UnmanagedFunctionPointer (CallingConvention.Cdecl)]"); - writer.WriteLine ($"public delegate {returnType} {Name} ({parameters.TypesAndNames})"); - writer.WriteLine (); + // Public API delegate which uses managed types. + writer.WriteLine ("[UnmanagedFunctionPointer (CallingConvention.Cdecl)]"); + writer.WriteLine ($"public delegate {returnType} {Name} ({parameters.TypesAndNames})"); + writer.WriteLine (); - // Internal API delegate which uses unmanaged types. - writer.WriteLine ("[UnmanagedFunctionPointer (CallingConvention.Cdecl)]"); - // TODO: Use native marshal types. - writer.WriteLine ($"internal delegate {returnType} {Name}Native ({parameters.TypesAndNames})"); - writer.WriteLine (); + // Internal API delegate which uses unmanaged types. + writer.WriteLine ("[UnmanagedFunctionPointer (CallingConvention.Cdecl)]"); + // TODO: Use native marshal types. + writer.WriteLine ($"internal delegate {returnType} {Name}Native ({parameters.TypesAndNames})"); + writer.WriteLine (); - // Generate wrapper class - static if we can use gchandle, otherwise instance - // Check callback convention - async, notify, call - writer.WriteLine ($"internal static class {Name}Wrapper"); + // Generate wrapper class - static if we can use gchandle, otherwise instance + // Check callback convention - async, notify, call + writer.WriteLine ($"internal static class {Name}Wrapper"); + writer.WriteLine ("{"); + using (writer.Indent ()) { + writer.WriteLine ($"public static void NativeCallback ({parameters.TypesAndNames})"); writer.WriteLine ("{"); - using (writer.Indent ()) { - writer.WriteLine ($"public static void NativeCallback ({parameters.TypesAndNames})"); - writer.WriteLine ("{"); - // TODO: marshal params, call, handle exceptions - writer.WriteLine ("}"); - } + // TODO: marshal params, call, handle exceptions writer.WriteLine ("}"); } + writer.WriteLine ("}"); } } } diff --git a/src/Gir/Generation/Class.cs b/src/Gir/Generation/Class.cs index f21bf48..79ffdbb 100644 --- a/src/Gir/Generation/Class.cs +++ b/src/Gir/Generation/Class.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; namespace Gir @@ -7,27 +7,26 @@ public partial class Class : IGeneratable, IDocumented { public void Generate (GenerationOptions opts) { - using (var writer = this.GetWriter (opts)) { - this.GenerateDocumentation (writer); + using var writer = this.GetWriter (opts); + this.GenerateDocumentation (writer); - var inheritanceList = new List (); - if (!string.IsNullOrEmpty (Parent)) - inheritanceList.Add (Parent); - inheritanceList.AddRange (Implements.Select (x => opts.GenerateInterfacesWithIPrefix ? "I" + x.Name : x.Name)); + var inheritanceList = new List (); + if (!string.IsNullOrEmpty (Parent)) + inheritanceList.Add (Parent); + inheritanceList.AddRange (Implements.Select (x => opts.GenerateInterfacesWithIPrefix ? "I" + x.Name : x.Name)); - var inheritanceString = string.Join (", ", inheritanceList.ToArray ()); - if (!string.IsNullOrEmpty (inheritanceString)) { - writer.WriteLine ($"public class {Name} : {inheritanceString}"); - } else { - writer.WriteLine ($"public class {Name}"); - } - writer.WriteLine ("{"); + var inheritanceString = string.Join (", ", inheritanceList.ToArray ()); + if (!string.IsNullOrEmpty (inheritanceString)) { + writer.WriteLine ($"public class {Name} : {inheritanceString}"); + } else { + writer.WriteLine ($"public class {Name}"); + } + writer.WriteLine ("{"); - using (writer.Indent ()) { - this.GenerateMembers (writer); - } - writer.WriteLine ("}"); + using (writer.Indent ()) { + this.GenerateMembers (writer); } + writer.WriteLine ("}"); } } } diff --git a/src/Gir/Generation/Enumeration.cs b/src/Gir/Generation/Enumeration.cs index 646f12f..100a0a7 100644 --- a/src/Gir/Generation/Enumeration.cs +++ b/src/Gir/Generation/Enumeration.cs @@ -1,20 +1,19 @@ - + namespace Gir { public partial class Enumeration : IGeneratable, IDocumented { public void Generate (GenerationOptions opts) { - using (var writer = this.GetWriter (opts)) { - this.GenerateDocumentation (writer); - writer.WriteLine ("public enum " + Name); - writer.WriteLine ("{"); + using var writer = this.GetWriter (opts); + this.GenerateDocumentation (writer); + writer.WriteLine ("public enum " + Name); + writer.WriteLine ("{"); - using (writer.Indent ()) { - this.GenerateMembers (writer); - } - writer.WriteLine ("}"); + using (writer.Indent ()) { + this.GenerateMembers (writer); } + writer.WriteLine ("}"); } } } diff --git a/src/Gir/Generation/Interface.cs b/src/Gir/Generation/Interface.cs index e19a0dd..266deba 100644 --- a/src/Gir/Generation/Interface.cs +++ b/src/Gir/Generation/Interface.cs @@ -1,21 +1,20 @@ - + namespace Gir { public partial class Interface : IGeneratable, IDocumented { public void Generate (GenerationOptions opts) { - using (var writer = this.GetWriter (opts)) { - this.GenerateDocumentation (writer); - var interfaceName = (opts.GenerateInterfacesWithIPrefix) ? $"I{Name}" : Name; - writer.WriteLine ($"public interface {interfaceName}"); - writer.WriteLine ("{"); + using var writer = this.GetWriter (opts); + this.GenerateDocumentation (writer); + var interfaceName = (opts.GenerateInterfacesWithIPrefix) ? $"I{Name}" : Name; + writer.WriteLine ($"public interface {interfaceName}"); + writer.WriteLine ("{"); - using (writer.Indent ()) { - this.GenerateMembers (writer); - } - writer.WriteLine ("}"); + using (writer.Indent ()) { + this.GenerateMembers (writer); } + writer.WriteLine ("}"); } } } diff --git a/src/Gir/Generation/Record.cs b/src/Gir/Generation/Record.cs index 45f1278..737a56d 100644 --- a/src/Gir/Generation/Record.cs +++ b/src/Gir/Generation/Record.cs @@ -5,22 +5,21 @@ public partial class Record : IGeneratable, IDocumented { public void Generate (GenerationOptions opts) { - using (var writer = this.GetWriter (opts)) { - this.GenerateDocumentation (writer); + using var writer = this.GetWriter (opts); + this.GenerateDocumentation (writer); - var access = "public"; - if (!string.IsNullOrEmpty (GLibIsGTypeStructFor)) - access = "internal"; + var access = "public"; + if (!string.IsNullOrEmpty (GLibIsGTypeStructFor)) + access = "internal"; - writer.WriteLine ("[StructLayout (LayoutKind.Sequential)]"); - writer.WriteLine ($"{access} struct {Name}"); - writer.WriteLine ("{"); + writer.WriteLine ("[StructLayout (LayoutKind.Sequential)]"); + writer.WriteLine ($"{access} struct {Name}"); + writer.WriteLine ("{"); - using (writer.Indent ()) { - this.GenerateMembers (writer); - } - writer.WriteLine ("}"); + using (writer.Indent ()) { + this.GenerateMembers (writer); } + writer.WriteLine ("}"); } } } diff --git a/src/Gir/Parser.cs b/src/Gir/Parser.cs index 121b3e8..a114059 100644 --- a/src/Gir/Parser.cs +++ b/src/Gir/Parser.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.IO; using System.Linq; @@ -9,9 +9,8 @@ public static class Parser public static IEnumerable Parse (string fileName, string includeDir, out Repository mainRepository) { - using (var fs = File.OpenRead (fileName)) { - return Parse (fs, includeDir, out mainRepository); - } + using var fs = File.OpenRead (fileName); + return Parse (fs, includeDir, out mainRepository); } public static IEnumerable Parse (Stream s, string includeDir, out Repository mainRepository) @@ -32,14 +31,13 @@ public static IEnumerable ParseRecursive (Repository repository, str yield return repository; foreach (var include in repository.Includes) { - using (var fs = File.OpenRead (Path.Combine (includeDir, include.GirName))) { - var serializer = new System.Xml.Serialization.XmlSerializer (typeof (Repository)); - var repo = (Repository)serializer.Deserialize (fs); + using var fs = File.OpenRead (Path.Combine (includeDir, include.GirName)); + var serializer = new System.Xml.Serialization.XmlSerializer (typeof (Repository)); + var repo = (Repository)serializer.Deserialize (fs); - foreach (var incRepo in ParseRecursive (repo, includeDir, resolvedRepositories)) { - yield return incRepo; - } + foreach (var incRepo in ParseRecursive (repo, includeDir, resolvedRepositories)) { + yield return incRepo; } } } From a5da619a3bfddd584b75328683042889e6e4709e Mon Sep 17 00:00:00 2001 From: Stephen Shaw Date: Wed, 22 Apr 2020 22:08:58 -0600 Subject: [PATCH 5/5] Fix a handful of Messages --- .editorconfig | 2 +- Gir.sln | 16 ++++++++++++++-- src/Gir/Generation/Bitfield.cs | 2 +- src/Gir/Generation/IGeneratableExtensions.cs | 12 ++++++------ src/Gir/Generation/Member.cs | 4 ++-- src/Gir/GenerationOptions.cs | 2 +- src/Gir/Marshal/SymbolTable.cs | 8 ++++---- src/Gir/Parser.cs | 6 +++--- src/Gir/Program.cs | 6 +++--- src/Gir/Statistics.cs | 4 ++-- src/Gir/Utils.cs | 6 +++--- 11 files changed, 40 insertions(+), 28 deletions(-) diff --git a/.editorconfig b/.editorconfig index f429f07..1e4aca3 100644 --- a/.editorconfig +++ b/.editorconfig @@ -64,7 +64,7 @@ csharp_indent_switch_labels = false # Prefer "var" everywhere it's apparent csharp_style_var_for_built_in_types = true:suggestion csharp_style_var_when_type_is_apparent = true:suggestion -csharp_style_var_elsewhere = false:suggestion +csharp_style_var_elsewhere = true:suggestion # Prefer method-like constructs to have a block body csharp_style_expression_bodied_methods = false:none diff --git a/Gir.sln b/Gir.sln index 6dd975b..6514b60 100644 --- a/Gir.sln +++ b/Gir.sln @@ -2,9 +2,21 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 16 VisualStudioVersion = 16.0.30014.187 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gir", "src\Gir\Gir.csproj", "{D8FC3B49-B1A1-4DEB-8E76-EE537195AD38}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Gir", "src\Gir\Gir.csproj", "{D8FC3B49-B1A1-4DEB-8E76-EE537195AD38}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gir.Tests", "src\Gir.Tests\Gir.Tests.csproj", "{51FB7677-5684-4664-A59C-075CA6976F57}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Gir.Tests", "src\Gir.Tests\Gir.Tests.csproj", "{51FB7677-5684-4664-A59C-075CA6976F57}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{489766B3-C14A-4C72-A8D1-F3340A835755}" + ProjectSection(SolutionItems) = preProject + .editorconfig = .editorconfig + .gitignore = .gitignore + .jenkins.groovy = .jenkins.groovy + .jenkins.pullrequest.groovy = .jenkins.pullrequest.groovy + CODEOWNERS = CODEOWNERS + Directory.Build.props = Directory.Build.props + Directory.Build.targets = Directory.Build.targets + README.md = README.md + EndProjectSection EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/src/Gir/Generation/Bitfield.cs b/src/Gir/Generation/Bitfield.cs index d03264f..0206043 100644 --- a/src/Gir/Generation/Bitfield.cs +++ b/src/Gir/Generation/Bitfield.cs @@ -5,7 +5,7 @@ public partial class Bitfield : IGeneratable, IDocumented, IEnumFormatter { public string FormatValue (string value) { - int intValue = int.Parse (value); + var intValue = int.Parse (value); // Maybe pad with leading zeroes based on the value? return $"0x{intValue:X}"; diff --git a/src/Gir/Generation/IGeneratableExtensions.cs b/src/Gir/Generation/IGeneratableExtensions.cs index 0fabf0a..0617d2d 100644 --- a/src/Gir/Generation/IGeneratableExtensions.cs +++ b/src/Gir/Generation/IGeneratableExtensions.cs @@ -26,7 +26,7 @@ public static void GenerateDocumentation (this IDocumented gen, IndentWriter wri public static void GenerateMembers (this IGeneratable gen, IndentWriter writer, Func where = null) { var array = gen.GetMemberGeneratables ().Where (x => where == null || where (x)).ToArray (); - for (int i = 0; i < array.Length; ++i) { + for (var i = 0; i < array.Length; ++i) { var member = array [i]; // Generate pinvoke signature for a method @@ -100,7 +100,7 @@ public static void GenerateCallableDefinition (this INativeCallable callable, IG writer.WriteLine("{"); using (writer.Indent()) { - string prefix = returnType != "void" ? "return " : string.Empty; + var prefix = returnType != "void" ? "return " : string.Empty; writer.WriteLine($"{prefix}{callable.CIdentifier} ({result.Names});"); } writer.WriteLine("}"); @@ -127,7 +127,7 @@ public static ParametersResult BuildParameters(this IMethodLike callable, Genera var typeAndName = new List (parameters.Count); var parameterNames = new List (parameters.Count); - for (int i = 0; i < parameters.Count; ++i) { + for (var i = 0; i < parameters.Count; ++i) { var parameter = parameters [i]; if (!appendInstanceParameters) { if (parameter is InstanceParameter) @@ -145,9 +145,9 @@ public static ParametersResult BuildParameters(this IMethodLike callable, Genera } // PERF: Use an array as the string[] overload of Join is way more efficient than the IEnumerable one. - string marshalParameterString = string.Join(", ", marshalTypeAndName.ToArray()); - string parameterString = string.Join (", ", typeAndName.ToArray ()); - string baseParams = string.Join (", ", parameterNames.ToArray ()); + var marshalParameterString = string.Join(", ", marshalTypeAndName.ToArray()); + var parameterString = string.Join (", ", typeAndName.ToArray ()); + var baseParams = string.Join (", ", parameterNames.ToArray ()); return new ParametersResult(marshalParameterString, parameterString, baseParams); } diff --git a/src/Gir/Generation/Member.cs b/src/Gir/Generation/Member.cs index a3d2ec4..763bf88 100644 --- a/src/Gir/Generation/Member.cs +++ b/src/Gir/Generation/Member.cs @@ -1,4 +1,4 @@ - + namespace Gir { public partial class Member : IMemberGeneratable, IDocumented @@ -7,7 +7,7 @@ public partial class Member : IMemberGeneratable, IDocumented public void Generate (IGeneratable parent, IndentWriter writer) { - string value = Value; + var value = Value; if (parent is IEnumFormatter formatter) value = formatter.FormatValue (value); diff --git a/src/Gir/GenerationOptions.cs b/src/Gir/GenerationOptions.cs index eea5856..78053c0 100644 --- a/src/Gir/GenerationOptions.cs +++ b/src/Gir/GenerationOptions.cs @@ -39,7 +39,7 @@ public sealed class GenerationOptions IEnumerable AllRepositories { get; } Repository Repository { get; } - List allGeneratables = new List (); + readonly List allGeneratables = new List (); public GenerationOptions (string dir, IEnumerable allRepos, Repository repo, ToggleOptions options = null) { diff --git a/src/Gir/Marshal/SymbolTable.cs b/src/Gir/Marshal/SymbolTable.cs index 7f040c3..fe299ed 100644 --- a/src/Gir/Marshal/SymbolTable.cs +++ b/src/Gir/Marshal/SymbolTable.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections; using System.Collections.Generic; using System.Linq; @@ -8,7 +8,7 @@ namespace Gir public partial class SymbolTable : IEnumerable { readonly Dictionary typeMap = new Dictionary (); - Statistics statistics; + readonly Statistics statistics; public SymbolTable (Statistics statistics, bool nativeWin64) { @@ -19,7 +19,7 @@ public SymbolTable (Statistics statistics, bool nativeWin64) public void AddTypes (IEnumerable symbols, Repository repository = null) { - string nsPrefix = repository != null ? repository.Namespace.Name + "." : string.Empty; + var nsPrefix = repository != null ? repository.Namespace.Name + "." : string.Empty; foreach (var symbol in symbols) AddTypeCommon (nsPrefix + symbol.Name, symbol); @@ -27,7 +27,7 @@ public void AddTypes (IEnumerable symbols, Repository repository = null public void AddType (ISymbol symbol, Repository repository = null) { - string nsPrefix = repository != null ? repository.Namespace.Name + "." : string.Empty; + var nsPrefix = repository != null ? repository.Namespace.Name + "." : string.Empty; AddTypeCommon (nsPrefix + symbol.Name, symbol); } diff --git a/src/Gir/Parser.cs b/src/Gir/Parser.cs index a114059..d78268e 100644 --- a/src/Gir/Parser.cs +++ b/src/Gir/Parser.cs @@ -1,12 +1,12 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Xml.Serialization; namespace Gir { public static class Parser { - public static IEnumerable Parse (string fileName, string includeDir, out Repository mainRepository) { using var fs = File.OpenRead (fileName); @@ -15,7 +15,7 @@ public static IEnumerable Parse (string fileName, string includeDir, public static IEnumerable Parse (Stream s, string includeDir, out Repository mainRepository) { - var serializer = new System.Xml.Serialization.XmlSerializer (typeof (Repository)); + var serializer = new XmlSerializer (typeof (Repository)); mainRepository = (Repository)serializer.Deserialize (s); var repositories = ParseRecursive (mainRepository, includeDir, new Dictionary ()).ToList (); @@ -32,7 +32,7 @@ public static IEnumerable ParseRecursive (Repository repository, str foreach (var include in repository.Includes) { using var fs = File.OpenRead (Path.Combine (includeDir, include.GirName)); - var serializer = new System.Xml.Serialization.XmlSerializer (typeof (Repository)); + var serializer = new XmlSerializer (typeof (Repository)); var repo = (Repository)serializer.Deserialize (fs); diff --git a/src/Gir/Program.cs b/src/Gir/Program.cs index eaed79d..8dd335c 100644 --- a/src/Gir/Program.cs +++ b/src/Gir/Program.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.IO; @@ -37,7 +37,7 @@ public static int Main (string[] args) } var opt = new OptionSet (); - foreach (string arg in args) + foreach (var arg in args) ParseArg (opt, arg); opt.AllRepositories = Parser.Parse (args [0], opt.IncludeSearchDirectory, out opt.GenerationRepository); @@ -51,7 +51,7 @@ public static int Main (string[] args) if (!Directory.Exists (opt.OutputDirectory)) Directory.CreateDirectory (opt.OutputDirectory); - foreach (IGeneratable gen in genOpts.AllGeneratables) { + foreach (var gen in genOpts.AllGeneratables) { gen.Generate (genOpts); } diff --git a/src/Gir/Statistics.cs b/src/Gir/Statistics.cs index 3ecfb1b..5af8a37 100644 --- a/src/Gir/Statistics.cs +++ b/src/Gir/Statistics.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; @@ -45,7 +45,7 @@ public IEnumerable GetErrorsContent () public void RegisterType (ISymbol symbol) { var type = symbol.GetType (); - RegisteredCount.TryGetValue (type, out int count); + RegisteredCount.TryGetValue (type, out var count); RegisteredCount [type] = ++count; } diff --git a/src/Gir/Utils.cs b/src/Gir/Utils.cs index 0be72f1..c5b4f83 100644 --- a/src/Gir/Utils.cs +++ b/src/Gir/Utils.cs @@ -1,4 +1,4 @@ -using System.Collections; +using System.Collections; using System.Collections.Generic; using System.Linq; using System.Reflection; @@ -14,7 +14,7 @@ public static string ToCSharp (this string cname) // Capitalize the first letter, and parse for underscores, capitalizing the letters after them var sb = new StringBuilder (cname.Length); - bool isUpper = true; + var isUpper = true; foreach (var c in cname) { if (c == '_' || c == '-') { isUpper = true; @@ -57,7 +57,7 @@ static bool IsCollectionOf (System.Type t) continue; var args = @interface.GetGenericArguments (); - bool isOfT = typeof (T).IsAssignableFrom (args [0]); + var isOfT = typeof (T).IsAssignableFrom (args [0]); if (isOfT) return true; }