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.
5 #include "tools/gn/commands.h"
6 #include "tools/gn/item.h"
7 #include "tools/gn/item_node.h"
8 #include "tools/gn/label.h"
9 #include "tools/gn/setup.h"
10 #include "tools/gn/standard_out.h"
11 #include "tools/gn/target.h"
15 CommandInfo::CommandInfo()
21 CommandInfo::CommandInfo(const char* in_help_short
,
23 CommandRunner in_runner
)
24 : help_short(in_help_short
),
29 const CommandInfoMap
& GetCommands() {
30 static CommandInfoMap info_map
;
31 if (info_map
.empty()) {
32 #define INSERT_COMMAND(cmd) \
33 info_map[k##cmd] = CommandInfo(k##cmd##_HelpShort, \
49 const Target
* GetTargetForDesc(const std::vector
<std::string
>& args
) {
50 // Deliberately leaked to avoid expensive process teardown.
51 Setup
* setup
= new Setup
;
52 if (!setup
->DoSetup())
55 // FIXME(brettw): set the output dir to be a sandbox one to avoid polluting
56 // the real output dir with files written by the build scripts.
58 // Do the actual load. This will also write out the target ninja files.
62 // Need to resolve the label after we know the default toolchain.
63 // TODO(brettw) find the current directory and resolve the input label
65 Label default_toolchain
= setup
->build_settings().toolchain_manager()
66 .GetDefaultToolchainUnlocked();
67 Value
arg_value(NULL
, args
[0]);
70 Label::Resolve(SourceDir("//"), default_toolchain
, arg_value
, &err
);
71 if (err
.has_error()) {
78 base::AutoLock
lock(setup
->build_settings().item_tree().lock());
79 node
= setup
->build_settings().item_tree().GetExistingNodeLocked(label
);
83 "I don't know about this \"" + label
.GetUserVisibleName(false) +
84 "\"").PrintToStdout();
88 const Target
* target
= node
->item()->AsTarget();
90 Err(Location(), "Not a target.",
91 "The \"" + label
.GetUserVisibleName(false) + "\" thing\n"
92 "is not a target. Somebody should probably implement this command for "
93 "other\nitem types.");
100 } // namespace commands