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

Side by Side Diff: experimental/visual_studio_plugin/src/NaClVsx.Tasks/NaClExec.cs

Issue 10928195: First round of dead file removal (Closed) Base URL: https://github.com/samclegg/nativeclient-sdk.git@master
Patch Set: Created 8 years, 3 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 unified diff | Download patch
OLDNEW
(Empty)
1 #region
2
3 using System.Collections.Specialized;
4 using System.IO;
5 using System.Text;
6 using System.Text.RegularExpressions;
7 using Microsoft.Build.Framework;
8 using Microsoft.Build.Utilities;
9
10 #endregion
11
12 namespace NaClVsx.Tasks {
13 /// <summary>
14 /// The NaClExec task is used by the NaCl.Common.targets file as a build
15 /// rule. In NaCl.Common.targets, the 'Compile' step gets passed all the
16 /// source files as a list, but then NaClExec is called with each file to
17 /// compile it. When NaClExec is called/used in NaCl.Common.targets
18 /// arguments are supplied, which are reflected by the properties below
19 /// (which have get and/or set definitions). Here is a sample usage:
20 /// <NaClExec Command = "$(gcpp)"
21 /// C_Command = "$(gcc)"
22 /// CFlags = "$(CFLAGS)"
23 /// CCFlags = "$(CCFLAGS)"
24 /// CXXFlags = "$(CXXFLAGS)"
25 /// FileExtension = "@(Compile -> '%(extension)')"
26 /// Arguments = "$(cflags) $(INCLUDES) $(OPT_FLAGS) $(archflag) -c
27 /// '%(FullPath)' -o @(Compile -> '$(IntermediatePath)%(filename).o')"
28 /// ToolPath = "$(NaClSDKRoot)\toolchain\$(Toolchain)\bin\" />
29 /// </summary>
30 /// Note that we pass in both Command and C_Command, since this task looks at
31 /// FileExtension and then chooses the correct Command (nacl-gcc or nacl-g++).
32 public class NaClExec : ToolTask {
33 public string Command {
34 get { return command_; }
35 set { command_ = value; }
36 }
37
38 /// <summary>
39 /// Command to execute for C files (i.e. when extension is ".c"
40 /// </summary>
41 public string C_Command {
42 get { return c_command_; }
43 set { c_command_ = value; }
44 }
45
46 /// <summary>
47 /// Compilation arguments...except not CFLAGS, CCFLAGS, or CXXFLAGS
48 /// </summary>
49 public string Arguments {
50 get { return arguments_; }
51 set { arguments_ = value; }
52 }
53
54 public string CFlags {
55 get { return c_flags_; }
56 set { c_flags_ = value; }
57 }
58
59 public string CCFlags {
60 get { return cc_flags_; }
61 set { cc_flags_ = value; }
62 }
63
64 public string CXXFLags {
65 get { return cxx_flags_; }
66 set { cxx_flags_ = value; }
67 }
68
69 public string FileExtension {
70 get { return file_extension_; }
71 set { file_extension_ = value; }
72 }
73
74 public string NaclPath {
75 get { return naclPath_; }
76 set { naclPath_ = value; }
77 }
78
79 #region Overrides of Task
80
81 /// <summary>
82 /// The ToolName depends on the extension of the file. For .c files,
83 /// return the C command (<arch>-nacl-gcc);
84 /// otherwise, return command (<arch>-nacl-g++).
85 /// </summary>
86 protected override string ToolName {
87 get {
88 if (file_extension_ == ".c") {
89 return c_command_;
90 } else {
91 return command_;
92 }
93 }
94 }
95
96 protected override Encoding StandardErrorEncoding {
97 // GDB uses Unicode characters for forward and backticks;
98 // failing to set utf8 encoding causes the logger to emit
99 // garbage characters instead.
100 get { return Encoding.UTF8; }
101 }
102
103 protected override StringDictionary EnvironmentOverride {
104 get {
105 var result = new StringDictionary();
106 result.Add("CYGWIN", "nodosfilewarning");
107 return result;
108 }
109 }
110
111 protected override string GenerateFullPathToTool() {
112 return Path.Combine(naclPath_, command_);
113 }
114
115 /// <summary>
116 /// CommandLineCommands is the concatenation of several values.
117 /// It is *either* CFLAGS or CXXFLAGS, followed by CCFLAGS,
118 /// followed by arguments_.
119 /// </summary>
120 protected override string GenerateCommandLineCommands() {
121 if (file_extension_ == ".c") {
122 return c_flags_ + " " + cc_flags_ + " " + arguments_;
123 } else {
124 return cxx_flags_ + " " + cc_flags_ + " " + arguments_;
125 }
126 }
127
128 protected override void LogEventsFromTextOutput(string singleLine,
129 MessageImportance
130 messageImportance) {
131 var capture = errorTransform.Match(singleLine);
132 var outputLine = errorTransform.Replace(singleLine, @"(${line}):");
133 base.LogEventsFromTextOutput(outputLine, messageImportance);
134 }
135
136 #endregion
137
138 #region Private Implementation
139
140 private readonly Regex errorTransform = new Regex(
141 @":(?<line>\d+):", RegexOptions.Compiled);
142
143 private string arguments_;
144 private string c_command_;
145 private string c_flags_;
146 private string cc_flags_;
147 private string command_;
148 private string cxx_flags_;
149 private string file_extension_;
150 private string naclPath_;
151
152 #endregion
153 }
154 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698