| 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 994 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1005 // should all be done in parallel. | 1005 // should all be done in parallel. |
| 1006 if (args.size() != 1) { | 1006 if (args.size() != 1) { |
| 1007 Err(Location(), "Expecting exactly one argument, see `gn help format`.\n") | 1007 Err(Location(), "Expecting exactly one argument, see `gn help format`.\n") |
| 1008 .PrintToStdout(); | 1008 .PrintToStdout(); |
| 1009 return 1; | 1009 return 1; |
| 1010 } | 1010 } |
| 1011 | 1011 |
| 1012 Setup setup; | 1012 Setup setup; |
| 1013 SourceDir source_dir = | 1013 SourceDir source_dir = |
| 1014 SourceDirForCurrentDirectory(setup.build_settings().root_path()); | 1014 SourceDirForCurrentDirectory(setup.build_settings().root_path()); |
| 1015 SourceFile file = source_dir.ResolveRelativeFile(args[0]); | 1015 |
| 1016 Err err; |
| 1017 SourceFile file = source_dir.ResolveRelativeFile(Value(nullptr, args[0]), |
| 1018 &err); |
| 1019 if (err.has_error()) { |
| 1020 err.PrintToStdout(); |
| 1021 return 1; |
| 1022 } |
| 1016 | 1023 |
| 1017 std::string output_string; | 1024 std::string output_string; |
| 1018 if (FormatFileToString(&setup, file, dump_tree, &output_string)) { | 1025 if (FormatFileToString(&setup, file, dump_tree, &output_string)) { |
| 1019 if (in_place) { | 1026 if (in_place) { |
| 1020 base::FilePath to_write = setup.build_settings().GetFullPath(file); | 1027 base::FilePath to_write = setup.build_settings().GetFullPath(file); |
| 1021 std::string original_contents; | 1028 std::string original_contents; |
| 1022 if (!base::ReadFileToString(to_write, &original_contents)) { | 1029 if (!base::ReadFileToString(to_write, &original_contents)) { |
| 1023 Err(Location(), std::string("Couldn't read \"") + | 1030 Err(Location(), std::string("Couldn't read \"") + |
| 1024 to_write.AsUTF8Unsafe() + | 1031 to_write.AsUTF8Unsafe() + |
| 1025 std::string("\" for comparison.")).PrintToStdout(); | 1032 std::string("\" for comparison.")).PrintToStdout(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1040 } | 1047 } |
| 1041 } else { | 1048 } else { |
| 1042 printf("%s", output_string.c_str()); | 1049 printf("%s", output_string.c_str()); |
| 1043 } | 1050 } |
| 1044 } | 1051 } |
| 1045 | 1052 |
| 1046 return 0; | 1053 return 0; |
| 1047 } | 1054 } |
| 1048 | 1055 |
| 1049 } // namespace commands | 1056 } // namespace commands |
| OLD | NEW |