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

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

Issue 711113004: original (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: win compile fix Created 6 years, 1 month 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 | « tools/gn/build_settings.cc ('k') | tools/gn/filesystem_utils.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/files/file_util.h" 8 #include "base/files/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 728 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 // should all be done in parallel. 739 // should all be done in parallel.
740 if (args.size() != 1) { 740 if (args.size() != 1) {
741 Err(Location(), "Expecting exactly one argument, see `gn help format`.\n") 741 Err(Location(), "Expecting exactly one argument, see `gn help format`.\n")
742 .PrintToStdout(); 742 .PrintToStdout();
743 return 1; 743 return 1;
744 } 744 }
745 745
746 Setup setup; 746 Setup setup;
747 SourceDir source_dir = 747 SourceDir source_dir =
748 SourceDirForCurrentDirectory(setup.build_settings().root_path()); 748 SourceDirForCurrentDirectory(setup.build_settings().root_path());
749 SourceFile file = source_dir.ResolveRelativeFile(args[0]); 749 SourceFile file = source_dir.ResolveRelativeFile(args[0],
750 setup.build_settings().root_path_utf8());
750 751
751 std::string output_string; 752 std::string output_string;
752 if (FormatFileToString(&setup, file, dump_tree, &output_string)) { 753 if (FormatFileToString(&setup, file, dump_tree, &output_string)) {
753 bool in_place = 754 bool in_place =
754 base::CommandLine::ForCurrentProcess()->HasSwitch(kSwitchInPlace); 755 base::CommandLine::ForCurrentProcess()->HasSwitch(kSwitchInPlace);
755 if (in_place) { 756 if (in_place) {
756 base::FilePath to_write = setup.build_settings().GetFullPath(file); 757 base::FilePath to_write = setup.build_settings().GetFullPath(file);
757 if (base::WriteFile(to_write, 758 if (base::WriteFile(to_write,
758 output_string.data(), 759 output_string.data(),
759 static_cast<int>(output_string.size())) == -1) { 760 static_cast<int>(output_string.size())) == -1) {
760 Err(Location(), 761 Err(Location(),
761 std::string("Failed to write formatted output back to \"") + 762 std::string("Failed to write formatted output back to \"") +
762 to_write.AsUTF8Unsafe() + std::string("\".")).PrintToStdout(); 763 to_write.AsUTF8Unsafe() + std::string("\".")).PrintToStdout();
763 return 1; 764 return 1;
764 } 765 }
765 printf("Wrote formatted to '%s'.\n", to_write.AsUTF8Unsafe().c_str()); 766 printf("Wrote formatted to '%s'.\n", to_write.AsUTF8Unsafe().c_str());
766 } else { 767 } else {
767 printf("%s", output_string.c_str()); 768 printf("%s", output_string.c_str());
768 } 769 }
769 } 770 }
770 771
771 return 0; 772 return 0;
772 } 773 }
773 774
774 } // namespace commands 775 } // namespace commands
OLDNEW
« no previous file with comments | « tools/gn/build_settings.cc ('k') | tools/gn/filesystem_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698