OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include "tools/gn/err.h" | 7 #include "tools/gn/err.h" |
8 #include "tools/gn/filesystem_utils.h" | 8 #include "tools/gn/filesystem_utils.h" |
9 #include "tools/gn/functions.h" | 9 #include "tools/gn/functions.h" |
10 #include "tools/gn/parse_tree.h" | 10 #include "tools/gn/parse_tree.h" |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 return std::string(); | 114 return std::string(); |
115 } | 115 } |
116 } | 116 } |
117 | 117 |
118 } // namespace | 118 } // namespace |
119 | 119 |
120 const char kGetPathInfo[] = "get_path_info"; | 120 const char kGetPathInfo[] = "get_path_info"; |
121 const char kGetPathInfo_HelpShort[] = | 121 const char kGetPathInfo_HelpShort[] = |
122 "get_path_info: Extract parts of a file or directory name."; | 122 "get_path_info: Extract parts of a file or directory name."; |
123 const char kGetPathInfo_Help[] = | 123 const char kGetPathInfo_Help[] = |
124 "get_path_info: Extract parts of a file or directory name.\n" | 124 R"(get_path_info: Extract parts of a file or directory name. |
125 "\n" | 125 |
126 " get_path_info(input, what)\n" | 126 get_path_info(input, what) |
127 "\n" | 127 |
128 " The first argument is either a string representing a file or\n" | 128 The first argument is either a string representing a file or directory name, |
129 " directory name, or a list of such strings. If the input is a list\n" | 129 or a list of such strings. If the input is a list the return value will be a |
130 " the return value will be a list containing the result of applying the\n" | 130 list containing the result of applying the rule to each item in the input. |
131 " rule to each item in the input.\n" | 131 |
132 "\n" | 132 Possible values for the "what" parameter |
133 "Possible values for the \"what\" parameter\n" | 133 |
134 "\n" | 134 "file" |
135 " \"file\"\n" | 135 The substring after the last slash in the path, including the name and |
136 " The substring after the last slash in the path, including the name\n" | 136 extension. If the input ends in a slash, the empty string will be |
137 " and extension. If the input ends in a slash, the empty string will\n" | 137 returned. |
138 " be returned.\n" | 138 "foo/bar.txt" => "bar.txt" |
139 " \"foo/bar.txt\" => \"bar.txt\"\n" | 139 "bar.txt" => "bar.txt" |
140 " \"bar.txt\" => \"bar.txt\"\n" | 140 "foo/" => "" |
141 " \"foo/\" => \"\"\n" | 141 "" => "" |
142 " \"\" => \"\"\n" | 142 |
143 "\n" | 143 "name" |
144 " \"name\"\n" | 144 The substring of the file name not including the extension. |
145 " The substring of the file name not including the extension.\n" | 145 "foo/bar.txt" => "bar" |
146 " \"foo/bar.txt\" => \"bar\"\n" | 146 "foo/bar" => "bar" |
147 " \"foo/bar\" => \"bar\"\n" | 147 "foo/" => "" |
148 " \"foo/\" => \"\"\n" | 148 |
149 "\n" | 149 "extension" |
150 " \"extension\"\n" | 150 The substring following the last period following the last slash, or the |
151 " The substring following the last period following the last slash,\n" | 151 empty string if not found. The period is not included. |
152 " or the empty string if not found. The period is not included.\n" | 152 "foo/bar.txt" => "txt" |
153 " \"foo/bar.txt\" => \"txt\"\n" | 153 "foo/bar" => "" |
154 " \"foo/bar\" => \"\"\n" | 154 |
155 "\n" | 155 "dir" |
156 " \"dir\"\n" | 156 The directory portion of the name, not including the slash. |
157 " The directory portion of the name, not including the slash.\n" | 157 "foo/bar.txt" => "foo" |
158 " \"foo/bar.txt\" => \"foo\"\n" | 158 "//foo/bar" => "//foo" |
159 " \"//foo/bar\" => \"//foo\"\n" | 159 "foo" => "." |
160 " \"foo\" => \".\"\n" | 160 |
161 "\n" | 161 The result will never end in a slash, so if the resulting is empty, the |
162 " The result will never end in a slash, so if the resulting\n" | 162 system ("/") or source ("//") roots, a "." will be appended such that it |
163 " is empty, the system (\"/\") or source (\"//\") roots, a \".\"\n" | 163 is always legal to append a slash and a filename and get a valid path. |
164 " will be appended such that it is always legal to append a slash\n" | 164 |
165 " and a filename and get a valid path.\n" | 165 "out_dir" |
166 "\n" | 166 The output file directory corresponding to the path of the given file, |
167 " \"out_dir\"\n" | 167 not including a trailing slash. |
168 " The output file directory corresponding to the path of the\n" | 168 "//foo/bar/baz.txt" => "//out/Default/obj/foo/bar" |
169 " given file, not including a trailing slash.\n" | 169 |
170 " \"//foo/bar/baz.txt\" => \"//out/Default/obj/foo/bar\"\n" | 170 "gen_dir" |
171 "\n" | 171 The generated file directory corresponding to the path of the given file, |
172 " \"gen_dir\"\n" | 172 not including a trailing slash. |
173 " The generated file directory corresponding to the path of the\n" | 173 "//foo/bar/baz.txt" => "//out/Default/gen/foo/bar" |
174 " given file, not including a trailing slash.\n" | 174 |
175 " \"//foo/bar/baz.txt\" => \"//out/Default/gen/foo/bar\"\n" | 175 "abspath" |
176 "\n" | 176 The full absolute path name to the file or directory. It will be resolved |
177 " \"abspath\"\n" | 177 relative to the current directory, and then the source- absolute version |
178 " The full absolute path name to the file or directory. It will be\n" | 178 will be returned. If the input is system- absolute, the same input will |
179 " resolved relative to the current directory, and then the source-\n" | 179 be returned. |
180 " absolute version will be returned. If the input is system-\n" | 180 "foo/bar.txt" => "//mydir/foo/bar.txt" |
181 " absolute, the same input will be returned.\n" | 181 "foo/" => "//mydir/foo/" |
182 " \"foo/bar.txt\" => \"//mydir/foo/bar.txt\"\n" | 182 "//foo/bar" => "//foo/bar" (already absolute) |
183 " \"foo/\" => \"//mydir/foo/\"\n" | 183 "/usr/include" => "/usr/include" (already absolute) |
184 " \"//foo/bar\" => \"//foo/bar\" (already absolute)\n" | 184 |
185 " \"/usr/include\" => \"/usr/include\" (already absolute)\n" | 185 If you want to make the path relative to another directory, or to be |
186 "\n" | 186 system-absolute, see rebase_path(). |
187 " If you want to make the path relative to another directory, or to\n" | 187 |
188 " be system-absolute, see rebase_path().\n" | 188 Examples |
189 "\n" | 189 sources = [ "foo.cc", "foo.h" ] |
190 "Examples\n" | 190 result = get_path_info(source, "abspath") |
191 " sources = [ \"foo.cc\", \"foo.h\" ]\n" | 191 # result will be [ "//mydir/foo.cc", "//mydir/foo.h" ] |
192 " result = get_path_info(source, \"abspath\")\n" | 192 |
193 " # result will be [ \"//mydir/foo.cc\", \"//mydir/foo.h\" ]\n" | 193 result = get_path_info("//foo/bar/baz.cc", "dir") |
194 "\n" | 194 # result will be "//foo/bar" |
195 " result = get_path_info(\"//foo/bar/baz.cc\", \"dir\")\n" | 195 |
196 " # result will be \"//foo/bar\"\n" | 196 # Extract the source-absolute directory name, |
197 "\n" | 197 result = get_path_info(get_path_info(path, "dir"), "abspath")"; |
198 " # Extract the source-absolute directory name,\n" | |
199 " result = get_path_info(get_path_info(path, \"dir\"), \"abspath\")\n"; | |
200 | 198 |
201 Value RunGetPathInfo(Scope* scope, | 199 Value RunGetPathInfo(Scope* scope, |
202 const FunctionCallNode* function, | 200 const FunctionCallNode* function, |
203 const std::vector<Value>& args, | 201 const std::vector<Value>& args, |
204 Err* err) { | 202 Err* err) { |
205 if (args.size() != 2) { | 203 if (args.size() != 2) { |
206 *err = Err(function, "Expecting two arguments to get_path_info."); | 204 *err = Err(function, "Expecting two arguments to get_path_info."); |
207 return Value(); | 205 return Value(); |
208 } | 206 } |
209 | 207 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 return Value(); | 242 return Value(); |
245 } | 243 } |
246 return result; | 244 return result; |
247 } | 245 } |
248 | 246 |
249 *err = Err(args[0], "Path must be a string or a list of strings."); | 247 *err = Err(args[0], "Path must be a string or a list of strings."); |
250 return Value(); | 248 return Value(); |
251 } | 249 } |
252 | 250 |
253 } // namespace functions | 251 } // namespace functions |
OLD | NEW |