| 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 728 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 |
| OLD | NEW |