OLD | NEW |
---|---|
1 using System; | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 using System; | |
2 using System.Collections.Generic; | 5 using System.Collections.Generic; |
3 using System.Linq; | 6 using System.Linq; |
4 using System.Text; | 7 using System.Text; |
5 | 8 |
6 using System.IO; | 9 using System.IO; |
7 using System.Text.RegularExpressions; | 10 using System.Text.RegularExpressions; |
8 | 11 |
9 namespace NaCl.Build.CPPTasks | 12 namespace NaCl.Build.CPPTasks |
10 { | 13 { |
14 /// <summary> | |
15 /// Untility functions for dealing with gcc toolchain on windows. | |
binji
2012/11/08 19:13:06
sp: Utility
| |
16 /// </summary> | |
11 class GCCUtilities | 17 class GCCUtilities |
12 { | 18 { |
13 public const int s_CommandLineLength = 256; | 19 public const int s_CommandLineLength = 256; |
14 | 20 |
21 /// <summary> | |
22 /// Add quotes around a string, if they are needed. | |
23 /// </summary> | |
24 /// <returns>The input arg surrounded by quotes as appropriate.</returns > | |
25 public static string QuoteIfNeeded(string arg) | |
26 { | |
27 var match = arg.IndexOfAny(new char[] { ' ', '\t', ';', '&' }) != -1 ; | |
28 if (!match) | |
29 return arg; | |
30 return "\"" + arg + "\""; | |
31 } | |
32 | |
33 /// <summary> | |
34 /// Convert windows path in to a cygwin path suitable for passing to gcc | |
35 /// command line. | |
36 /// </summary> | |
15 public static string ConvertPathWindowsToPosix(string path) | 37 public static string ConvertPathWindowsToPosix(string path) |
16 { | 38 { |
17 return path.Replace('\\', '/'); | 39 string rtn = path.Replace('\\', '/'); |
40 rtn = QuoteIfNeeded(rtn); | |
41 return rtn; | |
18 } | 42 } |
19 | 43 |
20 public static string ConvertPathPosixToWindows(string path) | 44 public static string ConvertPathPosixToWindows(string path) |
21 { | 45 { |
22 path = path.Replace('/', '\\'); | 46 path = path.Replace('/', '\\'); |
23 // also make double backslashes a single slash | 47 // also make double backslashes a single slash |
24 // TODO: speed this up by iterating instead of two replaces | 48 // TODO: speed this up by iterating instead of two replaces |
25 return path.Replace("\\\\", "\\"); | 49 return path.Replace("\\\\", "\\"); |
26 } | 50 } |
27 | 51 |
28 // replace GCC error are warning output to Visual Studio format to suppo rt going to source code from error output. | 52 /// <summary> |
53 /// Replace GCC error are warning output to Visual Studio format to | |
54 /// support going to source code from error output. | |
55 /// </summary> | |
29 public static string ConvertGCCOutput(string line) | 56 public static string ConvertGCCOutput(string line) |
30 { | 57 { |
31 string result; | 58 string result; |
32 foreach (GCCRegexLineConverter converter in s_RegexConverters) | 59 foreach (GCCRegexLineConverter converter in s_RegexConverters) |
33 { | 60 { |
34 result = converter.Convert(line); | 61 result = converter.Convert(line); |
35 if (result.Length > 0) | 62 if (result.Length > 0) |
36 { | 63 { |
37 return result; | 64 return result; |
38 } | 65 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
92 }, | 119 }, |
93 new GCCRegexLineConverter | 120 new GCCRegexLineConverter |
94 { | 121 { |
95 OutputExpression = new Regex(@"^\s*(.?.?[^:]*.*?):(.?.?[^:] *.*?):([1-9]\d*):(.*$)"), | 122 OutputExpression = new Regex(@"^\s*(.?.?[^:]*.*?):(.?.?[^:] *.*?):([1-9]\d*):(.*$)"), |
96 FilenameIdentifier = @"$2", | 123 FilenameIdentifier = @"$2", |
97 RemainderIdentifier = @"($3):'$1' $4" | 124 RemainderIdentifier = @"($3):'$1' $4" |
98 } | 125 } |
99 }; | 126 }; |
100 } // GCCUtilities | 127 } // GCCUtilities |
101 } // namespace | 128 } // namespace |
OLD | NEW |