OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/err.h" | 5 #include "tools/gn/err.h" |
6 #include "tools/gn/filesystem_utils.h" | 6 #include "tools/gn/filesystem_utils.h" |
7 #include "tools/gn/functions.h" | 7 #include "tools/gn/functions.h" |
8 #include "tools/gn/label.h" | 8 #include "tools/gn/label.h" |
9 #include "tools/gn/parse_tree.h" | 9 #include "tools/gn/parse_tree.h" |
10 #include "tools/gn/value.h" | 10 #include "tools/gn/value.h" |
11 | 11 |
12 namespace functions { | 12 namespace functions { |
13 | 13 |
14 namespace { | |
15 | |
16 bool ToolchainIsDefault(const Scope* scope, const Label& toolchain_label) { | |
17 return scope->settings()->default_toolchain_label() == toolchain_label; | |
18 } | |
19 | |
20 } // namespace | |
21 | |
22 const char kGetLabelInfo[] = "get_label_info"; | 14 const char kGetLabelInfo[] = "get_label_info"; |
23 const char kGetLabelInfo_HelpShort[] = | 15 const char kGetLabelInfo_HelpShort[] = |
24 "get_label_info: Get an attribute from a target's label."; | 16 "get_label_info: Get an attribute from a target's label."; |
25 const char kGetLabelInfo_Help[] = | 17 const char kGetLabelInfo_Help[] = |
26 "get_label_info: Get an attribute from a target's label.\n" | 18 "get_label_info: Get an attribute from a target's label.\n" |
27 "\n" | 19 "\n" |
28 " get_label_info(target_label, what)\n" | 20 " get_label_info(target_label, what)\n" |
29 "\n" | 21 "\n" |
30 " Given the label of a target, returns some attribute of that target.\n" | 22 " Given the label of a target, returns some attribute of that target.\n" |
31 " The target need not have been previously defined in the same file,\n" | 23 " The target need not have been previously defined in the same file,\n" |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 const std::string& what = args[1].string_value(); | 102 const std::string& what = args[1].string_value(); |
111 | 103 |
112 Value result(function, Value::STRING); | 104 Value result(function, Value::STRING); |
113 if (what == "name") { | 105 if (what == "name") { |
114 result.string_value() = label.name(); | 106 result.string_value() = label.name(); |
115 | 107 |
116 } else if (what == "dir") { | 108 } else if (what == "dir") { |
117 result.string_value() = DirectoryWithNoLastSlash(label.dir()); | 109 result.string_value() = DirectoryWithNoLastSlash(label.dir()); |
118 | 110 |
119 } else if (what == "target_gen_dir") { | 111 } else if (what == "target_gen_dir") { |
120 result.string_value() = DirectoryWithNoLastSlash( | 112 result.string_value() = DirectoryWithNoLastSlash(GetSubBuildDirAsSourceDir( |
121 GetGenDirForSourceDir(scope->settings(), label.dir())); | 113 BuildDirContext(scope, label.GetToolchainLabel()), |
| 114 label.dir(), |
| 115 BuildDirType::GEN)); |
122 | 116 |
123 } else if (what == "root_gen_dir") { | 117 } else if (what == "root_gen_dir") { |
124 Label toolchain_label = label.GetToolchainLabel(); | 118 result.string_value() = DirectoryWithNoLastSlash(GetBuildDirAsSourceDir( |
125 result.string_value() = DirectoryWithNoLastSlash( | 119 BuildDirContext(scope, label.GetToolchainLabel()), BuildDirType::GEN)); |
126 GetToolchainGenDir(scope->settings()->build_settings(), | |
127 toolchain_label, | |
128 ToolchainIsDefault(scope, toolchain_label))); | |
129 | 120 |
130 } else if (what == "target_out_dir") { | 121 } else if (what == "target_out_dir") { |
131 Label toolchain_label = label.GetToolchainLabel(); | 122 result.string_value() = DirectoryWithNoLastSlash(GetSubBuildDirAsSourceDir( |
132 result.string_value() = DirectoryWithNoLastSlash( | 123 BuildDirContext(scope, label.GetToolchainLabel()), |
133 GetOutputDirForSourceDir(scope->settings()->build_settings(), | 124 label.dir(), |
134 label.dir(), toolchain_label, | 125 BuildDirType::OBJ)); |
135 ToolchainIsDefault(scope, toolchain_label))); | |
136 | 126 |
137 } else if (what == "root_out_dir") { | 127 } else if (what == "root_out_dir") { |
138 Label toolchain_label = label.GetToolchainLabel(); | 128 result.string_value() = DirectoryWithNoLastSlash(GetBuildDirAsSourceDir( |
139 result.string_value() = DirectoryWithNoLastSlash( | 129 BuildDirContext(scope, label.GetToolchainLabel()), |
140 GetToolchainOutputDir(scope->settings()->build_settings(), | 130 BuildDirType::TOOLCHAIN_ROOT)); |
141 toolchain_label, | |
142 ToolchainIsDefault(scope, toolchain_label))); | |
143 | 131 |
144 } else if (what == "toolchain") { | 132 } else if (what == "toolchain") { |
145 result.string_value() = label.GetToolchainLabel().GetUserVisibleName(false); | 133 result.string_value() = label.GetToolchainLabel().GetUserVisibleName(false); |
146 | 134 |
147 } else if (what == "label_no_toolchain") { | 135 } else if (what == "label_no_toolchain") { |
148 result.string_value() = | 136 result.string_value() = |
149 label.GetWithNoToolchain().GetUserVisibleName(false); | 137 label.GetWithNoToolchain().GetUserVisibleName(false); |
150 | 138 |
151 } else if (what == "label_with_toolchain") { | 139 } else if (what == "label_with_toolchain") { |
152 result.string_value() = label.GetUserVisibleName(true); | 140 result.string_value() = label.GetUserVisibleName(true); |
153 | 141 |
154 } else { | 142 } else { |
155 *err = Err(args[1], "Unknown value for \"what\" parameter."); | 143 *err = Err(args[1], "Unknown value for \"what\" parameter."); |
156 return Value(); | 144 return Value(); |
157 } | 145 } |
158 | 146 |
159 return result; | 147 return result; |
160 } | 148 } |
161 | 149 |
162 } // namespace functions | 150 } // namespace functions |
OLD | NEW |