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/filesystem_utils.h" |
11 #include "tools/gn/setup.h" | 12 #include "tools/gn/setup.h" |
12 | 13 |
13 namespace { | 14 namespace { |
14 | 15 |
15 // Extracts from a build.ninja the commands to run GN. | 16 // Extracts from a build.ninja the commands to run GN. |
16 // | 17 // |
17 // The commands to run GN are the gn rule and build.ninja build step at the top | 18 // 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 | 19 // 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. | 20 // we want to preserve the command-line flags to GN. |
20 // | 21 // |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 return 1; | 78 return 1; |
78 | 79 |
79 base::FilePath build_dir(setup->build_settings().GetFullPath( | 80 base::FilePath build_dir(setup->build_settings().GetFullPath( |
80 SourceDir(setup->build_settings().build_dir().value()))); | 81 SourceDir(setup->build_settings().build_dir().value()))); |
81 | 82 |
82 // NOTE: Not all GN builds have args.gn file hence we check here | 83 // NOTE: Not all GN builds have args.gn file hence we check here |
83 // if a build.ninja.d files exists instead. | 84 // if a build.ninja.d files exists instead. |
84 base::FilePath build_ninja_d_file = build_dir.AppendASCII("build.ninja.d"); | 85 base::FilePath build_ninja_d_file = build_dir.AppendASCII("build.ninja.d"); |
85 if (!base::PathExists(build_ninja_d_file)) { | 86 if (!base::PathExists(build_ninja_d_file)) { |
86 Err(Location(), | 87 Err(Location(), |
87 base::StringPrintf("%s does not look like a build directory.\n", | 88 base::StringPrintf( |
88 build_ninja_d_file.DirName().value().c_str())) | 89 "%s does not look like a build directory.\n", |
| 90 FilePathToUTF8(build_ninja_d_file.DirName().value()).c_str())) |
89 .PrintToStdout(); | 91 .PrintToStdout(); |
90 return 1; | 92 return 1; |
91 } | 93 } |
92 | 94 |
93 // Erase everything but the args file, and write a dummy build.ninja file that | 95 // Erase everything but the args file, and write a dummy build.ninja file that |
94 // will automatically rerun GN the next time Ninja is run. | 96 // will automatically rerun GN the next time Ninja is run. |
95 base::FilePath build_ninja_file = build_dir.AppendASCII("build.ninja"); | 97 base::FilePath build_ninja_file = build_dir.AppendASCII("build.ninja"); |
96 std::string build_commands = ExtractGNBuildCommands(build_ninja_file); | 98 std::string build_commands = ExtractGNBuildCommands(build_ninja_file); |
97 | 99 |
98 // Read the args.gn file, if any. Not all GN builds have one. | 100 // Read the args.gn file, if any. Not all GN builds have one. |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 static_cast<int>(dummy_content.size())) == -1) { | 143 static_cast<int>(dummy_content.size())) == -1) { |
142 Err(Location(), std::string("Failed to write build.ninja.d.")) | 144 Err(Location(), std::string("Failed to write build.ninja.d.")) |
143 .PrintToStdout(); | 145 .PrintToStdout(); |
144 return 1; | 146 return 1; |
145 } | 147 } |
146 | 148 |
147 return 0; | 149 return 0; |
148 } | 150 } |
149 | 151 |
150 } // namespace commands | 152 } // namespace commands |
OLD | NEW |