xamarin-macios/msbuild/Xamarin.MacDev.Tasks.Core/Tasks/MetalTaskBase.cs

123 строки
3.1 KiB
C#
Исходник Обычный вид История

2016-04-21 16:40:25 +03:00
using System;
using System.IO;
using System.Collections.Generic;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using Xamarin.MacDev;
namespace Xamarin.MacDev.Tasks
{
public abstract class MetalTaskBase : ToolTask
{
#region Inputs
public string SessionId { get; set; }
public ITaskItem AppManifest { get; set; }
2016-04-21 16:40:25 +03:00
[Required]
public string IntermediateOutputPath { get; set; }
[Required]
public string ProjectDir { get; set; }
[Required]
public string ResourcePrefix { get; set; }
[Required]
public string SdkDevPath { get; set; }
[Required]
public string SdkVersion { get; set; }
2016-04-21 16:40:25 +03:00
[Required]
public ITaskItem SourceFile { get; set; }
#endregion
[Output]
public ITaskItem OutputFile { get; set; }
protected abstract string MinimumDeploymentTargetKey {
get;
}
2016-04-21 16:40:25 +03:00
protected abstract string OperatingSystem {
get;
}
protected abstract string DevicePlatformBinDir {
get;
}
protected override string ToolName {
get { return "metal"; }
}
protected override string GenerateFullPathToTool ()
{
if (!string.IsNullOrEmpty (ToolPath))
return Path.Combine (ToolPath, ToolExe);
var path = Path.Combine (DevicePlatformBinDir, ToolExe);
return File.Exists (path) ? path : ToolExe;
}
protected override string GenerateCommandLineCommands ()
{
var prefixes = BundleResource.SplitResourcePrefixes (ResourcePrefix);
var intermediate = Path.Combine (IntermediateOutputPath, ToolName);
var logicalName = BundleResource.GetLogicalName (ProjectDir, prefixes, SourceFile, !string.IsNullOrEmpty(SessionId));
2016-04-21 16:40:25 +03:00
var path = Path.Combine (intermediate, logicalName);
var args = new CommandLineArgumentBuilder ();
2016-04-21 16:40:25 +03:00
var dir = Path.GetDirectoryName (path);
string minimumDeploymentTarget;
2016-04-21 16:40:25 +03:00
if (!Directory.Exists (dir))
Directory.CreateDirectory (dir);
if (AppManifest != null) {
var plist = PDictionary.FromFile (AppManifest.ItemSpec);
PString value;
if (!plist.TryGetValue (MinimumDeploymentTargetKey, out value) || string.IsNullOrEmpty (value.Value))
minimumDeploymentTarget = SdkVersion;
else
minimumDeploymentTarget = value.Value;
} else {
minimumDeploymentTarget = SdkVersion;
}
2016-04-21 16:40:25 +03:00
OutputFile = new TaskItem (Path.ChangeExtension (path, ".air"));
OutputFile.SetMetadata ("LogicalName", Path.ChangeExtension (logicalName, ".air"));
args.Add ("-arch", "air64");
args.Add ("-emit-llvm");
args.Add ("-c");
args.Add ("-gline-tables-only");
args.Add ("-ffast-math");
args.Add ("-serialize-diagnostics");
args.AddQuoted (Path.ChangeExtension (path, ".dia"));
args.Add ("-o");
args.AddQuoted (Path.ChangeExtension (path, ".air"));
args.Add (string.Format ("-m{0}-version-min={1}", OperatingSystem, minimumDeploymentTarget));
2016-04-21 16:40:25 +03:00
args.AddQuoted (SourceFile.ItemSpec);
return args.ToString ();
}
protected override void LogEventsFromTextOutput (string singleLine, MessageImportance messageImportance)
{
// TODO: do proper parsing of error messages and such
Log.LogMessage (messageImportance, "{0}", singleLine);
}
}
}