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 14 class Target; 15 16 // Each "Run" command returns the value we should return from main(). 17 18 namespace commands { 19 20 typedef int (*CommandRunner)(const std::vector<std::string>&); 21 22 extern const char kArgs[]; 23 extern const char kArgs_HelpShort[]; 24 extern const char kArgs_Help[]; 25 int RunArgs(const std::vector<std::string>& args); 26 27 extern const char kDesc[]; 28 extern const char kDesc_HelpShort[]; 29 extern const char kDesc_Help[]; 30 int RunDesc(const std::vector<std::string>& args); 31 32 extern const char kGen[]; 33 extern const char kGen_HelpShort[]; 34 extern const char kGen_Help[]; 35 int RunGen(const std::vector<std::string>& args); 36 37 extern const char kGyp[]; 38 extern const char kGyp_HelpShort[]; 39 extern const char kGyp_Help[]; 40 int RunGyp(const std::vector<std::string>& args); 41 42 extern const char kHelp[]; 43 extern const char kHelp_HelpShort[]; 44 extern const char kHelp_Help[]; 45 int RunHelp(const std::vector<std::string>& args); 46 47 extern const char kRefs[]; 48 extern const char kRefs_HelpShort[]; 49 extern const char kRefs_Help[]; 50 int RunRefs(const std::vector<std::string>& args); 51 52 // ----------------------------------------------------------------------------- 53 54 struct CommandInfo { 55 CommandInfo(); 56 CommandInfo(const char* in_help_short, 57 const char* in_help, 58 CommandRunner in_runner); 59 60 const char* help_short; 61 const char* help; 62 CommandRunner runner; 63 }; 64 65 typedef std::map<base::StringPiece, CommandInfo> CommandInfoMap; 66 67 const CommandInfoMap& GetCommands(); 68 69 // Helper functions for some commands ------------------------------------------ 70 71 // Runs a build for the given command line, returning the target identified by 72 // the first non-switch command line parameter. 73 // 74 // Note that a lot of memory is leaked to avoid proper teardown under the 75 // assumption that you will only run this once and exit. 76 // 77 // On failure, prints an error message and returns NULL. 78 const Target* GetTargetForDesc(const std::vector<std::string>& args); 79 80 } // namespace commands 81 82 #endif // TOOLS_GN_COMMANDS_H_ 83