Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "configuration/ConfigurationParser.h" |
| 18 | |
| 19 | #include <algorithm> |
| 20 | #include <functional> |
Shane Farmer | 5766943 | 2017-06-19 12:52:04 -0700 | [diff] [blame] | 21 | #include <map> |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 22 | #include <memory> |
Shane Farmer | 11cdc1c | 2018-01-31 16:43:24 -0800 | [diff] [blame] | 23 | #include <string> |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 24 | #include <utility> |
| 25 | |
Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 26 | #include "ResourceUtils.h" |
Adam Lesinski | efeb7af | 2017-08-02 14:57:43 -0700 | [diff] [blame] | 27 | #include "android-base/file.h" |
| 28 | #include "android-base/logging.h" |
Mårten Kongstad | 24c9aa6 | 2018-06-20 08:46:41 +0200 | [diff] [blame] | 29 | #include "androidfw/ConfigDescription.h" |
Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 30 | #include "androidfw/IDiagnostics.h" |
Shane Farmer | cb6c3f9 | 2017-11-27 13:19:36 -0800 | [diff] [blame] | 31 | #include "configuration/ConfigurationParser.internal.h" |
Shane Farmer | b102727 | 2017-06-14 09:10:28 -0700 | [diff] [blame] | 32 | #include "io/File.h" |
| 33 | #include "io/FileSystem.h" |
Adam Lesinski | 0045116 | 2017-10-03 07:44:08 -0700 | [diff] [blame] | 34 | #include "io/StringStream.h" |
Shane Farmer | 9ecc075 | 2017-08-24 15:55:36 -0700 | [diff] [blame] | 35 | #include "util/Files.h" |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 36 | #include "util/Util.h" |
| 37 | #include "xml/XmlActionExecutor.h" |
| 38 | #include "xml/XmlDom.h" |
| 39 | #include "xml/XmlUtil.h" |
| 40 | |
Mårten Kongstad | 24c9aa6 | 2018-06-20 08:46:41 +0200 | [diff] [blame] | 41 | using ::android::ConfigDescription; |
| 42 | |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 43 | namespace aapt { |
| 44 | |
| 45 | namespace { |
| 46 | |
| 47 | using ::aapt::configuration::Abi; |
| 48 | using ::aapt::configuration::AndroidManifest; |
| 49 | using ::aapt::configuration::AndroidSdk; |
Shane Farmer | cb6c3f9 | 2017-11-27 13:19:36 -0800 | [diff] [blame] | 50 | using ::aapt::configuration::ConfiguredArtifact; |
| 51 | using ::aapt::configuration::DeviceFeature; |
| 52 | using ::aapt::configuration::Entry; |
Shane Farmer | 78c43d7 | 2017-12-04 09:08:38 -0800 | [diff] [blame] | 53 | using ::aapt::configuration::ExtractConfiguration; |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 54 | using ::aapt::configuration::GlTexture; |
| 55 | using ::aapt::configuration::Group; |
| 56 | using ::aapt::configuration::Locale; |
Shane Farmer | 78c43d7 | 2017-12-04 09:08:38 -0800 | [diff] [blame] | 57 | using ::aapt::configuration::OrderedEntry; |
Shane Farmer | cb6c3f9 | 2017-11-27 13:19:36 -0800 | [diff] [blame] | 58 | using ::aapt::configuration::OutputArtifact; |
| 59 | using ::aapt::configuration::PostProcessingConfiguration; |
| 60 | using ::aapt::configuration::handler::AbiGroupTagHandler; |
Shane Farmer | 78c43d7 | 2017-12-04 09:08:38 -0800 | [diff] [blame] | 61 | using ::aapt::configuration::handler::AndroidSdkTagHandler; |
Shane Farmer | cb6c3f9 | 2017-11-27 13:19:36 -0800 | [diff] [blame] | 62 | using ::aapt::configuration::handler::ArtifactFormatTagHandler; |
| 63 | using ::aapt::configuration::handler::ArtifactTagHandler; |
| 64 | using ::aapt::configuration::handler::DeviceFeatureGroupTagHandler; |
| 65 | using ::aapt::configuration::handler::GlTextureGroupTagHandler; |
| 66 | using ::aapt::configuration::handler::LocaleGroupTagHandler; |
| 67 | using ::aapt::configuration::handler::ScreenDensityGroupTagHandler; |
Shane Farmer | b102727 | 2017-06-14 09:10:28 -0700 | [diff] [blame] | 68 | using ::aapt::io::IFile; |
| 69 | using ::aapt::io::RegularFile; |
Adam Lesinski | efeb7af | 2017-08-02 14:57:43 -0700 | [diff] [blame] | 70 | using ::aapt::io::StringInputStream; |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 71 | using ::aapt::util::TrimWhitespace; |
| 72 | using ::aapt::xml::Element; |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 73 | using ::aapt::xml::NodeCast; |
| 74 | using ::aapt::xml::XmlActionExecutor; |
| 75 | using ::aapt::xml::XmlActionExecutorPolicy; |
| 76 | using ::aapt::xml::XmlNodeAction; |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 77 | using ::android::StringPiece; |
Shane Farmer | cb6c3f9 | 2017-11-27 13:19:36 -0800 | [diff] [blame] | 78 | using ::android::base::ReadFileToString; |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 79 | |
Shane Farmer | cb6c3f9 | 2017-11-27 13:19:36 -0800 | [diff] [blame] | 80 | const std::unordered_map<StringPiece, Abi> kStringToAbiMap = { |
Shane Farmer | 5766943 | 2017-06-19 12:52:04 -0700 | [diff] [blame] | 81 | {"armeabi", Abi::kArmeV6}, {"armeabi-v7a", Abi::kArmV7a}, {"arm64-v8a", Abi::kArm64V8a}, |
| 82 | {"x86", Abi::kX86}, {"x86_64", Abi::kX86_64}, {"mips", Abi::kMips}, |
| 83 | {"mips64", Abi::kMips64}, {"universal", Abi::kUniversal}, |
| 84 | }; |
Shane Farmer | cb6c3f9 | 2017-11-27 13:19:36 -0800 | [diff] [blame] | 85 | const std::array<StringPiece, 8> kAbiToStringMap = { |
| 86 | {"armeabi", "armeabi-v7a", "arm64-v8a", "x86", "x86_64", "mips", "mips64", "universal"}}; |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 87 | |
| 88 | constexpr const char* kAaptXmlNs = "http://schemas.android.com/tools/aapt"; |
| 89 | |
Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 90 | android::NoOpDiagnostics noop_; |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 91 | |
Shane Farmer | 11cdc1c | 2018-01-31 16:43:24 -0800 | [diff] [blame] | 92 | /** Returns the value of the label attribute for a given element. */ |
Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 93 | std::string GetLabel(const Element* element, android::IDiagnostics* diag) { |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 94 | std::string label; |
| 95 | for (const auto& attr : element->attributes) { |
| 96 | if (attr.name == "label") { |
| 97 | label = attr.value; |
| 98 | break; |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | if (label.empty()) { |
Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 103 | diag->Error(android::DiagMessage() << "No label found for element " << element->name); |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 104 | } |
| 105 | return label; |
| 106 | } |
| 107 | |
Shane Farmer | 11cdc1c | 2018-01-31 16:43:24 -0800 | [diff] [blame] | 108 | /** Returns the value of the version-code-order attribute for a given element. */ |
Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 109 | std::optional<int32_t> GetVersionCodeOrder(const Element* element, android::IDiagnostics* diag) { |
Shane Farmer | 11cdc1c | 2018-01-31 16:43:24 -0800 | [diff] [blame] | 110 | const xml::Attribute* version = element->FindAttribute("", "version-code-order"); |
| 111 | if (version == nullptr) { |
| 112 | std::string label = GetLabel(element, diag); |
Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 113 | diag->Error(android::DiagMessage() << "No version-code-order found for element '" |
| 114 | << element->name << "' with label '" << label << "'"); |
Shane Farmer | 11cdc1c | 2018-01-31 16:43:24 -0800 | [diff] [blame] | 115 | return {}; |
| 116 | } |
| 117 | return std::stoi(version->value); |
| 118 | } |
| 119 | |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 120 | /** XML node visitor that removes all of the namespace URIs from the node and all children. */ |
| 121 | class NamespaceVisitor : public xml::Visitor { |
| 122 | public: |
| 123 | void Visit(xml::Element* node) override { |
| 124 | node->namespace_uri.clear(); |
| 125 | VisitChildren(node); |
| 126 | } |
| 127 | }; |
| 128 | |
Shane Farmer | cb6c3f9 | 2017-11-27 13:19:36 -0800 | [diff] [blame] | 129 | /** Copies the values referenced in a configuration group to the target list. */ |
| 130 | template <typename T> |
Ryan Mitchell | 4382e44 | 2021-07-14 12:53:01 -0700 | [diff] [blame] | 131 | bool CopyXmlReferences(const std::optional<std::string>& name, const Group<T>& groups, |
Shane Farmer | cb6c3f9 | 2017-11-27 13:19:36 -0800 | [diff] [blame] | 132 | std::vector<T>* target) { |
| 133 | // If there was no item configured, there is nothing to do and no error. |
| 134 | if (!name) { |
| 135 | return true; |
| 136 | } |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 137 | |
Shane Farmer | cb6c3f9 | 2017-11-27 13:19:36 -0800 | [diff] [blame] | 138 | // If the group could not be found, then something is wrong. |
| 139 | auto group = groups.find(name.value()); |
| 140 | if (group == groups.end()) { |
| 141 | return false; |
| 142 | } |
Shane Farmer | b102727 | 2017-06-14 09:10:28 -0700 | [diff] [blame] | 143 | |
Shane Farmer | 78c43d7 | 2017-12-04 09:08:38 -0800 | [diff] [blame] | 144 | for (const T& item : group->second.entry) { |
Shane Farmer | cb6c3f9 | 2017-11-27 13:19:36 -0800 | [diff] [blame] | 145 | target->push_back(item); |
| 146 | } |
| 147 | return true; |
Shane Farmer | 5766943 | 2017-06-19 12:52:04 -0700 | [diff] [blame] | 148 | } |
| 149 | |
Shane Farmer | 9f0e7f1 | 2017-06-22 12:26:44 -0700 | [diff] [blame] | 150 | /** |
| 151 | * Attempts to replace the placeholder in the name string with the provided value. Returns true on |
| 152 | * success, or false if the either the placeholder is not found in the name, or the value is not |
| 153 | * present and the placeholder was. |
| 154 | */ |
Yurii Zubrytskyi | a577514 | 2022-11-02 17:49:49 -0700 | [diff] [blame] | 155 | bool ReplacePlaceholder(StringPiece placeholder, const std::optional<StringPiece>& value, |
Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 156 | std::string* name, android::IDiagnostics* diag) { |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 157 | size_t offset = name->find(placeholder.data()); |
Shane Farmer | 1a21b8c | 2017-07-21 09:42:42 -0700 | [diff] [blame] | 158 | bool found = (offset != std::string::npos); |
| 159 | |
| 160 | // Make sure the placeholder was present if the desired value is present. |
| 161 | if (!found) { |
| 162 | if (value) { |
Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 163 | diag->Error(android::DiagMessage() << "Missing placeholder for artifact: " << placeholder); |
Shane Farmer | 9f0e7f1 | 2017-06-22 12:26:44 -0700 | [diff] [blame] | 164 | return false; |
| 165 | } |
Shane Farmer | 9f0e7f1 | 2017-06-22 12:26:44 -0700 | [diff] [blame] | 166 | return true; |
| 167 | } |
| 168 | |
Shane Farmer | 1a21b8c | 2017-07-21 09:42:42 -0700 | [diff] [blame] | 169 | DCHECK(found) << "Missing return path for placeholder not found"; |
| 170 | |
Shane Farmer | 9f0e7f1 | 2017-06-22 12:26:44 -0700 | [diff] [blame] | 171 | // Make sure the placeholder was not present if the desired value was not present. |
Shane Farmer | 1a21b8c | 2017-07-21 09:42:42 -0700 | [diff] [blame] | 172 | if (!value) { |
Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 173 | diag->Error(android::DiagMessage() |
| 174 | << "Placeholder present but no value for artifact: " << placeholder); |
Shane Farmer | 1a21b8c | 2017-07-21 09:42:42 -0700 | [diff] [blame] | 175 | return false; |
Shane Farmer | 9f0e7f1 | 2017-06-22 12:26:44 -0700 | [diff] [blame] | 176 | } |
Shane Farmer | 1a21b8c | 2017-07-21 09:42:42 -0700 | [diff] [blame] | 177 | |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 178 | name->replace(offset, placeholder.length(), value.value().data()); |
Shane Farmer | 1a21b8c | 2017-07-21 09:42:42 -0700 | [diff] [blame] | 179 | |
| 180 | // Make sure there was only one instance of the placeholder. |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 181 | if (name->find(placeholder.data()) != std::string::npos) { |
Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 182 | diag->Error(android::DiagMessage() << "Placeholder present multiple times: " << placeholder); |
Shane Farmer | 1a21b8c | 2017-07-21 09:42:42 -0700 | [diff] [blame] | 183 | return false; |
| 184 | } |
| 185 | return true; |
Shane Farmer | 9f0e7f1 | 2017-06-22 12:26:44 -0700 | [diff] [blame] | 186 | } |
| 187 | |
Shane Farmer | 9ecc075 | 2017-08-24 15:55:36 -0700 | [diff] [blame] | 188 | /** |
Shane Farmer | cb6c3f9 | 2017-11-27 13:19:36 -0800 | [diff] [blame] | 189 | * An ActionHandler for processing XML elements in the XmlActionExecutor. Returns true if the |
| 190 | * element was successfully processed, otherwise returns false. |
| 191 | */ |
| 192 | using ActionHandler = std::function<bool(configuration::PostProcessingConfiguration* config, |
Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 193 | xml::Element* element, android::IDiagnostics* diag)>; |
Shane Farmer | cb6c3f9 | 2017-11-27 13:19:36 -0800 | [diff] [blame] | 194 | |
| 195 | /** Binds an ActionHandler to the current configuration being populated. */ |
| 196 | xml::XmlNodeAction::ActionFuncWithDiag Bind(configuration::PostProcessingConfiguration* config, |
| 197 | const ActionHandler& handler) { |
Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 198 | return [config, handler](xml::Element* root_element, android::SourcePathDiagnostics* diag) { |
Shane Farmer | cb6c3f9 | 2017-11-27 13:19:36 -0800 | [diff] [blame] | 199 | return handler(config, root_element, diag); |
| 200 | }; |
| 201 | } |
| 202 | |
Shane Farmer | cb6c3f9 | 2017-11-27 13:19:36 -0800 | [diff] [blame] | 203 | /** Converts a ConfiguredArtifact into an OutputArtifact. */ |
Ryan Mitchell | 4382e44 | 2021-07-14 12:53:01 -0700 | [diff] [blame] | 204 | std::optional<OutputArtifact> ToOutputArtifact(const ConfiguredArtifact& artifact, |
| 205 | const std::string& apk_name, |
| 206 | const PostProcessingConfiguration& config, |
Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 207 | android::IDiagnostics* diag) { |
Shane Farmer | cb6c3f9 | 2017-11-27 13:19:36 -0800 | [diff] [blame] | 208 | if (!artifact.name && !config.artifact_format) { |
Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 209 | diag->Error(android::DiagMessage() |
| 210 | << "Artifact does not have a name and no global name template defined"); |
Shane Farmer | cb6c3f9 | 2017-11-27 13:19:36 -0800 | [diff] [blame] | 211 | return {}; |
| 212 | } |
| 213 | |
Ryan Mitchell | 4382e44 | 2021-07-14 12:53:01 -0700 | [diff] [blame] | 214 | std::optional<std::string> artifact_name = |
Shane Farmer | cb6c3f9 | 2017-11-27 13:19:36 -0800 | [diff] [blame] | 215 | (artifact.name) ? artifact.Name(apk_name, diag) |
| 216 | : artifact.ToArtifactName(config.artifact_format.value(), apk_name, diag); |
| 217 | |
| 218 | if (!artifact_name) { |
Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 219 | diag->Error(android::DiagMessage() << "Could not determine split APK artifact name"); |
Shane Farmer | cb6c3f9 | 2017-11-27 13:19:36 -0800 | [diff] [blame] | 220 | return {}; |
| 221 | } |
| 222 | |
| 223 | OutputArtifact output_artifact; |
| 224 | output_artifact.name = artifact_name.value(); |
| 225 | |
Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 226 | android::SourcePathDiagnostics src_diag{{output_artifact.name}, diag}; |
Shane Farmer | cb6c3f9 | 2017-11-27 13:19:36 -0800 | [diff] [blame] | 227 | bool has_errors = false; |
| 228 | |
| 229 | if (!CopyXmlReferences(artifact.abi_group, config.abi_groups, &output_artifact.abis)) { |
Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 230 | src_diag.Error(android::DiagMessage() |
| 231 | << "Could not lookup required ABIs: " << artifact.abi_group.value()); |
Shane Farmer | cb6c3f9 | 2017-11-27 13:19:36 -0800 | [diff] [blame] | 232 | has_errors = true; |
| 233 | } |
| 234 | |
| 235 | if (!CopyXmlReferences(artifact.locale_group, config.locale_groups, &output_artifact.locales)) { |
Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 236 | src_diag.Error(android::DiagMessage() |
| 237 | << "Could not lookup required locales: " << artifact.locale_group.value()); |
Shane Farmer | cb6c3f9 | 2017-11-27 13:19:36 -0800 | [diff] [blame] | 238 | has_errors = true; |
| 239 | } |
| 240 | |
| 241 | if (!CopyXmlReferences(artifact.screen_density_group, config.screen_density_groups, |
| 242 | &output_artifact.screen_densities)) { |
Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 243 | src_diag.Error(android::DiagMessage() << "Could not lookup required screen densities: " |
| 244 | << artifact.screen_density_group.value()); |
Shane Farmer | cb6c3f9 | 2017-11-27 13:19:36 -0800 | [diff] [blame] | 245 | has_errors = true; |
| 246 | } |
| 247 | |
| 248 | if (!CopyXmlReferences(artifact.device_feature_group, config.device_feature_groups, |
| 249 | &output_artifact.features)) { |
Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 250 | src_diag.Error(android::DiagMessage() << "Could not lookup required device features: " |
| 251 | << artifact.device_feature_group.value()); |
Shane Farmer | cb6c3f9 | 2017-11-27 13:19:36 -0800 | [diff] [blame] | 252 | has_errors = true; |
| 253 | } |
| 254 | |
| 255 | if (!CopyXmlReferences(artifact.gl_texture_group, config.gl_texture_groups, |
| 256 | &output_artifact.textures)) { |
Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 257 | src_diag.Error(android::DiagMessage() << "Could not lookup required OpenGL texture formats: " |
| 258 | << artifact.gl_texture_group.value()); |
Shane Farmer | cb6c3f9 | 2017-11-27 13:19:36 -0800 | [diff] [blame] | 259 | has_errors = true; |
| 260 | } |
| 261 | |
Shane Farmer | 78c43d7 | 2017-12-04 09:08:38 -0800 | [diff] [blame] | 262 | if (artifact.android_sdk) { |
| 263 | auto entry = config.android_sdks.find(artifact.android_sdk.value()); |
| 264 | if (entry == config.android_sdks.end()) { |
Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 265 | src_diag.Error(android::DiagMessage() << "Could not lookup required Android SDK version: " |
| 266 | << artifact.android_sdk.value()); |
Shane Farmer | cb6c3f9 | 2017-11-27 13:19:36 -0800 | [diff] [blame] | 267 | has_errors = true; |
| 268 | } else { |
| 269 | output_artifact.android_sdk = {entry->second}; |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | if (has_errors) { |
| 274 | return {}; |
| 275 | } |
| 276 | return {output_artifact}; |
| 277 | } |
| 278 | |
| 279 | } // namespace |
| 280 | |
| 281 | namespace configuration { |
| 282 | |
Shane Farmer | 78c43d7 | 2017-12-04 09:08:38 -0800 | [diff] [blame] | 283 | /** Returns the binary reprasentation of the XML configuration. */ |
Ryan Mitchell | 4382e44 | 2021-07-14 12:53:01 -0700 | [diff] [blame] | 284 | std::optional<PostProcessingConfiguration> ExtractConfiguration(const std::string& contents, |
| 285 | const std::string& config_path, |
Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 286 | android::IDiagnostics* diag) { |
Shane Farmer | 78c43d7 | 2017-12-04 09:08:38 -0800 | [diff] [blame] | 287 | StringInputStream in(contents); |
Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 288 | std::unique_ptr<xml::XmlResource> doc = xml::Inflate(&in, diag, android::Source(config_path)); |
Shane Farmer | 78c43d7 | 2017-12-04 09:08:38 -0800 | [diff] [blame] | 289 | if (!doc) { |
| 290 | return {}; |
| 291 | } |
| 292 | |
| 293 | // Strip any namespaces from the XML as the XmlActionExecutor ignores anything with a namespace. |
| 294 | Element* root = doc->root.get(); |
| 295 | if (root == nullptr) { |
Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 296 | diag->Error(android::DiagMessage() << "Could not find the root element in the XML document"); |
Shane Farmer | 78c43d7 | 2017-12-04 09:08:38 -0800 | [diff] [blame] | 297 | return {}; |
| 298 | } |
| 299 | |
| 300 | std::string& xml_ns = root->namespace_uri; |
| 301 | if (!xml_ns.empty()) { |
| 302 | if (xml_ns != kAaptXmlNs) { |
Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 303 | diag->Error(android::DiagMessage() << "Unknown namespace found on root element: " << xml_ns); |
Shane Farmer | 78c43d7 | 2017-12-04 09:08:38 -0800 | [diff] [blame] | 304 | return {}; |
| 305 | } |
| 306 | |
| 307 | xml_ns.clear(); |
| 308 | NamespaceVisitor visitor; |
| 309 | root->Accept(&visitor); |
| 310 | } |
| 311 | |
| 312 | XmlActionExecutor executor; |
| 313 | XmlNodeAction& root_action = executor["post-process"]; |
| 314 | XmlNodeAction& artifacts_action = root_action["artifacts"]; |
| 315 | |
| 316 | PostProcessingConfiguration config; |
| 317 | |
| 318 | // Parse the artifact elements. |
| 319 | artifacts_action["artifact"].Action(Bind(&config, ArtifactTagHandler)); |
| 320 | artifacts_action["artifact-format"].Action(Bind(&config, ArtifactFormatTagHandler)); |
| 321 | |
| 322 | // Parse the different configuration groups. |
| 323 | root_action["abi-groups"]["abi-group"].Action(Bind(&config, AbiGroupTagHandler)); |
| 324 | root_action["screen-density-groups"]["screen-density-group"].Action( |
| 325 | Bind(&config, ScreenDensityGroupTagHandler)); |
| 326 | root_action["locale-groups"]["locale-group"].Action(Bind(&config, LocaleGroupTagHandler)); |
| 327 | root_action["android-sdks"]["android-sdk"].Action(Bind(&config, AndroidSdkTagHandler)); |
| 328 | root_action["gl-texture-groups"]["gl-texture-group"].Action( |
| 329 | Bind(&config, GlTextureGroupTagHandler)); |
| 330 | root_action["device-feature-groups"]["device-feature-group"].Action( |
| 331 | Bind(&config, DeviceFeatureGroupTagHandler)); |
| 332 | |
| 333 | if (!executor.Execute(XmlActionExecutorPolicy::kNone, diag, doc.get())) { |
Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 334 | diag->Error(android::DiagMessage() << "Could not process XML document"); |
Shane Farmer | 78c43d7 | 2017-12-04 09:08:38 -0800 | [diff] [blame] | 335 | return {}; |
| 336 | } |
| 337 | |
| 338 | return {config}; |
| 339 | } |
| 340 | |
Yurii Zubrytskyi | a577514 | 2022-11-02 17:49:49 -0700 | [diff] [blame] | 341 | StringPiece AbiToString(Abi abi) { |
Shane Farmer | cb6c3f9 | 2017-11-27 13:19:36 -0800 | [diff] [blame] | 342 | return kAbiToStringMap.at(static_cast<size_t>(abi)); |
| 343 | } |
| 344 | |
| 345 | /** |
Shane Farmer | 9ecc075 | 2017-08-24 15:55:36 -0700 | [diff] [blame] | 346 | * Returns the common artifact base name from a template string. |
| 347 | */ |
Yurii Zubrytskyi | a577514 | 2022-11-02 17:49:49 -0700 | [diff] [blame] | 348 | std::optional<std::string> ToBaseName(std::string result, StringPiece apk_name, |
Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 349 | android::IDiagnostics* diag) { |
Shane Farmer | 9ecc075 | 2017-08-24 15:55:36 -0700 | [diff] [blame] | 350 | const StringPiece ext = file::GetExtension(apk_name); |
Yurii Zubrytskyi | a577514 | 2022-11-02 17:49:49 -0700 | [diff] [blame] | 351 | size_t end_index = apk_name.rfind(ext); |
Shane Farmer | 9ecc075 | 2017-08-24 15:55:36 -0700 | [diff] [blame] | 352 | const std::string base_name = |
| 353 | (end_index != std::string::npos) ? std::string{apk_name.begin(), end_index} : ""; |
Shane Farmer | 9f0e7f1 | 2017-06-22 12:26:44 -0700 | [diff] [blame] | 354 | |
Shane Farmer | 9ecc075 | 2017-08-24 15:55:36 -0700 | [diff] [blame] | 355 | // Base name is optional. |
| 356 | if (result.find("${basename}") != std::string::npos) { |
Ryan Mitchell | 4382e44 | 2021-07-14 12:53:01 -0700 | [diff] [blame] | 357 | auto maybe_base_name = base_name.empty() ? std::nullopt |
| 358 | : std::optional<StringPiece>{base_name}; |
Shane Farmer | 9ecc075 | 2017-08-24 15:55:36 -0700 | [diff] [blame] | 359 | if (!ReplacePlaceholder("${basename}", maybe_base_name, &result, diag)) { |
| 360 | return {}; |
| 361 | } |
Shane Farmer | 9f0e7f1 | 2017-06-22 12:26:44 -0700 | [diff] [blame] | 362 | } |
| 363 | |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 364 | // Extension is optional. |
| 365 | if (result.find("${ext}") != std::string::npos) { |
Shane Farmer | 9ecc075 | 2017-08-24 15:55:36 -0700 | [diff] [blame] | 366 | // Make sure we disregard the '.' in the extension when replacing the placeholder. |
| 367 | if (!ReplacePlaceholder("${ext}", {ext.substr(1)}, &result, diag)) { |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 368 | return {}; |
| 369 | } |
Shane Farmer | 9ecc075 | 2017-08-24 15:55:36 -0700 | [diff] [blame] | 370 | } else { |
| 371 | // If no extension is specified, and the name template does not end in the current extension, |
| 372 | // add the existing extension. |
| 373 | if (!util::EndsWith(result, ext)) { |
Yurii Zubrytskyi | a577514 | 2022-11-02 17:49:49 -0700 | [diff] [blame] | 374 | result.append(ext); |
Shane Farmer | 9ecc075 | 2017-08-24 15:55:36 -0700 | [diff] [blame] | 375 | } |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 376 | } |
| 377 | |
Shane Farmer | 9ecc075 | 2017-08-24 15:55:36 -0700 | [diff] [blame] | 378 | return result; |
| 379 | } |
| 380 | |
Yurii Zubrytskyi | a577514 | 2022-11-02 17:49:49 -0700 | [diff] [blame] | 381 | std::optional<std::string> ConfiguredArtifact::ToArtifactName(StringPiece format, |
| 382 | StringPiece apk_name, |
Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 383 | android::IDiagnostics* diag) const { |
Yurii Zubrytskyi | a577514 | 2022-11-02 17:49:49 -0700 | [diff] [blame] | 384 | std::optional<std::string> base = ToBaseName(std::string(format), apk_name, diag); |
Shane Farmer | 9ecc075 | 2017-08-24 15:55:36 -0700 | [diff] [blame] | 385 | if (!base) { |
| 386 | return {}; |
| 387 | } |
| 388 | std::string result = std::move(base.value()); |
| 389 | |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 390 | if (!ReplacePlaceholder("${abi}", abi_group, &result, diag)) { |
Shane Farmer | 9f0e7f1 | 2017-06-22 12:26:44 -0700 | [diff] [blame] | 391 | return {}; |
| 392 | } |
| 393 | |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 394 | if (!ReplacePlaceholder("${density}", screen_density_group, &result, diag)) { |
Shane Farmer | 9f0e7f1 | 2017-06-22 12:26:44 -0700 | [diff] [blame] | 395 | return {}; |
| 396 | } |
| 397 | |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 398 | if (!ReplacePlaceholder("${locale}", locale_group, &result, diag)) { |
Shane Farmer | 9f0e7f1 | 2017-06-22 12:26:44 -0700 | [diff] [blame] | 399 | return {}; |
| 400 | } |
| 401 | |
Shane Farmer | 78c43d7 | 2017-12-04 09:08:38 -0800 | [diff] [blame] | 402 | if (!ReplacePlaceholder("${sdk}", android_sdk, &result, diag)) { |
Shane Farmer | 9f0e7f1 | 2017-06-22 12:26:44 -0700 | [diff] [blame] | 403 | return {}; |
| 404 | } |
| 405 | |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 406 | if (!ReplacePlaceholder("${feature}", device_feature_group, &result, diag)) { |
Shane Farmer | 9f0e7f1 | 2017-06-22 12:26:44 -0700 | [diff] [blame] | 407 | return {}; |
| 408 | } |
| 409 | |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 410 | if (!ReplacePlaceholder("${gl}", gl_texture_group, &result, diag)) { |
| 411 | return {}; |
| 412 | } |
| 413 | |
| 414 | return result; |
| 415 | } |
| 416 | |
Yurii Zubrytskyi | a577514 | 2022-11-02 17:49:49 -0700 | [diff] [blame] | 417 | std::optional<std::string> ConfiguredArtifact::Name(StringPiece apk_name, |
Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 418 | android::IDiagnostics* diag) const { |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 419 | if (!name) { |
| 420 | return {}; |
| 421 | } |
| 422 | |
Shane Farmer | 9ecc075 | 2017-08-24 15:55:36 -0700 | [diff] [blame] | 423 | return ToBaseName(name.value(), apk_name, diag); |
| 424 | } |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 425 | |
Shane Farmer | 5766943 | 2017-06-19 12:52:04 -0700 | [diff] [blame] | 426 | } // namespace configuration |
Shane Farmer | b102727 | 2017-06-14 09:10:28 -0700 | [diff] [blame] | 427 | |
| 428 | /** Returns a ConfigurationParser for the file located at the provided path. */ |
Ryan Mitchell | 4382e44 | 2021-07-14 12:53:01 -0700 | [diff] [blame] | 429 | std::optional<ConfigurationParser> ConfigurationParser::ForPath(const std::string& path) { |
Shane Farmer | b102727 | 2017-06-14 09:10:28 -0700 | [diff] [blame] | 430 | std::string contents; |
| 431 | if (!ReadFileToString(path, &contents, true)) { |
| 432 | return {}; |
| 433 | } |
Shane Farmer | 78c43d7 | 2017-12-04 09:08:38 -0800 | [diff] [blame] | 434 | return ConfigurationParser(contents, path); |
Shane Farmer | b102727 | 2017-06-14 09:10:28 -0700 | [diff] [blame] | 435 | } |
| 436 | |
Shane Farmer | 78c43d7 | 2017-12-04 09:08:38 -0800 | [diff] [blame] | 437 | ConfigurationParser::ConfigurationParser(std::string contents, const std::string& config_path) |
| 438 | : contents_(std::move(contents)), config_path_(config_path), diag_(&noop_) { |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 439 | } |
| 440 | |
Ryan Mitchell | 4382e44 | 2021-07-14 12:53:01 -0700 | [diff] [blame] | 441 | std::optional<std::vector<OutputArtifact>> ConfigurationParser::Parse( |
Yurii Zubrytskyi | a577514 | 2022-11-02 17:49:49 -0700 | [diff] [blame] | 442 | android::StringPiece apk_path) { |
Ryan Mitchell | 4382e44 | 2021-07-14 12:53:01 -0700 | [diff] [blame] | 443 | std::optional<PostProcessingConfiguration> maybe_config = |
Shane Farmer | 78c43d7 | 2017-12-04 09:08:38 -0800 | [diff] [blame] | 444 | ExtractConfiguration(contents_, config_path_, diag_); |
Shane Farmer | cb6c3f9 | 2017-11-27 13:19:36 -0800 | [diff] [blame] | 445 | if (!maybe_config) { |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 446 | return {}; |
| 447 | } |
Shane Farmer | cb6c3f9 | 2017-11-27 13:19:36 -0800 | [diff] [blame] | 448 | |
| 449 | // Convert from a parsed configuration to a list of artifacts for processing. |
Yurii Zubrytskyi | a577514 | 2022-11-02 17:49:49 -0700 | [diff] [blame] | 450 | const std::string apk_name(file::GetFilename(apk_path)); |
Shane Farmer | cb6c3f9 | 2017-11-27 13:19:36 -0800 | [diff] [blame] | 451 | std::vector<OutputArtifact> output_artifacts; |
Shane Farmer | cb6c3f9 | 2017-11-27 13:19:36 -0800 | [diff] [blame] | 452 | |
Shane Farmer | 78c43d7 | 2017-12-04 09:08:38 -0800 | [diff] [blame] | 453 | PostProcessingConfiguration& config = maybe_config.value(); |
Shane Farmer | 78c43d7 | 2017-12-04 09:08:38 -0800 | [diff] [blame] | 454 | |
Shane Farmer | 11cdc1c | 2018-01-31 16:43:24 -0800 | [diff] [blame] | 455 | bool valid = true; |
Shane Farmer | 78c43d7 | 2017-12-04 09:08:38 -0800 | [diff] [blame] | 456 | int version = 1; |
Shane Farmer | 11cdc1c | 2018-01-31 16:43:24 -0800 | [diff] [blame] | 457 | |
Shane Farmer | 78c43d7 | 2017-12-04 09:08:38 -0800 | [diff] [blame] | 458 | for (const ConfiguredArtifact& artifact : config.artifacts) { |
Ryan Mitchell | 4382e44 | 2021-07-14 12:53:01 -0700 | [diff] [blame] | 459 | std::optional<OutputArtifact> output_artifact = |
| 460 | ToOutputArtifact(artifact, apk_name, config, diag_); |
Shane Farmer | cb6c3f9 | 2017-11-27 13:19:36 -0800 | [diff] [blame] | 461 | if (!output_artifact) { |
| 462 | // Defer return an error condition so that all errors are reported. |
Shane Farmer | 11cdc1c | 2018-01-31 16:43:24 -0800 | [diff] [blame] | 463 | valid = false; |
Shane Farmer | cb6c3f9 | 2017-11-27 13:19:36 -0800 | [diff] [blame] | 464 | } else { |
Shane Farmer | 78c43d7 | 2017-12-04 09:08:38 -0800 | [diff] [blame] | 465 | output_artifact.value().version = version++; |
Shane Farmer | cb6c3f9 | 2017-11-27 13:19:36 -0800 | [diff] [blame] | 466 | output_artifacts.push_back(std::move(output_artifact.value())); |
| 467 | } |
| 468 | } |
| 469 | |
Shane Farmer | 11cdc1c | 2018-01-31 16:43:24 -0800 | [diff] [blame] | 470 | if (!config.ValidateVersionCodeOrdering(diag_)) { |
Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 471 | diag_->Error(android::DiagMessage() << "could not validate post processing configuration"); |
Shane Farmer | 11cdc1c | 2018-01-31 16:43:24 -0800 | [diff] [blame] | 472 | valid = false; |
| 473 | } |
| 474 | |
| 475 | if (valid) { |
| 476 | // Sorting artifacts requires that all references are valid as it uses them to determine order. |
| 477 | config.SortArtifacts(); |
| 478 | } |
| 479 | |
| 480 | if (!valid) { |
Shane Farmer | cb6c3f9 | 2017-11-27 13:19:36 -0800 | [diff] [blame] | 481 | return {}; |
| 482 | } |
Shane Farmer | 11cdc1c | 2018-01-31 16:43:24 -0800 | [diff] [blame] | 483 | |
Shane Farmer | cb6c3f9 | 2017-11-27 13:19:36 -0800 | [diff] [blame] | 484 | return {output_artifacts}; |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 485 | } |
| 486 | |
Shane Farmer | cb6c3f9 | 2017-11-27 13:19:36 -0800 | [diff] [blame] | 487 | namespace configuration { |
| 488 | namespace handler { |
| 489 | |
| 490 | bool ArtifactTagHandler(PostProcessingConfiguration* config, Element* root_element, |
Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 491 | android::IDiagnostics* diag) { |
Shane Farmer | cb6c3f9 | 2017-11-27 13:19:36 -0800 | [diff] [blame] | 492 | ConfiguredArtifact artifact{}; |
Shane Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 493 | for (const auto& attr : root_element->attributes) { |
| 494 | if (attr.name == "name") { |
| 495 | artifact.name = attr.value; |
| 496 | } else if (attr.name == "abi-group") { |
| 497 | artifact.abi_group = {attr.value}; |
| 498 | } else if (attr.name == "screen-density-group") { |
| 499 | artifact.screen_density_group = {attr.value}; |
| 500 | } else if (attr.name == "locale-group") { |
| 501 | artifact.locale_group = {attr.value}; |
Shane Farmer | 78c43d7 | 2017-12-04 09:08:38 -0800 | [diff] [blame] | 502 | } else if (attr.name == "android-sdk") { |
| 503 | artifact.android_sdk = {attr.value}; |
Shane Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 504 | } else if (attr.name == "gl-texture-group") { |
| 505 | artifact.gl_texture_group = {attr.value}; |
| 506 | } else if (attr.name == "device-feature-group") { |
| 507 | artifact.device_feature_group = {attr.value}; |
| 508 | } else { |
Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 509 | diag->Note(android::DiagMessage() |
| 510 | << "Unknown artifact attribute: " << attr.name << " = " << attr.value); |
Shane Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 511 | } |
| 512 | } |
| 513 | config->artifacts.push_back(artifact); |
| 514 | return true; |
| 515 | }; |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 516 | |
Shane Farmer | cb6c3f9 | 2017-11-27 13:19:36 -0800 | [diff] [blame] | 517 | bool ArtifactFormatTagHandler(PostProcessingConfiguration* config, Element* root_element, |
Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 518 | android::IDiagnostics* /* diag */) { |
Shane Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 519 | for (auto& node : root_element->children) { |
| 520 | xml::Text* t; |
| 521 | if ((t = NodeCast<xml::Text>(node.get())) != nullptr) { |
Yurii Zubrytskyi | a577514 | 2022-11-02 17:49:49 -0700 | [diff] [blame] | 522 | config->artifact_format.emplace(TrimWhitespace(t->text)); |
Shane Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 523 | break; |
| 524 | } |
| 525 | } |
| 526 | return true; |
| 527 | }; |
| 528 | |
Shane Farmer | cb6c3f9 | 2017-11-27 13:19:36 -0800 | [diff] [blame] | 529 | bool AbiGroupTagHandler(PostProcessingConfiguration* config, Element* root_element, |
Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 530 | android::IDiagnostics* diag) { |
Shane Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 531 | std::string label = GetLabel(root_element, diag); |
| 532 | if (label.empty()) { |
| 533 | return false; |
| 534 | } |
| 535 | |
Shane Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 536 | bool valid = true; |
Shane Farmer | 11cdc1c | 2018-01-31 16:43:24 -0800 | [diff] [blame] | 537 | OrderedEntry<Abi>& entry = config->abi_groups[label]; |
Ryan Mitchell | 4382e44 | 2021-07-14 12:53:01 -0700 | [diff] [blame] | 538 | std::optional<int32_t> order = GetVersionCodeOrder(root_element, diag); |
Shane Farmer | 11cdc1c | 2018-01-31 16:43:24 -0800 | [diff] [blame] | 539 | if (!order) { |
| 540 | valid = false; |
| 541 | } else { |
| 542 | entry.order = order.value(); |
| 543 | } |
| 544 | auto& group = entry.entry; |
Shane Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 545 | |
Shane Farmer | 39e474f | 2017-12-18 14:44:11 -0800 | [diff] [blame] | 546 | // Special case for empty abi-group tag. Label will be used as the ABI. |
| 547 | if (root_element->GetChildElements().empty()) { |
| 548 | auto abi = kStringToAbiMap.find(label); |
| 549 | if (abi == kStringToAbiMap.end()) { |
| 550 | return false; |
| 551 | } |
| 552 | group.push_back(abi->second); |
Shane Farmer | 11cdc1c | 2018-01-31 16:43:24 -0800 | [diff] [blame] | 553 | return valid; |
Shane Farmer | 39e474f | 2017-12-18 14:44:11 -0800 | [diff] [blame] | 554 | } |
| 555 | |
Shane Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 556 | for (auto* child : root_element->GetChildElements()) { |
| 557 | if (child->name != "abi") { |
Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 558 | diag->Error(android::DiagMessage() << "Unexpected element in ABI group: " << child->name); |
Shane Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 559 | valid = false; |
| 560 | } else { |
| 561 | for (auto& node : child->children) { |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 562 | xml::Text* t; |
| 563 | if ((t = NodeCast<xml::Text>(node.get())) != nullptr) { |
Yurii Zubrytskyi | a577514 | 2022-11-02 17:49:49 -0700 | [diff] [blame] | 564 | auto abi = kStringToAbiMap.find(TrimWhitespace(t->text)); |
Shane Farmer | 39e474f | 2017-12-18 14:44:11 -0800 | [diff] [blame] | 565 | if (abi != kStringToAbiMap.end()) { |
| 566 | group.push_back(abi->second); |
| 567 | } else { |
Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 568 | diag->Error(android::DiagMessage() << "Could not parse ABI value: " << t->text); |
Shane Farmer | 39e474f | 2017-12-18 14:44:11 -0800 | [diff] [blame] | 569 | valid = false; |
| 570 | } |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 571 | break; |
| 572 | } |
| 573 | } |
Shane Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 574 | } |
| 575 | } |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 576 | |
Shane Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 577 | return valid; |
| 578 | }; |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 579 | |
Shane Farmer | cb6c3f9 | 2017-11-27 13:19:36 -0800 | [diff] [blame] | 580 | bool ScreenDensityGroupTagHandler(PostProcessingConfiguration* config, Element* root_element, |
Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 581 | android::IDiagnostics* diag) { |
Shane Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 582 | std::string label = GetLabel(root_element, diag); |
| 583 | if (label.empty()) { |
| 584 | return false; |
| 585 | } |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 586 | |
Shane Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 587 | bool valid = true; |
Shane Farmer | 11cdc1c | 2018-01-31 16:43:24 -0800 | [diff] [blame] | 588 | OrderedEntry<ConfigDescription>& entry = config->screen_density_groups[label]; |
Ryan Mitchell | 4382e44 | 2021-07-14 12:53:01 -0700 | [diff] [blame] | 589 | std::optional<int32_t> order = GetVersionCodeOrder(root_element, diag); |
Shane Farmer | 11cdc1c | 2018-01-31 16:43:24 -0800 | [diff] [blame] | 590 | if (!order) { |
| 591 | valid = false; |
| 592 | } else { |
| 593 | entry.order = order.value(); |
| 594 | } |
| 595 | auto& group = entry.entry; |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 596 | |
Shane Farmer | 39e474f | 2017-12-18 14:44:11 -0800 | [diff] [blame] | 597 | // Special case for empty screen-density-group tag. Label will be used as the screen density. |
| 598 | if (root_element->GetChildElements().empty()) { |
| 599 | ConfigDescription config_descriptor; |
| 600 | bool parsed = ConfigDescription::Parse(label, &config_descriptor); |
| 601 | if (parsed && |
| 602 | (config_descriptor.CopyWithoutSdkVersion().diff(ConfigDescription::DefaultConfig()) == |
| 603 | android::ResTable_config::CONFIG_DENSITY)) { |
| 604 | // Copy the density with the minimum SDK version stripped out. |
| 605 | group.push_back(config_descriptor.CopyWithoutSdkVersion()); |
| 606 | } else { |
Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 607 | diag->Error(android::DiagMessage() |
| 608 | << "Could not parse config descriptor for empty screen-density-group: " << label); |
Shane Farmer | 39e474f | 2017-12-18 14:44:11 -0800 | [diff] [blame] | 609 | valid = false; |
| 610 | } |
| 611 | |
| 612 | return valid; |
| 613 | } |
| 614 | |
Shane Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 615 | for (auto* child : root_element->GetChildElements()) { |
| 616 | if (child->name != "screen-density") { |
Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 617 | diag->Error(android::DiagMessage() |
| 618 | << "Unexpected root_element in screen density group: " << child->name); |
Shane Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 619 | valid = false; |
| 620 | } else { |
| 621 | for (auto& node : child->children) { |
| 622 | xml::Text* t; |
| 623 | if ((t = NodeCast<xml::Text>(node.get())) != nullptr) { |
| 624 | ConfigDescription config_descriptor; |
Yurii Zubrytskyi | a577514 | 2022-11-02 17:49:49 -0700 | [diff] [blame] | 625 | android::StringPiece text = TrimWhitespace(t->text); |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 626 | bool parsed = ConfigDescription::Parse(text, &config_descriptor); |
| 627 | if (parsed && |
| 628 | (config_descriptor.CopyWithoutSdkVersion().diff(ConfigDescription::DefaultConfig()) == |
| 629 | android::ResTable_config::CONFIG_DENSITY)) { |
Shane Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 630 | // Copy the density with the minimum SDK version stripped out. |
| 631 | group.push_back(config_descriptor.CopyWithoutSdkVersion()); |
| 632 | } else { |
Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 633 | diag->Error(android::DiagMessage() |
Shane Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 634 | << "Could not parse config descriptor for screen-density: " << text); |
| 635 | valid = false; |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 636 | } |
Shane Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 637 | break; |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 638 | } |
| 639 | } |
Shane Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 640 | } |
| 641 | } |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 642 | |
Shane Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 643 | return valid; |
| 644 | }; |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 645 | |
Shane Farmer | cb6c3f9 | 2017-11-27 13:19:36 -0800 | [diff] [blame] | 646 | bool LocaleGroupTagHandler(PostProcessingConfiguration* config, Element* root_element, |
Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 647 | android::IDiagnostics* diag) { |
Shane Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 648 | std::string label = GetLabel(root_element, diag); |
| 649 | if (label.empty()) { |
| 650 | return false; |
| 651 | } |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 652 | |
Shane Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 653 | bool valid = true; |
Shane Farmer | 11cdc1c | 2018-01-31 16:43:24 -0800 | [diff] [blame] | 654 | OrderedEntry<ConfigDescription>& entry = config->locale_groups[label]; |
Ryan Mitchell | 4382e44 | 2021-07-14 12:53:01 -0700 | [diff] [blame] | 655 | std::optional<int32_t> order = GetVersionCodeOrder(root_element, diag); |
Shane Farmer | 11cdc1c | 2018-01-31 16:43:24 -0800 | [diff] [blame] | 656 | if (!order) { |
| 657 | valid = false; |
| 658 | } else { |
| 659 | entry.order = order.value(); |
| 660 | } |
| 661 | auto& group = entry.entry; |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 662 | |
Shane Farmer | 39e474f | 2017-12-18 14:44:11 -0800 | [diff] [blame] | 663 | // Special case to auto insert a locale for an empty group. Label will be used for locale. |
| 664 | if (root_element->GetChildElements().empty()) { |
| 665 | ConfigDescription config_descriptor; |
| 666 | bool parsed = ConfigDescription::Parse(label, &config_descriptor); |
| 667 | if (parsed && |
| 668 | (config_descriptor.CopyWithoutSdkVersion().diff(ConfigDescription::DefaultConfig()) == |
| 669 | android::ResTable_config::CONFIG_LOCALE)) { |
| 670 | // Copy the locale with the minimum SDK version stripped out. |
| 671 | group.push_back(config_descriptor.CopyWithoutSdkVersion()); |
| 672 | } else { |
Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 673 | diag->Error(android::DiagMessage() |
| 674 | << "Could not parse config descriptor for empty screen-density-group: " << label); |
Shane Farmer | 39e474f | 2017-12-18 14:44:11 -0800 | [diff] [blame] | 675 | valid = false; |
| 676 | } |
| 677 | |
| 678 | return valid; |
| 679 | } |
| 680 | |
Shane Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 681 | for (auto* child : root_element->GetChildElements()) { |
| 682 | if (child->name != "locale") { |
Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 683 | diag->Error(android::DiagMessage() |
| 684 | << "Unexpected root_element in screen density group: " << child->name); |
Shane Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 685 | valid = false; |
| 686 | } else { |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 687 | for (auto& node : child->children) { |
| 688 | xml::Text* t; |
| 689 | if ((t = NodeCast<xml::Text>(node.get())) != nullptr) { |
| 690 | ConfigDescription config_descriptor; |
Yurii Zubrytskyi | a577514 | 2022-11-02 17:49:49 -0700 | [diff] [blame] | 691 | android::StringPiece text = TrimWhitespace(t->text); |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 692 | bool parsed = ConfigDescription::Parse(text, &config_descriptor); |
| 693 | if (parsed && |
| 694 | (config_descriptor.CopyWithoutSdkVersion().diff(ConfigDescription::DefaultConfig()) == |
| 695 | android::ResTable_config::CONFIG_LOCALE)) { |
| 696 | // Copy the locale with the minimum SDK version stripped out. |
| 697 | group.push_back(config_descriptor.CopyWithoutSdkVersion()); |
| 698 | } else { |
Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 699 | diag->Error(android::DiagMessage() |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 700 | << "Could not parse config descriptor for screen-density: " << text); |
| 701 | valid = false; |
| 702 | } |
| 703 | break; |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 704 | } |
| 705 | } |
Shane Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 706 | } |
| 707 | } |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 708 | |
Shane Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 709 | return valid; |
| 710 | }; |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 711 | |
Shane Farmer | 78c43d7 | 2017-12-04 09:08:38 -0800 | [diff] [blame] | 712 | bool AndroidSdkTagHandler(PostProcessingConfiguration* config, Element* root_element, |
Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 713 | android::IDiagnostics* diag) { |
Shane Farmer | 78c43d7 | 2017-12-04 09:08:38 -0800 | [diff] [blame] | 714 | AndroidSdk entry = AndroidSdk::ForMinSdk(-1); |
Shane Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 715 | bool valid = true; |
Shane Farmer | 78c43d7 | 2017-12-04 09:08:38 -0800 | [diff] [blame] | 716 | for (const auto& attr : root_element->attributes) { |
| 717 | bool valid_attr = false; |
| 718 | if (attr.name == "label") { |
| 719 | entry.label = attr.value; |
| 720 | valid_attr = true; |
| 721 | } else if (attr.name == "minSdkVersion") { |
Ryan Mitchell | 4382e44 | 2021-07-14 12:53:01 -0700 | [diff] [blame] | 722 | std::optional<int> version = ResourceUtils::ParseSdkVersion(attr.value); |
Shane Farmer | 78c43d7 | 2017-12-04 09:08:38 -0800 | [diff] [blame] | 723 | if (version) { |
| 724 | valid_attr = true; |
| 725 | entry.min_sdk_version = version.value(); |
| 726 | } |
| 727 | } else if (attr.name == "targetSdkVersion") { |
Ryan Mitchell | 4382e44 | 2021-07-14 12:53:01 -0700 | [diff] [blame] | 728 | std::optional<int> version = ResourceUtils::ParseSdkVersion(attr.value); |
Shane Farmer | 78c43d7 | 2017-12-04 09:08:38 -0800 | [diff] [blame] | 729 | if (version) { |
| 730 | valid_attr = true; |
| 731 | entry.target_sdk_version = version; |
| 732 | } |
| 733 | } else if (attr.name == "maxSdkVersion") { |
Ryan Mitchell | 4382e44 | 2021-07-14 12:53:01 -0700 | [diff] [blame] | 734 | std::optional<int> version = ResourceUtils::ParseSdkVersion(attr.value); |
Shane Farmer | 78c43d7 | 2017-12-04 09:08:38 -0800 | [diff] [blame] | 735 | if (version) { |
| 736 | valid_attr = true; |
| 737 | entry.max_sdk_version = version; |
| 738 | } |
| 739 | } |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 740 | |
Shane Farmer | 78c43d7 | 2017-12-04 09:08:38 -0800 | [diff] [blame] | 741 | if (!valid_attr) { |
Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 742 | diag->Error(android::DiagMessage() |
| 743 | << "Invalid attribute: " << attr.name << " = " << attr.value); |
Shane Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 744 | valid = false; |
Shane Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 745 | } |
| 746 | } |
| 747 | |
Shane Farmer | 78c43d7 | 2017-12-04 09:08:38 -0800 | [diff] [blame] | 748 | if (entry.min_sdk_version == -1) { |
Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 749 | diag->Error(android::DiagMessage() << "android-sdk is missing minSdkVersion attribute"); |
Shane Farmer | 78c43d7 | 2017-12-04 09:08:38 -0800 | [diff] [blame] | 750 | valid = false; |
| 751 | } |
| 752 | |
| 753 | // TODO: Fill in the manifest details when they are finalised. |
| 754 | for (auto node : root_element->GetChildElements()) { |
| 755 | if (node->name == "manifest") { |
| 756 | if (entry.manifest) { |
Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 757 | diag->Warn(android::DiagMessage() << "Found multiple manifest tags. Ignoring duplicates."); |
Shane Farmer | 78c43d7 | 2017-12-04 09:08:38 -0800 | [diff] [blame] | 758 | continue; |
| 759 | } |
| 760 | entry.manifest = {AndroidManifest()}; |
| 761 | } |
| 762 | } |
| 763 | |
| 764 | config->android_sdks[entry.label] = entry; |
Shane Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 765 | return valid; |
| 766 | }; |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 767 | |
Shane Farmer | cb6c3f9 | 2017-11-27 13:19:36 -0800 | [diff] [blame] | 768 | bool GlTextureGroupTagHandler(PostProcessingConfiguration* config, Element* root_element, |
Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 769 | android::IDiagnostics* diag) { |
Shane Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 770 | std::string label = GetLabel(root_element, diag); |
| 771 | if (label.empty()) { |
| 772 | return false; |
| 773 | } |
| 774 | |
Shane Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 775 | bool valid = true; |
Shane Farmer | 11cdc1c | 2018-01-31 16:43:24 -0800 | [diff] [blame] | 776 | OrderedEntry<GlTexture>& entry = config->gl_texture_groups[label]; |
Ryan Mitchell | 4382e44 | 2021-07-14 12:53:01 -0700 | [diff] [blame] | 777 | std::optional<int32_t> order = GetVersionCodeOrder(root_element, diag); |
Shane Farmer | 11cdc1c | 2018-01-31 16:43:24 -0800 | [diff] [blame] | 778 | if (!order) { |
| 779 | valid = false; |
| 780 | } else { |
| 781 | entry.order = order.value(); |
| 782 | } |
| 783 | auto& group = entry.entry; |
Shane Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 784 | |
| 785 | GlTexture result; |
| 786 | for (auto* child : root_element->GetChildElements()) { |
| 787 | if (child->name != "gl-texture") { |
Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 788 | diag->Error(android::DiagMessage() |
| 789 | << "Unexpected element in GL texture group: " << child->name); |
Shane Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 790 | valid = false; |
| 791 | } else { |
| 792 | for (const auto& attr : child->attributes) { |
| 793 | if (attr.name == "name") { |
| 794 | result.name = attr.value; |
| 795 | break; |
| 796 | } |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 797 | } |
| 798 | |
Shane Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 799 | for (auto* element : child->GetChildElements()) { |
| 800 | if (element->name != "texture-path") { |
Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 801 | diag->Error(android::DiagMessage() |
| 802 | << "Unexpected element in gl-texture element: " << child->name); |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 803 | valid = false; |
Shane Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 804 | continue; |
| 805 | } |
| 806 | for (auto& node : element->children) { |
| 807 | xml::Text* t; |
| 808 | if ((t = NodeCast<xml::Text>(node.get())) != nullptr) { |
Yurii Zubrytskyi | a577514 | 2022-11-02 17:49:49 -0700 | [diff] [blame] | 809 | result.texture_paths.emplace_back(TrimWhitespace(t->text)); |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 810 | } |
| 811 | } |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 812 | } |
Shane Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 813 | } |
| 814 | group.push_back(result); |
| 815 | } |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 816 | |
Shane Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 817 | return valid; |
| 818 | }; |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 819 | |
Shane Farmer | cb6c3f9 | 2017-11-27 13:19:36 -0800 | [diff] [blame] | 820 | bool DeviceFeatureGroupTagHandler(PostProcessingConfiguration* config, Element* root_element, |
Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 821 | android::IDiagnostics* diag) { |
Shane Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 822 | std::string label = GetLabel(root_element, diag); |
| 823 | if (label.empty()) { |
| 824 | return false; |
| 825 | } |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 826 | |
Shane Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 827 | bool valid = true; |
Shane Farmer | 11cdc1c | 2018-01-31 16:43:24 -0800 | [diff] [blame] | 828 | OrderedEntry<DeviceFeature>& entry = config->device_feature_groups[label]; |
Ryan Mitchell | 4382e44 | 2021-07-14 12:53:01 -0700 | [diff] [blame] | 829 | std::optional<int32_t> order = GetVersionCodeOrder(root_element, diag); |
Shane Farmer | 11cdc1c | 2018-01-31 16:43:24 -0800 | [diff] [blame] | 830 | if (!order) { |
| 831 | valid = false; |
| 832 | } else { |
| 833 | entry.order = order.value(); |
| 834 | } |
| 835 | auto& group = entry.entry; |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 836 | |
Shane Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 837 | for (auto* child : root_element->GetChildElements()) { |
| 838 | if (child->name != "supports-feature") { |
Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 839 | diag->Error(android::DiagMessage() |
| 840 | << "Unexpected root_element in device feature group: " << child->name); |
Shane Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 841 | valid = false; |
| 842 | } else { |
| 843 | for (auto& node : child->children) { |
| 844 | xml::Text* t; |
| 845 | if ((t = NodeCast<xml::Text>(node.get())) != nullptr) { |
Yurii Zubrytskyi | a577514 | 2022-11-02 17:49:49 -0700 | [diff] [blame] | 846 | group.emplace_back(TrimWhitespace(t->text)); |
Shane Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 847 | break; |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 848 | } |
| 849 | } |
Shane Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 850 | } |
| 851 | } |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 852 | |
Shane Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 853 | return valid; |
| 854 | }; |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 855 | |
Shane Farmer | cb6c3f9 | 2017-11-27 13:19:36 -0800 | [diff] [blame] | 856 | } // namespace handler |
| 857 | } // namespace configuration |
| 858 | |
Shane Farmer | 74cdea3 | 2017-05-12 16:22:36 -0700 | [diff] [blame] | 859 | } // namespace aapt |