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

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

Issue 500423003: Enhance GN diagnostic tools (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: use patterns for gn check Created 6 years, 3 months 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/BUILD.gn ('k') | tools/gn/command_desc.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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/commands.h" 5 #include "tools/gn/commands.h"
6 #include "tools/gn/header_checker.h"
6 #include "tools/gn/setup.h" 7 #include "tools/gn/setup.h"
7 #include "tools/gn/standard_out.h" 8 #include "tools/gn/standard_out.h"
9 #include "tools/gn/trace.h"
8 10
9 namespace commands { 11 namespace commands {
10 12
11 const char kCheck[] = "check"; 13 const char kCheck[] = "check";
12 const char kCheck_HelpShort[] = 14 const char kCheck_HelpShort[] =
13 "check: Check header dependencies."; 15 "check: Check header dependencies.";
14 const char kCheck_Help[] = 16 const char kCheck_Help[] =
15 "gn check: Check header dependencies.\n" 17 "gn check <out_dir> [<target label>]\n"
16 "\n" 18 "\n"
17 " \"gn check\" is the same thing as \"gn gen\" with the \"--check\" flag\n" 19 " \"gn check\" is the same thing as \"gn gen\" with the \"--check\" flag\n"
18 " except that this command does not write out any build files. It's\n" 20 " except that this command does not write out any build files. It's\n"
19 " intended to be an easy way to manually trigger include file checking.\n" 21 " intended to be an easy way to manually trigger include file checking.\n"
20 "\n" 22 "\n"
21 " See \"gn help\" for the common command-line switches.\n"; 23 " The <label_pattern> can take exact labels or patterns that match more\n"
24 " than one (although not general regular expressions). If specified,\n"
25 " only those matching targets will be checked.\n"
26 " See \"gn help label_pattern\" for details.\n"
27 "\n"
28 " See \"gn help\" for the common command-line switches.\n"
29 "\n"
30 "Examples\n"
31 "\n"
32 " gn check out/Debug\n"
33 " Check everything.\n"
34 "\n"
35 " gn check out/Default //foo:bar\n"
36 " Check only the files in the //foo:bar target.\n"
37 "\n"
38 " gn check out/Default \"//foo/*\n"
39 " Check only the files in targets in the //foo directory tree.\n";
22 40
23 int RunCheck(const std::vector<std::string>& args) { 41 int RunCheck(const std::vector<std::string>& args) {
42 if (args.size() != 1 && args.size() != 2) {
43 Err(Location(), "You're holding it wrong.",
44 "Usage: \"gn check <out_dir> [<target_label>]\"").PrintToStdout();
45 return 1;
46 }
47
24 // Deliberately leaked to avoid expensive process teardown. 48 // Deliberately leaked to avoid expensive process teardown.
25 Setup* setup = new Setup(); 49 Setup* setup = new Setup();
26 // TODO(brettw) bug 343726: Use a temporary directory instead of this 50 if (!setup->DoSetup(args[0]))
27 // default one to avoid messing up any build that's in there.
28 if (!setup->DoSetup("//out/Default"))
29 return 1; 51 return 1;
30 setup->set_check_public_headers(true); 52 if (!setup->Run())
53 return 1;
31 54
32 if (!setup->Run()) 55 std::vector<const Target*> targets_to_check;
56 if (args.size() == 2) {
57 // Compute the target to check (empty means everything).
58 if (!ResolveTargetsFromCommandLinePattern(setup, args[1], false,
59 &targets_to_check))
60 return 1;
61 if (targets_to_check.size() == 0) {
62 OutputString("No matching targets.\n");
63 return 1;
64 }
65 }
66
67 if (!CheckPublicHeaders(&setup->build_settings(),
68 setup->builder()->GetAllResolvedTargets(),
69 targets_to_check))
33 return 1; 70 return 1;
34 71
35 OutputString("Header dependency check OK\n", DECORATION_GREEN); 72 OutputString("Header dependency check OK\n", DECORATION_GREEN);
36 return 0; 73 return 0;
37 } 74 }
38 75
76 bool CheckPublicHeaders(const BuildSettings* build_settings,
77 const std::vector<const Target*>& all_targets,
78 const std::vector<const Target*>& to_check) {
79 ScopedTrace trace(TraceItem::TRACE_CHECK_HEADERS, "Check headers");
80
81 scoped_refptr<HeaderChecker> header_checker(
82 new HeaderChecker(build_settings, all_targets));
83
84 std::vector<Err> header_errors;
85 header_checker->Run(to_check, &header_errors);
86 for (size_t i = 0; i < header_errors.size(); i++) {
87 if (i > 0)
88 OutputString("___________________\n", DECORATION_YELLOW);
89 header_errors[i].PrintToStdout();
90 }
91 return header_errors.empty();
92 }
93
39 } // namespace commands 94 } // namespace commands
OLDNEW
« no previous file with comments | « tools/gn/BUILD.gn ('k') | tools/gn/command_desc.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698