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

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: merge 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/binary_target_generator.cc ('k') | tools/gn/commands.h » ('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/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 19 matching lines...) Expand all
57 // Compute the target to check (empty means everything). 61 // Compute the target to check (empty means everything).
58 if (!ResolveTargetsFromCommandLinePattern(setup, args[1], false, 62 if (!ResolveTargetsFromCommandLinePattern(setup, args[1], false,
59 &targets_to_check)) 63 &targets_to_check))
60 return 1; 64 return 1;
61 if (targets_to_check.size() == 0) { 65 if (targets_to_check.size() == 0) {
62 OutputString("No matching targets.\n"); 66 OutputString("No matching targets.\n");
63 return 1; 67 return 1;
64 } 68 }
65 } 69 }
66 70
71 const CommandLine* cmdline = CommandLine::ForCurrentProcess();
72 bool force = cmdline->HasSwitch("force");
73
67 if (!CheckPublicHeaders(&setup->build_settings(), 74 if (!CheckPublicHeaders(&setup->build_settings(),
68 setup->builder()->GetAllResolvedTargets(), 75 setup->builder()->GetAllResolvedTargets(),
69 targets_to_check)) 76 targets_to_check,
77 force))
70 return 1; 78 return 1;
71 79
72 OutputString("Header dependency check OK\n", DECORATION_GREEN); 80 OutputString("Header dependency check OK\n", DECORATION_GREEN);
73 return 0; 81 return 0;
74 } 82 }
75 83
76 bool CheckPublicHeaders(const BuildSettings* build_settings, 84 bool CheckPublicHeaders(const BuildSettings* build_settings,
77 const std::vector<const Target*>& all_targets, 85 const std::vector<const Target*>& all_targets,
78 const std::vector<const Target*>& to_check) { 86 const std::vector<const Target*>& to_check,
87 bool force_check) {
79 ScopedTrace trace(TraceItem::TRACE_CHECK_HEADERS, "Check headers"); 88 ScopedTrace trace(TraceItem::TRACE_CHECK_HEADERS, "Check headers");
80 89
81 scoped_refptr<HeaderChecker> header_checker( 90 scoped_refptr<HeaderChecker> header_checker(
82 new HeaderChecker(build_settings, all_targets)); 91 new HeaderChecker(build_settings, all_targets));
83 92
84 std::vector<Err> header_errors; 93 std::vector<Err> header_errors;
85 header_checker->Run(to_check, &header_errors); 94 header_checker->Run(to_check, force_check, &header_errors);
86 for (size_t i = 0; i < header_errors.size(); i++) { 95 for (size_t i = 0; i < header_errors.size(); i++) {
87 if (i > 0) 96 if (i > 0)
88 OutputString("___________________\n", DECORATION_YELLOW); 97 OutputString("___________________\n", DECORATION_YELLOW);
89 header_errors[i].PrintToStdout(); 98 header_errors[i].PrintToStdout();
90 } 99 }
91 return header_errors.empty(); 100 return header_errors.empty();
92 } 101 }
93 102
94 } // namespace commands 103 } // namespace commands
OLDNEW
« no previous file with comments | « tools/gn/binary_target_generator.cc ('k') | tools/gn/commands.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698