diff --git a/src/Microsoft.DotNet.Tools.Compiler.Native/NativeCompileSettings.cs b/src/Microsoft.DotNet.Tools.Compiler.Native/NativeCompileSettings.cs index 260c62ec5..ac933b28b 100644 --- a/src/Microsoft.DotNet.Tools.Compiler.Native/NativeCompileSettings.cs +++ b/src/Microsoft.DotNet.Tools.Compiler.Native/NativeCompileSettings.cs @@ -1,22 +1,39 @@ 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; } public string OutputDirectory { get; set; } public string IntermediateDirectory { get; set; } - + public BuildConfiguration BuildType { get; set; } + + public string BuildTypeString + { + set + { + try + { + BuildType = EnumExtensions.Parse(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(); ReferencePaths = new List(); - } + + 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); } } - - } \ No newline at end of file diff --git a/src/Microsoft.DotNet.Tools.Compiler.Native/Program.cs b/src/Microsoft.DotNet.Tools.Compiler.Native/Program.cs index db6156493..53e8fa7ba 100644 --- a/src/Microsoft.DotNet.Tools.Compiler.Native/Program.cs +++ b/src/Microsoft.DotNet.Tools.Compiler.Native/Program.cs @@ -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,18 +159,8 @@ 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 { config.Architecture = EnumExtensions.Parse(args.Architecture.ToLower()); @@ -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)) @@ -294,49 +257,8 @@ 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; - } + } } }