Browse Source

General CLI code cleanups.

pull/1865/head
Joao Matos 11 months ago
parent
commit
aaaffff727
  1. 11
      src/CLI/CLI.cs
  2. 29
      src/CLI/Generator.cs

11
src/CLI/CLI.cs

@ -152,7 +152,9 @@ namespace CppSharp
{ {
bool searchQuery = args.IndexOf('*') >= 0 || args.IndexOf('?') >= 0; bool searchQuery = args.IndexOf('*') >= 0 || args.IndexOf('?') >= 0;
if (searchQuery || Directory.Exists(args)) if (searchQuery || Directory.Exists(args))
{
GetFilesFromPath(args, errorMessages); GetFilesFromPath(args, errorMessages);
}
else if (File.Exists(args)) else if (File.Exists(args))
options.HeaderFiles.Add(args); options.HeaderFiles.Add(args);
else else
@ -175,7 +177,8 @@ namespace CppSharp
if (lastSeparatorPosition >= 0) if (lastSeparatorPosition >= 0)
{ {
if (path.IndexOf('*', lastSeparatorPosition) >= lastSeparatorPosition || path.IndexOf('?', lastSeparatorPosition) >= lastSeparatorPosition) if (path.IndexOf('*', lastSeparatorPosition) >= lastSeparatorPosition ||
path.IndexOf('?', lastSeparatorPosition) >= lastSeparatorPosition)
{ {
searchPattern = path.Substring(lastSeparatorPosition + 1); searchPattern = path.Substring(lastSeparatorPosition + 1);
path = path.Substring(0, lastSeparatorPosition); path = path.Substring(0, lastSeparatorPosition);
@ -257,7 +260,8 @@ namespace CppSharp
return; return;
} }
errorMessages.Add($"Unknown target architecture: {architecture}. Defaulting to {options.Architecture}"); errorMessages.Add($@"Unknown target architecture: {architecture}. \
Defaulting to {options.Architecture}");
} }
static void PrintErrorMessages(List<string> errorMessages) static void PrintErrorMessages(List<string> errorMessages)
@ -275,7 +279,8 @@ namespace CppSharp
{ {
PrintErrorMessages(errorMessages); PrintErrorMessages(errorMessages);
// Don't need to show the help since if ParseCommandLineArgs returns false the help has already been shown // Don't need to show the help since if ParseCommandLineArgs returns false
// since the help has already been shown
return; return;
} }

29
src/CLI/Generator.cs

@ -91,6 +91,21 @@ namespace CppSharp
options.OutputDir = Path.Combine(Directory.GetCurrentDirectory(), "gen"); options.OutputDir = Path.Combine(Directory.GetCurrentDirectory(), "gen");
} }
if (string.IsNullOrEmpty(options.OutputFileName))
options.OutputFileName = GetModuleNameFromHeaderFiles();
if (string.IsNullOrEmpty(options.OutputNamespace))
options.OutputNamespace = GetModuleNameFromHeaderFiles();
if (options.IncludeDirs.Count == 0)
options.IncludeDirs.Add(Path.GetDirectoryName(options.HeaderFiles.First()));
SetupTargetTriple();
return true;
string GetModuleNameFromHeaderFiles()
{
string moduleName; string moduleName;
if (options.HeaderFiles.Count == 1) if (options.HeaderFiles.Count == 1)
{ {
@ -102,18 +117,8 @@ namespace CppSharp
moduleName = new DirectoryInfo(dir).Name; moduleName = new DirectoryInfo(dir).Name;
} }
if (string.IsNullOrEmpty(options.OutputFileName)) return moduleName;
options.OutputFileName = moduleName; }
if (string.IsNullOrEmpty(options.OutputNamespace))
options.OutputNamespace = moduleName;
if (options.IncludeDirs.Count == 0)
options.IncludeDirs.Add(Path.GetDirectoryName(options.HeaderFiles.First()));
SetupTargetTriple();
return true;
} }
public void Setup(Driver driver) public void Setup(Driver driver)

Loading…
Cancel
Save