OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <map> | 5 #include <map> |
6 | 6 |
7 #include "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "tools/gn/commands.h" | 9 #include "tools/gn/commands.h" |
10 #include "tools/gn/input_file.h" | 10 #include "tools/gn/input_file.h" |
(...skipping 24 matching lines...) Expand all Loading... | |
35 | 35 |
36 size_t cur = offset; | 36 size_t cur = offset; |
37 do { | 37 do { |
38 cur --; | 38 cur --; |
39 if (Tokenizer::IsNewline(data, cur)) | 39 if (Tokenizer::IsNewline(data, cur)) |
40 return cur + 1; // Want the first character *after* the newline. | 40 return cur + 1; // Want the first character *after* the newline. |
41 } while (cur > 0); | 41 } while (cur > 0); |
42 return 0; | 42 return 0; |
43 } | 43 } |
44 | 44 |
45 // Assumes DoesLineBeginWithComment(). | 45 // Assumes DoesLineBeginWithComment(), this strips the # character from the |
46 std::string StripCommentFromLine(const base::StringPiece& line) { | 46 // beginning and normalizes preceeding whitespace. |
47 std::string ret = line.as_string(); | 47 std::string StripHashFromLine(const base::StringPiece& line) { |
48 for (size_t i = 0; i < ret.size(); i++) { | 48 std::string ret; |
viettrungluu
2014/02/12 23:09:35
Can't this just be something like:
return " " +
| |
49 if (ret[i] == '#') { | 49 for (size_t i = 0; i < line.size(); i++) { |
50 ret[i] = ' '; | 50 if (line[i] == '#') { |
51 // Replace the # sign and everything before it with 3 spaces, so that | |
52 // a normal comment that has a space after the # will be indented 4 | |
53 // spaces (which makes our formatting come out nicely). If the comment is | |
54 // indented from there, we want to preserve that indenting. | |
55 ret.assign(" "); | |
56 ret.append(line.substr(i + 1).as_string()); | |
51 break; | 57 break; |
52 } | 58 } |
53 } | 59 } |
54 return ret; | 60 return ret; |
55 } | 61 } |
56 | 62 |
57 // Tries to find the comment before the setting of the given value. | 63 // Tries to find the comment before the setting of the given value. |
58 void GetContextForValue(const Value& value, | 64 void GetContextForValue(const Value& value, |
59 std::string* location_str, | 65 std::string* location_str, |
60 std::string* comment) { | 66 std::string* comment) { |
(...skipping 11 matching lines...) Expand all Loading... | |
72 | 78 |
73 while (line_off > 1) { | 79 while (line_off > 1) { |
74 line_off -= 2; // Back up to end of previous line. | 80 line_off -= 2; // Back up to end of previous line. |
75 size_t previous_line_offset = BackUpToLineBegin(data, line_off); | 81 size_t previous_line_offset = BackUpToLineBegin(data, line_off); |
76 | 82 |
77 base::StringPiece line(&data[previous_line_offset], | 83 base::StringPiece line(&data[previous_line_offset], |
78 line_off - previous_line_offset + 1); | 84 line_off - previous_line_offset + 1); |
79 if (!DoesLineBeginWithComment(line)) | 85 if (!DoesLineBeginWithComment(line)) |
80 break; | 86 break; |
81 | 87 |
82 comment->insert(0, StripCommentFromLine(line) + "\n"); | 88 comment->insert(0, StripHashFromLine(line) + "\n"); |
83 line_off = previous_line_offset; | 89 line_off = previous_line_offset; |
84 } | 90 } |
85 } | 91 } |
86 | 92 |
87 void PrintArgHelp(const base::StringPiece& name, const Value& value) { | 93 void PrintArgHelp(const base::StringPiece& name, const Value& value) { |
88 OutputString(name.as_string(), DECORATION_YELLOW); | 94 OutputString(name.as_string(), DECORATION_YELLOW); |
89 OutputString(" Default = " + value.ToString(true) + "\n"); | 95 OutputString(" Default = " + value.ToString(true) + "\n"); |
90 | 96 |
91 if (value.origin()) { | 97 if (value.origin()) { |
92 std::string location, comment; | 98 std::string location, comment; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
143 "Usage: \"gn args [arg name]\"").PrintToStdout(); | 149 "Usage: \"gn args [arg name]\"").PrintToStdout(); |
144 return 1; | 150 return 1; |
145 } | 151 } |
146 | 152 |
147 // List all arguments. First put them in a regular map so they're sorted. | 153 // List all arguments. First put them in a regular map so they're sorted. |
148 std::map<base::StringPiece, Value> sorted_args; | 154 std::map<base::StringPiece, Value> sorted_args; |
149 for (Scope::KeyValueMap::const_iterator i = build_args.begin(); | 155 for (Scope::KeyValueMap::const_iterator i = build_args.begin(); |
150 i != build_args.end(); ++i) | 156 i != build_args.end(); ++i) |
151 sorted_args.insert(*i); | 157 sorted_args.insert(*i); |
152 | 158 |
159 OutputString( | |
160 "Available build arguments. Note that the which arguments are declared\n" | |
161 "and their default values may depend on other arguments or the current\n" | |
162 "platform and architecture. So setting some values may add, remove, or\n" | |
163 "change the default value of other values.\n\n"); | |
164 | |
153 for (std::map<base::StringPiece, Value>::iterator i = sorted_args.begin(); | 165 for (std::map<base::StringPiece, Value>::iterator i = sorted_args.begin(); |
154 i != sorted_args.end(); ++i) { | 166 i != sorted_args.end(); ++i) { |
155 PrintArgHelp(i->first, i->second); | 167 PrintArgHelp(i->first, i->second); |
156 OutputString("\n"); | 168 OutputString("\n"); |
157 } | 169 } |
158 | 170 |
159 return 0; | 171 return 0; |
160 } | 172 } |
161 | 173 |
162 } // namespace commands | 174 } // namespace commands |
OLD | NEW |