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/substitution_type.h" | 5 #include "tools/gn/substitution_type.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdlib.h> | 8 #include <stdlib.h> |
9 | 9 |
10 #include "tools/gn/err.h" | 10 #include "tools/gn/err.h" |
11 | 11 |
12 const char* kSubstitutionNames[SUBSTITUTION_NUM_TYPES] = { | 12 const char* kSubstitutionNames[SUBSTITUTION_NUM_TYPES] = { |
13 "<<literal>>", // SUBSTITUTION_LITERAL | 13 "<<literal>>", // SUBSTITUTION_LITERAL |
14 | 14 |
15 "{{source}}", // SUBSTITUTION_SOURCE | 15 "{{source}}", // SUBSTITUTION_SOURCE |
16 "{{output}}", // SUBSTITUTION_OUTPUT | 16 "{{output}}", // SUBSTITUTION_OUTPUT |
17 | 17 |
18 "{{source_name_part}}", // SUBSTITUTION_NAME_PART | 18 "{{source_name_part}}", // SUBSTITUTION_NAME_PART |
19 "{{source_file_part}}", // SUBSTITUTION_FILE_PART | 19 "{{source_file_part}}", // SUBSTITUTION_FILE_PART |
20 "{{source_dir}}", // SUBSTITUTION_SOURCE_DIR | 20 "{{source_dir}}", // SUBSTITUTION_SOURCE_DIR |
21 "{{source_root_relative_dir}}", // SUBSTITUTION_SOURCE_ROOT_RELATIVE_DIR | 21 "{{source_root_relative_dir}}", // SUBSTITUTION_SOURCE_ROOT_RELATIVE_DIR |
22 "{{source_gen_dir}}", // SUBSTITUTION_SOURCE_GEN_DIR | 22 "{{source_gen_dir}}", // SUBSTITUTION_SOURCE_GEN_DIR |
23 "{{source_out_dir}}", // SUBSTITUTION_SOURCE_OUT_DIR | 23 "{{source_out_dir}}", // SUBSTITUTION_SOURCE_OUT_DIR |
| 24 "{{source_target_relative}}", // SUBSTITUTION_SOURCE_TARGET_RELATIVE |
24 | 25 |
25 "{{label}}", // SUBSTITUTION_LABEL | 26 "{{label}}", // SUBSTITUTION_LABEL |
26 "{{label_name}}", // SUBSTITUTION_LABEL_NAME | 27 "{{label_name}}", // SUBSTITUTION_LABEL_NAME |
27 "{{root_gen_dir}}", // SUBSTITUTION_ROOT_GEN_DIR | 28 "{{root_gen_dir}}", // SUBSTITUTION_ROOT_GEN_DIR |
28 "{{root_out_dir}}", // SUBSTITUTION_ROOT_OUT_DIR | 29 "{{root_out_dir}}", // SUBSTITUTION_ROOT_OUT_DIR |
29 "{{target_gen_dir}}", // SUBSTITUTION_TARGET_GEN_DIR | 30 "{{target_gen_dir}}", // SUBSTITUTION_TARGET_GEN_DIR |
30 "{{target_out_dir}}", // SUBSTITUTION_TARGET_OUT_DIR | 31 "{{target_out_dir}}", // SUBSTITUTION_TARGET_OUT_DIR |
31 "{{target_output_name}}", // SUBSTITUTION_TARGET_OUTPUT_NAME | 32 "{{target_output_name}}", // SUBSTITUTION_TARGET_OUTPUT_NAME |
32 | 33 |
33 "{{asmflags}}", // SUBSTITUTION_ASMFLAGS | 34 "{{asmflags}}", // SUBSTITUTION_ASMFLAGS |
(...skipping 29 matching lines...) Expand all Loading... |
63 | 64 |
64 "in", // SUBSTITUTION_SOURCE | 65 "in", // SUBSTITUTION_SOURCE |
65 "out", // SUBSTITUTION_OUTPUT | 66 "out", // SUBSTITUTION_OUTPUT |
66 | 67 |
67 "source_name_part", // SUBSTITUTION_NAME_PART | 68 "source_name_part", // SUBSTITUTION_NAME_PART |
68 "source_file_part", // SUBSTITUTION_FILE_PART | 69 "source_file_part", // SUBSTITUTION_FILE_PART |
69 "source_dir", // SUBSTITUTION_SOURCE_DIR | 70 "source_dir", // SUBSTITUTION_SOURCE_DIR |
70 "source_root_relative_dir", // SUBSTITUTION_SOURCE_ROOT_RELATIVE_DIR | 71 "source_root_relative_dir", // SUBSTITUTION_SOURCE_ROOT_RELATIVE_DIR |
71 "source_gen_dir", // SUBSTITUTION_SOURCE_GEN_DIR | 72 "source_gen_dir", // SUBSTITUTION_SOURCE_GEN_DIR |
72 "source_out_dir", // SUBSTITUTION_SOURCE_OUT_DIR | 73 "source_out_dir", // SUBSTITUTION_SOURCE_OUT_DIR |
| 74 "source_target_relative", // SUBSTITUTION_SOURCE_TARGET_RELATIVE |
73 | 75 |
74 "label", // SUBSTITUTION_LABEL | 76 "label", // SUBSTITUTION_LABEL |
75 "label_name", // SUBSTITUTION_LABEL_NAME | 77 "label_name", // SUBSTITUTION_LABEL_NAME |
76 "root_gen_dir", // SUBSTITUTION_ROOT_GEN_DIR | 78 "root_gen_dir", // SUBSTITUTION_ROOT_GEN_DIR |
77 "root_out_dir", // SUBSTITUTION_ROOT_OUT_DIR | 79 "root_out_dir", // SUBSTITUTION_ROOT_OUT_DIR |
78 "target_gen_dir", // SUBSTITUTION_TARGET_GEN_DIR | 80 "target_gen_dir", // SUBSTITUTION_TARGET_GEN_DIR |
79 "target_out_dir", // SUBSTITUTION_TARGET_OUT_DIR | 81 "target_out_dir", // SUBSTITUTION_TARGET_OUT_DIR |
80 "target_output_name", // SUBSTITUTION_TARGET_OUTPUT_NAME | 82 "target_output_name", // SUBSTITUTION_TARGET_OUTPUT_NAME |
81 | 83 |
82 "asmflags", // SUBSTITUTION_ASMFLAGS | 84 "asmflags", // SUBSTITUTION_ASMFLAGS |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 } | 155 } |
154 | 156 |
155 bool IsValidSourceSubstitution(SubstitutionType type) { | 157 bool IsValidSourceSubstitution(SubstitutionType type) { |
156 return type == SUBSTITUTION_LITERAL || | 158 return type == SUBSTITUTION_LITERAL || |
157 type == SUBSTITUTION_SOURCE || | 159 type == SUBSTITUTION_SOURCE || |
158 type == SUBSTITUTION_SOURCE_NAME_PART || | 160 type == SUBSTITUTION_SOURCE_NAME_PART || |
159 type == SUBSTITUTION_SOURCE_FILE_PART || | 161 type == SUBSTITUTION_SOURCE_FILE_PART || |
160 type == SUBSTITUTION_SOURCE_DIR || | 162 type == SUBSTITUTION_SOURCE_DIR || |
161 type == SUBSTITUTION_SOURCE_ROOT_RELATIVE_DIR || | 163 type == SUBSTITUTION_SOURCE_ROOT_RELATIVE_DIR || |
162 type == SUBSTITUTION_SOURCE_GEN_DIR || | 164 type == SUBSTITUTION_SOURCE_GEN_DIR || |
163 type == SUBSTITUTION_SOURCE_OUT_DIR; | 165 type == SUBSTITUTION_SOURCE_OUT_DIR || |
| 166 type == SUBSTITUTION_SOURCE_TARGET_RELATIVE; |
164 } | 167 } |
165 | 168 |
166 bool IsValidToolSubstitution(SubstitutionType type) { | 169 bool IsValidToolSubstitution(SubstitutionType type) { |
167 return type == SUBSTITUTION_LITERAL || | 170 return type == SUBSTITUTION_LITERAL || |
168 type == SUBSTITUTION_OUTPUT || | 171 type == SUBSTITUTION_OUTPUT || |
169 type == SUBSTITUTION_LABEL || | 172 type == SUBSTITUTION_LABEL || |
170 type == SUBSTITUTION_LABEL_NAME || | 173 type == SUBSTITUTION_LABEL_NAME || |
171 type == SUBSTITUTION_ROOT_GEN_DIR || | 174 type == SUBSTITUTION_ROOT_GEN_DIR || |
172 type == SUBSTITUTION_ROOT_OUT_DIR || | 175 type == SUBSTITUTION_ROOT_OUT_DIR || |
173 type == SUBSTITUTION_TARGET_GEN_DIR || | 176 type == SUBSTITUTION_TARGET_GEN_DIR || |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 if (!IsValidSourceSubstitution(types[i])) { | 244 if (!IsValidSourceSubstitution(types[i])) { |
242 *err = Err(origin, "Invalid substitution type.", | 245 *err = Err(origin, "Invalid substitution type.", |
243 "The substitution " + std::string(kSubstitutionNames[types[i]]) + | 246 "The substitution " + std::string(kSubstitutionNames[types[i]]) + |
244 " isn't valid for something\n" | 247 " isn't valid for something\n" |
245 "operating on a source file such as this."); | 248 "operating on a source file such as this."); |
246 return false; | 249 return false; |
247 } | 250 } |
248 } | 251 } |
249 return true; | 252 return true; |
250 } | 253 } |
OLD | NEW |