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/filesystem_utils.h" | 6 #include "tools/gn/filesystem_utils.h" |
7 #include "tools/gn/item.h" | 7 #include "tools/gn/item.h" |
8 #include "tools/gn/label.h" | 8 #include "tools/gn/label.h" |
9 #include "tools/gn/label_pattern.h" | 9 #include "tools/gn/label_pattern.h" |
10 #include "tools/gn/setup.h" | 10 #include "tools/gn/setup.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 | 51 |
52 const Target* ResolveTargetFromCommandLineString( | 52 const Target* ResolveTargetFromCommandLineString( |
53 Setup* setup, | 53 Setup* setup, |
54 const std::string& label_string) { | 54 const std::string& label_string) { |
55 // Need to resolve the label after we know the default toolchain. | 55 // Need to resolve the label after we know the default toolchain. |
56 Label default_toolchain = setup->loader()->default_toolchain_label(); | 56 Label default_toolchain = setup->loader()->default_toolchain_label(); |
57 Value arg_value(NULL, label_string); | 57 Value arg_value(NULL, label_string); |
58 Err err; | 58 Err err; |
59 Label label = Label::Resolve(SourceDirForCurrentDirectory( | 59 Label label = Label::Resolve(SourceDirForCurrentDirectory( |
60 setup->build_settings().root_path()), | 60 setup->build_settings().root_path()), |
61 default_toolchain, arg_value, &err); | 61 default_toolchain, arg_value, |
| 62 setup->build_settings().root_path(), |
| 63 &err); |
62 if (err.has_error()) { | 64 if (err.has_error()) { |
63 err.PrintToStdout(); | 65 err.PrintToStdout(); |
64 return NULL; | 66 return NULL; |
65 } | 67 } |
66 | 68 |
67 const Item* item = setup->builder()->GetItem(label); | 69 const Item* item = setup->builder()->GetItem(label); |
68 if (!item) { | 70 if (!item) { |
69 Err(Location(), "Label not found.", | 71 Err(Location(), "Label not found.", |
70 label.GetUserVisibleName(false) + " not found.").PrintToStdout(); | 72 label.GetUserVisibleName(false) + " not found.").PrintToStdout(); |
71 return NULL; | 73 return NULL; |
(...skipping 13 matching lines...) Expand all Loading... |
85 | 87 |
86 bool ResolveTargetsFromCommandLinePattern( | 88 bool ResolveTargetsFromCommandLinePattern( |
87 Setup* setup, | 89 Setup* setup, |
88 const std::string& label_pattern, | 90 const std::string& label_pattern, |
89 bool all_toolchains, | 91 bool all_toolchains, |
90 std::vector<const Target*>* matches) { | 92 std::vector<const Target*>* matches) { |
91 Value pattern_value(NULL, label_pattern); | 93 Value pattern_value(NULL, label_pattern); |
92 | 94 |
93 Err err; | 95 Err err; |
94 LabelPattern pattern = LabelPattern::GetPattern( | 96 LabelPattern pattern = LabelPattern::GetPattern( |
| 97 setup->build_settings().root_path(), |
95 SourceDirForCurrentDirectory(setup->build_settings().root_path()), | 98 SourceDirForCurrentDirectory(setup->build_settings().root_path()), |
96 pattern_value, | 99 pattern_value, |
97 &err); | 100 &err); |
98 if (err.has_error()) { | 101 if (err.has_error()) { |
99 err.PrintToStdout(); | 102 err.PrintToStdout(); |
100 return false; | 103 return false; |
101 } | 104 } |
102 | 105 |
103 if (!all_toolchains) { | 106 if (!all_toolchains) { |
104 // By default a pattern with an empty toolchain will match all toolchains. | 107 // By default a pattern with an empty toolchain will match all toolchains. |
105 // IF the caller wants to default to the main toolchain only, set it | 108 // IF the caller wants to default to the main toolchain only, set it |
106 // explicitly. | 109 // explicitly. |
107 if (pattern.toolchain().is_null()) { | 110 if (pattern.toolchain().is_null()) { |
108 // No explicit toolchain set. | 111 // No explicit toolchain set. |
109 pattern.set_toolchain(setup->loader()->default_toolchain_label()); | 112 pattern.set_toolchain(setup->loader()->default_toolchain_label()); |
110 } | 113 } |
111 } | 114 } |
112 | 115 |
113 std::vector<const Target*> all_targets = | 116 std::vector<const Target*> all_targets = |
114 setup->builder()->GetAllResolvedTargets(); | 117 setup->builder()->GetAllResolvedTargets(); |
115 | 118 |
116 for (const auto& target : all_targets) { | 119 for (const auto& target : all_targets) { |
117 if (pattern.Matches(target->label())) | 120 if (pattern.Matches(target->label())) |
118 matches->push_back(target); | 121 matches->push_back(target); |
119 } | 122 } |
120 return true; | 123 return true; |
121 } | 124 } |
122 | 125 |
123 } // namespace commands | 126 } // namespace commands |
OLD | NEW |