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 "tools/gn/runtime_deps.h" | 5 #include "tools/gn/runtime_deps.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <set> | 8 #include <set> |
9 #include <sstream> | 9 #include <sstream> |
10 | 10 |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 for (const auto& pair : ComputeRuntimeDeps(target)) | 197 for (const auto& pair : ComputeRuntimeDeps(target)) |
198 contents << pair.first.value() << std::endl; | 198 contents << pair.first.value() << std::endl; |
199 | 199 |
200 ScopedTrace trace(TraceItem::TRACE_FILE_WRITE, output_as_source.value()); | 200 ScopedTrace trace(TraceItem::TRACE_FILE_WRITE, output_as_source.value()); |
201 return WriteFileIfChanged(data_deps_file, contents.str(), err); | 201 return WriteFileIfChanged(data_deps_file, contents.str(), err); |
202 } | 202 } |
203 | 203 |
204 } // namespace | 204 } // namespace |
205 | 205 |
206 const char kRuntimeDeps_Help[] = | 206 const char kRuntimeDeps_Help[] = |
207 "Runtime dependencies\n" | 207 R"(Runtime dependencies |
208 "\n" | 208 |
209 " Runtime dependencies of a target are exposed via the \"runtime_deps\"\n" | 209 Runtime dependencies of a target are exposed via the "runtime_deps" category |
210 " category of \"gn desc\" (see \"gn help desc\") or they can be written\n" | 210 of "gn desc" (see "gn help desc") or they can be written at build generation |
211 " at build generation time via write_runtime_deps(), or\n" | 211 time via write_runtime_deps(), or --runtime-deps-list-file (see "gn help |
212 " --runtime-deps-list-file (see \"gn help --runtime-deps-list-file\").\n" | 212 --runtime-deps-list-file"). |
213 "\n" | 213 |
214 " To a first approximation, the runtime dependencies of a target are\n" | 214 To a first approximation, the runtime dependencies of a target are the set of |
215 " the set of \"data\" files, data directories, and the shared libraries\n" | 215 "data" files, data directories, and the shared libraries from all transitive |
216 " from all transitive dependencies. Executables, shared libraries, and\n" | 216 dependencies. Executables, shared libraries, and loadable modules are |
217 " loadable modules are considered runtime dependencies of themselves.\n" | 217 considered runtime dependencies of themselves. |
218 "\n" | 218 |
219 "Executables\n" | 219 Executables |
220 "\n" | 220 |
221 " Executable targets and those executable targets' transitive\n" | 221 Executable targets and those executable targets' transitive dependencies are |
222 " dependencies are not considered unless that executable is listed in\n" | 222 not considered unless that executable is listed in "data_deps". Otherwise, GN |
223 " \"data_deps\". Otherwise, GN assumes that the executable (and\n" | 223 assumes that the executable (and everything it requires) is a build-time |
224 " everything it requires) is a build-time dependency only.\n" | 224 dependency only. |
225 "\n" | 225 |
226 "Actions and copies\n" | 226 Actions and copies |
227 "\n" | 227 |
228 " Action and copy targets that are listed as \"data_deps\" will have all\n" | 228 Action and copy targets that are listed as "data_deps" will have all of their |
229 " of their outputs and data files considered as runtime dependencies.\n" | 229 outputs and data files considered as runtime dependencies. Action and copy |
230 " Action and copy targets that are \"deps\" or \"public_deps\" will have\n" | 230 targets that are "deps" or "public_deps" will have only their data files |
231 " only their data files considered as runtime dependencies. These\n" | 231 considered as runtime dependencies. These targets can list an output file in |
232 " targets can list an output file in both the \"outputs\" and \"data\"\n" | 232 both the "outputs" and "data" lists to force an output file as a runtime |
233 " lists to force an output file as a runtime dependency in all cases.\n" | 233 dependency in all cases. |
234 "\n" | 234 |
235 " The different rules for deps and data_deps are to express build-time\n" | 235 The different rules for deps and data_deps are to express build-time (deps) |
236 " (deps) vs. run-time (data_deps) outputs. If GN counted all build-time\n" | 236 vs. run-time (data_deps) outputs. If GN counted all build-time copy steps as |
237 " copy steps as data dependencies, there would be a lot of extra stuff,\n" | 237 data dependencies, there would be a lot of extra stuff, and if GN counted all |
238 " and if GN counted all run-time dependencies as regular deps, the\n" | 238 run-time dependencies as regular deps, the build's parallelism would be |
239 " build's parallelism would be unnecessarily constrained.\n" | 239 unnecessarily constrained. |
240 "\n" | 240 |
241 " This rule can sometimes lead to unintuitive results. For example,\n" | 241 This rule can sometimes lead to unintuitive results. For example, given the |
242 " given the three targets:\n" | 242 three targets: |
243 " A --[data_deps]--> B --[deps]--> ACTION\n" | 243 A --[data_deps]--> B --[deps]--> ACTION |
244 " GN would say that A does not have runtime deps on the result of the\n" | 244 GN would say that A does not have runtime deps on the result of the ACTION, |
245 " ACTION, which is often correct. But the purpose of the B target might\n" | 245 which is often correct. But the purpose of the B target might be to collect |
246 " be to collect many actions into one logic unit, and the \"data\"-ness\n" | 246 many actions into one logic unit, and the "data"-ness of A's dependency is |
247 " of A's dependency is lost. Solutions:\n" | 247 lost. Solutions: |
248 "\n" | 248 |
249 " - List the outputs of the action in it's data section (if the\n" | 249 - List the outputs of the action in it's data section (if the results of |
250 " results of that action are always runtime files).\n" | 250 that action are always runtime files). |
251 " - Have B list the action in data_deps (if the outputs of the actions\n" | 251 - Have B list the action in data_deps (if the outputs of the actions are |
252 " are always runtime files).\n" | 252 always runtime files). |
253 " - Have B list the action in both deps and data deps (if the outputs\n" | 253 - Have B list the action in both deps and data deps (if the outputs might be |
254 " might be used in both contexts and you don't care about unnecessary\n" | 254 used in both contexts and you don't care about unnecessary entries in the |
255 " entries in the list of files required at runtime).\n" | 255 list of files required at runtime). |
256 " - Split B into run-time and build-time versions with the appropriate\n" | 256 - Split B into run-time and build-time versions with the appropriate "deps" |
257 " \"deps\" for each.\n" | 257 for each. |
258 "\n" | 258 |
259 "Static libraries and source sets\n" | 259 Static libraries and source sets |
260 "\n" | 260 |
261 " The results of static_library or source_set targets are not considered\n" | 261 The results of static_library or source_set targets are not considered |
262 " runtime dependencies since these are assumed to be intermediate\n" | 262 runtime dependencies since these are assumed to be intermediate targets only. |
263 " targets only. If you need to list a static library as a runtime\n" | 263 If you need to list a static library as a runtime dependency, you can |
264 " dependency, you can manually compute the .a/.lib file name for the\n" | 264 manually compute the .a/.lib file name for the current platform and list it |
265 " current platform and list it in the \"data\" list of a target\n" | 265 in the "data" list of a target (possibly on the static library target |
266 " (possibly on the static library target itself).\n" | 266 itself). |
267 "\n" | 267 |
268 "Multiple outputs\n" | 268 Multiple outputs |
269 "\n" | 269 |
270 " Linker tools can specify which of their outputs should be considered\n" | 270 Linker tools can specify which of their outputs should be considered when |
271 " when computing the runtime deps by setting runtime_outputs. If this\n" | 271 computing the runtime deps by setting runtime_outputs. If this is unset on |
272 " is unset on the tool, the default will be the first output only.\n"; | 272 the tool, the default will be the first output only. |
| 273 )"; |
273 | 274 |
274 RuntimeDepsVector ComputeRuntimeDeps(const Target* target) { | 275 RuntimeDepsVector ComputeRuntimeDeps(const Target* target) { |
275 RuntimeDepsVector result; | 276 RuntimeDepsVector result; |
276 std::map<const Target*, bool> seen_targets; | 277 std::map<const Target*, bool> seen_targets; |
277 std::set<OutputFile> found_files; | 278 std::set<OutputFile> found_files; |
278 | 279 |
279 // The initial target is not considered a data dependency so that actions's | 280 // The initial target is not considered a data dependency so that actions's |
280 // outputs (if the current target is an action) are not automatically | 281 // outputs (if the current target is an action) are not automatically |
281 // considered data deps. | 282 // considered data deps. |
282 RecursiveCollectRuntimeDeps(target, false, | 283 RecursiveCollectRuntimeDeps(target, false, |
(...skipping 14 matching lines...) Expand all Loading... |
297 | 298 |
298 for (const auto& entry : files_to_write) { | 299 for (const auto& entry : files_to_write) { |
299 // Currently this writes all runtime deps files sequentially. We generally | 300 // Currently this writes all runtime deps files sequentially. We generally |
300 // expect few of these. We can run this on the worker pool if it looks | 301 // expect few of these. We can run this on the worker pool if it looks |
301 // like it's talking a long time. | 302 // like it's talking a long time. |
302 if (!WriteRuntimeDepsFile(entry.first, entry.second, err)) | 303 if (!WriteRuntimeDepsFile(entry.first, entry.second, err)) |
303 return false; | 304 return false; |
304 } | 305 } |
305 return true; | 306 return true; |
306 } | 307 } |
OLD | NEW |