| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef TOOLS_GN_COMMANDS_H_ | 5 #ifndef TOOLS_GN_COMMANDS_H_ |
| 6 #define TOOLS_GN_COMMANDS_H_ | 6 #define TOOLS_GN_COMMANDS_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> |
| 9 #include <string> | 10 #include <string> |
| 10 #include <vector> | 11 #include <vector> |
| 11 | 12 |
| 12 #include "base/strings/string_piece.h" | 13 #include "base/strings/string_piece.h" |
| 14 #include "tools/gn/target.h" |
| 15 #include "tools/gn/unique_vector.h" |
| 13 | 16 |
| 14 class BuildSettings; | 17 class BuildSettings; |
| 18 class Config; |
| 15 class LabelPattern; | 19 class LabelPattern; |
| 16 class Setup; | 20 class Setup; |
| 21 class SourceFile; |
| 17 class Target; | 22 class Target; |
| 23 class Toolchain; |
| 18 | 24 |
| 19 // Each "Run" command returns the value we should return from main(). | 25 // Each "Run" command returns the value we should return from main(). |
| 20 | 26 |
| 21 namespace commands { | 27 namespace commands { |
| 22 | 28 |
| 23 typedef int (*CommandRunner)(const std::vector<std::string>&); | 29 typedef int (*CommandRunner)(const std::vector<std::string>&); |
| 24 | 30 |
| 25 extern const char kArgs[]; | 31 extern const char kArgs[]; |
| 26 extern const char kArgs_HelpShort[]; | 32 extern const char kArgs_HelpShort[]; |
| 27 extern const char kArgs_Help[]; | 33 extern const char kArgs_Help[]; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 | 92 |
| 87 // Helper functions for some commands ------------------------------------------ | 93 // Helper functions for some commands ------------------------------------------ |
| 88 | 94 |
| 89 // Given a setup that has already been run and some command-line input, | 95 // Given a setup that has already been run and some command-line input, |
| 90 // resolves that input as a target label and returns the corresponding target. | 96 // resolves that input as a target label and returns the corresponding target. |
| 91 // On failure, returns null and prints the error to the standard output. | 97 // On failure, returns null and prints the error to the standard output. |
| 92 const Target* ResolveTargetFromCommandLineString( | 98 const Target* ResolveTargetFromCommandLineString( |
| 93 Setup* setup, | 99 Setup* setup, |
| 94 const std::string& label_string); | 100 const std::string& label_string); |
| 95 | 101 |
| 96 // Like above but the input string can be a pattern that matches multiple | 102 // Resolves a vector of command line inputs and figures out the full set of |
| 97 // targets. If the input does not parse as a pattern, prints and error and | 103 // things they resolve to. |
| 98 // returns false. If the pattern is valid, fills the vector (which might be | |
| 99 // empty if there are no matches) and returns true. | |
| 100 // | 104 // |
| 101 // If all_tolchains is false, a pattern with an unspecified toolchain will | 105 // Patterns with wildcards will only match targets. The file_matches aren't |
| 102 // match the default toolchain only. If true, all toolchains will be matched. | 106 // validated that they are real files or referenced by any targets. They're just |
| 103 bool ResolveTargetsFromCommandLinePattern( | 107 // the set of things that didn't match anything else. |
| 108 bool ResolveFromCommandLineInput( |
| 104 Setup* setup, | 109 Setup* setup, |
| 105 const std::string& label_pattern, | 110 const std::vector<std::string>& input, |
| 106 bool all_toolchains, | 111 bool all_toolchains, |
| 107 std::vector<const Target*>* matches); | 112 UniqueVector<const Target*>* target_matches, |
| 113 UniqueVector<const Config*>* config_matches, |
| 114 UniqueVector<const Toolchain*>* toolchain_matches, |
| 115 UniqueVector<SourceFile>* file_matches); |
| 108 | 116 |
| 109 // Runs the header checker. All targets in the build should be given in | 117 // Runs the header checker. All targets in the build should be given in |
| 110 // all_targets, and the specific targets to check should be in to_check. | 118 // all_targets, and the specific targets to check should be in to_check. |
| 111 // | 119 // |
| 112 // force_check, if true, will override targets opting out of header checking | 120 // force_check, if true, will override targets opting out of header checking |
| 113 // with "check_includes = false" and will check them anyway. | 121 // with "check_includes = false" and will check them anyway. |
| 114 // | 122 // |
| 115 // On success, returns true. If the check fails, the error(s) will be printed | 123 // On success, returns true. If the check fails, the error(s) will be printed |
| 116 // to stdout and false will be returned. | 124 // to stdout and false will be returned. |
| 117 bool CheckPublicHeaders(const BuildSettings* build_settings, | 125 bool CheckPublicHeaders(const BuildSettings* build_settings, |
| 118 const std::vector<const Target*>& all_targets, | 126 const std::vector<const Target*>& all_targets, |
| 119 const std::vector<const Target*>& to_check, | 127 const std::vector<const Target*>& to_check, |
| 120 bool force_check); | 128 bool force_check); |
| 121 | 129 |
| 122 // Filters the given list of targets by the given pattern list. This is a | 130 // Filters the given list of targets by the given pattern list. |
| 123 // helper function for setting up a call to CheckPublicHeaders based on a check | |
| 124 // filter. | |
| 125 void FilterTargetsByPatterns(const std::vector<const Target*>& input, | 131 void FilterTargetsByPatterns(const std::vector<const Target*>& input, |
| 126 const std::vector<LabelPattern>& filter, | 132 const std::vector<LabelPattern>& filter, |
| 127 std::vector<const Target*>* output); | 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); |
| 137 |
| 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" |
| 163 |
| 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. |
| 166 // |
| 167 // If indent is true, the results will be indented two spaces. |
| 168 // |
| 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); |
| 128 | 173 |
| 129 } // namespace commands | 174 } // namespace commands |
| 130 | 175 |
| 131 #endif // TOOLS_GN_COMMANDS_H_ | 176 #endif // TOOLS_GN_COMMANDS_H |
| OLD | NEW |