Update V8 to version 4.6.61.
[chromium-blink-merge.git] / tools / gn / commands.h
blob3d26dba26ce5189519455ebfc19ec5626491920e
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 kPath[];
72 extern const char kPath_HelpShort[];
73 extern const char kPath_Help[];
74 int RunPath(const std::vector<std::string>& args);
76 extern const char kRefs[];
77 extern const char kRefs_HelpShort[];
78 extern const char kRefs_Help[];
79 int RunRefs(const std::vector<std::string>& args);
81 // -----------------------------------------------------------------------------
83 struct CommandInfo {
84 CommandInfo();
85 CommandInfo(const char* in_help_short,
86 const char* in_help,
87 CommandRunner in_runner);
89 const char* help_short;
90 const char* help;
91 CommandRunner runner;
94 typedef std::map<base::StringPiece, CommandInfo> CommandInfoMap;
96 const CommandInfoMap& GetCommands();
98 // Helper functions for some commands ------------------------------------------
100 // Given a setup that has already been run and some command-line input,
101 // resolves that input as a target label and returns the corresponding target.
102 // On failure, returns null and prints the error to the standard output.
103 const Target* ResolveTargetFromCommandLineString(
104 Setup* setup,
105 const std::string& label_string);
107 // Resolves a vector of command line inputs and figures out the full set of
108 // things they resolve to.
110 // Patterns with wildcards will only match targets. The file_matches aren't
111 // validated that they are real files or referenced by any targets. They're just
112 // the set of things that didn't match anything else.
113 bool ResolveFromCommandLineInput(
114 Setup* setup,
115 const std::vector<std::string>& input,
116 bool all_toolchains,
117 UniqueVector<const Target*>* target_matches,
118 UniqueVector<const Config*>* config_matches,
119 UniqueVector<const Toolchain*>* toolchain_matches,
120 UniqueVector<SourceFile>* file_matches);
122 // Runs the header checker. All targets in the build should be given in
123 // all_targets, and the specific targets to check should be in to_check.
125 // force_check, if true, will override targets opting out of header checking
126 // with "check_includes = false" and will check them anyway.
128 // On success, returns true. If the check fails, the error(s) will be printed
129 // to stdout and false will be returned.
130 bool CheckPublicHeaders(const BuildSettings* build_settings,
131 const std::vector<const Target*>& all_targets,
132 const std::vector<const Target*>& to_check,
133 bool force_check);
135 // Filters the given list of targets by the given pattern list.
136 void FilterTargetsByPatterns(const std::vector<const Target*>& input,
137 const std::vector<LabelPattern>& filter,
138 std::vector<const Target*>* output);
139 void FilterTargetsByPatterns(const std::vector<const Target*>& input,
140 const std::vector<LabelPattern>& filter,
141 UniqueVector<const Target*>* output);
143 // These are the documentation strings for the command-line flags used by
144 // FilterAndPrintTargets. Commands that call that function should incorporate
145 // these into their help.
146 #define TARGET_PRINTING_MODE_COMMAND_LINE_HELP \
147 " --as=(buildfile|label|output)\n"\
148 " How to print targets.\n"\
149 "\n"\
150 " buildfile\n"\
151 " Prints the build files where the given target was declared as\n"\
152 " file names.\n"\
153 " label (default)\n"\
154 " Prints the label of the target.\n"\
155 " output\n"\
156 " Prints the first output file for the target relative to the\n"\
157 " current directory.\n"
158 #define TARGET_TYPE_FILTER_COMMAND_LINE_HELP \
159 " --type=(action|copy|executable|group|shared_library|source_set|\n"\
160 " static_library)\n"\
161 " Restrict outputs to targets matching the given type. If\n"\
162 " unspecified, no filtering will be performed.\n"
163 #define TARGET_TESTONLY_FILTER_COMMAND_LINE_HELP \
164 " --testonly=(true|false)\n"\
165 " Restrict outputs to targets with the testonly flag set\n"\
166 " accordingly. When unspecified, the target's testonly flags are\n"\
167 " ignored.\n"
169 // Applies any testonly and type filters specified on the command line,
170 // and prints the targets as specified by the --as command line flag.
172 // If indent is true, the results will be indented two spaces.
174 // The vector will be modified so that only the printed targets will remain.
175 void FilterAndPrintTargets(bool indent, std::vector<const Target*>* targets);
176 void FilterAndPrintTargetSet(bool indent,
177 const std::set<const Target*>& targets);
179 } // namespace commands
181 #endif // TOOLS_GN_COMMANDS_H_