| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
#ifndef AAPT2_CONFIGURATION_H |
| 18 |
#define AAPT2_CONFIGURATION_H |
| 19 |
|
| 20 |
#include <optional> |
| 21 |
#include <set> |
| 22 |
#include <string> |
| 23 |
#include <unordered_map> |
| 24 |
#include <vector> |
| 25 |
|
| 26 |
#include "androidfw/ConfigDescription.h" |
| 27 |
|
| 28 |
#include "Diagnostics.h" |
| 29 |
|
| 30 |
namespace aapt { |
| 31 |
|
| 32 |
namespace configuration { |
| 33 |
|
| 34 |
|
| 35 |
enum class Abi { |
| 36 |
kArmeV6, |
| 37 |
kArmV7a, |
| 38 |
kArm64V8a, |
| 39 |
kX86, |
| 40 |
kX86_64, |
| 41 |
kMips, |
| 42 |
kMips64, |
| 43 |
kUniversal |
| 44 |
}; |
| 45 |
|
| 46 |
|
| 47 |
const android::StringPiece& AbiToString(Abi abi); |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
struct Locale { |
| 57 |
|
| 58 |
std::optional<std::string> lang; |
| 59 |
|
| 60 |
std::optional<std::string> region; |
| 61 |
|
| 62 |
inline friend bool operator==(const Locale& lhs, const Locale& rhs) { |
| 63 |
return lhs.lang == rhs.lang && lhs.region == rhs.region; |
| 64 |
} |
| 65 |
}; |
| 66 |
|
| 67 |
|
| 68 |
struct AndroidManifest { |
| 69 |
inline friend bool operator==(const AndroidManifest& lhs, const AndroidManifest& rhs) { |
| 70 |
return true; |
| 71 |
} |
| 72 |
}; |
| 73 |
|
| 74 |
struct AndroidSdk { |
| 75 |
std::string label; |
| 76 |
int min_sdk_version; |
| 77 |
std::optional<int> target_sdk_version; |
| 78 |
std::optional<int> max_sdk_version; |
| 79 |
std::optional<AndroidManifest> manifest; |
| 80 |
|
| 81 |
static AndroidSdk ForMinSdk(int min_sdk) { |
| 82 |
AndroidSdk sdk; |
| 83 |
sdk.min_sdk_version = min_sdk; |
| 84 |
return sdk; |
| 85 |
} |
| 86 |
|
| 87 |
inline friend bool operator==(const AndroidSdk& lhs, const AndroidSdk& rhs) { |
| 88 |
return lhs.min_sdk_version == rhs.min_sdk_version && |
| 89 |
lhs.target_sdk_version == rhs.target_sdk_version && |
| 90 |
lhs.max_sdk_version == rhs.max_sdk_version && |
| 91 |
lhs.manifest == rhs.manifest; |
| 92 |
} |
| 93 |
}; |
| 94 |
|
| 95 |
|
| 96 |
using DeviceFeature = std::string; |
| 97 |
|
| 98 |
|
| 99 |
struct GlTexture { |
| 100 |
std::string name; |
| 101 |
std::vector<std::string> texture_paths; |
| 102 |
|
| 103 |
inline friend bool operator==(const GlTexture& lhs, const GlTexture& rhs) { |
| 104 |
return lhs.name == rhs.name && lhs.texture_paths == rhs.texture_paths; |
| 105 |
} |
| 106 |
}; |
| 107 |
|
| 108 |
|
| 109 |
struct OutputArtifact { |
| 110 |
std::string name; |
| 111 |
int version; |
| 112 |
std::vector<Abi> abis; |
| 113 |
std::vector<android::ConfigDescription> screen_densities; |
| 114 |
std::vector<android::ConfigDescription> locales; |
| 115 |
std::optional<AndroidSdk> android_sdk; |
| 116 |
std::vector<DeviceFeature> features; |
| 117 |
std::vector<GlTexture> textures; |
| 118 |
|
| 119 |
inline int GetMinSdk(int default_value = -1) const { |
| 120 |
if (!android_sdk) { |
| 121 |
return default_value; |
| 122 |
} |
| 123 |
return android_sdk.value().min_sdk_version; |
| 124 |
} |
| 125 |
}; |
| 126 |
|
| 127 |
} |
| 128 |
|
| 129 |
|
| 130 |
struct IDiagnostics; |
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
class ConfigurationParser { |
| 136 |
public: |
| 137 |
|
| 138 |
|
| 139 |
static std::optional<ConfigurationParser> ForPath(const std::string& path); |
| 140 |
|
| 141 |
|
| 142 |
static ConfigurationParser ForContents(const std::string& contents, const std::string& path) { |
| 143 |
ConfigurationParser parser{contents, path}; |
| 144 |
return parser; |
| 145 |
} |
| 146 |
|
| 147 |
|
| 148 |
ConfigurationParser& WithDiagnostics(IDiagnostics* diagnostics) { |
| 149 |
diag_ = diagnostics; |
| 150 |
return *this; |
| 151 |
} |
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
std::optional<std::vector<configuration::OutputArtifact>> Parse( |
| 158 |
const android::StringPiece& apk_path); |
| 159 |
|
| 160 |
protected: |
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
ConfigurationParser(std::string contents, const std::string& config_path); |
| 167 |
|
| 168 |
|
| 169 |
IDiagnostics* diagnostics() { |
| 170 |
return diag_; |
| 171 |
} |
| 172 |
|
| 173 |
private: |
| 174 |
|
| 175 |
const std::string contents_; |
| 176 |
|
| 177 |
const std::string config_path_; |
| 178 |
|
| 179 |
IDiagnostics* diag_; |
| 180 |
}; |
| 181 |
|
| 182 |
} |
| 183 |
|
| 184 |
#endif |