Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(490)

Unified Diff: visual_studio/NativeClientVSAddIn/NaCl.Build.CPPTasks/NaClLink.cs

Issue 11266051: Add PNaCl support for VS addin. (Closed) Base URL: http://nativeclient-sdk.googlecode.com/svn/trunk/src
Patch Set: fix nits and tests Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: visual_studio/NativeClientVSAddIn/NaCl.Build.CPPTasks/NaClLink.cs
diff --git a/visual_studio/NativeClientVSAddIn/NaCl.Build.CPPTasks/NaClLink.cs b/visual_studio/NativeClientVSAddIn/NaCl.Build.CPPTasks/NaClLink.cs
index 768051e501fb8aa4a34cc26b42d35f66a75c243b..9bb5f067a73ad6cfcd3952c4ab991f05332693c2 100644
--- a/visual_studio/NativeClientVSAddIn/NaCl.Build.CPPTasks/NaClLink.cs
+++ b/visual_studio/NativeClientVSAddIn/NaCl.Build.CPPTasks/NaClLink.cs
@@ -6,16 +6,33 @@ using System.Reflection;
using System.Text;
using Microsoft.Build.Framework;
using Microsoft.Build.CPPTasks;
+using Microsoft.Build.Utilities;
namespace NaCl.Build.CPPTasks
{
- public class NaClLink : TrackedVCToolTask
- {
- private XamlParser m_XamlParser;
-
+ public class NaClLink : NaClToolTask
+ {
public bool BuildingInIDE { get; set; }
+ /// <summary>
+ /// Property set only in PNaCl builds to signal that the translator
+ /// should be run post-link.
+ /// </summary>
+ public string TranslateARM { get; set; }
+
+ /// <summary>
+ /// Property set only in PNaCl builds to signal that the translator
+ /// should be run post-link.
+ /// </summary>
+ public string TranslateX86 { get; set; }
+
+ /// <summary>
+ /// Property set only in PNaCl builds to signal that the translator
+ /// should be run post-link.
+ /// </summary>
+ public string TranslateX64 { get; set; }
+
[Required]
public string OutputCommandLine { get; set; }
@@ -23,51 +40,87 @@ namespace NaCl.Build.CPPTasks
public string NaClLinkerPath { get; set; }
[Required]
- public virtual string OutputFile { get; set; }
+ public string Platform { get; set; }
[Required]
- public string PropertiesFile { get; set; }
+ public virtual string OutputFile { get; set; }
[Required]
- public virtual ITaskItem[] Sources { get; set; }
+ public string PropertiesFile { get; set; }
[Required]
public string ConfigurationType { get; set; }
- public NaClLink()
- : base(new ResourceManager("NaCl.Build.CPPTasks.Properties.Resources", Assembly.GetExecutingAssembly()))
+ protected override CanonicalTrackedOutputFiles OutputWriteTLog(ITaskItem[] inputs)
{
- this.EnvironmentVariables = new string[] { "CYGWIN=nodosfilewarning", "LC_CTYPE=C" };
- }
+ string path = Path.Combine(TlogDirectory, WriteTLogFilename);
+ TaskItem item = new TaskItem(path);
+ CanonicalTrackedOutputFiles trackedFiles =
+ new CanonicalTrackedOutputFiles(new TaskItem[] { item });
- protected override string CommandTLogName
- {
- get
+ foreach (ITaskItem sourceItem in Sources)
{
- return "default.link.command.tlog";
+ //remove this entry associated with compiled source which is about to be recomputed
+ trackedFiles.RemoveEntriesForSource(sourceItem);
+
+ //add entry with updated information
+ string upper = Path.GetFullPath(sourceItem.ItemSpec).ToUpperInvariant();
+ trackedFiles.AddComputedOutputForSourceRoot(upper, OutputFile);
}
+
+ //output tlog
+ trackedFiles.SaveTlog();
+
+ return trackedFiles;
}
- protected override string[] ReadTLogNames
+ protected override void OutputReadTLog(ITaskItem[] compiledSources, CanonicalTrackedOutputFiles outputs)
{
- get
+ string trackerPath = Path.GetFullPath(TlogDirectory + ReadTLogFilenames[0]);
+
+ using (StreamWriter writer = new StreamWriter(trackerPath, false, Encoding.Unicode))
{
- return new string[] {
- "default.link.read.tlog"
- };
+ string sourcePath = "";
+ foreach (ITaskItem source in Sources)
+ {
+ if (sourcePath != "")
+ sourcePath += "|";
+ sourcePath += Path.GetFullPath(source.ItemSpec).ToUpperInvariant();
+ }
+
+ writer.WriteLine("^" + sourcePath);
+ foreach (ITaskItem source in Sources)
+ {
+ writer.WriteLine(Path.GetFullPath(source.ItemSpec).ToUpperInvariant());
+ }
+ writer.WriteLine(Path.GetFullPath(OutputFile).ToUpperInvariant());
}
}
- protected override string[] WriteTLogNames
+ protected override void OutputCommandTLog(ITaskItem[] compiledSources)
{
- get
+ using (StreamWriter writer = new StreamWriter(TLogCommandFile.GetMetadata("FullPath"), false, Encoding.Unicode))
{
- return new string[] {
- "default.link.write.tlog"
- };
+ string cmds = GenerateResponseFileCommands();
+ string sourcePath = "";
+ foreach (ITaskItem source in Sources)
+ {
+ if (sourcePath != "")
+ sourcePath += "|";
+ sourcePath += Path.GetFullPath(source.ItemSpec).ToUpperInvariant();
+ }
+
+ writer.WriteLine("^" + sourcePath);
+ writer.WriteLine(cmds);
}
}
+ public NaClLink()
+ : base(new ResourceManager("NaCl.Build.CPPTasks.Properties.Resources", Assembly.GetExecutingAssembly()))
+ {
+ this.EnvironmentVariables = new string[] { "CYGWIN=nodosfilewarning", "LC_CTYPE=C" };
+ }
+
protected override void LogEventsFromTextOutput(string singleLine, MessageImportance messageImportance)
{
base.LogEventsFromTextOutput(GCCUtilities.ConvertGCCOutput(singleLine), messageImportance);
@@ -88,20 +141,58 @@ namespace NaCl.Build.CPPTasks
}
responseFileCmds.Append("-Wl,--end-group ");
- responseFileCmds.Append(m_XamlParser.Parse(Sources[0], false));
+ responseFileCmds.Append(xamlParser.Parse(Sources[0], false));
return responseFileCmds.ToString();
}
+ private bool Translate(string arch)
+ {
+ string nexeBase = Path.GetFileNameWithoutExtension(OutputFile) + "_" + arch + ".nexe";
+ string outfile = Path.Combine(Path.GetDirectoryName(OutputFile), nexeBase);
+
+ string commandLineCommands = String.Format("-arch {0} \"{1}\" -o \"{2}\"", arch, OutputFile, outfile);
+
+ string translateTool = Path.Combine(Path.GetDirectoryName(GenerateFullPathToTool()), "pnacl-translate.bat");
+ if (OutputCommandLine != "true")
+ Log.LogMessage("pnacl-translate {0}", Path.GetFileName(nexeBase));
+
+ if (ExecuteTool(translateTool, commandLineCommands, string.Empty) != 0)
+ {
+ return false;
+ }
+
+ return true;
+ }
+
public override bool Execute()
{
+ if (Platform.Equals("pnacl", StringComparison.OrdinalIgnoreCase))
+ {
+ if (!GCCUtilities.FindPython())
+ {
+ Log.LogError("PNaCl linking requires python in your executable path.");
+ return false;
+ }
+ }
+
bool returnResult = false;
try
{
- m_XamlParser = new XamlParser(PropertiesFile);
-
+ xamlParser = new XamlParser(PropertiesFile);
+ if (!Setup())
+ return false;
returnResult = base.Execute();
+
+ if (TranslateX64 == "true" && !Translate("x86_64"))
+ return false;
+
+ if (TranslateX86 == "true" && !Translate("i686"))
+ return false;
+
+ if (TranslateARM == "true" && !Translate("arm"))
+ return false;
}
finally
{
@@ -121,29 +212,11 @@ namespace NaCl.Build.CPPTasks
return base.ExecuteTool(pathToTool, responseFileCommands, commandLineCommands);
}
- protected override void PostProcessSwitchList()
- {
- //skip default behavior
- }
-
protected override string GenerateFullPathToTool()
{
return this.ToolName;
}
- protected override string TrackerIntermediateDirectory
- {
- get
- {
- if (this.TrackerLogDirectory != null)
- {
- return this.TrackerLogDirectory;
- }
-
- return string.Empty;
- }
- }
-
protected override Encoding ResponseFileEncoding
{
get
@@ -152,38 +225,37 @@ namespace NaCl.Build.CPPTasks
}
}
- protected override ITaskItem[] TrackedInputFiles
+ protected override string ToolName
{
get
{
- return this.Sources;
+ return NaClLinkerPath;
}
}
- protected override bool MaintainCompositeRootingMarkers
+ protected override string CommandTLogFilename
{
get
{
- return true;
+ return BaseTool() + ".link.command.1.tlog";
}
-
}
- protected override string ToolName
+ protected override string[] ReadTLogFilenames
{
get
{
- return NaClLinkerPath;
+ return new string[] { BaseTool() + ".link.read.1.tlog" };
}
}
- public override bool AttributeFileTracking
+ protected override string WriteTLogFilename
{
get
{
- return true;
+ return BaseTool() + ".link.write.1.tlog";
}
- }
+ }
public virtual string PlatformToolset
{
@@ -193,8 +265,6 @@ namespace NaCl.Build.CPPTasks
}
set
{}
- }
-
- public string TrackerLogDirectory { get; set; }
- }
+ }
+ }
}

Powered by Google App Engine
This is Rietveld 408576698