Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Side by Side Diff: tools/gn/setup.cc

Issue 1723453002: Revert of GN: Normalize the build directory path (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
244 } // namespace 229 } // namespace
245 230
246 const char Setup::kBuildArgFileName[] = "args.gn"; 231 const char Setup::kBuildArgFileName[] = "args.gn";
247 232
248 Setup::Setup() 233 Setup::Setup()
249 : build_settings_(), 234 : build_settings_(),
250 loader_(new LoaderImpl(&build_settings_)), 235 loader_(new LoaderImpl(&build_settings_)),
251 builder_(new Builder(loader_.get())), 236 builder_(new Builder(loader_.get())),
252 root_build_file_("//BUILD.gn"), 237 root_build_file_("//BUILD.gn"),
253 check_public_headers_(false), 238 check_public_headers_(false),
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 if (dotfile_name_.empty()) { 506 if (dotfile_name_.empty()) {
522 Err(Location(), "Can't find source root.", 507 Err(Location(), "Can't find source root.",
523 "I could not find a \".gn\" file in the current directory or any " 508 "I could not find a \".gn\" file in the current directory or any "
524 "parent,\nand the --root command-line argument was not specified.") 509 "parent,\nand the --root command-line argument was not specified.")
525 .PrintToStdout(); 510 .PrintToStdout();
526 return false; 511 return false;
527 } 512 }
528 root_path = dotfile_name_.DirName(); 513 root_path = dotfile_name_.DirName();
529 } 514 }
530 515
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 }
538 if (scheduler_.verbose_logging()) 516 if (scheduler_.verbose_logging())
539 scheduler_.Log("Using source root", FilePathToUTF8(root_path_normalized)); 517 scheduler_.Log("Using source root", FilePathToUTF8(root_path));
540 build_settings_.SetRootPath(root_path_normalized); 518 build_settings_.SetRootPath(root_path);
541 519
542 return true; 520 return true;
543 } 521 }
544 522
545 bool Setup::FillBuildDir(const std::string& build_dir, bool require_exists) { 523 bool Setup::FillBuildDir(const std::string& build_dir, bool require_exists) {
546 Err err; 524 Err err;
547 SourceDir resolved = 525 SourceDir resolved =
548 SourceDirForCurrentDirectory(build_settings_.root_path()). 526 SourceDirForCurrentDirectory(build_settings_.root_path()).
549 ResolveRelativeDir(Value(nullptr, build_dir), &err, 527 ResolveRelativeDir(Value(nullptr, build_dir), &err,
550 build_settings_.root_path_utf8()); 528 build_settings_.root_path_utf8());
551 if (err.has_error()) { 529 if (err.has_error()) {
552 err.PrintToStdout(); 530 err.PrintToStdout();
553 return false; 531 return false;
554 } 532 }
555 533
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
567 if (scheduler_.verbose_logging()) 534 if (scheduler_.verbose_logging())
568 scheduler_.Log("Using build dir", resolved.value()); 535 scheduler_.Log("Using build dir", resolved.value());
569 536
570 if (require_exists) { 537 if (require_exists) {
538 base::FilePath build_dir_path = build_settings_.GetFullPath(resolved);
571 if (!base::PathExists(build_dir_path.Append( 539 if (!base::PathExists(build_dir_path.Append(
572 FILE_PATH_LITERAL("build.ninja")))) { 540 FILE_PATH_LITERAL("build.ninja")))) {
573 Err(Location(), "Not a build directory.", 541 Err(Location(), "Not a build directory.",
574 "This command requires an existing build directory. I interpreted " 542 "This command requires an existing build directory. I interpreted "
575 "your input\n\"" + build_dir + "\" as:\n " + 543 "your input\n\"" + build_dir + "\" as:\n " +
576 FilePathToUTF8(build_dir_path) + 544 FilePathToUTF8(build_dir_path) +
577 "\nwhich doesn't seem to contain a previously-generated build.") 545 "\nwhich doesn't seem to contain a previously-generated build.")
578 .PrintToStdout(); 546 .PrintToStdout();
579 return false; 547 return false;
580 } 548 }
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
716 if (err.has_error()) { 684 if (err.has_error()) {
717 err.PrintToStdout(); 685 err.PrintToStdout();
718 return false; 686 return false;
719 } 687 }
720 } 688 }
721 build_settings_.set_exec_script_whitelist(std::move(whitelist)); 689 build_settings_.set_exec_script_whitelist(std::move(whitelist));
722 } 690 }
723 691
724 return true; 692 return true;
725 } 693 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698