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. 4 5#ifndef TOOLS_GN_COMMANDS_H_ 6#define TOOLS_GN_COMMANDS_H_ 7 8#include <map> 9#include <string> 10#include <vector> 11 12#include "base/strings/string_piece.h" 13 14class BuildSettings; 15class Setup; 16class Target; 17 18// Each "Run" command returns the value we should return from main(). 19 20namespace commands { 21 22typedef int (*CommandRunner)(const std::vector<std::string>&); 23 24extern const char kArgs[]; 25extern const char kArgs_HelpShort[]; 26extern const char kArgs_Help[]; 27int RunArgs(const std::vector<std::string>& args); 28 29extern const char kCheck[]; 30extern const char kCheck_HelpShort[]; 31extern const char kCheck_Help[]; 32int RunCheck(const std::vector<std::string>& args); 33 34extern const char kDesc[]; 35extern const char kDesc_HelpShort[]; 36extern const char kDesc_Help[]; 37int RunDesc(const std::vector<std::string>& args); 38 39extern const char kGen[]; 40extern const char kGen_HelpShort[]; 41extern const char kGen_Help[]; 42int RunGen(const std::vector<std::string>& args); 43 44extern const char kFormat[]; 45extern const char kFormat_HelpShort[]; 46extern const char kFormat_Help[]; 47int RunFormat(const std::vector<std::string>& args); 48 49extern const char kHelp[]; 50extern const char kHelp_HelpShort[]; 51extern const char kHelp_Help[]; 52int RunHelp(const std::vector<std::string>& args); 53 54extern const char kLs[]; 55extern const char kLs_HelpShort[]; 56extern const char kLs_Help[]; 57int RunLs(const std::vector<std::string>& args); 58 59extern const char kRefs[]; 60extern const char kRefs_HelpShort[]; 61extern const char kRefs_Help[]; 62int RunRefs(const std::vector<std::string>& args); 63 64// ----------------------------------------------------------------------------- 65 66struct CommandInfo { 67 CommandInfo(); 68 CommandInfo(const char* in_help_short, 69 const char* in_help, 70 CommandRunner in_runner); 71 72 const char* help_short; 73 const char* help; 74 CommandRunner runner; 75}; 76 77typedef std::map<base::StringPiece, CommandInfo> CommandInfoMap; 78 79const CommandInfoMap& GetCommands(); 80 81// Helper functions for some commands ------------------------------------------ 82 83// Given a setup that has already been run and some command-line input, 84// resolves that input as a target label and returns the corresponding target. 85// On failure, returns null and prints the error to the standard output. 86const Target* ResolveTargetFromCommandLineString( 87 Setup* setup, 88 const std::string& label_string); 89 90// Like above but the input string can be a pattern that matches multiple 91// targets. If the input does not parse as a pattern, prints and error and 92// returns false. If the pattern is valid, fills the vector (which might be 93// empty if there are no matches) and returns true. 94// 95// If all_tolchains is false, a pattern with an unspecified toolchain will 96// match the default toolchain only. If true, all toolchains will be matched. 97bool ResolveTargetsFromCommandLinePattern( 98 Setup* setup, 99 const std::string& label_pattern, 100 bool all_toolchains, 101 std::vector<const Target*>* matches); 102 103// Runs the header checker. All targets in the build should be given in 104// all_targets, and the specific targets to check should be in to_check. If 105// to_check is empty, all targets will be checked. 106// 107// force_check, if true, will override targets opting out of header checking 108// with "check_includes = false" and will check them anyway. 109// 110// On success, returns true. If the check fails, the error(s) will be printed 111// to stdout and false will be returned. 112bool CheckPublicHeaders(const BuildSettings* build_settings, 113 const std::vector<const Target*>& all_targets, 114 const std::vector<const Target*>& to_check, 115 bool force_check); 116 117} // namespace commands 118 119#endif // TOOLS_GN_COMMANDS_H_ 120