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