| 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" |
| 11 #include "tools/gn/setup.h" | 11 #include "tools/gn/setup.h" |
| 12 | 12 |
| 13 namespace { | 13 namespace { |
| 14 | 14 |
| 15 // Extracts from a build.ninja the commands to run GN. | 15 // Extracts from a build.ninja the commands to run GN. |
| 16 // | 16 // |
| 17 // The commands to run GN are the gn rule and build.ninja build step at the top | 17 // The commands to run GN are the gn rule and build.ninja build step at the top |
| 18 // of the build.ninja file. We want to keep these when deleting GN builds since | 18 // of the build.ninja file. We want to keep these when deleting GN builds since |
| 19 // we want to preserve the command-line flags to GN. | 19 // we want to preserve the command-line flags to GN. |
| 20 // | 20 // |
| 21 // On error, returns the empty string. | 21 // On error, returns the empty string. |
| 22 std::string ExtractGNBuildCommands(const base::FilePath& build_ninja_file) { | 22 std::string ExtractGNBuildCommands(const base::FilePath& build_ninja_file) { |
| 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 = base::SplitString( |
| 29 base::SplitStringDontTrim(file_contents, '\n', &lines); | 29 file_contents, "\n", base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL); |
| 30 | 30 |
| 31 std::string result; | 31 std::string result; |
| 32 int num_blank_lines = 0; | 32 int num_blank_lines = 0; |
| 33 for (const auto& line : lines) { | 33 for (const auto& line : lines) { |
| 34 result += line; | 34 result += line; |
| 35 result += "\n"; | 35 result += "\n"; |
| 36 if (line.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) |
| (...skipping 101 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 |