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

Side by Side 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: Created 8 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1  1 
2 using System; 2 using System;
3 using System.IO; 3 using System.IO;
4 using System.Resources; 4 using System.Resources;
5 using System.Reflection; 5 using System.Reflection;
6 using System.Text; 6 using System.Text;
7 using Microsoft.Build.Framework; 7 using Microsoft.Build.Framework;
8 using Microsoft.Build.CPPTasks; 8 using Microsoft.Build.CPPTasks;
9 using Microsoft.Build.Utilities;
9 10
10 11
11 namespace NaCl.Build.CPPTasks 12 namespace NaCl.Build.CPPTasks
12 { 13 {
13 public class NaClLink : TrackedVCToolTask 14 public class NaClLink : NaClToolTask
14 » { 15 {
15 private XamlParser m_XamlParser; 16 private XamlParser m_XamlParser;
16 17
17 public bool BuildingInIDE { get; set; } 18 public bool BuildingInIDE { get; set; }
18 19
19 [Required] 20 [Required]
20 public string OutputCommandLine { get; set; } 21 public string OutputCommandLine { get; set; }
21 22
22 [Required] 23 [Required]
23 public string NaClLinkerPath { get; set; } 24 public string NaClLinkerPath { get; set; }
24 25
25 [Required] 26 [Required]
27 public string Platform { get; set; }
28
29 [Required]
26 public virtual string OutputFile { get; set; } 30 public virtual string OutputFile { get; set; }
27 31
28 [Required] 32 [Required]
29 public string PropertiesFile { get; set; } 33 public string PropertiesFile { get; set; }
30 34
31 [Required] 35 [Required]
32 public virtual ITaskItem[] Sources { get; set; } 36 public string ConfigurationType { get; set; }
33 37
34 [Required] 38 protected override CanonicalTrackedOutputFiles OutputWriteTLog(ITaskItem [] inputs)
35 public string ConfigurationType { get; set; } 39 {
40 string path = Path.Combine(TlogDirectory, WriteTLogFilename);
41 TaskItem item = new TaskItem(path);
42 CanonicalTrackedOutputFiles trackedFiles = new CanonicalTrackedOutpu tFiles(new TaskItem[] { item });
43
44 foreach (ITaskItem sourceItem in Sources)
45 {
46 //remove this entry associated with compiled source which is abo ut to be recomputed
47 trackedFiles.RemoveEntriesForSource(sourceItem);
48
49 //add entry with updated information
50 trackedFiles.AddComputedOutputForSourceRoot(Path.GetFullPath(sou rceItem.ItemSpec).ToUpperInvariant(),
51 OutputFile);
52 }
53
54 //output tlog
55 trackedFiles.SaveTlog();
56
57 return trackedFiles;
58 }
59
60 protected override void OutputReadTLog(ITaskItem[] compiledSources, Cano nicalTrackedOutputFiles outputs)
61 {
62 string trackerPath = Path.GetFullPath(TlogDirectory + ReadTLogFilena mes[0]);
63
64 using (StreamWriter writer = new StreamWriter(trackerPath, false, En coding.Unicode))
65 {
66 string sourcePath = "";
67 foreach (ITaskItem source in Sources)
68 {
69 if (sourcePath != "")
70 sourcePath += "|";
71 sourcePath += Path.GetFullPath(source.ItemSpec).ToUpperInvar iant();
72 }
73
74 writer.WriteLine("^" + sourcePath);
75 foreach (ITaskItem source in Sources)
76 {
77 writer.WriteLine(Path.GetFullPath(source.ItemSpec).ToUpperIn variant());
78 }
79 writer.WriteLine(Path.GetFullPath(OutputFile).ToUpperInvariant() );
80 }
81 }
82
83 protected override void OutputCommandTLog(ITaskItem[] compiledSources)
84 {
85 //write tlog
86 using (StreamWriter writer = new StreamWriter(TLogCommandFile.GetMet adata("FullPath"), false, Encoding.Unicode))
87 {
88 string cmds = GenerateResponseFileCommands();
89 string sourcePath = "";
90 foreach (ITaskItem source in Sources)
91 {
92 if (sourcePath != "")
93 sourcePath += "|";
94 sourcePath += Path.GetFullPath(source.ItemSpec).ToUpperInvar iant();
95 }
96
97 writer.WriteLine("^" + sourcePath);
98 writer.WriteLine(cmds);
99 }
100 }
36 101
37 public NaClLink() 102 public NaClLink()
38 : base(new ResourceManager("NaCl.Build.CPPTasks.Properties.Resources ", Assembly.GetExecutingAssembly())) 103 : base(new ResourceManager("NaCl.Build.CPPTasks.Properties.Resources ", Assembly.GetExecutingAssembly()))
39 { 104 {
40 this.EnvironmentVariables = new string[] { "CYGWIN=nodosfilewarning", "LC_CTYPE=C" }; 105 this.EnvironmentVariables = new string[] { "CYGWIN=nodosfilewarning" , "LC_CTYPE=C" };
41 }
42
43 protected override string CommandTLogName
44 {
45 get
46 {
47 return "default.link.command.tlog";
48 }
49 }
50
51 protected override string[] ReadTLogNames
52 {
53 get
54 {
55 return new string[] {
56 "default.link.read.tlog"
57 };
58 }
59 }
60
61 protected override string[] WriteTLogNames
62 {
63 get
64 {
65 return new string[] {
66 "default.link.write.tlog"
67 };
68 }
69 } 106 }
70 107
71 protected override void LogEventsFromTextOutput(string singleLine, Messa geImportance messageImportance) 108 protected override void LogEventsFromTextOutput(string singleLine, Messa geImportance messageImportance)
72 { 109 {
73 base.LogEventsFromTextOutput(GCCUtilities.ConvertGCCOutput(singleLin e), messageImportance); 110 base.LogEventsFromTextOutput(GCCUtilities.ConvertGCCOutput(singleLin e), messageImportance);
74 } 111 }
75 112
76 protected override string GenerateResponseFileCommands() 113 protected override string GenerateResponseFileCommands()
77 { 114 {
78 StringBuilder responseFileCmds = new StringBuilder(GCCUtilities.s_Co mmandLineLength); 115 StringBuilder responseFileCmds = new StringBuilder(GCCUtilities.s_Co mmandLineLength);
79 116
80 // We want GCC to behave more like visual studio in term of library dependencies 117 // We want GCC to behave more like visual studio in term of library dependencies
81 // so we wrap all the inputs (libraries and object) into one group s o they are 118 // so we wrap all the inputs (libraries and object) into one group s o they are
82 // searched iteratively. 119 // searched iteratively.
83 responseFileCmds.Append("-Wl,--start-group "); 120 responseFileCmds.Append("-Wl,--start-group ");
84 foreach (ITaskItem sourceFile in Sources) 121 foreach (ITaskItem sourceFile in Sources)
85 { 122 {
86 responseFileCmds.Append(GCCUtilities.ConvertPathWindowsToPosix(s ourceFile.GetMetadata("Identity"))); 123 responseFileCmds.Append(GCCUtilities.ConvertPathWindowsToPosix(s ourceFile.GetMetadata("Identity")));
87 responseFileCmds.Append(" "); 124 responseFileCmds.Append(" ");
88 } 125 }
89 responseFileCmds.Append("-Wl,--end-group "); 126 responseFileCmds.Append("-Wl,--end-group ");
90 127
91 responseFileCmds.Append(m_XamlParser.Parse(Sources[0], false)); 128 responseFileCmds.Append(m_XamlParser.Parse(Sources[0], false));
92 129
93 return responseFileCmds.ToString(); 130 return responseFileCmds.ToString();
94 } 131 }
95 132
96 public override bool Execute() 133 public override bool Execute()
97 { 134 {
135 if (Platform.Equals("pnacl", StringComparison.OrdinalIgnoreCase))
136 {
137 if (!GCCUtilities.FindPython())
138 {
139 Log.LogError("PNaCl linking requires python in your executab le path.");
140 return false;
141 }
142 }
143
98 bool returnResult = false; 144 bool returnResult = false;
99 145
100 try 146 try
101 { 147 {
102 m_XamlParser = new XamlParser(PropertiesFile); 148 m_XamlParser = new XamlParser(PropertiesFile);
103 149 if (!Setup())
150 return false;
104 returnResult = base.Execute(); 151 returnResult = base.Execute();
105 } 152 }
106 finally 153 finally
107 { 154 {
108 155
109 } 156 }
110 157
111 return returnResult; 158 return returnResult;
112 } 159 }
113 160
114 protected override int ExecuteTool(string pathToTool, string responseFil eCommands, string commandLineCommands) 161 protected override int ExecuteTool(string pathToTool, string responseFil eCommands, string commandLineCommands)
115 { 162 {
116 if (OutputCommandLine == "true") 163 if (OutputCommandLine == "true")
117 { 164 {
118 Log.LogMessage(MessageImportance.High, pathToTool + " " + respo nseFileCommands); 165 Log.LogMessage(MessageImportance.High, pathToTool + " " + respo nseFileCommands);
119 } 166 }
120 167
121 return base.ExecuteTool(pathToTool, responseFileCommands, commandLin eCommands); 168 return base.ExecuteTool(pathToTool, responseFileCommands, commandLin eCommands);
122 } 169 }
123 170
124 protected override void PostProcessSwitchList()
125 {
126 //skip default behavior
127 }
128
129 protected override string GenerateFullPathToTool() 171 protected override string GenerateFullPathToTool()
130 { 172 {
131 return this.ToolName; 173 return this.ToolName;
132 } 174 }
133 175
134 protected override string TrackerIntermediateDirectory
135 {
136 get
137 {
138 if (this.TrackerLogDirectory != null)
139 {
140 return this.TrackerLogDirectory;
141 }
142
143 return string.Empty;
144 }
145 }
146
147 protected override Encoding ResponseFileEncoding 176 protected override Encoding ResponseFileEncoding
148 { 177 {
149 get 178 get
150 { 179 {
151 return Encoding.ASCII; 180 return Encoding.ASCII;
152 } 181 }
153 } 182 }
154 183
155 protected override ITaskItem[] TrackedInputFiles
156 {
157 get
158 {
159 return this.Sources;
160 }
161 }
162
163 protected override bool MaintainCompositeRootingMarkers
164 {
165 get
166 {
167 return true;
168 }
169
170 }
171
172 protected override string ToolName 184 protected override string ToolName
173 { 185 {
174 get 186 get
175 { 187 {
176 return NaClLinkerPath; 188 return NaClLinkerPath;
177 } 189 }
178 } 190 }
179 191
180 public override bool AttributeFileTracking 192 protected override string CommandTLogFilename
181 { 193 {
182 get 194 get
183 { 195 {
184 return true; 196 return BaseTool() + ".link.command.1.tlog";
185 } 197 }
186 } 198 }
199
200 protected override string[] ReadTLogFilenames
201 {
202 get
203 {
204 return new string[] { BaseTool() + ".link.read.1.tlog" };
205 }
206 }
207
208 protected override string WriteTLogFilename
209 {
210 get
211 {
212 return BaseTool() + ".link.write.1.tlog";
213 }
214 }
187 215
188 public virtual string PlatformToolset 216 public virtual string PlatformToolset
189 { 217 {
190 get 218 get
191 { 219 {
192 return "GCC"; 220 return "GCC";
193 } 221 }
194 set 222 set
195 {} 223 {}
196 } 224 }
197 225 }
198 public string TrackerLogDirectory { get; set; }
199 » }
200 } 226 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698