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

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

Issue 630223002: gn: Support build directories outside the source tree. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updated patch set Created 6 years, 2 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <sstream> 5 #include <sstream>
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/strings/string_split.h" 9 #include "base/strings/string_split.h"
10 #include "tools/gn/commands.h" 10 #include "tools/gn/commands.h"
(...skipping 689 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 // should all be done in parallel. 700 // should all be done in parallel.
701 if (args.size() != 1) { 701 if (args.size() != 1) {
702 Err(Location(), "Expecting exactly one argument, see `gn help format`.\n") 702 Err(Location(), "Expecting exactly one argument, see `gn help format`.\n")
703 .PrintToStdout(); 703 .PrintToStdout();
704 return 1; 704 return 1;
705 } 705 }
706 706
707 Setup setup; 707 Setup setup;
708 SourceDir source_dir = 708 SourceDir source_dir =
709 SourceDirForCurrentDirectory(setup.build_settings().root_path()); 709 SourceDirForCurrentDirectory(setup.build_settings().root_path());
710 SourceFile file = source_dir.ResolveRelativeFile(args[0]); 710 SourceFile file = source_dir.ResolveRelativeFile(args[0],
711 setup.build_settings().root_path());
711 712
712 std::string output_string; 713 std::string output_string;
713 if (FormatFileToString(&setup, file, dump_tree, &output_string)) { 714 if (FormatFileToString(&setup, file, dump_tree, &output_string)) {
714 bool in_place = 715 bool in_place =
715 base::CommandLine::ForCurrentProcess()->HasSwitch(kSwitchInPlace); 716 base::CommandLine::ForCurrentProcess()->HasSwitch(kSwitchInPlace);
716 if (in_place) { 717 if (in_place) {
717 base::FilePath to_write = setup.build_settings().GetFullPath(file); 718 base::FilePath to_write = setup.build_settings().GetFullPath(file);
718 printf("Writing formatted to '%s'.\n", to_write.AsUTF8Unsafe().c_str()); 719 printf("Writing formatted to '%s'.\n", to_write.AsUTF8Unsafe().c_str());
719 if (base::WriteFile(to_write, 720 if (base::WriteFile(to_write,
720 output_string.data(), 721 output_string.data(),
721 static_cast<int>(output_string.size())) == -1) { 722 static_cast<int>(output_string.size())) == -1) {
722 Err(Location(), 723 Err(Location(),
723 std::string("Failed to write formatted output back to \"") + 724 std::string("Failed to write formatted output back to \"") +
724 to_write.AsUTF8Unsafe() + std::string("\".")).PrintToStdout(); 725 to_write.AsUTF8Unsafe() + std::string("\".")).PrintToStdout();
725 return 1; 726 return 1;
726 } 727 }
727 } else { 728 } else {
728 printf("%s", output_string.c_str()); 729 printf("%s", output_string.c_str());
729 } 730 }
730 } 731 }
731 732
732 return 0; 733 return 0;
733 } 734 }
734 735
735 } // namespace commands 736 } // namespace commands
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698