Moving default values inside NativeCompileSettings
This commit is contained in:
parent
da70b047e9
commit
0b6a084d1f
2 changed files with 76 additions and 98 deletions
|
@ -1,15 +1,16 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
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
|
||||
{
|
||||
public class NativeCompileSettings
|
||||
{
|
||||
private const BuildConfiguration DefaultBuiltType = BuildConfiguration.debug;
|
||||
private const NativeIntermediateMode DefaultNativeModel = NativeIntermediateMode.ryujit;
|
||||
private const ArchitectureMode DefaultArchitectureMode = ArchitectureMode.x64;
|
||||
|
||||
public string LogPath { get; set; }
|
||||
public string InputManagedAssemblyPath { get; set; }
|
||||
|
||||
|
@ -17,6 +18,22 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
|
|||
public string IntermediateDirectory { get; set; }
|
||||
|
||||
public BuildConfiguration BuildType { get; set; }
|
||||
|
||||
public string BuildTypeString
|
||||
{
|
||||
set
|
||||
{
|
||||
try
|
||||
{
|
||||
BuildType = EnumExtensions.Parse<BuildConfiguration>(value.ToLower());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new Exception("Invalid Configuration Option.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ArchitectureMode Architecture { get; set; }
|
||||
public NativeIntermediateMode NativeMode { get; set; }
|
||||
public OSMode OS { get; set; }
|
||||
|
@ -31,23 +48,62 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
|
|||
public string AppDepSDKPath { get; set; }
|
||||
public string IlcPath { get; set; }
|
||||
|
||||
public NativeCompileSettings()
|
||||
private NativeCompileSettings()
|
||||
{
|
||||
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"));
|
||||
}
|
||||
|
||||
public static NativeCompileSettings Default
|
||||
{
|
||||
get
|
||||
{
|
||||
var nativeCompileSettings = new NativeCompileSettings
|
||||
{
|
||||
OS = RuntimeInformationExtensions.GetCurrentOS()
|
||||
};
|
||||
|
||||
nativeCompileSettings.SetDefaultOutputDirectory();
|
||||
nativeCompileSettings.SetDefaultIntermediateDirectory();
|
||||
|
||||
return nativeCompileSettings;
|
||||
}
|
||||
}
|
||||
|
||||
public string DetermineFinalOutputPath()
|
||||
{
|
||||
var outputDirectory = this.OutputDirectory;
|
||||
var outputDirectory = OutputDirectory;
|
||||
|
||||
var filename = Path.GetFileNameWithoutExtension(this.InputManagedAssemblyPath);
|
||||
var filename = Path.GetFileNameWithoutExtension(InputManagedAssemblyPath);
|
||||
|
||||
var outFile = Path.Combine(outputDirectory, filename + Constants.ExeSuffix);
|
||||
|
||||
return outFile;
|
||||
}
|
||||
|
||||
private void SetDefaultOutputDirectory()
|
||||
{
|
||||
OutputDirectory = GetOutputDirectory(Constants.BinDirectoryName);
|
||||
}
|
||||
|
||||
|
||||
private void SetDefaultIntermediateDirectory()
|
||||
{
|
||||
IntermediateDirectory = GetOutputDirectory(Constants.ObjDirectoryName);
|
||||
}
|
||||
|
||||
private string GetOutputDirectory(string beginsWith)
|
||||
{
|
||||
var dir = Path.Combine(beginsWith, Architecture.ToString(), BuildType.ToString(), "native");
|
||||
|
||||
return Path.GetFullPath(dir);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -147,7 +147,7 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
|
|||
|
||||
private static NativeCompileSettings ParseAndValidateArgs(ArgValues args)
|
||||
{
|
||||
var config = new NativeCompileSettings();
|
||||
var config = NativeCompileSettings.Default;
|
||||
|
||||
// Managed Input
|
||||
if (string.IsNullOrEmpty(args.InputManagedAssemblyPath) || !File.Exists(args.InputManagedAssemblyPath))
|
||||
|
@ -159,17 +159,7 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
|
|||
config.InputManagedAssemblyPath = Path.GetFullPath(args.InputManagedAssemblyPath);
|
||||
|
||||
// Architecture
|
||||
if(string.IsNullOrEmpty(args.Architecture))
|
||||
{
|
||||
config.Architecture = RuntimeExtensions.GetCurrentArchitecture();
|
||||
|
||||
// CoreRT does not support x86 yet
|
||||
if (config.Architecture != ArchitectureMode.x64)
|
||||
{
|
||||
throw new Exception("Native Compilation currently only supported for x64.");
|
||||
}
|
||||
}
|
||||
else
|
||||
if(!string.IsNullOrEmpty(args.Architecture))
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -182,11 +172,7 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
|
|||
}
|
||||
|
||||
// BuildConfiguration
|
||||
if(string.IsNullOrEmpty(args.BuildConfiguration))
|
||||
{
|
||||
config.BuildType = GetDefaultBuildType();
|
||||
}
|
||||
else
|
||||
if(!string.IsNullOrEmpty(args.BuildConfiguration))
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -198,32 +184,20 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
|
|||
}
|
||||
}
|
||||
|
||||
// Output
|
||||
if(string.IsNullOrEmpty(args.OutputDirectory))
|
||||
{
|
||||
config.OutputDirectory = GetDefaultOutputDir(config);
|
||||
}
|
||||
else
|
||||
// TODO: track changing it when architeture or buildtype change Output
|
||||
if(!string.IsNullOrEmpty(args.OutputDirectory))
|
||||
{
|
||||
config.OutputDirectory = args.OutputDirectory;
|
||||
}
|
||||
|
||||
// Intermediate
|
||||
if(string.IsNullOrEmpty(args.IntermediateDirectory))
|
||||
{
|
||||
config.IntermediateDirectory = GetDefaultIntermediateDir(config);
|
||||
}
|
||||
else
|
||||
// TODO: same here Intermediate
|
||||
if(!string.IsNullOrEmpty(args.IntermediateDirectory))
|
||||
{
|
||||
config.IntermediateDirectory = args.IntermediateDirectory;
|
||||
}
|
||||
|
||||
// Mode
|
||||
if (string.IsNullOrEmpty(args.NativeMode))
|
||||
{
|
||||
config.NativeMode = GetDefaultNativeMode();
|
||||
}
|
||||
else
|
||||
if (!string.IsNullOrEmpty(args.NativeMode))
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -248,13 +222,6 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
|
|||
var reference = Path.Combine(config.AppDepSDKPath, "*.dll");
|
||||
config.ReferencePaths.Add(reference);
|
||||
}
|
||||
else
|
||||
{
|
||||
config.AppDepSDKPath = GetDefaultAppDepSDKPath();
|
||||
|
||||
var reference = Path.Combine(config.AppDepSDKPath, "*.dll");
|
||||
config.ReferencePaths.Add(reference);
|
||||
}
|
||||
|
||||
// IlcPath
|
||||
if (!string.IsNullOrEmpty(args.IlcPath))
|
||||
|
@ -266,10 +233,6 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
|
|||
|
||||
config.IlcPath = args.IlcPath;
|
||||
}
|
||||
else
|
||||
{
|
||||
config.IlcPath = GetDefaultIlcPath();
|
||||
}
|
||||
|
||||
// logpath
|
||||
if (!string.IsNullOrEmpty(args.LogPath))
|
||||
|
@ -295,48 +258,7 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
|
|||
config.LinkLibPaths.Add(lib);
|
||||
}
|
||||
|
||||
// OS
|
||||
config.OS = RuntimeInformationExtensions.GetCurrentOS();
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
private static string GetDefaultOutputDir(NativeCompileSettings config)
|
||||
{
|
||||
var dir = Path.Combine(Constants.BinDirectoryName, config.Architecture.ToString(), config.BuildType.ToString(), "native");
|
||||
|
||||
return Path.GetFullPath(dir);
|
||||
}
|
||||
|
||||
private static string GetDefaultIntermediateDir(NativeCompileSettings config)
|
||||
{
|
||||
var dir = Path.Combine(Constants.ObjDirectoryName, config.Architecture.ToString(), config.BuildType.ToString(), "native");
|
||||
|
||||
return Path.GetFullPath(dir);
|
||||
}
|
||||
|
||||
private static BuildConfiguration GetDefaultBuildType()
|
||||
{
|
||||
return BuildConfiguration.debug;
|
||||
}
|
||||
|
||||
private static NativeIntermediateMode GetDefaultNativeMode()
|
||||
{
|
||||
return NativeIntermediateMode.ryujit;
|
||||
}
|
||||
|
||||
private static string GetDefaultAppDepSDKPath()
|
||||
{
|
||||
var appRoot = AppContext.BaseDirectory;
|
||||
|
||||
var dir = Path.Combine(appRoot, "appdepsdk");
|
||||
|
||||
return dir;
|
||||
}
|
||||
|
||||
private static string GetDefaultIlcPath()
|
||||
{
|
||||
return AppContext.BaseDirectory;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue