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

Side by Side Diff: visual_studio/NativeClientVSAddIn/NaCl.Build.CPPTasks/NaClLink.cs

Issue 11348050: [VS Addin] Add automatic nmf creation (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 using Microsoft.Build.Utilities;
10 10
11 11
12 namespace NaCl.Build.CPPTasks 12 namespace NaCl.Build.CPPTasks
13 { 13 {
14 public class NaClLink : NaClToolTask 14 public class NaClLink : NaClToolTask
15 { 15 {
16 public bool BuildingInIDE { get; set; } 16 public bool BuildingInIDE { get; set; }
17 17
18 /// <summary> 18 /// <summary>
19 /// Property set only in PNaCl builds to signal that the translator 19 /// Property set only in PNaCl builds to signal that the translator
20 /// should be run post-link. 20 /// should be run post-link.
21 /// </summary> 21 /// </summary>
22 public string TranslateARM { get; set; } 22 public bool TranslateARM { get; set; }
23 23
24 /// <summary> 24 /// <summary>
25 /// Property set only in PNaCl builds to signal that the translator 25 /// Property set only in PNaCl builds to signal that the translator
26 /// should be run post-link. 26 /// should be run post-link.
27 /// </summary> 27 /// </summary>
28 public string TranslateX86 { get; set; } 28 public bool TranslateX86 { get; set; }
29 29
30 /// <summary> 30 /// <summary>
31 /// Property set only in PNaCl builds to signal that the translator 31 /// Property set only in PNaCl builds to signal that the translator
32 /// should be run post-link. 32 /// should be run post-link.
33 /// </summary> 33 /// </summary>
34 public string TranslateX64 { get; set; } 34 public bool TranslateX64 { get; set; }
35 35
36 [Required] 36 [Required]
37 public string OutputCommandLine { get; set; } 37 public bool OutputCommandLine { get; set; }
38
39 [Required]
40 public bool CreateNMF { get; set; }
38 41
39 [Required] 42 [Required]
40 public string NaClLinkerPath { get; set; } 43 public string NaClLinkerPath { get; set; }
41 44
42 [Required] 45 [Required]
46 public string ProjectName { get; set; }
47
48 [Required]
49 public string ToolchainName { get; set; }
50
51 [Required]
43 public string Platform { get; set; } 52 public string Platform { get; set; }
44 53
45 [Required] 54 [Required]
55 public string CreateNMFPath { get; set; }
56
57 [Required]
46 public virtual string OutputFile { get; set; } 58 public virtual string OutputFile { get; set; }
47 59
48 [Required] 60 [Required]
49 public string PropertiesFile { get; set; } 61 public string PropertiesFile { get; set; }
50 62
51 [Required] 63 [Required]
52 public string ConfigurationType { get; set; } 64 public string ConfigurationType { get; set; }
53 65
54 protected override CanonicalTrackedOutputFiles OutputWriteTLog(ITaskItem [] inputs) 66 protected override CanonicalTrackedOutputFiles OutputWriteTLog(ITaskItem [] inputs)
55 { 67 {
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 responseFileCmds.Append(GCCUtilities.ConvertPathWindowsToPosix(s ourceFile.GetMetadata("Identity"))); 151 responseFileCmds.Append(GCCUtilities.ConvertPathWindowsToPosix(s ourceFile.GetMetadata("Identity")));
140 responseFileCmds.Append(" "); 152 responseFileCmds.Append(" ");
141 } 153 }
142 responseFileCmds.Append("-Wl,--end-group "); 154 responseFileCmds.Append("-Wl,--end-group ");
143 155
144 responseFileCmds.Append(xamlParser.Parse(Sources[0], false)); 156 responseFileCmds.Append(xamlParser.Parse(Sources[0], false));
145 157
146 return responseFileCmds.ToString(); 158 return responseFileCmds.ToString();
147 } 159 }
148 160
149 private bool Translate(string arch) 161 private static string PexeToNexe(string pexe, string arch)
150 { 162 {
151 string nexeBase = Path.GetFileNameWithoutExtension(OutputFile) + "_" + arch + ".nexe"; 163 string basename = Path.GetFileNameWithoutExtension(pexe) + "_" + arc h + ".nexe";
152 string outfile = Path.Combine(Path.GetDirectoryName(OutputFile), nex eBase); 164 return Path.Combine(Path.GetDirectoryName(pexe), basename);
165 }
153 166
154 string commandLineCommands = String.Format("-arch {0} \"{1}\" -o \"{ 2}\"", arch, OutputFile, outfile); 167 private bool Translate(string arch, string pnacl_arch=null)
168 {
169 if (pnacl_arch == null)
170 pnacl_arch = arch;
171 string outfile = PexeToNexe(OutputFile, arch);
172 string cmd = String.Format("-arch {0} \"{1}\" -o \"{2}\"",
173 pnacl_arch, OutputFile, outfile);
155 174
156 string translateTool = Path.Combine(Path.GetDirectoryName(GenerateFu llPathToTool()), "pnacl-translate.bat"); 175 string dirname = Path.GetDirectoryName(GenerateFullPathToTool();
binji 2012/10/30 23:38:40 doesn't look like this will compile -- missing clo
157 if (OutputCommandLine != "true") 176 string translateTool = Path.Combine(dirname, "pnacl-translate.bat");
158 Log.LogMessage("pnacl-translate {0}", Path.GetFileName(nexeBase) ); 177 if (!OutputCommandLine)
178 Log.LogMessage("pnacl-translate {0}", Path.GetFileName(outfile)) ;
159 179
160 if (ExecuteTool(translateTool, commandLineCommands, string.Empty) != 0) 180 if (ExecuteTool(translateTool, cmd, string.Empty) != 0)
161 { 181 {
162 return false; 182 return false;
163 } 183 }
164 184
165 return true; 185 return true;
166 } 186 }
167 187
188 private bool IsPNaCl()
189 {
190 return Platform.Equals("pnacl", StringComparison.OrdinalIgnoreCase);
191 }
192
168 public override bool Execute() 193 public override bool Execute()
169 { 194 {
170 if (Platform.Equals("pnacl", StringComparison.OrdinalIgnoreCase)) 195 if (IsPNaCl())
171 { 196 {
172 if (!GCCUtilities.FindPython()) 197 if (!GCCUtilities.FindPython())
173 { 198 {
174 Log.LogError("PNaCl linking requires python in your executab le path."); 199 Log.LogError("PNaCl linking requires python in your executab le path.");
175 return false; 200 return false;
176 } 201 }
177 } 202 }
178 203
179 bool returnResult = false; 204 xamlParser = new XamlParser(PropertiesFile);
205 if (!Setup())
206 return false;
180 207
181 try 208 if (!OutputCommandLine)
209 Log.LogMessage("Linking: {0}", Path.GetFileName(OutputFile));
210
211 if (!base.Execute())
212 return false;
213
214 if (!PostLink())
215 return false;
216
217 return true;
218 }
219
220 protected bool PostLink()
221 {
222 if (IsPNaCl())
182 { 223 {
183 xamlParser = new XamlParser(PropertiesFile); 224 if (TranslateX64 && !Translate("64", "x86-64"))
184 if (!Setup())
185 return false;
186 returnResult = base.Execute();
187
188 if (TranslateX64 == "true" && !Translate("x86_64"))
189 return false; 225 return false;
190 226
191 if (TranslateX86 == "true" && !Translate("i686")) 227 if (TranslateX86 && !Translate("32", "i686"))
192 return false; 228 return false;
193 229
194 if (TranslateARM == "true" && !Translate("arm")) 230 if (TranslateARM && !Translate("arm"))
195 return false; 231 return false;
196 } 232 }
197 finally 233
234 if (CreateNMF)
198 { 235 {
236 if (!GCCUtilities.FindPython())
237 {
238 Log.LogError("Automatic NMF creation requires python in your executable path.");
239 return false;
240 }
199 241
242 string outputRoot = ToolchainName;
243 if (IsPNaCl())
244 outputRoot = "PNaCl";
245
246 if (!Directory.Exists(outputRoot))
247 Directory.CreateDirectory(outputRoot);
248
249 string nmfPath = Path.Combine(outputRoot, Path.ChangeExtension(P rojectName, ".nmf"));
binji 2012/10/30 23:38:40 just over 100 chars... :-/
250
251 string cmd = "\"" + CreateNMFPath + "\" -o \"" + nmfPath + "\"";
252 cmd += " -t " + ToolchainName + " -s " + ToolchainName;
253
254 if (IsPNaCl())
255 {
256 if (!TranslateARM && !TranslateX64 && !TranslateX86)
257 // Don't run create_nmf unless we actaully produced a ne xe file.
258 return true;
259
260 foreach (var arch in new string []{ "arm", "32", "64" })
261 {
262 string nexe = PexeToNexe(OutputFile, arch);
263 if (File.Exists(nexe))
264 cmd += " \"" + nexe + "\"";
265 }
266 }
267 else
268 {
269 if (ToolchainName == "glibc")
270 {
271 string bindir = Path.GetDirectoryName(NaClLinkerPath);
272 string tcroot = Path.GetDirectoryName(bindir);
273 cmd += " -D \"" + Path.Combine(bindir, "x86_64-nacl-objd ump.exe") + "\"";
274 cmd += " -L \"" + Path.Combine(tcroot, "x86_64-nacl", "l ib") + "\"";
275 cmd += " -L \"" + Path.Combine(tcroot, "x86_64-nacl", "l ib32") + "\"";
276 }
277 cmd += " \"" + OutputFile + "\"";
278 }
279
280 if (!OutputCommandLine)
281 Log.LogMessage("CreateNMF");
282
283 if (ExecuteTool("python", string.Empty, cmd) != 0)
284 {
285 return false;
286 }
200 } 287 }
201 288
202 return returnResult; 289 return true;
203 } 290 }
204 291
205 protected override int ExecuteTool(string pathToTool, string responseFil eCommands, string commandLineCommands) 292 protected override int ExecuteTool(string pathToTool, string responseFil eCommands, string commandLineCommands)
binji 2012/10/30 23:38:40 nit: wrap at 100
206 { 293 {
207 if (OutputCommandLine == "true") 294 if (OutputCommandLine)
208 { 295 {
209 Log.LogMessage(MessageImportance.High, pathToTool + " " + respo nseFileCommands); 296 Log.LogMessage(MessageImportance.High, pathToTool + " " + respo nseFileCommands + " " + commandLineCommands);
binji 2012/10/30 23:38:40 nit: wrap at 100
210 } 297 }
211 298
212 return base.ExecuteTool(pathToTool, responseFileCommands, commandLin eCommands); 299 return base.ExecuteTool(pathToTool, responseFileCommands, commandLin eCommands);
213 } 300 }
214 301
215 protected override string GenerateFullPathToTool() 302 protected override string GenerateFullPathToTool()
216 { 303 {
217 return this.ToolName; 304 return this.ToolName;
218 } 305 }
219 306
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 { 348 {
262 get 349 get
263 { 350 {
264 return "GCC"; 351 return "GCC";
265 } 352 }
266 set 353 set
267 {} 354 {}
268 } 355 }
269 } 356 }
270 } 357 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698