2015-11-17 20:10:19 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using Microsoft.DotNet.Cli.Utils;
|
|
|
|
|
|
|
|
|
|
namespace Microsoft.DotNet.Tools.Compiler.Native
|
|
|
|
|
{
|
2016-01-31 05:47:50 +00:00
|
|
|
|
public class CompileNativeCommand
|
2015-11-17 20:10:19 +00:00
|
|
|
|
{
|
2016-01-31 05:47:50 +00:00
|
|
|
|
public static int Run(string[] args)
|
2015-11-17 20:10:19 +00:00
|
|
|
|
{
|
|
|
|
|
DebugHelper.HandleDebugSwitch(ref args);
|
2015-11-18 19:56:35 +00:00
|
|
|
|
|
|
|
|
|
return ExecuteApp(args);
|
2015-11-21 01:23:19 +00:00
|
|
|
|
}
|
2015-11-18 19:56:35 +00:00
|
|
|
|
|
|
|
|
|
private static int ExecuteApp(string[] args)
|
2015-11-17 20:10:19 +00:00
|
|
|
|
{
|
|
|
|
|
// Support Response File
|
|
|
|
|
foreach(var arg in args)
|
|
|
|
|
{
|
|
|
|
|
if(arg.Contains(".rsp"))
|
|
|
|
|
{
|
|
|
|
|
args = ParseResponseFile(arg);
|
|
|
|
|
|
|
|
|
|
if (args == null)
|
|
|
|
|
{
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2015-11-21 01:23:19 +00:00
|
|
|
|
var cmdLineArgs = ArgumentsParser.Parse(args);
|
2015-12-16 23:45:24 +00:00
|
|
|
|
|
|
|
|
|
if (cmdLineArgs.IsHelp) return cmdLineArgs.ReturnCode;
|
|
|
|
|
|
2015-11-21 01:23:19 +00:00
|
|
|
|
var config = cmdLineArgs.GetNativeCompileSettings();
|
2015-11-18 19:56:35 +00:00
|
|
|
|
|
|
|
|
|
DirectoryExtensions.CleanOrCreateDirectory(config.OutputDirectory);
|
|
|
|
|
DirectoryExtensions.CleanOrCreateDirectory(config.IntermediateDirectory);
|
|
|
|
|
|
|
|
|
|
var nativeCompiler = NativeCompiler.Create(config);
|
|
|
|
|
|
|
|
|
|
var result = nativeCompiler.CompileToNative(config);
|
|
|
|
|
|
|
|
|
|
return result ? 0 : 1;
|
2015-11-17 20:10:19 +00:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
#if DEBUG
|
2015-11-21 00:38:50 +00:00
|
|
|
|
Console.WriteLine(ex);
|
2015-11-17 20:10:19 +00:00
|
|
|
|
#else
|
|
|
|
|
Reporter.Error.WriteLine(ex.Message);
|
|
|
|
|
#endif
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static string[] ParseResponseFile(string rspPath)
|
|
|
|
|
{
|
|
|
|
|
if (!File.Exists(rspPath))
|
|
|
|
|
{
|
|
|
|
|
Reporter.Error.WriteLine("Invalid Response File Path");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-21 00:38:50 +00:00
|
|
|
|
string content;
|
2015-11-17 20:10:19 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
content = File.ReadAllText(rspPath);
|
|
|
|
|
}
|
2015-11-21 00:38:50 +00:00
|
|
|
|
catch (Exception)
|
2015-11-17 20:10:19 +00:00
|
|
|
|
{
|
|
|
|
|
Reporter.Error.WriteLine("Unable to Read Response File");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-21 00:38:50 +00:00
|
|
|
|
var nArgs = content.Split(new [] {"\r\n", "\n"}, StringSplitOptions.RemoveEmptyEntries);
|
2015-11-17 20:10:19 +00:00
|
|
|
|
return nArgs;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|