| 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 #ifndef TOOLS_GN_SUBSTITUTION_TYPE_H_ | 5 #ifndef TOOLS_GN_SUBSTITUTION_TYPE_H_ |
| 6 #define TOOLS_GN_SUBSTITUTION_TYPE_H_ | 6 #define TOOLS_GN_SUBSTITUTION_TYPE_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 class Err; | 10 class Err; |
| 11 class ParseNode; | 11 class ParseNode; |
| 12 | 12 |
| 13 // Keep kSubstitutionNames, kSubstitutionNinjaNames and the | 13 // Keep kSubstitutionNames, kSubstitutionNinjaNames and the |
| 14 // IsValid*Substutition functions in sync if you change anything here. | 14 // IsValid*Substutition functions in sync if you change anything here. |
| 15 enum SubstitutionType { | 15 enum SubstitutionType { |
| 16 SUBSTITUTION_LITERAL = 0, | 16 SUBSTITUTION_LITERAL = 0, |
| 17 | 17 |
| 18 // The index of the first pattern. To loop overal all patterns, go from here | 18 // The index of the first pattern. To loop overal all patterns, go from here |
| 19 // until NUM_TYPES. | 19 // until NUM_TYPES. |
| 20 SUBSTITUTION_FIRST_PATTERN, | 20 SUBSTITUTION_FIRST_PATTERN, |
| 21 | 21 |
| 22 // These map to Ninja's {in} and {out} variables. |
| 22 SUBSTITUTION_SOURCE = SUBSTITUTION_FIRST_PATTERN, // {{source}} | 23 SUBSTITUTION_SOURCE = SUBSTITUTION_FIRST_PATTERN, // {{source}} |
| 24 SUBSTITUTION_OUTPUT, // {{output}} |
| 25 |
| 26 // Valid for all compiler tools. |
| 23 SUBSTITUTION_SOURCE_NAME_PART, // {{source_name_part}} | 27 SUBSTITUTION_SOURCE_NAME_PART, // {{source_name_part}} |
| 24 SUBSTITUTION_SOURCE_FILE_PART, // {{source_file_part}} | 28 SUBSTITUTION_SOURCE_FILE_PART, // {{source_file_part}} |
| 25 SUBSTITUTION_SOURCE_DIR, // {{source_dir}} | 29 SUBSTITUTION_SOURCE_DIR, // {{source_dir}} |
| 26 SUBSTITUTION_SOURCE_ROOT_RELATIVE_DIR, // {{root_relative_dir}} | 30 SUBSTITUTION_SOURCE_ROOT_RELATIVE_DIR, // {{root_relative_dir}} |
| 27 SUBSTITUTION_SOURCE_GEN_DIR, // {{source_gen_dir}} | 31 SUBSTITUTION_SOURCE_GEN_DIR, // {{source_gen_dir}} |
| 28 SUBSTITUTION_SOURCE_OUT_DIR, // {{source_out_dir}} | 32 SUBSTITUTION_SOURCE_OUT_DIR, // {{source_out_dir}} |
| 29 | 33 |
| 30 // Valid for all compiler and linker tools (depends on target). | 34 // Valid for all compiler and linker tools. These depend on the target and |
| 31 SUBSTITUTION_OUTPUT, // {{output}} | 35 // no not vary on a per-file basis. |
| 36 SUBSTITUTION_LABEL, // {{label}} |
| 32 SUBSTITUTION_ROOT_GEN_DIR, // {{root_gen_dir}} | 37 SUBSTITUTION_ROOT_GEN_DIR, // {{root_gen_dir}} |
| 33 SUBSTITUTION_ROOT_OUT_DIR, // {{root_out_dir}} | 38 SUBSTITUTION_ROOT_OUT_DIR, // {{root_out_dir}} |
| 34 SUBSTITUTION_TARGET_GEN_DIR, // {{target_gen_dir}} | 39 SUBSTITUTION_TARGET_GEN_DIR, // {{target_gen_dir}} |
| 35 SUBSTITUTION_TARGET_OUT_DIR, // {{target_out_dir}} | 40 SUBSTITUTION_TARGET_OUT_DIR, // {{target_out_dir}} |
| 36 SUBSTITUTION_TARGET_OUTPUT_NAME, // {{target_output_name}} | 41 SUBSTITUTION_TARGET_OUTPUT_NAME, // {{target_output_name}} |
| 37 | 42 |
| 38 // Valid for compiler tools. | 43 // Valid for compiler tools. |
| 39 SUBSTITUTION_CFLAGS, // {{cflags}} | 44 SUBSTITUTION_CFLAGS, // {{cflags}} |
| 40 SUBSTITUTION_CFLAGS_C, // {{cflags_c}} | 45 SUBSTITUTION_CFLAGS_C, // {{cflags_c}} |
| 41 SUBSTITUTION_CFLAGS_CC, // {{cflags_cc}} | 46 SUBSTITUTION_CFLAGS_CC, // {{cflags_cc}} |
| (...skipping 14 matching lines...) Expand all Loading... |
| 56 | 61 |
| 57 // An array of size SUBSTITUTION_NUM_TYPES that lists the names of the | 62 // An array of size SUBSTITUTION_NUM_TYPES that lists the names of the |
| 58 // substitution patterns, including the curly braces. So, for example, | 63 // substitution patterns, including the curly braces. So, for example, |
| 59 // kSubstitutionNames[SUBSTITUTION_SOURCE] == "{{source}}". | 64 // kSubstitutionNames[SUBSTITUTION_SOURCE] == "{{source}}". |
| 60 extern const char* kSubstitutionNames[SUBSTITUTION_NUM_TYPES]; | 65 extern const char* kSubstitutionNames[SUBSTITUTION_NUM_TYPES]; |
| 61 | 66 |
| 62 // Ninja variables corresponding to each substitution. These do not include | 67 // Ninja variables corresponding to each substitution. These do not include |
| 63 // the dollar sign. | 68 // the dollar sign. |
| 64 extern const char* kSubstitutionNinjaNames[SUBSTITUTION_NUM_TYPES]; | 69 extern const char* kSubstitutionNinjaNames[SUBSTITUTION_NUM_TYPES]; |
| 65 | 70 |
| 71 // A wrapper around an array if flags indicating whether a give substitution |
| 72 // type is required in some context. By convention, the LITERAL type bit is |
| 73 // not set. |
| 74 struct SubstitutionBits { |
| 75 SubstitutionBits(); |
| 76 |
| 77 // Merges any bits set in the given "other" to this one. This object will |
| 78 // then be the union of all bits in the two lists. |
| 79 void MergeFrom(const SubstitutionBits& other); |
| 80 |
| 81 // Converts the substitution type bitfield (with a true set for each required |
| 82 // item) to a vector of the types listed. Does not include LITERAL. |
| 83 void FillVector(std::vector<SubstitutionType>* vect) const; |
| 84 |
| 85 bool used[SUBSTITUTION_NUM_TYPES]; |
| 86 }; |
| 87 |
| 66 // Returns true if the given substitution pattern references the output | 88 // Returns true if the given substitution pattern references the output |
| 67 // directory. This is used to check strings that begin with a substitution to | 89 // directory. This is used to check strings that begin with a substitution to |
| 68 // verify that the produce a file in the output directory. | 90 // verify that the produce a file in the output directory. |
| 69 bool SubstitutionIsInOutputDir(SubstitutionType type); | 91 bool SubstitutionIsInOutputDir(SubstitutionType type); |
| 70 | 92 |
| 71 // Returns true if the given substitution is valid for the named purpose. | 93 // Returns true if the given substitution is valid for the named purpose. |
| 72 bool IsValidSourceSubstitution(SubstitutionType type); | 94 bool IsValidSourceSubstitution(SubstitutionType type); |
| 73 // Both compiler and linker tools. | 95 // Both compiler and linker tools. |
| 74 bool IsValidToolSubstutition(SubstitutionType type); | 96 bool IsValidToolSubstutition(SubstitutionType type); |
| 75 bool IsValidCompilerSubstitution(SubstitutionType type); | 97 bool IsValidCompilerSubstitution(SubstitutionType type); |
| 76 bool IsValidCompilerOutputsSubstitution(SubstitutionType type); | 98 bool IsValidCompilerOutputsSubstitution(SubstitutionType type); |
| 77 bool IsValidLinkerSubstitution(SubstitutionType type); | 99 bool IsValidLinkerSubstitution(SubstitutionType type); |
| 78 bool IsValidLinkerOutputsSubstitution(SubstitutionType type); | 100 bool IsValidLinkerOutputsSubstitution(SubstitutionType type); |
| 101 bool IsValidCopySubstitution(SubstitutionType type); |
| 79 | 102 |
| 80 // Like the "IsValid..." version above but checks a list of types and sets a | 103 // Like the "IsValid..." version above but checks a list of types and sets a |
| 81 // an error blaming the given source if the test fails. | 104 // an error blaming the given source if the test fails. |
| 82 bool EnsureValidSourcesSubstitutions( | 105 bool EnsureValidSourcesSubstitutions( |
| 83 const std::vector<SubstitutionType>& types, | 106 const std::vector<SubstitutionType>& types, |
| 84 const ParseNode* origin, | 107 const ParseNode* origin, |
| 85 Err* err); | 108 Err* err); |
| 86 | 109 |
| 87 #endif // TOOLS_GN_SUBSTITUTION_TYPE_H_ | 110 #endif // TOOLS_GN_SUBSTITUTION_TYPE_H_ |
| OLD | NEW |