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 InputManagedAssemblyPath { get; set; }
|
||||||
public string OutputDirectory { get; set; }
|
public string OutputDirectory { get; set; }
|
||||||
public string IntermediateDirectory { get; set; }
|
public string IntermediateDirectory { get; set; }
|
||||||
public string BuildConfiguration { get; set; }
|
public BuildConfiguration? BuildConfiguration { get; set; }
|
||||||
public string Architecture { get; set; }
|
public ArchitectureMode Architecture { get; set; }
|
||||||
public string NativeMode { get; set; }
|
public NativeIntermediateMode? NativeMode { get; set; }
|
||||||
public List<string> ReferencePaths { get; set; }
|
public List<string> ReferencePaths { get; set; }
|
||||||
public string IlcArgs { get; set; }
|
public string IlcArgs { get; set; }
|
||||||
public List<string> LinkLibPaths { get; set; }
|
public List<string> LinkLibPaths { get; set; }
|
||||||
|
|
|
@ -1,14 +1,4 @@
|
||||||
using System;
|
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
|
namespace Microsoft.DotNet.Tools.Compiler.Native
|
||||||
{
|
{
|
||||||
|
|
|
@ -11,72 +11,138 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
|
||||||
private const NativeIntermediateMode DefaultNativeModel = NativeIntermediateMode.ryujit;
|
private const NativeIntermediateMode DefaultNativeModel = NativeIntermediateMode.ryujit;
|
||||||
private const ArchitectureMode DefaultArchitectureMode = ArchitectureMode.x64;
|
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 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 InputManagedAssemblyPath
|
||||||
|
|
||||||
public string BuildTypeString
|
|
||||||
{
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _inputManagedAssemblyPath;
|
||||||
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
try
|
if(!File.Exists(value))
|
||||||
{
|
{
|
||||||
BuildType = EnumExtensions.Parse<BuildConfiguration>(value.ToLower());
|
throw new Exception($"Could not find the input managed assembly: {value}");
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
throw new Exception("Invalid Configuration Option.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_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 ArchitectureMode Architecture { get; set; }
|
||||||
public NativeIntermediateMode NativeMode { get; set; }
|
public NativeIntermediateMode NativeMode { get; set; }
|
||||||
public OSMode OS { 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)
|
// Optional Customization Points (Can be null)
|
||||||
public string IlcArgs { get; set; }
|
public string IlcArgs { get; set; }
|
||||||
public List<string> LinkLibPaths { get; set; }
|
public IEnumerable<string> LinkLibPaths => _linkLibPaths;
|
||||||
|
|
||||||
// Required Customization Points (Must have default)
|
// Required Customization Points (Must have default)
|
||||||
public string AppDepSDKPath { get; set; }
|
public string AppDepSDKPath {
|
||||||
public string IlcPath { get; set; }
|
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()
|
private NativeCompileSettings()
|
||||||
{
|
{
|
||||||
LinkLibPaths = new List<string>();
|
_linkLibPaths = new List<string>();
|
||||||
ReferencePaths = new List<string>();
|
_referencePaths = new List<string>();
|
||||||
|
|
||||||
IlcPath = AppContext.BaseDirectory;
|
IlcPath = AppContext.BaseDirectory;
|
||||||
Architecture = DefaultArchitectureMode;
|
Architecture = DefaultArchitectureMode;
|
||||||
BuildType = DefaultBuiltType;
|
BuildType = DefaultBuiltType;
|
||||||
NativeMode = DefaultNativeModel;
|
NativeMode = DefaultNativeModel;
|
||||||
AppDepSDKPath = Path.Combine(AppContext.BaseDirectory, "appdepsdk");
|
AppDepSDKPath = Path.Combine(AppContext.BaseDirectory, "appdepsdk");
|
||||||
|
|
||||||
ReferencePaths.Add(Path.Combine(AppDepSDKPath, "*.dll"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static NativeCompileSettings Default
|
public static NativeCompileSettings Default
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
var nativeCompileSettings = new NativeCompileSettings
|
var defaultNativeCompileSettings = new NativeCompileSettings
|
||||||
{
|
{
|
||||||
OS = RuntimeInformationExtensions.GetCurrentOS()
|
OS = RuntimeInformationExtensions.GetCurrentOS()
|
||||||
};
|
};
|
||||||
|
|
||||||
nativeCompileSettings.SetDefaultOutputDirectory();
|
return defaultNativeCompileSettings;
|
||||||
nativeCompileSettings.SetDefaultIntermediateDirectory();
|
|
||||||
|
|
||||||
return nativeCompileSettings;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public string DetermineFinalOutputPath()
|
public string DetermineFinalOutputPath()
|
||||||
{
|
{
|
||||||
|
@ -87,16 +153,26 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
|
||||||
var outFile = Path.Combine(outputDirectory, filename + Constants.ExeSuffix);
|
var outFile = Path.Combine(outputDirectory, filename + Constants.ExeSuffix);
|
||||||
|
|
||||||
return outFile;
|
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)
|
private string GetOutputDirectory(string beginsWith)
|
||||||
|
|
|
@ -22,7 +22,9 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
|
||||||
string outputDirectory = null;
|
string outputDirectory = null;
|
||||||
string temporaryOutputDirectory = null;
|
string temporaryOutputDirectory = null;
|
||||||
string configuration = null;
|
string configuration = null;
|
||||||
|
BuildConfiguration? buildConfiguration = null;
|
||||||
string mode = null;
|
string mode = null;
|
||||||
|
NativeIntermediateMode? nativeMode = null;
|
||||||
string ilcArgs = null;
|
string ilcArgs = null;
|
||||||
string ilcPath = null;
|
string ilcPath = null;
|
||||||
string appDepSdk = 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.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.");
|
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)
|
catch (ArgumentSyntaxException)
|
||||||
|
@ -64,14 +95,14 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
|
||||||
|
|
||||||
Console.WriteLine($"Input Assembly: {inputAssembly}");
|
Console.WriteLine($"Input Assembly: {inputAssembly}");
|
||||||
|
|
||||||
return new ArgValues()
|
return new ArgValues
|
||||||
{
|
{
|
||||||
InputManagedAssemblyPath = inputAssembly,
|
InputManagedAssemblyPath = inputAssembly,
|
||||||
OutputDirectory = outputDirectory,
|
OutputDirectory = outputDirectory,
|
||||||
IntermediateDirectory = temporaryOutputDirectory,
|
IntermediateDirectory = temporaryOutputDirectory,
|
||||||
Architecture = "x64",
|
Architecture = ArchitectureMode.x64,
|
||||||
BuildConfiguration = configuration,
|
BuildConfiguration = buildConfiguration,
|
||||||
NativeMode = mode,
|
NativeMode = nativeMode,
|
||||||
ReferencePaths = references.ToList(),
|
ReferencePaths = references.ToList(),
|
||||||
IlcArgs = ilcArgs,
|
IlcArgs = ilcArgs,
|
||||||
IlcPath = ilcPath,
|
IlcPath = ilcPath,
|
||||||
|
@ -114,7 +145,7 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
System.Console.WriteLine(ex);
|
Console.WriteLine(ex);
|
||||||
#else
|
#else
|
||||||
Reporter.Error.WriteLine(ex.Message);
|
Reporter.Error.WriteLine(ex.Message);
|
||||||
#endif
|
#endif
|
||||||
|
@ -130,132 +161,76 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
string content = null;
|
string content;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
content = File.ReadAllText(rspPath);
|
content = File.ReadAllText(rspPath);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
Reporter.Error.WriteLine("Unable to Read Response File");
|
Reporter.Error.WriteLine("Unable to Read Response File");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
string[] nArgs = content.Split(new [] {"\r\n", "\n"}, StringSplitOptions.RemoveEmptyEntries);
|
var nArgs = content.Split(new [] {"\r\n", "\n"}, StringSplitOptions.RemoveEmptyEntries);
|
||||||
return nArgs;
|
return nArgs;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static NativeCompileSettings ParseAndValidateArgs(ArgValues args)
|
private static NativeCompileSettings ParseAndValidateArgs(ArgValues args)
|
||||||
{
|
{
|
||||||
var config = NativeCompileSettings.Default;
|
var config = NativeCompileSettings.Default;
|
||||||
|
|
||||||
// Managed Input
|
config.InputManagedAssemblyPath = args.InputManagedAssemblyPath;
|
||||||
if (string.IsNullOrEmpty(args.InputManagedAssemblyPath) || !File.Exists(args.InputManagedAssemblyPath))
|
config.Architecture = args.Architecture;
|
||||||
|
|
||||||
|
if (args.BuildConfiguration.HasValue)
|
||||||
{
|
{
|
||||||
//TODO make this message good
|
config.BuildType = args.BuildConfiguration.Value;
|
||||||
throw new Exception("Invalid Managed Assembly Argument.");
|
}
|
||||||
}
|
|
||||||
|
|
||||||
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))
|
if(!string.IsNullOrEmpty(args.OutputDirectory))
|
||||||
{
|
{
|
||||||
config.OutputDirectory = args.OutputDirectory;
|
config.OutputDirectory = args.OutputDirectory;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: same here Intermediate
|
|
||||||
if(!string.IsNullOrEmpty(args.IntermediateDirectory))
|
if(!string.IsNullOrEmpty(args.IntermediateDirectory))
|
||||||
{
|
{
|
||||||
config.IntermediateDirectory = args.IntermediateDirectory;
|
config.IntermediateDirectory = args.IntermediateDirectory;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mode
|
if (args.NativeMode.HasValue)
|
||||||
if (!string.IsNullOrEmpty(args.NativeMode))
|
|
||||||
{
|
{
|
||||||
try
|
config.NativeMode = args.NativeMode.Value;
|
||||||
{
|
|
||||||
config.NativeMode = EnumExtensions.Parse<NativeIntermediateMode>(args.NativeMode.ToLower());
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
throw new Exception("Invalid Mode Option.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// AppDeps (TEMP)
|
|
||||||
if(!string.IsNullOrEmpty(args.AppDepSDKPath))
|
if(!string.IsNullOrEmpty(args.AppDepSDKPath))
|
||||||
{
|
{
|
||||||
if (!Directory.Exists(args.AppDepSDKPath))
|
|
||||||
{
|
|
||||||
throw new Exception("AppDepSDK Directory does not exist.");
|
|
||||||
}
|
|
||||||
|
|
||||||
config.AppDepSDKPath = args.AppDepSDKPath;
|
config.AppDepSDKPath = args.AppDepSDKPath;
|
||||||
|
|
||||||
var reference = Path.Combine(config.AppDepSDKPath, "*.dll");
|
|
||||||
config.ReferencePaths.Add(reference);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// IlcPath
|
|
||||||
if (!string.IsNullOrEmpty(args.IlcPath))
|
if (!string.IsNullOrEmpty(args.IlcPath))
|
||||||
{
|
{
|
||||||
if (!Directory.Exists(args.IlcPath))
|
|
||||||
{
|
|
||||||
throw new Exception("ILC Directory does not exist.");
|
|
||||||
}
|
|
||||||
|
|
||||||
config.IlcPath = args.IlcPath;
|
config.IlcPath = args.IlcPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
// logpath
|
|
||||||
if (!string.IsNullOrEmpty(args.LogPath))
|
if (!string.IsNullOrEmpty(args.LogPath))
|
||||||
{
|
{
|
||||||
config.LogPath = Path.GetFullPath(args.LogPath);
|
config.LogPath = Path.GetFullPath(args.LogPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
// CodeGenPath
|
|
||||||
if (!string.IsNullOrEmpty(args.IlcArgs))
|
if (!string.IsNullOrEmpty(args.IlcArgs))
|
||||||
{
|
{
|
||||||
config.IlcArgs = Path.GetFullPath(args.IlcArgs);
|
config.IlcArgs = Path.GetFullPath(args.IlcArgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reference Paths
|
|
||||||
foreach (var reference in args.ReferencePaths)
|
foreach (var reference in args.ReferencePaths)
|
||||||
{
|
{
|
||||||
config.ReferencePaths.Add(Path.GetFullPath(reference));
|
config.AddReference(reference);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Link Libs
|
|
||||||
foreach (var lib in args.LinkLibPaths)
|
foreach (var lib in args.LinkLibPaths)
|
||||||
{
|
{
|
||||||
config.LinkLibPaths.Add(lib);
|
config.AddLinkLibPath(lib);
|
||||||
}
|
}
|
||||||
|
|
||||||
return config;
|
return config;
|
||||||
|
|
Loading…
Add table
Reference in a new issue