Shane Farmer | cb6c3f9 | 2017-11-27 13:19:36 -0800 | [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 | #ifndef AAPT2_CONFIGURATIONPARSER_INTERNAL_H |
| 18 | #define AAPT2_CONFIGURATIONPARSER_INTERNAL_H |
| 19 | |
| 20 | namespace aapt { |
| 21 | namespace configuration { |
| 22 | |
| 23 | /** A mapping of group labels to group of configuration items. */ |
| 24 | template <class T> |
| 25 | using Group = std::unordered_map<std::string, std::vector<T>>; |
| 26 | |
| 27 | /** A mapping of group label to a single configuration item. */ |
| 28 | template <class T> |
| 29 | using Entry = std::unordered_map<std::string, T>; |
| 30 | |
| 31 | /** Output artifact configuration options. */ |
| 32 | struct ConfiguredArtifact { |
| 33 | /** Name to use for output of processing foo.apk -> foo.<name>.apk. */ |
| 34 | Maybe<std::string> name; |
| 35 | /** |
| 36 | * Value to add to the base Android manifest versionCode. If it is not present in the |
| 37 | * configuration file, it is set to the previous artifact + 1. If the first artifact does not have |
| 38 | * a value, artifacts are a 1 based index. |
| 39 | */ |
| 40 | int version; |
| 41 | /** If present, uses the ABI group with this name. */ |
| 42 | Maybe<std::string> abi_group; |
| 43 | /** If present, uses the screen density group with this name. */ |
| 44 | Maybe<std::string> screen_density_group; |
| 45 | /** If present, uses the locale group with this name. */ |
| 46 | Maybe<std::string> locale_group; |
| 47 | /** If present, uses the Android SDK group with this name. */ |
| 48 | Maybe<std::string> android_sdk_group; |
| 49 | /** If present, uses the device feature group with this name. */ |
| 50 | Maybe<std::string> device_feature_group; |
| 51 | /** If present, uses the OpenGL texture group with this name. */ |
| 52 | Maybe<std::string> gl_texture_group; |
| 53 | |
| 54 | /** Convert an artifact name template into a name string based on configuration contents. */ |
| 55 | Maybe<std::string> ToArtifactName(const android::StringPiece& format, |
| 56 | const android::StringPiece& apk_name, IDiagnostics* diag) const; |
| 57 | |
| 58 | /** Convert an artifact name template into a name string based on configuration contents. */ |
| 59 | Maybe<std::string> Name(const android::StringPiece& apk_name, IDiagnostics* diag) const; |
| 60 | |
| 61 | bool operator<(const ConfiguredArtifact& rhs) const { |
| 62 | // TODO(safarmer): Order by play store multi-APK requirements. |
| 63 | return version < rhs.version; |
| 64 | } |
| 65 | |
| 66 | bool operator==(const ConfiguredArtifact& rhs) const { |
| 67 | return version == rhs.version; |
| 68 | } |
| 69 | }; |
| 70 | |
| 71 | /** AAPT2 XML configuration file binary representation. */ |
| 72 | struct PostProcessingConfiguration { |
| 73 | // TODO: Support named artifacts? |
| 74 | std::vector<ConfiguredArtifact> artifacts; |
| 75 | Maybe<std::string> artifact_format; |
| 76 | |
| 77 | Group<Abi> abi_groups; |
| 78 | Group<ConfigDescription> screen_density_groups; |
| 79 | Group<ConfigDescription> locale_groups; |
| 80 | Entry<AndroidSdk> android_sdk_groups; |
| 81 | Group<DeviceFeature> device_feature_groups; |
| 82 | Group<GlTexture> gl_texture_groups; |
| 83 | }; |
| 84 | |
| 85 | namespace handler { |
| 86 | |
| 87 | /** Handler for <artifact> tags. */ |
| 88 | bool ArtifactTagHandler(configuration::PostProcessingConfiguration* config, xml::Element* element, |
| 89 | IDiagnostics* diag); |
| 90 | |
| 91 | /** Handler for <artifact-format> tags. */ |
| 92 | bool ArtifactFormatTagHandler(configuration::PostProcessingConfiguration* config, |
| 93 | xml::Element* element, IDiagnostics* diag); |
| 94 | |
| 95 | /** Handler for <abi-group> tags. */ |
| 96 | bool AbiGroupTagHandler(configuration::PostProcessingConfiguration* config, xml::Element* element, |
| 97 | IDiagnostics* diag); |
| 98 | |
| 99 | /** Handler for <screen-density-group> tags. */ |
| 100 | bool ScreenDensityGroupTagHandler(configuration::PostProcessingConfiguration* config, |
| 101 | xml::Element* element, IDiagnostics* diag); |
| 102 | |
| 103 | /** Handler for <locale-group> tags. */ |
| 104 | bool LocaleGroupTagHandler(configuration::PostProcessingConfiguration* config, |
| 105 | xml::Element* element, IDiagnostics* diag); |
| 106 | |
| 107 | /** Handler for <android-sdk-group> tags. */ |
| 108 | bool AndroidSdkGroupTagHandler(configuration::PostProcessingConfiguration* config, |
| 109 | xml::Element* element, IDiagnostics* diag); |
| 110 | |
| 111 | /** Handler for <gl-texture-group> tags. */ |
| 112 | bool GlTextureGroupTagHandler(configuration::PostProcessingConfiguration* config, |
| 113 | xml::Element* element, IDiagnostics* diag); |
| 114 | |
| 115 | /** Handler for <device-feature-group> tags. */ |
| 116 | bool DeviceFeatureGroupTagHandler(configuration::PostProcessingConfiguration* config, |
| 117 | xml::Element* element, IDiagnostics* diag); |
| 118 | |
| 119 | } // namespace handler |
| 120 | } // namespace configuration |
| 121 | } // namespace aapt |
| 122 | #endif // AAPT2_CONFIGURATIONPARSER_INTERNAL_H |