This source file includes following definitions.
- runner
- runner
- GetCommands
- GetTargetForDesc
#include "tools/gn/commands.h"
#include "tools/gn/filesystem_utils.h"
#include "tools/gn/item.h"
#include "tools/gn/label.h"
#include "tools/gn/setup.h"
#include "tools/gn/standard_out.h"
#include "tools/gn/target.h"
namespace commands {
CommandInfo::CommandInfo()
: help_short(NULL),
help(NULL),
runner(NULL) {
}
CommandInfo::CommandInfo(const char* in_help_short,
const char* in_help,
CommandRunner in_runner)
: help_short(in_help_short),
help(in_help),
runner(in_runner) {
}
const CommandInfoMap& GetCommands() {
static CommandInfoMap info_map;
if (info_map.empty()) {
#define INSERT_COMMAND(cmd) \
info_map[k##cmd] = CommandInfo(k##cmd##_HelpShort, \
k##cmd##_Help, \
&Run##cmd);
INSERT_COMMAND(Args)
INSERT_COMMAND(Desc)
INSERT_COMMAND(Gen)
INSERT_COMMAND(Help)
INSERT_COMMAND(Refs)
#undef INSERT_COMMAND
}
return info_map;
}
const Target* GetTargetForDesc(const std::vector<std::string>& args) {
Setup* setup = new Setup;
if (!setup->DoSetup("//out/Default/"))
return NULL;
if (!setup->Run())
return NULL;
Label default_toolchain = setup->loader()->default_toolchain_label();
Value arg_value(NULL, args[0]);
Err err;
Label label = Label::Resolve(SourceDirForCurrentDirectory(
setup->build_settings().root_path()),
default_toolchain, arg_value, &err);
if (err.has_error()) {
err.PrintToStdout();
return NULL;
}
const Item* item = setup->builder()->GetItem(label);
if (!item) {
Err(Location(), "Label not found.",
label.GetUserVisibleName(false) + " not found.").PrintToStdout();
return NULL;
}
const Target* target = item->AsTarget();
if (!target) {
Err(Location(), "Not a target.",
"The \"" + label.GetUserVisibleName(false) + "\" thing\n"
"is not a target. Somebody should probably implement this command for "
"other\nitem types.");
return NULL;
}
return target;
}
}