Skip to content

Commit 12c267d

Browse files
authored
Fixed a bug causing the header file to be included twice when Options.GenerateName is not null (#1803)
1 parent e068f2a commit 12c267d

File tree

4 files changed

+11
-4
lines changed

4 files changed

+11
-4
lines changed

src/Generator/Generators/C/CppHeaders.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.IO;
34
using System.Linq;
45
using CppSharp.AST;
56
using CppSharp.AST.Extensions;
@@ -87,7 +88,8 @@ public void GenerateIncludeForwardRefs(TranslationUnit unit)
8788
if (typeRef.Include.TranslationUnit == unit)
8889
continue;
8990

90-
if (typeRef.Include.File == unit.FileName)
91+
var filename = Context.Options.GenerateName != null ? $"{Context.Options.GenerateName(TranslationUnit)}{Path.GetExtension(TranslationUnit.FileName)}" : TranslationUnit.FileName;
92+
if (typeRef.Include.File == filename)
9193
continue;
9294

9395
var include = typeRef.Include;

src/Generator/Generators/C/CppSources.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ public virtual void GenerateForwardReferenceHeaders(TranslationUnit unit)
6464

6565
foreach (var typeRef in typeReferenceCollector.TypeReferences)
6666
{
67-
if (typeRef.Include.File == unit.FileName)
67+
var filename = Context.Options.GenerateName != null ? $"{Context.Options.GenerateName(TranslationUnit)}{Path.GetExtension(TranslationUnit.FileName)}" : TranslationUnit.FileName;
68+
if (typeRef.Include.File == filename)
6869
continue;
6970

7071
var include = typeRef.Include;

src/Generator/Generators/CLI/CLIHeaders.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.IO;
34
using System.Linq;
45
using CppSharp.AST;
56
using CppSharp.AST.Extensions;
@@ -61,7 +62,8 @@ public void GenerateIncludeForwardRefs()
6162
if (typeRef.Include.TranslationUnit == TranslationUnit)
6263
continue;
6364

64-
if (typeRef.Include.File == TranslationUnit.FileName)
65+
var filename = Context.Options.GenerateName != null ? $"{Context.Options.GenerateName(TranslationUnit)}{Path.GetExtension(TranslationUnit.FileName)}" : TranslationUnit.FileName;
66+
if (typeRef.Include.File == filename)
6567
continue;
6668

6769
var include = typeRef.Include;

src/Generator/Generators/CLI/CLISources.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Globalization;
4+
using System.IO;
45
using System.Linq;
56
using CppSharp.AST;
67
using CppSharp.AST.Extensions;
@@ -61,7 +62,8 @@ public void GenerateForwardReferenceHeaders()
6162

6263
foreach (var typeRef in typeReferenceCollector.TypeReferences)
6364
{
64-
if (typeRef.Include.File == TranslationUnit.FileName)
65+
var filename = Context.Options.GenerateName != null ? $"{Context.Options.GenerateName(TranslationUnit)}{Path.GetExtension(TranslationUnit.FileName)}" : TranslationUnit.FileName;
66+
if (typeRef.Include.File == filename)
6567
continue;
6668

6769
var include = typeRef.Include;

0 commit comments

Comments
 (0)