From 9555eec24f6c913cc64a228ff2cb30c27c5633b4 Mon Sep 17 00:00:00 2001 From: josetr <37419832+josetr@users.noreply.github.com> Date: Mon, 14 Mar 2022 11:38:49 +0000 Subject: [PATCH] Revert "Ignore external (no module) translation units" This reverts commit 0d8b236f7e7f4dfdd71c66aa87c340386b063d6d. --- src/Generator.Tests/GeneratorTest.cs | 9 +-------- src/Generator/Passes/CleanUnitPass.cs | 27 ++++++++++++--------------- src/Generator/Passes/DelegatesPass.cs | 5 ++--- 3 files changed, 15 insertions(+), 26 deletions(-) diff --git a/src/Generator.Tests/GeneratorTest.cs b/src/Generator.Tests/GeneratorTest.cs index feff986f..70d647f7 100644 --- a/src/Generator.Tests/GeneratorTest.cs +++ b/src/Generator.Tests/GeneratorTest.cs @@ -44,16 +44,9 @@ namespace CppSharp.Utils testModule.Libraries.Add($"{name}.Native"); Diagnostics.Message("Looking for tests in: {0}", path); - var files = Directory.EnumerateFiles(path, "*.h", SearchOption.AllDirectories); + var files = Directory.EnumerateFiles(path, "*.h"); foreach (var file in files) - { - string includeDir = Path.GetDirectoryName(file); - if (!testModule.IncludeDirs.Contains(includeDir)) - { - testModule.IncludeDirs.Add(includeDir); - } testModule.Headers.Add(Path.GetFileName(file)); - } } public virtual void Preprocess(Driver driver, ASTContext ctx) diff --git a/src/Generator/Passes/CleanUnitPass.cs b/src/Generator/Passes/CleanUnitPass.cs index 4d1b3750..c9978f92 100644 --- a/src/Generator/Passes/CleanUnitPass.cs +++ b/src/Generator/Passes/CleanUnitPass.cs @@ -31,14 +31,9 @@ namespace CppSharp.Passes includeDir = "."; includeDir = Path.GetFullPath(includeDir); - Module module = Options.Modules.Find( - m => m.IncludeDirs.Any(i => Path.GetFullPath(i) == includeDir)); - if (module == null) - { - unit.ExplicitlyIgnore(); - module = Options.Modules[1]; - } - return module; + return Options.Modules.FirstOrDefault( + m => m.IncludeDirs.Any(i => Path.GetFullPath(i) == includeDir)) ?? + Options.Modules[1]; } public override bool VisitDeclarationContext(DeclarationContext context) @@ -46,9 +41,10 @@ namespace CppSharp.Passes return false; } - private string GetIncludePath(string filePath) + string GetIncludePath(string filePath) { var includePath = filePath; + var shortestIncludePath = filePath; for (uint i = 0; i < Context.ParserOptions.IncludeDirsCount; ++i) { @@ -61,15 +57,16 @@ namespace CppSharp.Passes idx = filePath.IndexOf(path, System.StringComparison.Ordinal); } - if (idx != -1) - { - includePath = filePath[path.Length..]; - break; - } + if (idx == -1) continue; + + string inc = filePath.Substring(path.Length); + + if (inc.Length < includePath.Length && inc.Length < shortestIncludePath.Length) + shortestIncludePath = inc; } includePath = Options.IncludePrefix - + includePath.TrimStart(new char[] { '\\', '/' }); + + shortestIncludePath.TrimStart(new char[] { '\\', '/' }); return includePath.Replace('\\', '/'); } diff --git a/src/Generator/Passes/DelegatesPass.cs b/src/Generator/Passes/DelegatesPass.cs index 591eb2d0..51ed3c47 100644 --- a/src/Generator/Passes/DelegatesPass.cs +++ b/src/Generator/Passes/DelegatesPass.cs @@ -215,8 +215,7 @@ namespace CppSharp.Passes Namespace parent = null; if (string.IsNullOrEmpty(module.OutputNamespace)) { - var groups = module.Units.Where(u => u.IsGenerated).SelectMany( - u => u.Declarations).OfType( + var groups = module.Units.SelectMany(u => u.Declarations).OfType( ).GroupBy(d => d.Name).Where(g => g.Any(d => d.HasDeclarations)).ToList(); if (groups.Count == 1) parent = groups.Last().Last(); @@ -232,7 +231,7 @@ namespace CppSharp.Passes } if (parent == null) - parent = module.Units.Last(u => u.IsGenerated); + parent = module.Units.Last(); var namespaceDelegates = new Namespace {