OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "base/files/file_path.h" | 5 #include "base/files/file_path.h" |
6 #include "base/files/file_util.h" | 6 #include "base/files/file_util.h" |
7 #include "base/strings/string_split.h" | 7 #include "base/strings/string_split.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "tools/gn/commands.h" | 9 #include "tools/gn/commands.h" |
10 #include "tools/gn/err.h" | 10 #include "tools/gn/err.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 std::string file_contents; | 23 std::string file_contents; |
24 if (!base::ReadFileToString(build_ninja_file, &file_contents)) { | 24 if (!base::ReadFileToString(build_ninja_file, &file_contents)) { |
25 return std::string(); | 25 return std::string(); |
26 } | 26 } |
27 | 27 |
28 std::vector<std::string> lines; | 28 std::vector<std::string> lines; |
29 base::SplitStringDontTrim(file_contents, '\n', &lines); | 29 base::SplitStringDontTrim(file_contents, '\n', &lines); |
30 | 30 |
31 std::string result; | 31 std::string result; |
32 int num_blank_lines = 0; | 32 int num_blank_lines = 0; |
33 for (size_t i = 0; i < lines.size(); ++i) { | 33 for (const auto& line : lines) { |
34 result += lines[i]; | 34 result += line; |
35 result += "\n"; | 35 result += "\n"; |
36 if (lines[i].empty()) { | 36 if (line.empty()) { |
37 ++num_blank_lines; | 37 ++num_blank_lines; |
38 } | 38 } |
39 if (num_blank_lines == 2) | 39 if (num_blank_lines == 2) |
40 break; | 40 break; |
41 } | 41 } |
42 | 42 |
43 return result; | 43 return result; |
44 } | 44 } |
45 | 45 |
46 const char kDefaultNinjaFile[] = | 46 const char kDefaultNinjaFile[] = |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 static_cast<int>(dummy_content.size())) == -1) { | 141 static_cast<int>(dummy_content.size())) == -1) { |
142 Err(Location(), std::string("Failed to write build.ninja.d.")) | 142 Err(Location(), std::string("Failed to write build.ninja.d.")) |
143 .PrintToStdout(); | 143 .PrintToStdout(); |
144 return 1; | 144 return 1; |
145 } | 145 } |
146 | 146 |
147 return 0; | 147 return 0; |
148 } | 148 } |
149 | 149 |
150 } // namespace commands | 150 } // namespace commands |
OLD | NEW |