Home | History | Annotate | Download | only in gn
      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 BuildSettings;
     15 class Setup;
     16 class Target;
     17 
     18 // Each "Run" command returns the value we should return from main().
     19 
     20 namespace commands {
     21 
     22 typedef int (*CommandRunner)(const std::vector<std::string>&);
     23 
     24 extern const char kArgs[];
     25 extern const char kArgs_HelpShort[];
     26 extern const char kArgs_Help[];
     27 int RunArgs(const std::vector<std::string>& args);
     28 
     29 extern const char kCheck[];
     30 extern const char kCheck_HelpShort[];
     31 extern const char kCheck_Help[];
     32 int RunCheck(const std::vector<std::string>& args);
     33 
     34 extern const char kDesc[];
     35 extern const char kDesc_HelpShort[];
     36 extern const char kDesc_Help[];
     37 int RunDesc(const std::vector<std::string>& args);
     38 
     39 extern const char kGen[];
     40 extern const char kGen_HelpShort[];
     41 extern const char kGen_Help[];
     42 int RunGen(const std::vector<std::string>& args);
     43 
     44 extern const char kFormat[];
     45 extern const char kFormat_HelpShort[];
     46 extern const char kFormat_Help[];
     47 int RunFormat(const std::vector<std::string>& args);
     48 
     49 extern const char kHelp[];
     50 extern const char kHelp_HelpShort[];
     51 extern const char kHelp_Help[];
     52 int RunHelp(const std::vector<std::string>& args);
     53 
     54 extern const char kLs[];
     55 extern const char kLs_HelpShort[];
     56 extern const char kLs_Help[];
     57 int RunLs(const std::vector<std::string>& args);
     58 
     59 extern const char kRefs[];
     60 extern const char kRefs_HelpShort[];
     61 extern const char kRefs_Help[];
     62 int RunRefs(const std::vector<std::string>& args);
     63 
     64 // -----------------------------------------------------------------------------
     65 
     66 struct 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 
     77 typedef std::map<base::StringPiece, CommandInfo> CommandInfoMap;
     78 
     79 const 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.
     86 const 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.
     97 bool 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.
    112 bool 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