| OLD | NEW |
| 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 733 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 744 // should all be done in parallel. | 744 // should all be done in parallel. |
| 745 if (args.size() != 1) { | 745 if (args.size() != 1) { |
| 746 Err(Location(), "Expecting exactly one argument, see `gn help format`.\n") | 746 Err(Location(), "Expecting exactly one argument, see `gn help format`.\n") |
| 747 .PrintToStdout(); | 747 .PrintToStdout(); |
| 748 return 1; | 748 return 1; |
| 749 } | 749 } |
| 750 | 750 |
| 751 Setup setup; | 751 Setup setup; |
| 752 SourceDir source_dir = | 752 SourceDir source_dir = |
| 753 SourceDirForCurrentDirectory(setup.build_settings().root_path()); | 753 SourceDirForCurrentDirectory(setup.build_settings().root_path()); |
| 754 SourceFile file = source_dir.ResolveRelativeFile(args[0]); | 754 SourceFile file = source_dir.ResolveRelativeFile(args[0], |
| 755 setup.build_settings().root_path_utf8()); |
| 755 | 756 |
| 756 std::string output_string; | 757 std::string output_string; |
| 757 if (FormatFileToString(&setup, file, dump_tree, &output_string)) { | 758 if (FormatFileToString(&setup, file, dump_tree, &output_string)) { |
| 758 bool in_place = | 759 bool in_place = |
| 759 base::CommandLine::ForCurrentProcess()->HasSwitch(kSwitchInPlace); | 760 base::CommandLine::ForCurrentProcess()->HasSwitch(kSwitchInPlace); |
| 760 if (in_place) { | 761 if (in_place) { |
| 761 base::FilePath to_write = setup.build_settings().GetFullPath(file); | 762 base::FilePath to_write = setup.build_settings().GetFullPath(file); |
| 762 if (base::WriteFile(to_write, | 763 if (base::WriteFile(to_write, |
| 763 output_string.data(), | 764 output_string.data(), |
| 764 static_cast<int>(output_string.size())) == -1) { | 765 static_cast<int>(output_string.size())) == -1) { |
| 765 Err(Location(), | 766 Err(Location(), |
| 766 std::string("Failed to write formatted output back to \"") + | 767 std::string("Failed to write formatted output back to \"") + |
| 767 to_write.AsUTF8Unsafe() + std::string("\".")).PrintToStdout(); | 768 to_write.AsUTF8Unsafe() + std::string("\".")).PrintToStdout(); |
| 768 return 1; | 769 return 1; |
| 769 } | 770 } |
| 770 printf("Wrote formatted to '%s'.\n", to_write.AsUTF8Unsafe().c_str()); | 771 printf("Wrote formatted to '%s'.\n", to_write.AsUTF8Unsafe().c_str()); |
| 771 } else { | 772 } else { |
| 772 printf("%s", output_string.c_str()); | 773 printf("%s", output_string.c_str()); |
| 773 } | 774 } |
| 774 } | 775 } |
| 775 | 776 |
| 776 return 0; | 777 return 0; |
| 777 } | 778 } |
| 778 | 779 |
| 779 } // namespace commands | 780 } // namespace commands |
| OLD | NEW |