diff --git a/src/CLI/Generator.cs b/src/CLI/Generator.cs index ed215001d..58db9ac72 100644 --- a/src/CLI/Generator.cs +++ b/src/CLI/Generator.cs @@ -108,6 +108,9 @@ public bool ValidateOptions(List messages) if (string.IsNullOrEmpty(options.OutputNamespace)) options.OutputNamespace = moduleName; + if (options.IncludeDirs.Count == 0) + options.IncludeDirs.Add(Path.GetDirectoryName(options.HeaderFiles.First())); + SetupTargetTriple(); return true; diff --git a/src/Generator/Driver.cs b/src/Generator/Driver.cs index 29e36d968..82780bfa2 100644 --- a/src/Generator/Driver.cs +++ b/src/Generator/Driver.cs @@ -439,7 +439,12 @@ public static void Run(ILibrary library) } new CleanUnitPass { Context = driver.Context }.VisitASTContext(driver.Context.ASTContext); - options.Modules.RemoveAll(m => m != options.SystemModule && !m.Units.GetGenerated().Any()); + foreach (var module in options.Modules.Where( + m => m != options.SystemModule && !m.Units.GetGenerated().Any())) + { + Diagnostics.Message($"Removing module {module} because no translation units are generated..."); + options.Modules.Remove(module); + } if (!options.Quiet) Diagnostics.Message("Processing code..."); diff --git a/src/Generator/Passes/CleanUnitPass.cs b/src/Generator/Passes/CleanUnitPass.cs index 4d1b3750d..3afaa028f 100644 --- a/src/Generator/Passes/CleanUnitPass.cs +++ b/src/Generator/Passes/CleanUnitPass.cs @@ -31,6 +31,11 @@ private Module GetModule(TranslationUnit unit) includeDir = "."; includeDir = Path.GetFullPath(includeDir); + // Added in https://github.com/mono/CppSharp/pull/1736, but causes us issues. + // return Options.Modules.FirstOrDefault( + // m => m.IncludeDirs.Any(i => Path.GetFullPath(i) == includeDir)) ?? + // Options.Modules[1]; + Module module = Options.Modules.Find( m => m.IncludeDirs.Any(i => Path.GetFullPath(i) == includeDir)); if (module == null)