Moving validation into NativeCompileSettings. Left argument requirement and argument to enum validation in the ArgumentSyntax delegate
This commit is contained in:
parent
0b6a084d1f
commit
db3a9ffc20
4 changed files with 170 additions and 129 deletions
|
@ -18,9 +18,9 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
|
|||
public string InputManagedAssemblyPath { get; set; }
|
||||
public string OutputDirectory { get; set; }
|
||||
public string IntermediateDirectory { get; set; }
|
||||
public string BuildConfiguration { get; set; }
|
||||
public string Architecture { get; set; }
|
||||
public string NativeMode { get; set; }
|
||||
public BuildConfiguration? BuildConfiguration { get; set; }
|
||||
public ArchitectureMode Architecture { get; set; }
|
||||
public NativeIntermediateMode? NativeMode { get; set; }
|
||||
public List<string> ReferencePaths { get; set; }
|
||||
public string IlcArgs { get; set; }
|
||||
public List<string> LinkLibPaths { get; set; }
|
||||
|
|
|
@ -1,14 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.IO;
|
||||
|
||||
using Microsoft.Dnx.Runtime.Common.CommandLine;
|
||||
using Microsoft.DotNet.Cli.Utils;
|
||||
using Microsoft.DotNet.Tools.Common;
|
||||
|
||||
namespace Microsoft.DotNet.Tools.Compiler.Native
|
||||
{
|
||||
|
|
|
@ -11,72 +11,138 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
|
|||
private const NativeIntermediateMode DefaultNativeModel = NativeIntermediateMode.ryujit;
|
||||
private const ArchitectureMode DefaultArchitectureMode = ArchitectureMode.x64;
|
||||
|
||||
private string _inputManagedAssemblyPath;
|
||||
private string _appDepSdkPath;
|
||||
private string _ilcPath;
|
||||
private string _outputDirectory;
|
||||
private string _intermediateDirectory;
|
||||
private readonly List<string> _referencePaths;
|
||||
private readonly List<string> _linkLibPaths;
|
||||
|
||||
public string LogPath { get; set; }
|
||||
public string InputManagedAssemblyPath { get; set; }
|
||||
|
||||
public string OutputDirectory { get; set; }
|
||||
public string IntermediateDirectory { get; set; }
|
||||
|
||||
public BuildConfiguration BuildType { get; set; }
|
||||
|
||||
public string BuildTypeString
|
||||
public string InputManagedAssemblyPath
|
||||
{
|
||||
get
|
||||
{
|
||||
return _inputManagedAssemblyPath;
|
||||
}
|
||||
set
|
||||
{
|
||||
try
|
||||
if(!File.Exists(value))
|
||||
{
|
||||
BuildType = EnumExtensions.Parse<BuildConfiguration>(value.ToLower());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new Exception("Invalid Configuration Option.");
|
||||
throw new Exception($"Could not find the input managed assembly: {value}");
|
||||
}
|
||||
|
||||
_inputManagedAssemblyPath = Path.GetFullPath(value);
|
||||
}
|
||||
}
|
||||
|
||||
public string OutputDirectory
|
||||
{
|
||||
get
|
||||
{
|
||||
return _outputDirectory ?? GetDefaultOutputDirectory();
|
||||
}
|
||||
set
|
||||
{
|
||||
_outputDirectory = value;
|
||||
}
|
||||
}
|
||||
|
||||
public string IntermediateDirectory
|
||||
{
|
||||
get
|
||||
{
|
||||
return _intermediateDirectory ?? GetDefaultIntermediateDirectory();
|
||||
}
|
||||
set
|
||||
{
|
||||
_intermediateDirectory = value;
|
||||
}
|
||||
}
|
||||
|
||||
public BuildConfiguration BuildType { get; set; }
|
||||
|
||||
public ArchitectureMode Architecture { get; set; }
|
||||
public NativeIntermediateMode NativeMode { get; set; }
|
||||
public OSMode OS { get; set; }
|
||||
|
||||
public List<string> ReferencePaths { get; set; }
|
||||
|
||||
|
||||
public IEnumerable<string> ReferencePaths
|
||||
{
|
||||
get
|
||||
{
|
||||
var referencePaths = new List<string>(_referencePaths)
|
||||
{
|
||||
Path.Combine(AppDepSDKPath, "*.dll")
|
||||
};
|
||||
|
||||
return referencePaths;
|
||||
}
|
||||
}
|
||||
|
||||
// Optional Customization Points (Can be null)
|
||||
public string IlcArgs { get; set; }
|
||||
public List<string> LinkLibPaths { get; set; }
|
||||
|
||||
public IEnumerable<string> LinkLibPaths => _linkLibPaths;
|
||||
|
||||
// Required Customization Points (Must have default)
|
||||
public string AppDepSDKPath { get; set; }
|
||||
public string IlcPath { get; set; }
|
||||
public string AppDepSDKPath {
|
||||
get
|
||||
{
|
||||
return _appDepSdkPath;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (!Directory.Exists(value))
|
||||
{
|
||||
throw new Exception($"AppDepSDK Directory does not exist: {value}.");
|
||||
}
|
||||
|
||||
_appDepSdkPath = value;
|
||||
}
|
||||
}
|
||||
|
||||
public string IlcPath
|
||||
{
|
||||
get
|
||||
{
|
||||
return _ilcPath;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (!Directory.Exists(value))
|
||||
{
|
||||
throw new Exception($"ILC Directory does not exist: {value}.");
|
||||
}
|
||||
|
||||
_ilcPath = value;
|
||||
}
|
||||
}
|
||||
|
||||
private NativeCompileSettings()
|
||||
{
|
||||
LinkLibPaths = new List<string>();
|
||||
ReferencePaths = new List<string>();
|
||||
_linkLibPaths = new List<string>();
|
||||
_referencePaths = new List<string>();
|
||||
|
||||
IlcPath = AppContext.BaseDirectory;
|
||||
Architecture = DefaultArchitectureMode;
|
||||
BuildType = DefaultBuiltType;
|
||||
NativeMode = DefaultNativeModel;
|
||||
AppDepSDKPath = Path.Combine(AppContext.BaseDirectory, "appdepsdk");
|
||||
|
||||
ReferencePaths.Add(Path.Combine(AppDepSDKPath, "*.dll"));
|
||||
AppDepSDKPath = Path.Combine(AppContext.BaseDirectory, "appdepsdk");
|
||||
}
|
||||
|
||||
public static NativeCompileSettings Default
|
||||
{
|
||||
get
|
||||
{
|
||||
var nativeCompileSettings = new NativeCompileSettings
|
||||
{
|
||||
var defaultNativeCompileSettings = new NativeCompileSettings
|
||||
{
|
||||
OS = RuntimeInformationExtensions.GetCurrentOS()
|
||||
};
|
||||
|
||||
nativeCompileSettings.SetDefaultOutputDirectory();
|
||||
nativeCompileSettings.SetDefaultIntermediateDirectory();
|
||||
|
||||
return nativeCompileSettings;
|
||||
return defaultNativeCompileSettings;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string DetermineFinalOutputPath()
|
||||
{
|
||||
|
@ -87,16 +153,26 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
|
|||
var outFile = Path.Combine(outputDirectory, filename + Constants.ExeSuffix);
|
||||
|
||||
return outFile;
|
||||
}
|
||||
|
||||
private void SetDefaultOutputDirectory()
|
||||
{
|
||||
OutputDirectory = GetOutputDirectory(Constants.BinDirectoryName);
|
||||
}
|
||||
|
||||
private void SetDefaultIntermediateDirectory()
|
||||
public void AddReference(string reference)
|
||||
{
|
||||
IntermediateDirectory = GetOutputDirectory(Constants.ObjDirectoryName);
|
||||
_referencePaths.Add(Path.GetFullPath(reference));
|
||||
}
|
||||
|
||||
public void AddLinkLibPath(string linkLibPath)
|
||||
{
|
||||
_linkLibPaths.Add(linkLibPath);
|
||||
}
|
||||
|
||||
private string GetDefaultOutputDirectory()
|
||||
{
|
||||
return GetOutputDirectory(Constants.BinDirectoryName);
|
||||
}
|
||||
|
||||
private string GetDefaultIntermediateDirectory()
|
||||
{
|
||||
return GetOutputDirectory(Constants.ObjDirectoryName);
|
||||
}
|
||||
|
||||
private string GetOutputDirectory(string beginsWith)
|
||||
|
|
|
@ -22,7 +22,9 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
|
|||
string outputDirectory = null;
|
||||
string temporaryOutputDirectory = null;
|
||||
string configuration = null;
|
||||
BuildConfiguration? buildConfiguration = null;
|
||||
string mode = null;
|
||||
NativeIntermediateMode? nativeMode = null;
|
||||
string ilcArgs = null;
|
||||
string ilcPath = null;
|
||||
string appDepSdk = null;
|
||||
|
@ -55,6 +57,35 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
|
|||
syntax.DefineOption("logpath", ref logPath, "Use to dump Native Compilation Logs to a file.");
|
||||
|
||||
syntax.DefineParameter("INPUT_ASSEMBLY", ref inputAssembly, "The managed input assembly to compile to native.");
|
||||
|
||||
if (string.IsNullOrWhiteSpace(inputAssembly))
|
||||
{
|
||||
syntax.ReportError("Input Assembly is a required parameter.");
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(configuration))
|
||||
{
|
||||
try
|
||||
{
|
||||
buildConfiguration = EnumExtensions.Parse<BuildConfiguration>(configuration);
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
syntax.ReportError($"Invalid Configuration Option: {configuration}");
|
||||
}
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(mode))
|
||||
{
|
||||
try
|
||||
{
|
||||
nativeMode = EnumExtensions.Parse<NativeIntermediateMode>(mode);
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
syntax.ReportError($"Invalid Mode Option: {mode}");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (ArgumentSyntaxException)
|
||||
|
@ -64,14 +95,14 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
|
|||
|
||||
Console.WriteLine($"Input Assembly: {inputAssembly}");
|
||||
|
||||
return new ArgValues()
|
||||
return new ArgValues
|
||||
{
|
||||
InputManagedAssemblyPath = inputAssembly,
|
||||
OutputDirectory = outputDirectory,
|
||||
IntermediateDirectory = temporaryOutputDirectory,
|
||||
Architecture = "x64",
|
||||
BuildConfiguration = configuration,
|
||||
NativeMode = mode,
|
||||
Architecture = ArchitectureMode.x64,
|
||||
BuildConfiguration = buildConfiguration,
|
||||
NativeMode = nativeMode,
|
||||
ReferencePaths = references.ToList(),
|
||||
IlcArgs = ilcArgs,
|
||||
IlcPath = ilcPath,
|
||||
|
@ -114,7 +145,7 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
|
|||
catch (Exception ex)
|
||||
{
|
||||
#if DEBUG
|
||||
System.Console.WriteLine(ex);
|
||||
Console.WriteLine(ex);
|
||||
#else
|
||||
Reporter.Error.WriteLine(ex.Message);
|
||||
#endif
|
||||
|
@ -130,132 +161,76 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
|
|||
return null;
|
||||
}
|
||||
|
||||
string content = null;
|
||||
string content;
|
||||
try
|
||||
{
|
||||
content = File.ReadAllText(rspPath);
|
||||
}
|
||||
catch (Exception e)
|
||||
catch (Exception)
|
||||
{
|
||||
Reporter.Error.WriteLine("Unable to Read Response File");
|
||||
return null;
|
||||
}
|
||||
|
||||
string[] nArgs = content.Split(new [] {"\r\n", "\n"}, StringSplitOptions.RemoveEmptyEntries);
|
||||
var nArgs = content.Split(new [] {"\r\n", "\n"}, StringSplitOptions.RemoveEmptyEntries);
|
||||
return nArgs;
|
||||
}
|
||||
|
||||
private static NativeCompileSettings ParseAndValidateArgs(ArgValues args)
|
||||
{
|
||||
var config = NativeCompileSettings.Default;
|
||||
|
||||
// Managed Input
|
||||
if (string.IsNullOrEmpty(args.InputManagedAssemblyPath) || !File.Exists(args.InputManagedAssemblyPath))
|
||||
|
||||
config.InputManagedAssemblyPath = args.InputManagedAssemblyPath;
|
||||
config.Architecture = args.Architecture;
|
||||
|
||||
if (args.BuildConfiguration.HasValue)
|
||||
{
|
||||
//TODO make this message good
|
||||
throw new Exception("Invalid Managed Assembly Argument.");
|
||||
}
|
||||
config.BuildType = args.BuildConfiguration.Value;
|
||||
}
|
||||
|
||||
config.InputManagedAssemblyPath = Path.GetFullPath(args.InputManagedAssemblyPath);
|
||||
|
||||
// Architecture
|
||||
if(!string.IsNullOrEmpty(args.Architecture))
|
||||
{
|
||||
try
|
||||
{
|
||||
config.Architecture = EnumExtensions.Parse<ArchitectureMode>(args.Architecture.ToLower());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new Exception("Invalid Architecture Option.");
|
||||
}
|
||||
}
|
||||
|
||||
// BuildConfiguration
|
||||
if(!string.IsNullOrEmpty(args.BuildConfiguration))
|
||||
{
|
||||
try
|
||||
{
|
||||
config.BuildType = EnumExtensions.Parse<BuildConfiguration>(args.BuildConfiguration.ToLower());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new Exception("Invalid Configuration Option.");
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: track changing it when architeture or buildtype change Output
|
||||
if(!string.IsNullOrEmpty(args.OutputDirectory))
|
||||
{
|
||||
config.OutputDirectory = args.OutputDirectory;
|
||||
}
|
||||
|
||||
// TODO: same here Intermediate
|
||||
|
||||
if(!string.IsNullOrEmpty(args.IntermediateDirectory))
|
||||
{
|
||||
config.IntermediateDirectory = args.IntermediateDirectory;
|
||||
}
|
||||
|
||||
// Mode
|
||||
if (!string.IsNullOrEmpty(args.NativeMode))
|
||||
if (args.NativeMode.HasValue)
|
||||
{
|
||||
try
|
||||
{
|
||||
config.NativeMode = EnumExtensions.Parse<NativeIntermediateMode>(args.NativeMode.ToLower());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new Exception("Invalid Mode Option.");
|
||||
}
|
||||
config.NativeMode = args.NativeMode.Value;
|
||||
}
|
||||
|
||||
// AppDeps (TEMP)
|
||||
if(!string.IsNullOrEmpty(args.AppDepSDKPath))
|
||||
{
|
||||
if (!Directory.Exists(args.AppDepSDKPath))
|
||||
{
|
||||
throw new Exception("AppDepSDK Directory does not exist.");
|
||||
}
|
||||
|
||||
config.AppDepSDKPath = args.AppDepSDKPath;
|
||||
|
||||
var reference = Path.Combine(config.AppDepSDKPath, "*.dll");
|
||||
config.ReferencePaths.Add(reference);
|
||||
}
|
||||
|
||||
// IlcPath
|
||||
if (!string.IsNullOrEmpty(args.IlcPath))
|
||||
{
|
||||
if (!Directory.Exists(args.IlcPath))
|
||||
{
|
||||
throw new Exception("ILC Directory does not exist.");
|
||||
}
|
||||
|
||||
{
|
||||
config.IlcPath = args.IlcPath;
|
||||
}
|
||||
|
||||
// logpath
|
||||
if (!string.IsNullOrEmpty(args.LogPath))
|
||||
{
|
||||
config.LogPath = Path.GetFullPath(args.LogPath);
|
||||
}
|
||||
|
||||
// CodeGenPath
|
||||
if (!string.IsNullOrEmpty(args.IlcArgs))
|
||||
{
|
||||
config.IlcArgs = Path.GetFullPath(args.IlcArgs);
|
||||
}
|
||||
|
||||
// Reference Paths
|
||||
foreach (var reference in args.ReferencePaths)
|
||||
{
|
||||
config.ReferencePaths.Add(Path.GetFullPath(reference));
|
||||
config.AddReference(reference);
|
||||
}
|
||||
|
||||
// Link Libs
|
||||
foreach (var lib in args.LinkLibPaths)
|
||||
{
|
||||
config.LinkLibPaths.Add(lib);
|
||||
config.AddLinkLibPath(lib);
|
||||
}
|
||||
|
||||
return config;
|
||||
|
|
Loading…
Add table
Reference in a new issue