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

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

Issue 516683002: Add GN variables for controlling header checking. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@desc
Patch Set: 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
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/header_checker.h"
7 #include "tools/gn/setup.h" 7 #include "tools/gn/setup.h"
8 #include "tools/gn/standard_out.h" 8 #include "tools/gn/standard_out.h"
9 #include "tools/gn/trace.h" 9 #include "tools/gn/trace.h"
10 10
11 namespace commands { 11 namespace commands {
12 12
13 const char kCheck[] = "check"; 13 const char kCheck[] = "check";
14 const char kCheck_HelpShort[] = 14 const char kCheck_HelpShort[] =
15 "check: Check header dependencies."; 15 "check: Check header dependencies.";
16 const char kCheck_Help[] = 16 const char kCheck_Help[] =
17 "gn check <out_dir> [<target label>]\n" 17 "gn check <out_dir> [<target label>] [--force]\n"
18 "\n" 18 "\n"
19 " \"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"
20 " 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"
21 " 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"
22 "\n" 22 "\n"
23 " The <label_pattern> can take exact labels or patterns that match more\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" 24 " than one (although not general regular expressions). If specified,\n"
25 " only those matching targets will be checked.\n" 25 " only those matching targets will be checked.\n"
26 " See \"gn help label_pattern\" for details.\n" 26 " See \"gn help label_pattern\" for details.\n"
27 "\n" 27 "\n"
28 " --force\n"
29 " Ignores specifications of \"check_includes = false\" and checks\n"
30 " all target's files that match the target label.\n"
31 "\n"
28 " See \"gn help\" for the common command-line switches.\n" 32 " See \"gn help\" for the common command-line switches.\n"
29 "\n" 33 "\n"
30 "Examples\n" 34 "Examples\n"
31 "\n" 35 "\n"
32 " gn check out/Debug\n" 36 " gn check out/Debug\n"
33 " Check everything.\n" 37 " Check everything.\n"
34 "\n" 38 "\n"
35 " gn check out/Default //foo:bar\n" 39 " gn check out/Default //foo:bar\n"
36 " Check only the files in the //foo:bar target.\n" 40 " Check only the files in the //foo:bar target.\n"
37 "\n" 41 "\n"
(...skipping 16 matching lines...) Expand all
54 58
55 std::vector<const Target*> targets_to_check; 59 std::vector<const Target*> targets_to_check;
56 if (args.size() == 2) { 60 if (args.size() == 2) {
57 // Compute the target to check (empty means everything). 61 // Compute the target to check (empty means everything).
58 const Target* target = ResolveTargetFromCommandLineString(setup, args[1]); 62 const Target* target = ResolveTargetFromCommandLineString(setup, args[1]);
59 if (!target) 63 if (!target)
60 return 1; 64 return 1;
61 targets_to_check.push_back(target); 65 targets_to_check.push_back(target);
62 } 66 }
63 67
68 const CommandLine* cmdline = CommandLine::ForCurrentProcess();
69 bool force = cmdline->HasSwitch("force");
70
64 if (!CheckPublicHeaders(&setup->build_settings(), 71 if (!CheckPublicHeaders(&setup->build_settings(),
65 setup->builder()->GetAllResolvedTargets(), 72 setup->builder()->GetAllResolvedTargets(),
66 targets_to_check)) 73 targets_to_check,
74 force))
67 return 1; 75 return 1;
68 76
69 OutputString("Header dependency check OK\n", DECORATION_GREEN); 77 OutputString("Header dependency check OK\n", DECORATION_GREEN);
70 return 0; 78 return 0;
71 } 79 }
72 80
73 bool CheckPublicHeaders(const BuildSettings* build_settings, 81 bool CheckPublicHeaders(const BuildSettings* build_settings,
74 const std::vector<const Target*>& all_targets, 82 const std::vector<const Target*>& all_targets,
75 const std::vector<const Target*>& to_check) { 83 const std::vector<const Target*>& to_check,
84 bool force_check) {
76 ScopedTrace trace(TraceItem::TRACE_CHECK_HEADERS, "Check headers"); 85 ScopedTrace trace(TraceItem::TRACE_CHECK_HEADERS, "Check headers");
77 86
78 scoped_refptr<HeaderChecker> header_checker( 87 scoped_refptr<HeaderChecker> header_checker(
79 new HeaderChecker(build_settings, all_targets)); 88 new HeaderChecker(build_settings, all_targets));
80 89
81 std::vector<Err> header_errors; 90 std::vector<Err> header_errors;
82 header_checker->Run(to_check, &header_errors); 91 header_checker->Run(to_check, force_check, &header_errors);
83 for (size_t i = 0; i < header_errors.size(); i++) { 92 for (size_t i = 0; i < header_errors.size(); i++) {
84 if (i > 0) 93 if (i > 0)
85 OutputString("___________________\n", DECORATION_YELLOW); 94 OutputString("___________________\n", DECORATION_YELLOW);
86 header_errors[i].PrintToStdout(); 95 header_errors[i].PrintToStdout();
87 } 96 }
88 return header_errors.empty(); 97 return header_errors.empty();
89 } 98 }
90 99
91 } // namespace commands 100 } // namespace commands
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698