OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "tools/gn/commands.h" | 5 #include "tools/gn/commands.h" |
6 #include "tools/gn/item.h" | 6 #include "tools/gn/item.h" |
7 #include "tools/gn/item_node.h" | |
8 #include "tools/gn/label.h" | 7 #include "tools/gn/label.h" |
9 #include "tools/gn/setup.h" | 8 #include "tools/gn/setup.h" |
10 #include "tools/gn/standard_out.h" | 9 #include "tools/gn/standard_out.h" |
11 #include "tools/gn/target.h" | 10 #include "tools/gn/target.h" |
12 | 11 |
13 namespace commands { | 12 namespace commands { |
14 | 13 |
15 CommandInfo::CommandInfo() | 14 CommandInfo::CommandInfo() |
16 : help_short(NULL), | 15 : help_short(NULL), |
17 help(NULL), | 16 help(NULL), |
(...skipping 27 matching lines...) Expand all Loading... |
45 } | 44 } |
46 return info_map; | 45 return info_map; |
47 } | 46 } |
48 | 47 |
49 const Target* GetTargetForDesc(const std::vector<std::string>& args) { | 48 const Target* GetTargetForDesc(const std::vector<std::string>& args) { |
50 // Deliberately leaked to avoid expensive process teardown. | 49 // Deliberately leaked to avoid expensive process teardown. |
51 Setup* setup = new Setup; | 50 Setup* setup = new Setup; |
52 if (!setup->DoSetup()) | 51 if (!setup->DoSetup()) |
53 return NULL; | 52 return NULL; |
54 | 53 |
55 // FIXME(brettw): set the output dir to be a sandbox one to avoid polluting | 54 // TODO(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. | 55 // the real output dir with files written by the build scripts. |
57 | 56 |
58 // Do the actual load. This will also write out the target ninja files. | 57 // Do the actual load. This will also write out the target ninja files. |
59 if (!setup->Run()) | 58 if (!setup->Run()) |
60 return NULL; | 59 return NULL; |
61 | 60 |
62 // Need to resolve the label after we know the default toolchain. | 61 // Need to resolve the label after we know the default toolchain. |
63 // TODO(brettw) find the current directory and resolve the input label | 62 // TODO(brettw) find the current directory and resolve the input label |
64 // relative to that. | 63 // relative to that. |
65 Label default_toolchain = setup->build_settings().toolchain_manager() | 64 Label default_toolchain = setup->loader()->default_toolchain_label(); |
66 .GetDefaultToolchainUnlocked(); | |
67 Value arg_value(NULL, args[0]); | 65 Value arg_value(NULL, args[0]); |
68 Err err; | 66 Err err; |
69 Label label = | 67 Label label = |
70 Label::Resolve(SourceDir("//"), default_toolchain, arg_value, &err); | 68 Label::Resolve(SourceDir("//"), default_toolchain, arg_value, &err); |
71 if (err.has_error()) { | 69 if (err.has_error()) { |
72 err.PrintToStdout(); | 70 err.PrintToStdout(); |
73 return NULL; | 71 return NULL; |
74 } | 72 } |
75 | 73 |
76 ItemNode* node; | 74 const Item* item = setup->builder()->GetItem(label); |
77 { | 75 if (!item) { |
78 base::AutoLock lock(setup->build_settings().item_tree().lock()); | 76 Err(Location(), "Label not found.", |
79 node = setup->build_settings().item_tree().GetExistingNodeLocked(label); | 77 label.GetUserVisibleName(false) + " not found.").PrintToStdout(); |
80 } | |
81 if (!node) { | |
82 Err(Location(), "", | |
83 "I don't know about this \"" + label.GetUserVisibleName(false) + | |
84 "\"").PrintToStdout(); | |
85 return NULL; | 78 return NULL; |
86 } | 79 } |
87 | 80 |
88 const Target* target = node->item()->AsTarget(); | 81 const Target* target = item->AsTarget(); |
89 if (!target) { | 82 if (!target) { |
90 Err(Location(), "Not a target.", | 83 Err(Location(), "Not a target.", |
91 "The \"" + label.GetUserVisibleName(false) + "\" thing\n" | 84 "The \"" + label.GetUserVisibleName(false) + "\" thing\n" |
92 "is not a target. Somebody should probably implement this command for " | 85 "is not a target. Somebody should probably implement this command for " |
93 "other\nitem types."); | 86 "other\nitem types."); |
94 return NULL; | 87 return NULL; |
95 } | 88 } |
96 | 89 |
97 return target; | 90 return target; |
98 } | 91 } |
99 | 92 |
100 } // namespace commands | 93 } // namespace commands |
OLD | NEW |