Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(159)

Side by Side Diff: tools/gn/command_analyze.cc

Issue 2481423002: Convert gn docstrings to C++11 raw strings. (Closed)
Patch Set: Fixes Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/gn/args.cc ('k') | tools/gn/command_args.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 <algorithm> 5 #include <algorithm>
6 #include <iterator> 6 #include <iterator>
7 #include <set> 7 #include <set>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
11 #include "base/files/file_util.h" 11 #include "base/files/file_util.h"
12 #include "tools/gn/analyzer.h" 12 #include "tools/gn/analyzer.h"
13 #include "tools/gn/commands.h" 13 #include "tools/gn/commands.h"
14 #include "tools/gn/filesystem_utils.h" 14 #include "tools/gn/filesystem_utils.h"
15 #include "tools/gn/location.h" 15 #include "tools/gn/location.h"
16 #include "tools/gn/setup.h" 16 #include "tools/gn/setup.h"
17 17
18 namespace commands { 18 namespace commands {
19 19
20 const char kAnalyze[] = "analyze"; 20 const char kAnalyze[] = "analyze";
21 const char kAnalyze_HelpShort[] = 21 const char kAnalyze_HelpShort[] =
22 "analyze: Analyze which targets are affected by a list of files."; 22 "analyze: Analyze which targets are affected by a list of files.";
23 const char kAnalyze_Help[] = 23 const char kAnalyze_Help[] =
24 "gn analyze <out_dir> <input_path> <output_path>\n" 24 R"(gn analyze <out_dir> <input_path> <output_path>
25 "\n"
26 " Analyze which targets are affected by a list of files.\n"
27 "\n"
28 " This command takes three arguments:\n"
29 "\n"
30 " out_dir is the path to the build directory.\n"
31 "\n"
32 " input_path is a path to a file containing a JSON object with three\n"
33 " fields:\n"
34 "\n"
35 " - \"files\": A list of the filenames to check.\n"
36 "\n"
37 " - \"test_targets\": A list of the labels for targets that\n"
38 " are needed to run the tests we wish to run.\n"
39 "\n"
40 " - \"additional_compile_targets\": A list of the labels for\n"
41 " targets that we wish to rebuild, but aren't necessarily needed\n"
42 " for testing. The important difference between this field and\n"
43 " \"test_targets\" is that if an item in the\n"
44 " additional_compile_targets list refers to a group, then\n"
45 " any dependencies of that group will be returned if they are out\n"
46 " of date, but the group itself does not need to be. If the\n"
47 " dependencies themselves are groups, the same filtering is\n"
48 " repeated. This filtering can be used to avoid rebuilding\n"
49 " dependencies of a group that are unaffected by the input files.\n"
50 " The list may also contain the string \"all\" to refer to a\n"
51 " pseudo-group that contains every root target in the build\n"
52 " graph.\n"
53 "\n"
54 " This filtering behavior is also known as \"pruning\" the list\n"
55 " of compile targets.\n"
56 "\n"
57 " output_path is a path indicating where the results of the command\n"
58 " are to be written. The results will be a file containing a JSON\n"
59 " object with one or more of following fields:\n"
60 "\n"
61 " - \"compile_targets\": A list of the labels derived from the input\n"
62 " compile_targets list that are affected by the input files.\n"
63 " Due to the way the filtering works for compile targets as\n"
64 " described above, this list may contain targets that do not appear\n"
65 " in the input list.\n"
66 "\n"
67 " - \"test_targets\": A list of the labels from the input\n"
68 " test_targets list that are affected by the input files. This list\n"
69 " will be a proper subset of the input list.\n"
70 "\n"
71 " - \"invalid_targets\": A list of any names from the input that\n"
72 " do not exist in the build graph. If this list is non-empty,\n"
73 " the \"error\" field will also be set to \"Invalid targets\".\n"
74 "\n"
75 " - \"status\": A string containing one of three values:\n"
76 "\n"
77 " - \"Found dependency\"\n"
78 " - \"No dependency\"\n"
79 " - \"Found dependency (all)\"\n"
80 "\n"
81 " In the first case, the lists returned in compile_targets and\n"
82 " test_targets should be passed to ninja to build. In the second\n"
83 " case, nothing was affected and no build is necessary. In the third\n"
84 " case, GN could not determine the correct answer and returned the\n"
85 " input as the output in order to be safe.\n"
86 "\n"
87 " - \"error\": This will only be present if an error occurred, and\n"
88 " will contain a string describing the error. This includes cases\n"
89 " where the input file is not in the right format, or contains\n"
90 " invalid targets.\n"
91 25
92 " The command returns 1 if it is unable to read the input file or write\n" 26 Analyze which targets are affected by a list of files.
93 " the output file, or if there is something wrong with the build such\n" 27
94 " that gen would also fail, and 0 otherwise. In particular, it returns\n" 28 This command takes three arguments:
95 " 0 even if the \"error\" key is non-empty and a non-fatal error\n" 29
96 " occurred. In other words, it tries really hard to always write\n" 30 out_dir is the path to the build directory.
97 " something to the output JSON and convey errors that way rather than\n" 31
98 " via return codes.\n"; 32 input_path is a path to a file containing a JSON object with three fields:
33
34 - "files": A list of the filenames to check.
35
36 - "test_targets": A list of the labels for targets that are needed to run
37 the tests we wish to run.
38
39 - "additional_compile_targets": A list of the labels for targets that we
40 wish to rebuild, but aren't necessarily needed for testing. The important
41 difference between this field and "test_targets" is that if an item in
42 the additional_compile_targets list refers to a group, then any
43 dependencies of that group will be returned if they are out of date, but
44 the group itself does not need to be. If the dependencies themselves are
45 groups, the same filtering is repeated. This filtering can be used to
46 avoid rebuilding dependencies of a group that are unaffected by the input
47 files. The list may also contain the string "all" to refer to a
48 pseudo-group that contains every root target in the build graph.
49
50 This filtering behavior is also known as "pruning" the list of compile
51 targets.
52
53 output_path is a path indicating where the results of the command are to be
54 written. The results will be a file containing a JSON object with one or more
55 of following fields:
56
57 - "compile_targets": A list of the labels derived from the input
58 compile_targets list that are affected by the input files. Due to the way
59 the filtering works for compile targets as described above, this list may
60 contain targets that do not appear in the input list.
61
62 - "test_targets": A list of the labels from the input test_targets list that
63 are affected by the input files. This list will be a proper subset of the
64 input list.
65
66 - "invalid_targets": A list of any names from the input that do not exist in
67 the build graph. If this list is non-empty, the "error" field will also be
68 set to "Invalid targets".
69
70 - "status": A string containing one of three values:
71
72 - "Found dependency"
73 - "No dependency"
74 - "Found dependency (all) "
75
76 In the first case, the lists returned in compile_targets and test_targets
77 should be passed to ninja to build. In the second case, nothing was
78 affected and no build is necessary. In the third case, GN could not
79 determine the correct answer and returned the input as the output in order
80 to be safe.
81
82 - "error": This will only be present if an error occurred, and will contain
83 a string describing the error. This includes cases where the input file is
84 not in the right format, or contains invalid targets.
85
86 The command returns 1 if it is unable to read the input file or write the
87 output file, or if there is something wrong with the build such that gen
88 would also fail, and 0 otherwise. In particular, it returns 0 even if the
89 "error" key is non-empty and a non-fatal error occurred. In other words, it
90 tries really hard to always write something to the output JSON and convey
91 errors that way rather than via return codes.
92 )";
99 93
100 int RunAnalyze(const std::vector<std::string>& args) { 94 int RunAnalyze(const std::vector<std::string>& args) {
101 if (args.size() != 3) { 95 if (args.size() != 3) {
102 Err(Location(), "You're holding it wrong.", 96 Err(Location(), "You're holding it wrong.",
103 "Usage: \"gn analyze <out_dir> <input_path> <output_path>") 97 "Usage: \"gn analyze <out_dir> <input_path> <output_path>")
104 .PrintToStdout(); 98 .PrintToStdout();
105 return 1; 99 return 1;
106 } 100 }
107 101
108 std::string input; 102 std::string input;
(...skipping 20 matching lines...) Expand all
129 WriteFile(UTF8ToFilePath(args[2]), output, &err); 123 WriteFile(UTF8ToFilePath(args[2]), output, &err);
130 if (err.has_error()) { 124 if (err.has_error()) {
131 err.PrintToStdout(); 125 err.PrintToStdout();
132 return 1; 126 return 1;
133 } 127 }
134 128
135 return 0; 129 return 0;
136 } 130 }
137 131
138 } // namespace commands 132 } // namespace commands
OLDNEW
« no previous file with comments | « tools/gn/args.cc ('k') | tools/gn/command_args.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698