Index: tools/gn/command_check.cc |
diff --git a/tools/gn/command_check.cc b/tools/gn/command_check.cc |
index 3546b7c1aa945580d307bd15a57c0986f9be006b..74ffb42e098a24f4062fc142bfb725d99dc22da9 100644 |
--- a/tools/gn/command_check.cc |
+++ b/tools/gn/command_check.cc |
@@ -3,8 +3,10 @@ |
// found in the LICENSE file. |
#include "tools/gn/commands.h" |
+#include "tools/gn/header_checker.h" |
#include "tools/gn/setup.h" |
#include "tools/gn/standard_out.h" |
+#include "tools/gn/trace.h" |
namespace commands { |
@@ -12,28 +14,81 @@ const char kCheck[] = "check"; |
const char kCheck_HelpShort[] = |
"check: Check header dependencies."; |
const char kCheck_Help[] = |
- "gn check: Check header dependencies.\n" |
+ "gn check <out_dir> [<target label>]\n" |
"\n" |
" \"gn check\" is the same thing as \"gn gen\" with the \"--check\" flag\n" |
" except that this command does not write out any build files. It's\n" |
" intended to be an easy way to manually trigger include file checking.\n" |
"\n" |
- " See \"gn help\" for the common command-line switches.\n"; |
+ " The <label_pattern> can take exact labels or patterns that match more\n" |
+ " than one (although not general regular expressions). If specified,\n" |
+ " only those matching targets will be checked.\n" |
+ " See \"gn help label_pattern\" for details.\n" |
+ "\n" |
+ " See \"gn help\" for the common command-line switches.\n" |
+ "\n" |
+ "Examples\n" |
+ "\n" |
+ " gn check out/Debug\n" |
+ " Check everything.\n" |
+ "\n" |
+ " gn check out/Default //foo:bar\n" |
+ " Check only the files in the //foo:bar target.\n" |
+ "\n" |
+ " gn check out/Default \"//foo/*\n" |
+ " Check only the files in targets in the //foo directory tree.\n"; |
int RunCheck(const std::vector<std::string>& args) { |
+ if (args.size() != 1 && args.size() != 2) { |
+ Err(Location(), "You're holding it wrong.", |
+ "Usage: \"gn check <out_dir> [<target_label>]\"").PrintToStdout(); |
+ return 1; |
+ } |
+ |
// Deliberately leaked to avoid expensive process teardown. |
Setup* setup = new Setup(); |
- // TODO(brettw) bug 343726: Use a temporary directory instead of this |
- // default one to avoid messing up any build that's in there. |
- if (!setup->DoSetup("//out/Default")) |
+ if (!setup->DoSetup(args[0])) |
return 1; |
- setup->set_check_public_headers(true); |
- |
if (!setup->Run()) |
return 1; |
+ std::vector<const Target*> targets_to_check; |
+ if (args.size() == 2) { |
+ // Compute the target to check (empty means everything). |
+ if (!ResolveTargetsFromCommandLinePattern(setup, args[1], false, |
+ &targets_to_check)) |
+ return 1; |
+ if (targets_to_check.size() == 0) { |
+ OutputString("No matching targets.\n"); |
+ return 1; |
+ } |
+ } |
+ |
+ if (!CheckPublicHeaders(&setup->build_settings(), |
+ setup->builder()->GetAllResolvedTargets(), |
+ targets_to_check)) |
+ return 1; |
+ |
OutputString("Header dependency check OK\n", DECORATION_GREEN); |
return 0; |
} |
+bool CheckPublicHeaders(const BuildSettings* build_settings, |
+ const std::vector<const Target*>& all_targets, |
+ const std::vector<const Target*>& to_check) { |
+ ScopedTrace trace(TraceItem::TRACE_CHECK_HEADERS, "Check headers"); |
+ |
+ scoped_refptr<HeaderChecker> header_checker( |
+ new HeaderChecker(build_settings, all_targets)); |
+ |
+ std::vector<Err> header_errors; |
+ header_checker->Run(to_check, &header_errors); |
+ for (size_t i = 0; i < header_errors.size(); i++) { |
+ if (i > 0) |
+ OutputString("___________________\n", DECORATION_YELLOW); |
+ header_errors[i].PrintToStdout(); |
+ } |
+ return header_errors.empty(); |
+} |
+ |
} // namespace commands |