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 GetRealPath(const base::FilePath& path, base::FilePath* out) { | |
hashimoto
2016/02/23 10:17:31
Renamed this function to GetRealPath() as filesyst
| |
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_realpath; | |
532 if (!GetRealPath(root_path, &root_realpath)) { | |
533 Err(Location(), "Can't get the real root path.", | |
534 "I could not get the real path of \"" + 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_realpath)); |
518 build_settings_.SetRootPath(root_path); | 540 build_settings_.SetRootPath(root_realpath); |
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 if (!base::CreateDirectory(build_dir_path)) { | |
558 Err(Location(), "Can't create the build dir.", | |
559 "I could not create the build dir \"" + FilePathToUTF8(build_dir_path) + | |
560 "\".").PrintToStdout(); | |
561 return false; | |
562 } | |
563 base::FilePath build_dir_realpath; | |
564 if (!GetRealPath(build_dir_path, &build_dir_realpath)) { | |
565 Err(Location(), "Can't get the real build dir path.", | |
566 "I could not get the real path of \"" + FilePathToUTF8(build_dir_path) + | |
567 "\".").PrintToStdout(); | |
568 return false; | |
569 } | |
570 resolved = SourceDirForPath(build_settings_.root_path(), | |
571 build_dir_realpath); | |
572 | |
534 if (scheduler_.verbose_logging()) | 573 if (scheduler_.verbose_logging()) |
535 scheduler_.Log("Using build dir", resolved.value()); | 574 scheduler_.Log("Using build dir", resolved.value()); |
536 | 575 |
537 if (require_exists) { | 576 if (require_exists) { |
538 base::FilePath build_dir_path = build_settings_.GetFullPath(resolved); | |
539 if (!base::PathExists(build_dir_path.Append( | 577 if (!base::PathExists(build_dir_path.Append( |
540 FILE_PATH_LITERAL("build.ninja")))) { | 578 FILE_PATH_LITERAL("build.ninja")))) { |
541 Err(Location(), "Not a build directory.", | 579 Err(Location(), "Not a build directory.", |
542 "This command requires an existing build directory. I interpreted " | 580 "This command requires an existing build directory. I interpreted " |
543 "your input\n\"" + build_dir + "\" as:\n " + | 581 "your input\n\"" + build_dir + "\" as:\n " + |
544 FilePathToUTF8(build_dir_path) + | 582 FilePathToUTF8(build_dir_path) + |
545 "\nwhich doesn't seem to contain a previously-generated build.") | 583 "\nwhich doesn't seem to contain a previously-generated build.") |
546 .PrintToStdout(); | 584 .PrintToStdout(); |
547 return false; | 585 return false; |
548 } | 586 } |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
684 if (err.has_error()) { | 722 if (err.has_error()) { |
685 err.PrintToStdout(); | 723 err.PrintToStdout(); |
686 return false; | 724 return false; |
687 } | 725 } |
688 } | 726 } |
689 build_settings_.set_exec_script_whitelist(std::move(whitelist)); | 727 build_settings_.set_exec_script_whitelist(std::move(whitelist)); |
690 } | 728 } |
691 | 729 |
692 return true; | 730 return true; |
693 } | 731 } |
OLD | NEW |