Moving default values inside NativeCompileSettings

This commit is contained in:
Livar Cunha 2015-11-20 10:43:55 -08:00
parent da70b047e9
commit 0b6a084d1f
2 changed files with 76 additions and 98 deletions

View file

@ -1,22 +1,39 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using Microsoft.Dnx.Runtime.Common.CommandLine;
using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.Tools.Common;
namespace Microsoft.DotNet.Tools.Compiler.Native namespace Microsoft.DotNet.Tools.Compiler.Native
{ {
public class NativeCompileSettings 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 LogPath { get; set; }
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 BuildConfiguration BuildType { 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 ArchitectureMode Architecture { get; set; }
public NativeIntermediateMode NativeMode { get; set; } public NativeIntermediateMode NativeMode { get; set; }
public OSMode OS { get; set; } public OSMode OS { get; set; }
@ -31,23 +48,62 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
public string AppDepSDKPath { get; set; } public string AppDepSDKPath { get; set; }
public string IlcPath { get; set; } public string IlcPath { get; set; }
public NativeCompileSettings() private NativeCompileSettings()
{ {
LinkLibPaths = new List<string>(); LinkLibPaths = new List<string>();
ReferencePaths = 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() 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); var outFile = Path.Combine(outputDirectory, filename + Constants.ExeSuffix);
return outFile; 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);
} }
} }
} }

View file

@ -147,7 +147,7 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
private static NativeCompileSettings ParseAndValidateArgs(ArgValues args) private static NativeCompileSettings ParseAndValidateArgs(ArgValues args)
{ {
var config = new NativeCompileSettings(); var config = NativeCompileSettings.Default;
// Managed Input // Managed Input
if (string.IsNullOrEmpty(args.InputManagedAssemblyPath) || !File.Exists(args.InputManagedAssemblyPath)) if (string.IsNullOrEmpty(args.InputManagedAssemblyPath) || !File.Exists(args.InputManagedAssemblyPath))
@ -159,18 +159,8 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
config.InputManagedAssemblyPath = Path.GetFullPath(args.InputManagedAssemblyPath); config.InputManagedAssemblyPath = Path.GetFullPath(args.InputManagedAssemblyPath);
// Architecture // Architecture
if(string.IsNullOrEmpty(args.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
{
try try
{ {
config.Architecture = EnumExtensions.Parse<ArchitectureMode>(args.Architecture.ToLower()); config.Architecture = EnumExtensions.Parse<ArchitectureMode>(args.Architecture.ToLower());
@ -182,11 +172,7 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
} }
// BuildConfiguration // BuildConfiguration
if(string.IsNullOrEmpty(args.BuildConfiguration)) if(!string.IsNullOrEmpty(args.BuildConfiguration))
{
config.BuildType = GetDefaultBuildType();
}
else
{ {
try try
{ {
@ -198,32 +184,20 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
} }
} }
// Output // TODO: track changing it when architeture or buildtype change Output
if(string.IsNullOrEmpty(args.OutputDirectory)) if(!string.IsNullOrEmpty(args.OutputDirectory))
{
config.OutputDirectory = GetDefaultOutputDir(config);
}
else
{ {
config.OutputDirectory = args.OutputDirectory; config.OutputDirectory = args.OutputDirectory;
} }
// Intermediate // TODO: same here Intermediate
if(string.IsNullOrEmpty(args.IntermediateDirectory)) if(!string.IsNullOrEmpty(args.IntermediateDirectory))
{
config.IntermediateDirectory = GetDefaultIntermediateDir(config);
}
else
{ {
config.IntermediateDirectory = args.IntermediateDirectory; config.IntermediateDirectory = args.IntermediateDirectory;
} }
// Mode // Mode
if (string.IsNullOrEmpty(args.NativeMode)) if (!string.IsNullOrEmpty(args.NativeMode))
{
config.NativeMode = GetDefaultNativeMode();
}
else
{ {
try try
{ {
@ -248,13 +222,6 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
var reference = Path.Combine(config.AppDepSDKPath, "*.dll"); var reference = Path.Combine(config.AppDepSDKPath, "*.dll");
config.ReferencePaths.Add(reference); config.ReferencePaths.Add(reference);
} }
else
{
config.AppDepSDKPath = GetDefaultAppDepSDKPath();
var reference = Path.Combine(config.AppDepSDKPath, "*.dll");
config.ReferencePaths.Add(reference);
}
// IlcPath // IlcPath
if (!string.IsNullOrEmpty(args.IlcPath)) if (!string.IsNullOrEmpty(args.IlcPath))
@ -266,10 +233,6 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
config.IlcPath = args.IlcPath; config.IlcPath = args.IlcPath;
} }
else
{
config.IlcPath = GetDefaultIlcPath();
}
// logpath // logpath
if (!string.IsNullOrEmpty(args.LogPath)) if (!string.IsNullOrEmpty(args.LogPath))
@ -294,49 +257,8 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
{ {
config.LinkLibPaths.Add(lib); config.LinkLibPaths.Add(lib);
} }
// OS
config.OS = RuntimeInformationExtensions.GetCurrentOS();
return config; 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;
}
} }
} }