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/variables.h" | 5 #include "tools/gn/variables.h" |
6 | 6 |
7 namespace variables { | 7 namespace variables { |
8 | 8 |
9 // Built-in variables ---------------------------------------------------------- | 9 // Built-in variables ---------------------------------------------------------- |
10 | 10 |
(...skipping 26 matching lines...) Expand all Loading... |
37 " build system's settings.\n" | 37 " build system's settings.\n" |
38 "\n" | 38 "\n" |
39 " This value should generally be treated as read-only. It, however,\n" | 39 " This value should generally be treated as read-only. It, however,\n" |
40 " is not used internally by GN for any purpose.\n" | 40 " is not used internally by GN for any purpose.\n" |
41 "\n" | 41 "\n" |
42 "Some possible values:\n" | 42 "Some possible values:\n" |
43 " - \"linux\"\n" | 43 " - \"linux\"\n" |
44 " - \"mac\"\n" | 44 " - \"mac\"\n" |
45 " - \"win\"\n"; | 45 " - \"win\"\n"; |
46 | 46 |
| 47 const char kInvoker[] = "invoker"; |
| 48 const char kInvoker_HelpShort[] = |
| 49 "invoker: [string] The invoking scope inside a template."; |
| 50 const char kInvoker_Help[] = |
| 51 "invoker: [string] The invoking scope inside a template.\n" |
| 52 "\n" |
| 53 " Inside a template invocation, this variable refers to the scope of\n" |
| 54 " the invoker of the template. Outside of template invocations, this\n" |
| 55 " variable is undefined.\n" |
| 56 "\n" |
| 57 " All of the variables defined inside the template invocation are\n" |
| 58 " accessible as members of the \"invoker\" scope. This is the way that\n" |
| 59 " templates read values set by the callers.\n" |
| 60 "\n" |
| 61 " This is often used with \"defined\" to see if a value is set on the\n" |
| 62 " invoking scope.\n" |
| 63 "\n" |
| 64 " See \"gn help template\" for more examples.\n" |
| 65 "\n" |
| 66 "Example\n" |
| 67 "\n" |
| 68 " template(\"my_template\") {\n" |
| 69 " print(invoker.sources) # Prints [ \"a.cc\", \"b.cc\" ]\n" |
| 70 " print(defined(invoker.foo)) # Prints false.\n" |
| 71 " print(defined(invoker.bar)) # Prints true.\n" |
| 72 " }\n" |
| 73 "\n" |
| 74 " my_template(\"doom_melon\") {\n" |
| 75 " sources = [ \"a.cc\", \"b.cc\" ]\n" |
| 76 " bar = 123\n" |
| 77 " }\n"; |
| 78 |
47 const char kTargetCpu[] = "target_cpu"; | 79 const char kTargetCpu[] = "target_cpu"; |
48 const char kTargetCpu_HelpShort[] = | 80 const char kTargetCpu_HelpShort[] = |
49 "target_cpu: [string] The desired cpu architecture for the build."; | 81 "target_cpu: [string] The desired cpu architecture for the build."; |
50 const char kTargetCpu_Help[] = | 82 const char kTargetCpu_Help[] = |
51 "target_cpu: The desired cpu architecture for the build.\n" | 83 "target_cpu: The desired cpu architecture for the build.\n" |
52 "\n" | 84 "\n" |
53 " This value should be used to indicate the desired architecture for\n" | 85 " This value should be used to indicate the desired architecture for\n" |
54 " the primary objects of the build. It will match the cpu architecture\n" | 86 " the primary objects of the build. It will match the cpu architecture\n" |
55 " of the default toolchain, but not necessarily the current toolchain.\n" | 87 " of the default toolchain, but not necessarily the current toolchain.\n" |
56 "\n" | 88 "\n" |
(...skipping 12 matching lines...) Expand all Loading... |
69 "\n" | 101 "\n" |
70 " Where practical, use one of the following list of common values:\n" | 102 " Where practical, use one of the following list of common values:\n" |
71 "\n" | 103 "\n" |
72 "Possible values:\n" | 104 "Possible values:\n" |
73 " - \"x86\"\n" | 105 " - \"x86\"\n" |
74 " - \"x64\"\n" | 106 " - \"x64\"\n" |
75 " - \"arm\"\n" | 107 " - \"arm\"\n" |
76 " - \"arm64\"\n" | 108 " - \"arm64\"\n" |
77 " - \"mipsel\"\n"; | 109 " - \"mipsel\"\n"; |
78 | 110 |
| 111 const char kTargetName[] = "target_name"; |
| 112 const char kTargetName_HelpShort[] = |
| 113 "target_name: [string] The name of the current target."; |
| 114 const char kTargetName_Help[] = |
| 115 "target_name: [string] The name of the current target.\n" |
| 116 "\n" |
| 117 " Inside a target or template invocation, this variable refers to the\n" |
| 118 " name given to the target or template invocation. Outside of these,\n" |
| 119 " this variable is undefined.\n" |
| 120 "\n" |
| 121 " This is most often used in template definitions to name targets\n" |
| 122 " defined in the template based on the name of the invocation. This\n" |
| 123 " is necessary both to ensure generated targets have unique names and\n" |
| 124 " to generate a target with the exact name of the invocation that\n" |
| 125 " other targets can depend on.\n" |
| 126 "\n" |
| 127 " Be aware that this value will always reflect the innermost scope. So\n" |
| 128 " when defining a target inside a template, target_name will refer to\n" |
| 129 " the target rather than the template invocation. To get the name of the\n" |
| 130 " template invocation in this case, you should save target_name to a\n" |
| 131 " temporary variable outside of any target definitions.\n" |
| 132 "\n" |
| 133 " See \"gn help template\" for more examples.\n" |
| 134 "\n" |
| 135 "Example\n" |
| 136 "\n" |
| 137 " executable(\"doom_melon\") {\n" |
| 138 " print(target_name) # Prints \"doom_melon\".\n" |
| 139 " }\n" |
| 140 "\n" |
| 141 " template(\"my_template\") {\n" |
| 142 " print(target_name) # Prints \"space_ray\" when invoked below.\n" |
| 143 "\n" |
| 144 " executable(target_name + \"_impl\") {\n" |
| 145 " print(target_name) # Prints \"space_ray_impl\".\n" |
| 146 " }\n" |
| 147 " }\n" |
| 148 "\n" |
| 149 " my_template(\"space_ray\") {\n" |
| 150 " }\n"; |
| 151 |
79 const char kTargetOs[] = "target_os"; | 152 const char kTargetOs[] = "target_os"; |
80 const char kTargetOs_HelpShort[] = | 153 const char kTargetOs_HelpShort[] = |
81 "target_os: [string] The desired operating system for the build."; | 154 "target_os: [string] The desired operating system for the build."; |
82 const char kTargetOs_Help[] = | 155 const char kTargetOs_Help[] = |
83 "target_os: The desired operating system for the build.\n" | 156 "target_os: The desired operating system for the build.\n" |
84 "\n" | 157 "\n" |
85 " This value should be used to indicate the desired operating system\n" | 158 " This value should be used to indicate the desired operating system\n" |
86 " for the primary object(s) of the build. It will match the OS of\n" | 159 " for the primary object(s) of the build. It will match the OS of\n" |
87 " the default toolchain.\n" | 160 " the default toolchain.\n" |
88 "\n" | 161 "\n" |
(...skipping 1617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1706 | 1779 |
1707 const VariableInfoMap& GetBuiltinVariables() { | 1780 const VariableInfoMap& GetBuiltinVariables() { |
1708 static VariableInfoMap info_map; | 1781 static VariableInfoMap info_map; |
1709 if (info_map.empty()) { | 1782 if (info_map.empty()) { |
1710 INSERT_VARIABLE(CurrentCpu) | 1783 INSERT_VARIABLE(CurrentCpu) |
1711 INSERT_VARIABLE(CurrentOs) | 1784 INSERT_VARIABLE(CurrentOs) |
1712 INSERT_VARIABLE(CurrentToolchain) | 1785 INSERT_VARIABLE(CurrentToolchain) |
1713 INSERT_VARIABLE(DefaultToolchain) | 1786 INSERT_VARIABLE(DefaultToolchain) |
1714 INSERT_VARIABLE(HostCpu) | 1787 INSERT_VARIABLE(HostCpu) |
1715 INSERT_VARIABLE(HostOs) | 1788 INSERT_VARIABLE(HostOs) |
| 1789 INSERT_VARIABLE(Invoker) |
1716 INSERT_VARIABLE(PythonPath) | 1790 INSERT_VARIABLE(PythonPath) |
1717 INSERT_VARIABLE(RootBuildDir) | 1791 INSERT_VARIABLE(RootBuildDir) |
1718 INSERT_VARIABLE(RootGenDir) | 1792 INSERT_VARIABLE(RootGenDir) |
1719 INSERT_VARIABLE(RootOutDir) | 1793 INSERT_VARIABLE(RootOutDir) |
1720 INSERT_VARIABLE(TargetCpu) | 1794 INSERT_VARIABLE(TargetCpu) |
1721 INSERT_VARIABLE(TargetOs) | 1795 INSERT_VARIABLE(TargetOs) |
1722 INSERT_VARIABLE(TargetGenDir) | 1796 INSERT_VARIABLE(TargetGenDir) |
| 1797 INSERT_VARIABLE(TargetName) |
1723 INSERT_VARIABLE(TargetOutDir) | 1798 INSERT_VARIABLE(TargetOutDir) |
1724 } | 1799 } |
1725 return info_map; | 1800 return info_map; |
1726 } | 1801 } |
1727 | 1802 |
1728 const VariableInfoMap& GetTargetVariables() { | 1803 const VariableInfoMap& GetTargetVariables() { |
1729 static VariableInfoMap info_map; | 1804 static VariableInfoMap info_map; |
1730 if (info_map.empty()) { | 1805 if (info_map.empty()) { |
1731 INSERT_VARIABLE(AllDependentConfigs) | 1806 INSERT_VARIABLE(AllDependentConfigs) |
1732 INSERT_VARIABLE(AllowCircularIncludesFrom) | 1807 INSERT_VARIABLE(AllowCircularIncludesFrom) |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1778 INSERT_VARIABLE(Testonly) | 1853 INSERT_VARIABLE(Testonly) |
1779 INSERT_VARIABLE(Visibility) | 1854 INSERT_VARIABLE(Visibility) |
1780 INSERT_VARIABLE(WriteRuntimeDeps) | 1855 INSERT_VARIABLE(WriteRuntimeDeps) |
1781 } | 1856 } |
1782 return info_map; | 1857 return info_map; |
1783 } | 1858 } |
1784 | 1859 |
1785 #undef INSERT_VARIABLE | 1860 #undef INSERT_VARIABLE |
1786 | 1861 |
1787 } // namespace variables | 1862 } // namespace variables |
OLD | NEW |