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/setup.h" | 5 #include "tools/gn/setup.h" |
6 | 6 |
7 #include <stdlib.h> | 7 #include <stdlib.h> |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <sstream> | 9 #include <sstream> |
10 #include <utility> | 10 #include <utility> |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 if (base::PathExists(candidate_bat)) { | 219 if (base::PathExists(candidate_bat)) { |
220 base::FilePath python_exe = PythonBatToExe(candidate_bat); | 220 base::FilePath python_exe = PythonBatToExe(candidate_bat); |
221 if (!python_exe.empty()) | 221 if (!python_exe.empty()) |
222 return python_exe; | 222 return python_exe; |
223 } | 223 } |
224 } | 224 } |
225 return base::FilePath(); | 225 return base::FilePath(); |
226 } | 226 } |
227 #endif | 227 #endif |
228 | 228 |
| 229 // Expands all ./, ../, and symbolic links in the given path. |
| 230 bool NormalizePath(const base::FilePath& path, base::FilePath* out) { |
| 231 #if defined(OS_POSIX) |
| 232 char buf[PATH_MAX]; |
| 233 if (!realpath(path.value().c_str(), buf)) { |
| 234 return false; |
| 235 } |
| 236 *out = base::FilePath(buf); |
| 237 #else |
| 238 // Do nothing on a non-POSIX system. |
| 239 *out = path; |
| 240 #endif |
| 241 return true; |
| 242 } |
| 243 |
229 } // namespace | 244 } // namespace |
230 | 245 |
231 const char Setup::kBuildArgFileName[] = "args.gn"; | 246 const char Setup::kBuildArgFileName[] = "args.gn"; |
232 | 247 |
233 Setup::Setup() | 248 Setup::Setup() |
234 : build_settings_(), | 249 : build_settings_(), |
235 loader_(new LoaderImpl(&build_settings_)), | 250 loader_(new LoaderImpl(&build_settings_)), |
236 builder_(new Builder(loader_.get())), | 251 builder_(new Builder(loader_.get())), |
237 root_build_file_("//BUILD.gn"), | 252 root_build_file_("//BUILD.gn"), |
238 check_public_headers_(false), | 253 check_public_headers_(false), |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 if (dotfile_name_.empty()) { | 521 if (dotfile_name_.empty()) { |
507 Err(Location(), "Can't find source root.", | 522 Err(Location(), "Can't find source root.", |
508 "I could not find a \".gn\" file in the current directory or any " | 523 "I could not find a \".gn\" file in the current directory or any " |
509 "parent,\nand the --root command-line argument was not specified.") | 524 "parent,\nand the --root command-line argument was not specified.") |
510 .PrintToStdout(); | 525 .PrintToStdout(); |
511 return false; | 526 return false; |
512 } | 527 } |
513 root_path = dotfile_name_.DirName(); | 528 root_path = dotfile_name_.DirName(); |
514 } | 529 } |
515 | 530 |
| 531 base::FilePath root_path_normalized; |
| 532 if (!NormalizePath(root_path, &root_path_normalized)) { |
| 533 Err(Location(), "Can't normalize the root path.", |
| 534 "I could not normalize the path \"" + FilePathToUTF8(root_path) + "\".") |
| 535 .PrintToStdout(); |
| 536 return false; |
| 537 } |
516 if (scheduler_.verbose_logging()) | 538 if (scheduler_.verbose_logging()) |
517 scheduler_.Log("Using source root", FilePathToUTF8(root_path)); | 539 scheduler_.Log("Using source root", FilePathToUTF8(root_path_normalized)); |
518 build_settings_.SetRootPath(root_path); | 540 build_settings_.SetRootPath(root_path_normalized); |
519 | 541 |
520 return true; | 542 return true; |
521 } | 543 } |
522 | 544 |
523 bool Setup::FillBuildDir(const std::string& build_dir, bool require_exists) { | 545 bool Setup::FillBuildDir(const std::string& build_dir, bool require_exists) { |
524 Err err; | 546 Err err; |
525 SourceDir resolved = | 547 SourceDir resolved = |
526 SourceDirForCurrentDirectory(build_settings_.root_path()). | 548 SourceDirForCurrentDirectory(build_settings_.root_path()). |
527 ResolveRelativeDir(Value(nullptr, build_dir), &err, | 549 ResolveRelativeDir(Value(nullptr, build_dir), &err, |
528 build_settings_.root_path_utf8()); | 550 build_settings_.root_path_utf8()); |
529 if (err.has_error()) { | 551 if (err.has_error()) { |
530 err.PrintToStdout(); | 552 err.PrintToStdout(); |
531 return false; | 553 return false; |
532 } | 554 } |
533 | 555 |
| 556 base::FilePath build_dir_path = build_settings_.GetFullPath(resolved); |
| 557 base::FilePath build_dir_path_normalized; |
| 558 if (!NormalizePath(build_dir_path, &build_dir_path_normalized)) { |
| 559 Err(Location(), "Can't normalize the root path.", |
| 560 "I could not normalize the path \"" + FilePathToUTF8(build_dir_path) + |
| 561 "\".").PrintToStdout(); |
| 562 return false; |
| 563 } |
| 564 resolved = SourceDirForPath(build_settings_.root_path(), |
| 565 build_dir_path_normalized); |
| 566 |
534 if (scheduler_.verbose_logging()) | 567 if (scheduler_.verbose_logging()) |
535 scheduler_.Log("Using build dir", resolved.value()); | 568 scheduler_.Log("Using build dir", resolved.value()); |
536 | 569 |
537 if (require_exists) { | 570 if (require_exists) { |
538 base::FilePath build_dir_path = build_settings_.GetFullPath(resolved); | |
539 if (!base::PathExists(build_dir_path.Append( | 571 if (!base::PathExists(build_dir_path.Append( |
540 FILE_PATH_LITERAL("build.ninja")))) { | 572 FILE_PATH_LITERAL("build.ninja")))) { |
541 Err(Location(), "Not a build directory.", | 573 Err(Location(), "Not a build directory.", |
542 "This command requires an existing build directory. I interpreted " | 574 "This command requires an existing build directory. I interpreted " |
543 "your input\n\"" + build_dir + "\" as:\n " + | 575 "your input\n\"" + build_dir + "\" as:\n " + |
544 FilePathToUTF8(build_dir_path) + | 576 FilePathToUTF8(build_dir_path) + |
545 "\nwhich doesn't seem to contain a previously-generated build.") | 577 "\nwhich doesn't seem to contain a previously-generated build.") |
546 .PrintToStdout(); | 578 .PrintToStdout(); |
547 return false; | 579 return false; |
548 } | 580 } |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
684 if (err.has_error()) { | 716 if (err.has_error()) { |
685 err.PrintToStdout(); | 717 err.PrintToStdout(); |
686 return false; | 718 return false; |
687 } | 719 } |
688 } | 720 } |
689 build_settings_.set_exec_script_whitelist(std::move(whitelist)); | 721 build_settings_.set_exec_script_whitelist(std::move(whitelist)); |
690 } | 722 } |
691 | 723 |
692 return true; | 724 return true; |
693 } | 725 } |
OLD | NEW |