| 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" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 "{{defines}}", // SUBSTITUTION_DEFINES | 39 "{{defines}}", // SUBSTITUTION_DEFINES |
| 40 "{{include_dirs}}", // SUBSTITUTION_INCLUDE_DIRS | 40 "{{include_dirs}}", // SUBSTITUTION_INCLUDE_DIRS |
| 41 | 41 |
| 42 "{{inputs}}", // SUBSTITUTION_LINKER_INPUTS | 42 "{{inputs}}", // SUBSTITUTION_LINKER_INPUTS |
| 43 "{{inputs_newline}}", // SUBSTITUTION_LINKER_INPUTS_NEWLINE | 43 "{{inputs_newline}}", // SUBSTITUTION_LINKER_INPUTS_NEWLINE |
| 44 "{{ldflags}}", // SUBSTITUTION_LDFLAGS | 44 "{{ldflags}}", // SUBSTITUTION_LDFLAGS |
| 45 "{{libs}}", // SUBSTITUTION_LIBS | 45 "{{libs}}", // SUBSTITUTION_LIBS |
| 46 "{{output_extension}}", // SUBSTITUTION_OUTPUT_EXTENSION | 46 "{{output_extension}}", // SUBSTITUTION_OUTPUT_EXTENSION |
| 47 "{{solibs}}", // SUBSTITUTION_SOLIBS | 47 "{{solibs}}", // SUBSTITUTION_SOLIBS |
| 48 | 48 |
| 49 "{{bundle_root_dir}}", // SUBSTITUTION_BUNDLE_ROOT_DIR |
| 50 "{{bundle_resources_dir}}", // SUBSTITUTION_BUNDLE_RESOURCES_DIR |
| 51 "{{bundle_executable_dir}}", // SUBSTITUTION_BUNDLE_EXECUTABLE_DIR |
| 52 "{{bundle_plugins_dir}}", // SUBSTITUTION_BUNDLE_PLUGINS_DIR |
| 53 |
| 49 "{{response_file_name}}", // SUBSTITUTION_RSP_FILE_NAME | 54 "{{response_file_name}}", // SUBSTITUTION_RSP_FILE_NAME |
| 50 }; | 55 }; |
| 51 | 56 |
| 52 const char* kSubstitutionNinjaNames[SUBSTITUTION_NUM_TYPES] = { | 57 const char* kSubstitutionNinjaNames[SUBSTITUTION_NUM_TYPES] = { |
| 53 nullptr, // SUBSTITUTION_LITERAL | 58 nullptr, // SUBSTITUTION_LITERAL |
| 54 | 59 |
| 55 "in", // SUBSTITUTION_SOURCE | 60 "in", // SUBSTITUTION_SOURCE |
| 56 "out", // SUBSTITUTION_OUTPUT | 61 "out", // SUBSTITUTION_OUTPUT |
| 57 | 62 |
| 58 "source_name_part", // SUBSTITUTION_NAME_PART | 63 "source_name_part", // SUBSTITUTION_NAME_PART |
| (...skipping 23 matching lines...) Expand all Loading... |
| 82 // LINKER_INPUTS expands to the same Ninja var as SUBSTITUTION_SOURCE. These | 87 // LINKER_INPUTS expands to the same Ninja var as SUBSTITUTION_SOURCE. These |
| 83 // are used in different contexts and are named differently to keep things | 88 // are used in different contexts and are named differently to keep things |
| 84 // clear, but they both expand to the "set of input files" for a build rule. | 89 // clear, but they both expand to the "set of input files" for a build rule. |
| 85 "in", // SUBSTITUTION_LINKER_INPUTS | 90 "in", // SUBSTITUTION_LINKER_INPUTS |
| 86 "in_newline", // SUBSTITUTION_LINKER_INPUTS_NEWLINE | 91 "in_newline", // SUBSTITUTION_LINKER_INPUTS_NEWLINE |
| 87 "ldflags", // SUBSTITUTION_LDFLAGS | 92 "ldflags", // SUBSTITUTION_LDFLAGS |
| 88 "libs", // SUBSTITUTION_LIBS | 93 "libs", // SUBSTITUTION_LIBS |
| 89 "output_extension", // SUBSTITUTION_OUTPUT_EXTENSION | 94 "output_extension", // SUBSTITUTION_OUTPUT_EXTENSION |
| 90 "solibs", // SUBSTITUTION_SOLIBS | 95 "solibs", // SUBSTITUTION_SOLIBS |
| 91 | 96 |
| 97 "bundle_root_dir", // SUBSTITUTION_BUNDLE_ROOT_DIR |
| 98 "bundle_resources_dir", // SUBSTITUTION_BUNDLE_RESOURCES_DIR |
| 99 "bundle_executable_dir", // SUBSTITUTION_BUNDLE_EXECUTABLE_DIR |
| 100 "bundle_plugins_dir", // SUBSTITUTION_BUNDLE_PLUGINS_DIR |
| 101 |
| 92 "rspfile", // SUBSTITUTION_RSP_FILE_NAME | 102 "rspfile", // SUBSTITUTION_RSP_FILE_NAME |
| 93 }; | 103 }; |
| 94 | 104 |
| 95 SubstitutionBits::SubstitutionBits() : used() { | 105 SubstitutionBits::SubstitutionBits() : used() { |
| 96 } | 106 } |
| 97 | 107 |
| 98 void SubstitutionBits::MergeFrom(const SubstitutionBits& other) { | 108 void SubstitutionBits::MergeFrom(const SubstitutionBits& other) { |
| 99 for (size_t i = 0; i < SUBSTITUTION_NUM_TYPES; i++) | 109 for (size_t i = 0; i < SUBSTITUTION_NUM_TYPES; i++) |
| 100 used[i] |= other.used[i]; | 110 used[i] |= other.used[i]; |
| 101 } | 111 } |
| 102 | 112 |
| 103 void SubstitutionBits::FillVector(std::vector<SubstitutionType>* vect) const { | 113 void SubstitutionBits::FillVector(std::vector<SubstitutionType>* vect) const { |
| 104 for (size_t i = SUBSTITUTION_FIRST_PATTERN; i < SUBSTITUTION_NUM_TYPES; i++) { | 114 for (size_t i = SUBSTITUTION_FIRST_PATTERN; i < SUBSTITUTION_NUM_TYPES; i++) { |
| 105 if (used[i]) | 115 if (used[i]) |
| 106 vect->push_back(static_cast<SubstitutionType>(i)); | 116 vect->push_back(static_cast<SubstitutionType>(i)); |
| 107 } | 117 } |
| 108 } | 118 } |
| 109 | 119 |
| 110 bool SubstitutionIsInOutputDir(SubstitutionType type) { | 120 bool SubstitutionIsInOutputDir(SubstitutionType type) { |
| 111 return type == SUBSTITUTION_SOURCE_GEN_DIR || | 121 return type == SUBSTITUTION_SOURCE_GEN_DIR || |
| 112 type == SUBSTITUTION_SOURCE_OUT_DIR || | 122 type == SUBSTITUTION_SOURCE_OUT_DIR || |
| 113 type == SUBSTITUTION_ROOT_GEN_DIR || | 123 type == SUBSTITUTION_ROOT_GEN_DIR || |
| 114 type == SUBSTITUTION_ROOT_OUT_DIR || | 124 type == SUBSTITUTION_ROOT_OUT_DIR || |
| 115 type == SUBSTITUTION_TARGET_GEN_DIR || | 125 type == SUBSTITUTION_TARGET_GEN_DIR || |
| 116 type == SUBSTITUTION_TARGET_OUT_DIR; | 126 type == SUBSTITUTION_TARGET_OUT_DIR; |
| 117 } | 127 } |
| 118 | 128 |
| 129 bool SubstitutionIsInBundleDir(SubstitutionType type) { |
| 130 return type == SUBSTITUTION_BUNDLE_ROOT_DIR || |
| 131 type == SUBSTITUTION_BUNDLE_RESOURCES_DIR || |
| 132 type == SUBSTITUTION_BUNDLE_EXECUTABLE_DIR || |
| 133 type == SUBSTITUTION_BUNDLE_PLUGINS_DIR; |
| 134 } |
| 135 |
| 136 bool IsValidBundleDataSubstitution(SubstitutionType type) { |
| 137 return type == SUBSTITUTION_LITERAL || |
| 138 type == SUBSTITUTION_SOURCE_NAME_PART || |
| 139 type == SUBSTITUTION_SOURCE_FILE_PART || |
| 140 type == SUBSTITUTION_SOURCE_ROOT_RELATIVE_DIR || |
| 141 type == SUBSTITUTION_BUNDLE_ROOT_DIR || |
| 142 type == SUBSTITUTION_BUNDLE_RESOURCES_DIR || |
| 143 type == SUBSTITUTION_BUNDLE_EXECUTABLE_DIR || |
| 144 type == SUBSTITUTION_BUNDLE_PLUGINS_DIR; |
| 145 } |
| 146 |
| 119 bool IsValidSourceSubstitution(SubstitutionType type) { | 147 bool IsValidSourceSubstitution(SubstitutionType type) { |
| 120 return type == SUBSTITUTION_LITERAL || | 148 return type == SUBSTITUTION_LITERAL || |
| 121 type == SUBSTITUTION_SOURCE || | 149 type == SUBSTITUTION_SOURCE || |
| 122 type == SUBSTITUTION_SOURCE_NAME_PART || | 150 type == SUBSTITUTION_SOURCE_NAME_PART || |
| 123 type == SUBSTITUTION_SOURCE_FILE_PART || | 151 type == SUBSTITUTION_SOURCE_FILE_PART || |
| 124 type == SUBSTITUTION_SOURCE_DIR || | 152 type == SUBSTITUTION_SOURCE_DIR || |
| 125 type == SUBSTITUTION_SOURCE_ROOT_RELATIVE_DIR || | 153 type == SUBSTITUTION_SOURCE_ROOT_RELATIVE_DIR || |
| 126 type == SUBSTITUTION_SOURCE_GEN_DIR || | 154 type == SUBSTITUTION_SOURCE_GEN_DIR || |
| 127 type == SUBSTITUTION_SOURCE_OUT_DIR; | 155 type == SUBSTITUTION_SOURCE_OUT_DIR; |
| 128 } | 156 } |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 if (!IsValidSourceSubstitution(types[i])) { | 216 if (!IsValidSourceSubstitution(types[i])) { |
| 189 *err = Err(origin, "Invalid substitution type.", | 217 *err = Err(origin, "Invalid substitution type.", |
| 190 "The substitution " + std::string(kSubstitutionNames[types[i]]) + | 218 "The substitution " + std::string(kSubstitutionNames[types[i]]) + |
| 191 " isn't valid for something\n" | 219 " isn't valid for something\n" |
| 192 "operating on a source file such as this."); | 220 "operating on a source file such as this."); |
| 193 return false; | 221 return false; |
| 194 } | 222 } |
| 195 } | 223 } |
| 196 return true; | 224 return true; |
| 197 } | 225 } |
| OLD | NEW |