| 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 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 return true; // Output directory is hardcoded. | 325 return true; // Output directory is hardcoded. |
| 326 | 326 |
| 327 *err = Err(origin, "File is not inside output directory.", | 327 *err = Err(origin, "File is not inside output directory.", |
| 328 "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 " |
| 329 "specify\n\"$target_out_dir/foo\" or " | 329 "specify\n\"$target_out_dir/foo\" or " |
| 330 "\"$target_gen_dir/foo\". I interpreted this as\n\"" | 330 "\"$target_gen_dir/foo\". I interpreted this as\n\"" |
| 331 + str + "\"."); | 331 + str + "\"."); |
| 332 return false; | 332 return false; |
| 333 } | 333 } |
| 334 | 334 |
| 335 base::FilePath::StringType ComputeStringInOutputDir(const SourceDir& output_dir, |
| 336 const SourceFile& output_file, |
| 337 Err* err) { |
| 338 if (output_file.is_source_absolute() != output_dir.is_source_absolute()) { |
| 339 *err = Err(nullptr, |
| 340 "Cannot determine if output file is in output directory", |
| 341 "Absolute files/dirs are incomparable with source rooted ones."); |
| 342 return base::FilePath::StringType(); |
| 343 } |
| 344 |
| 345 const std::string& dir_str = output_dir.value(); |
| 346 const std::string& str = output_file.value(); |
| 347 if (str.compare(0, dir_str.length(), dir_str) != 0 || |
| 348 str.length() <= dir_str.length() || |
| 349 IsSlash(str[dir_str.length()])) { |
| 350 *err = Err(nullptr, "File is not inside output directory.", |
| 351 "The given file should be in the output directory. Normally you would " |
| 352 "specify\n\"$target_out_dir/foo\" or " |
| 353 "\"$target_gen_dir/foo\". I interpreted this as\n\"" |
| 354 + str + "\"."); |
| 355 return base::FilePath::StringType(); |
| 356 } |
| 357 return base::FilePath::StringType(str.c_str() + dir_str.length(), |
| 358 str.length() - dir_str.length()); |
| 359 } |
| 360 |
| 335 bool IsPathAbsolute(const base::StringPiece& path) { | 361 bool IsPathAbsolute(const base::StringPiece& path) { |
| 336 if (path.empty()) | 362 if (path.empty()) |
| 337 return false; | 363 return false; |
| 338 | 364 |
| 339 if (!IsSlash(path[0])) { | 365 if (!IsSlash(path[0])) { |
| 340 #if defined(OS_WIN) | 366 #if defined(OS_WIN) |
| 341 // Check for Windows system paths like "C:\foo". | 367 // Check for Windows system paths like "C:\foo". |
| 342 if (path.size() > 2 && path[1] == ':' && IsSlash(path[2])) | 368 if (path.size() > 2 && path[1] == ':' && IsSlash(path[2])) |
| 343 return true; | 369 return true; |
| 344 #endif | 370 #endif |
| (...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 814 | 840 |
| 815 SourceDir GetCurrentOutputDir(const Scope* scope) { | 841 SourceDir GetCurrentOutputDir(const Scope* scope) { |
| 816 return GetOutputDirForSourceDirAsOutputFile( | 842 return GetOutputDirForSourceDirAsOutputFile( |
| 817 scope->settings(), scope->GetSourceDir()).AsSourceDir( | 843 scope->settings(), scope->GetSourceDir()).AsSourceDir( |
| 818 scope->settings()->build_settings()); | 844 scope->settings()->build_settings()); |
| 819 } | 845 } |
| 820 | 846 |
| 821 SourceDir GetCurrentGenDir(const Scope* scope) { | 847 SourceDir GetCurrentGenDir(const Scope* scope) { |
| 822 return GetGenDirForSourceDir(scope->settings(), scope->GetSourceDir()); | 848 return GetGenDirForSourceDir(scope->settings(), scope->GetSourceDir()); |
| 823 } | 849 } |
| OLD | NEW |