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 const char kGetLabelInfo[] = "get_label_info"; | 14 const char kGetLabelInfo[] = "get_label_info"; |
15 const char kGetLabelInfo_HelpShort[] = | 15 const char kGetLabelInfo_HelpShort[] = |
16 "get_label_info: Get an attribute from a target's label."; | 16 "get_label_info: Get an attribute from a target's label."; |
17 const char kGetLabelInfo_Help[] = | 17 const char kGetLabelInfo_Help[] = |
18 "get_label_info: Get an attribute from a target's label.\n" | 18 R"*(get_label_info: Get an attribute from a target's label. |
19 "\n" | 19 |
20 " get_label_info(target_label, what)\n" | 20 get_label_info(target_label, what) |
21 "\n" | 21 |
22 " 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. The |
23 " The target need not have been previously defined in the same file,\n" | 23 target need not have been previously defined in the same file, since none of |
24 " since none of the attributes depend on the actual target definition,\n" | 24 the attributes depend on the actual target definition, only the label itself. |
25 " only the label itself.\n" | 25 |
26 "\n" | 26 See also "gn help get_target_outputs". |
27 " See also \"gn help get_target_outputs\".\n" | 27 |
28 "\n" | 28 Possible values for the "what" parameter |
29 "Possible values for the \"what\" parameter\n" | 29 |
30 "\n" | 30 "name" |
31 " \"name\"\n" | 31 The short name of the target. This will match the value of the |
32 " The short name of the target. This will match the value of the\n" | 32 "target_name" variable inside that target's declaration. For the label |
33 " \"target_name\" variable inside that target's declaration. For the\n" | 33 "//foo/bar:baz" this will return "baz". |
34 " label \"//foo/bar:baz\" this will return \"baz\".\n" | 34 |
35 "\n" | 35 "dir" |
36 " \"dir\"\n" | 36 The directory containing the target's definition, with no slash at the |
37 " The directory containing the target's definition, with no slash at\n" | 37 end. For the label "//foo/bar:baz" this will return "//foo/bar". |
38 " the end. For the label \"//foo/bar:baz\" this will return\n" | 38 |
39 " \"//foo/bar\".\n" | 39 "target_gen_dir" |
40 "\n" | 40 The generated file directory for the target. This will match the value of |
41 " \"target_gen_dir\"\n" | 41 the "target_gen_dir" variable when inside that target's declaration. |
42 " The generated file directory for the target. This will match the\n" | 42 |
43 " value of the \"target_gen_dir\" variable when inside that target's\n" | 43 "root_gen_dir" |
44 " declaration.\n" | 44 The root of the generated file tree for the target. This will match the |
45 "\n" | 45 value of the "root_gen_dir" variable when inside that target's |
46 " \"root_gen_dir\"\n" | 46 declaration. |
47 " The root of the generated file tree for the target. This will\n" | 47 |
48 " match the value of the \"root_gen_dir\" variable when inside that\n" | 48 "target_out_dir |
49 " target's declaration.\n" | 49 The output directory for the target. This will match the value of the |
50 "\n" | 50 "target_out_dir" variable when inside that target's declaration. |
51 " \"target_out_dir\n" | 51 |
52 " The output directory for the target. This will match the\n" | 52 "root_out_dir" |
53 " value of the \"target_out_dir\" variable when inside that target's\n" | 53 The root of the output file tree for the target. This will match the |
54 " declaration.\n" | 54 value of the "root_out_dir" variable when inside that target's |
55 "\n" | 55 declaration. |
56 " \"root_out_dir\"\n" | 56 |
57 " The root of the output file tree for the target. This will\n" | 57 "label_no_toolchain" |
58 " match the value of the \"root_out_dir\" variable when inside that\n" | 58 The fully qualified version of this label, not including the toolchain. |
59 " target's declaration.\n" | 59 For the input ":bar" it might return "//foo:bar". |
60 "\n" | 60 |
61 " \"label_no_toolchain\"\n" | 61 "label_with_toolchain" |
62 " The fully qualified version of this label, not including the\n" | 62 The fully qualified version of this label, including the toolchain. For |
63 " toolchain. For the input \":bar\" it might return\n" | 63 the input ":bar" it might return "//foo:bar(//toolchain:x64)". |
64 " \"//foo:bar\".\n" | 64 |
65 "\n" | 65 "toolchain" |
66 " \"label_with_toolchain\"\n" | 66 The label of the toolchain. This will match the value of the |
67 " The fully qualified version of this label, including the\n" | 67 "current_toolchain" variable when inside that target's declaration. |
68 " toolchain. For the input \":bar\" it might return\n" | 68 |
69 " \"//foo:bar(//toolchain:x64)\".\n" | 69 Examples |
70 "\n" | 70 |
71 " \"toolchain\"\n" | 71 get_label_info(":foo", "name") |
72 " The label of the toolchain. This will match the value of the\n" | 72 # Returns string "foo". |
73 " \"current_toolchain\" variable when inside that target's\n" | 73 |
74 " declaration.\n" | 74 get_label_info("//foo/bar:baz", "gen_dir") |
75 "\n" | 75 # Returns string "//out/Debug/gen/foo/bar".)*"; |
76 "Examples\n" | |
77 "\n" | |
78 " get_label_info(\":foo\", \"name\")\n" | |
79 " # Returns string \"foo\".\n" | |
80 "\n" | |
81 " get_label_info(\"//foo/bar:baz\", \"gen_dir\")\n" | |
82 " # Returns string \"//out/Debug/gen/foo/bar\".\n"; | |
83 | 76 |
84 Value RunGetLabelInfo(Scope* scope, | 77 Value RunGetLabelInfo(Scope* scope, |
85 const FunctionCallNode* function, | 78 const FunctionCallNode* function, |
86 const std::vector<Value>& args, | 79 const std::vector<Value>& args, |
87 Err* err) { | 80 Err* err) { |
88 if (args.size() != 2) { | 81 if (args.size() != 2) { |
89 *err = Err(function, "Expected two arguments."); | 82 *err = Err(function, "Expected two arguments."); |
90 return Value(); | 83 return Value(); |
91 } | 84 } |
92 | 85 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 | 134 |
142 } else { | 135 } else { |
143 *err = Err(args[1], "Unknown value for \"what\" parameter."); | 136 *err = Err(args[1], "Unknown value for \"what\" parameter."); |
144 return Value(); | 137 return Value(); |
145 } | 138 } |
146 | 139 |
147 return result; | 140 return result; |
148 } | 141 } |
149 | 142 |
150 } // namespace functions | 143 } // namespace functions |
OLD | NEW |