Remove no longer needed toolbar layer method.
[chromium-blink-merge.git] / tools / gn / commands.h
blob239c07b511ef43cba665896a65508e26dbe3fcb9
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
3 // found in the LICENSE file.
5 #ifndef TOOLS_GN_COMMANDS_H_
6 #define TOOLS_GN_COMMANDS_H_
8 #include <map>
9 #include <set>
10 #include <string>
11 #include <vector>
13 #include "base/strings/string_piece.h"
14 #include "tools/gn/target.h"
15 #include "tools/gn/unique_vector.h"
17 class BuildSettings;
18 class Config;
19 class LabelPattern;
20 class Setup;
21 class SourceFile;
22 class Target;
23 class Toolchain;
25 // Each "Run" command returns the value we should return from main().
27 namespace commands {
29 typedef int (*CommandRunner)(const std::vector<std::string>&);
31 extern const char kArgs[];
32 extern const char kArgs_HelpShort[];
33 extern const char kArgs_Help[];
34 int RunArgs(const std::vector<std::string>& args);
36 extern const char kCheck[];
37 extern const char kCheck_HelpShort[];
38 extern const char kCheck_Help[];
39 int RunCheck(const std::vector<std::string>& args);
41 extern const char kClean[];
42 extern const char kClean_HelpShort[];
43 extern const char kClean_Help[];
44 int RunClean(const std::vector<std::string>& args);
46 extern const char kDesc[];
47 extern const char kDesc_HelpShort[];
48 extern const char kDesc_Help[];
49 int RunDesc(const std::vector<std::string>& args);
51 extern const char kGen[];
52 extern const char kGen_HelpShort[];
53 extern const char kGen_Help[];
54 int RunGen(const std::vector<std::string>& args);
56 extern const char kFormat[];
57 extern const char kFormat_HelpShort[];
58 extern const char kFormat_Help[];
59 int RunFormat(const std::vector<std::string>& args);
61 extern const char kHelp[];
62 extern const char kHelp_HelpShort[];
63 extern const char kHelp_Help[];
64 int RunHelp(const std::vector<std::string>& args);
66 extern const char kLs[];
67 extern const char kLs_HelpShort[];
68 extern const char kLs_Help[];
69 int RunLs(const std::vector<std::string>& args);
71 extern const char kRefs[];
72 extern const char kRefs_HelpShort[];
73 extern const char kRefs_Help[];
74 int RunRefs(const std::vector<std::string>& args);
76 // -----------------------------------------------------------------------------
78 struct CommandInfo {
79 CommandInfo();
80 CommandInfo(const char* in_help_short,
81 const char* in_help,
82 CommandRunner in_runner);
84 const char* help_short;
85 const char* help;
86 CommandRunner runner;
89 typedef std::map<base::StringPiece, CommandInfo> CommandInfoMap;
91 const CommandInfoMap& GetCommands();
93 // Helper functions for some commands ------------------------------------------
95 // Given a setup that has already been run and some command-line input,
96 // resolves that input as a target label and returns the corresponding target.
97 // On failure, returns null and prints the error to the standard output.
98 const Target* ResolveTargetFromCommandLineString(
99 Setup* setup,
100 const std::string& label_string);
102 // Resolves a vector of command line inputs and figures out the full set of
103 // things they resolve to.
105 // Patterns with wildcards will only match targets. The file_matches aren't
106 // validated that they are real files or referenced by any targets. They're just
107 // the set of things that didn't match anything else.
108 bool ResolveFromCommandLineInput(
109 Setup* setup,
110 const std::vector<std::string>& input,
111 bool all_toolchains,
112 UniqueVector<const Target*>* target_matches,
113 UniqueVector<const Config*>* config_matches,
114 UniqueVector<const Toolchain*>* toolchain_matches,
115 UniqueVector<SourceFile>* file_matches);
117 // Runs the header checker. All targets in the build should be given in
118 // all_targets, and the specific targets to check should be in to_check.
120 // force_check, if true, will override targets opting out of header checking
121 // with "check_includes = false" and will check them anyway.
123 // On success, returns true. If the check fails, the error(s) will be printed
124 // to stdout and false will be returned.
125 bool CheckPublicHeaders(const BuildSettings* build_settings,
126 const std::vector<const Target*>& all_targets,
127 const std::vector<const Target*>& to_check,
128 bool force_check);
130 // Filters the given list of targets by the given pattern list.
131 void FilterTargetsByPatterns(const std::vector<const Target*>& input,
132 const std::vector<LabelPattern>& filter,
133 std::vector<const Target*>* output);
134 void FilterTargetsByPatterns(const std::vector<const Target*>& input,
135 const std::vector<LabelPattern>& filter,
136 UniqueVector<const Target*>* output);
138 // These are the documentation strings for the command-line flags used by
139 // FilterAndPrintTargets. Commands that call that function should incorporate
140 // these into their help.
141 #define TARGET_PRINTING_MODE_COMMAND_LINE_HELP \
142 " --as=(buildfile|label|output)\n"\
143 " How to print targets.\n"\
144 "\n"\
145 " buildfile\n"\
146 " Prints the build files where the given target was declared as\n"\
147 " file names.\n"\
148 " label (default)\n"\
149 " Prints the label of the target.\n"\
150 " output\n"\
151 " Prints the first output file for the target relative to the\n"\
152 " current directory.\n"
153 #define TARGET_TYPE_FILTER_COMMAND_LINE_HELP \
154 " --type=(action|copy|executable|group|shared_library|source_set|\n"\
155 " static_library)\n"\
156 " Restrict outputs to targets matching the given type. If\n"\
157 " unspecified, no filtering will be performed.\n"
158 #define TARGET_TESTONLY_FILTER_COMMAND_LINE_HELP \
159 " --testonly=(true|false)\n"\
160 " Restrict outputs to targets with the testonly flag set\n"\
161 " accordingly. When unspecified, the target's testonly flags are\n"\
162 " ignored.\n"
164 // Applies any testonly and type filters specified on the command line,
165 // and prints the targets as specified by the --as command line flag.
167 // If indent is true, the results will be indented two spaces.
169 // The vector will be modified so that only the printed targets will remain.
170 void FilterAndPrintTargets(bool indent, std::vector<const Target*>* targets);
171 void FilterAndPrintTargetSet(bool indent,
172 const std::set<const Target*>& targets);
174 } // namespace commands
176 #endif // TOOLS_GN_COMMANDS_H_