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 "tools/gn/filesystem_utils.h" | 5 #include "tools/gn/filesystem_utils.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 int end = cur; | 303 int end = cur; |
304 cur--; // Skip before the last slash. | 304 cur--; // Skip before the last slash. |
305 | 305 |
306 for (; cur >= 0; cur--) { | 306 for (; cur >= 0; cur--) { |
307 if (dir_string[cur] == '/') | 307 if (dir_string[cur] == '/') |
308 return base::StringPiece(&dir_string[cur + 1], end - cur - 1); | 308 return base::StringPiece(&dir_string[cur + 1], end - cur - 1); |
309 } | 309 } |
310 return base::StringPiece(&dir_string[0], end); | 310 return base::StringPiece(&dir_string[0], end); |
311 } | 311 } |
312 | 312 |
313 bool EnsureStringIsInOutputDir(const SourceDir& dir, | 313 bool IsStringInOutputDir(const SourceDir& output_dir, const std::string& str) { |
| 314 // This check will be wrong for all proper prefixes "e.g. "/output" will |
| 315 // match "/out" but we don't really care since this is just a sanity check. |
| 316 const std::string& dir_str = output_dir.value(); |
| 317 return str.compare(0, dir_str.length(), dir_str) == 0; |
| 318 } |
| 319 |
| 320 bool EnsureStringIsInOutputDir(const SourceDir& output_dir, |
314 const std::string& str, | 321 const std::string& str, |
315 const ParseNode* origin, | 322 const ParseNode* origin, |
316 Err* err) { | 323 Err* err) { |
317 // This check will be wrong for all proper prefixes "e.g. "/output" will | 324 if (IsStringInOutputDir(output_dir, str)) |
318 // match "/out" but we don't really care since this is just a sanity check. | |
319 const std::string& dir_str = dir.value(); | |
320 if (str.compare(0, dir_str.length(), dir_str) == 0) | |
321 return true; // Output directory is hardcoded. | 325 return true; // Output directory is hardcoded. |
322 | 326 |
323 *err = Err(origin, "File is not inside output directory.", | 327 *err = Err(origin, "File is not inside output directory.", |
324 "The given file should be in the output directory. Normally you would " | 328 "The given file should be in the output directory. Normally you would " |
325 "specify\n\"$target_out_dir/foo\" or " | 329 "specify\n\"$target_out_dir/foo\" or " |
326 "\"$target_gen_dir/foo\". I interpreted this as\n\"" | 330 "\"$target_gen_dir/foo\". I interpreted this as\n\"" |
327 + str + "\"."); | 331 + str + "\"."); |
328 return false; | 332 return false; |
329 } | 333 } |
330 | 334 |
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
809 | 813 |
810 SourceDir GetCurrentOutputDir(const Scope* scope) { | 814 SourceDir GetCurrentOutputDir(const Scope* scope) { |
811 return GetOutputDirForSourceDirAsOutputFile( | 815 return GetOutputDirForSourceDirAsOutputFile( |
812 scope->settings(), scope->GetSourceDir()).AsSourceDir( | 816 scope->settings(), scope->GetSourceDir()).AsSourceDir( |
813 scope->settings()->build_settings()); | 817 scope->settings()->build_settings()); |
814 } | 818 } |
815 | 819 |
816 SourceDir GetCurrentGenDir(const Scope* scope) { | 820 SourceDir GetCurrentGenDir(const Scope* scope) { |
817 return GetGenDirForSourceDir(scope->settings(), scope->GetSourceDir()); | 821 return GetGenDirForSourceDir(scope->settings(), scope->GetSourceDir()); |
818 } | 822 } |
OLD | NEW |