Adam Lesinski | 282e181 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 1 | // |
| 2 | // Copyright 2006 The Android Open Source Project |
| 3 | // |
| 4 | // State bundle. Used to pass around stuff like command-line args. |
| 5 | // |
| 6 | #ifndef __BUNDLE_H |
| 7 | #define __BUNDLE_H |
| 8 | |
| 9 | #include <stdlib.h> |
| 10 | #include <utils/Log.h> |
| 11 | #include <utils/threads.h> |
| 12 | #include <utils/List.h> |
| 13 | #include <utils/Errors.h> |
| 14 | #include <utils/String8.h> |
| 15 | #include <utils/Vector.h> |
| 16 | |
| 17 | enum { |
| 18 | SDK_CUPCAKE = 3, |
| 19 | SDK_DONUT = 4, |
| 20 | SDK_ECLAIR = 5, |
| 21 | SDK_ECLAIR_0_1 = 6, |
| 22 | SDK_MR1 = 7, |
| 23 | SDK_FROYO = 8, |
| 24 | SDK_HONEYCOMB_MR2 = 13, |
| 25 | SDK_ICE_CREAM_SANDWICH = 14, |
| 26 | SDK_ICE_CREAM_SANDWICH_MR1 = 15, |
| 27 | }; |
| 28 | |
| 29 | /* |
| 30 | * Things we can do. |
| 31 | */ |
| 32 | typedef enum Command { |
| 33 | kCommandUnknown = 0, |
| 34 | kCommandVersion, |
| 35 | kCommandList, |
| 36 | kCommandDump, |
| 37 | kCommandAdd, |
| 38 | kCommandRemove, |
| 39 | kCommandPackage, |
| 40 | kCommandCrunch, |
| 41 | kCommandSingleCrunch, |
| 42 | } Command; |
| 43 | |
| 44 | /* |
| 45 | * Bundle of goodies, including everything specified on the command line. |
| 46 | */ |
| 47 | class Bundle { |
| 48 | public: |
| 49 | Bundle(void) |
| 50 | : mCmd(kCommandUnknown), mVerbose(false), mAndroidList(false), |
| 51 | mForce(false), mGrayscaleTolerance(0), mMakePackageDirs(false), |
| 52 | mUpdate(false), mExtending(false), |
| 53 | mRequireLocalization(false), mPseudolocalize(false), |
| 54 | mWantUTF16(false), mValues(false), mIncludeMetaData(false), |
| 55 | mCompressionMethod(0), mJunkPath(false), mOutputAPKFile(NULL), |
| 56 | mManifestPackageNameOverride(NULL), mInstrumentationPackageNameOverride(NULL), |
| 57 | mAutoAddOverlay(false), mGenDependencies(false), |
Adam Lesinski | 282e181 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 58 | mCrunchedOutputDir(NULL), mProguardFile(NULL), |
| 59 | mAndroidManifestFile(NULL), mPublicOutputFile(NULL), |
| 60 | mRClassDir(NULL), mResourceIntermediatesDir(NULL), mManifestMinSdkVersion(NULL), |
| 61 | mMinSdkVersion(NULL), mTargetSdkVersion(NULL), mMaxSdkVersion(NULL), |
| 62 | mVersionCode(NULL), mVersionName(NULL), mCustomPackage(NULL), mExtraPackages(NULL), |
| 63 | mMaxResVersion(NULL), mDebugMode(false), mNonConstantId(false), mProduct(NULL), |
Ying Wang | cd28bd3 | 2013-11-14 17:12:10 -0800 | [diff] [blame] | 64 | mUseCrunchCache(false), mErrorOnFailedInsert(false), mErrorOnMissingConfigEntry(false), |
| 65 | mOutputTextSymbols(NULL), |
Adam Lesinski | 282e181 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 66 | mSingleCrunchInputFile(NULL), mSingleCrunchOutputFile(NULL), |
| 67 | mArgc(0), mArgv(NULL) |
| 68 | {} |
| 69 | ~Bundle(void) {} |
| 70 | |
| 71 | /* |
| 72 | * Set the command value. Returns "false" if it was previously set. |
| 73 | */ |
| 74 | Command getCommand(void) const { return mCmd; } |
| 75 | void setCommand(Command cmd) { mCmd = cmd; } |
| 76 | |
| 77 | /* |
| 78 | * Command modifiers. Not all modifiers are appropriate for all |
| 79 | * commands. |
| 80 | */ |
| 81 | bool getVerbose(void) const { return mVerbose; } |
| 82 | void setVerbose(bool val) { mVerbose = val; } |
| 83 | bool getAndroidList(void) const { return mAndroidList; } |
| 84 | void setAndroidList(bool val) { mAndroidList = val; } |
| 85 | bool getForce(void) const { return mForce; } |
| 86 | void setForce(bool val) { mForce = val; } |
| 87 | void setGrayscaleTolerance(int val) { mGrayscaleTolerance = val; } |
| 88 | int getGrayscaleTolerance() const { return mGrayscaleTolerance; } |
| 89 | bool getMakePackageDirs(void) const { return mMakePackageDirs; } |
| 90 | void setMakePackageDirs(bool val) { mMakePackageDirs = val; } |
| 91 | bool getUpdate(void) const { return mUpdate; } |
| 92 | void setUpdate(bool val) { mUpdate = val; } |
| 93 | bool getExtending(void) const { return mExtending; } |
| 94 | void setExtending(bool val) { mExtending = val; } |
| 95 | bool getRequireLocalization(void) const { return mRequireLocalization; } |
| 96 | void setRequireLocalization(bool val) { mRequireLocalization = val; } |
| 97 | bool getPseudolocalize(void) const { return mPseudolocalize; } |
| 98 | void setPseudolocalize(bool val) { mPseudolocalize = val; } |
| 99 | void setWantUTF16(bool val) { mWantUTF16 = val; } |
| 100 | bool getValues(void) const { return mValues; } |
| 101 | void setValues(bool val) { mValues = val; } |
| 102 | bool getIncludeMetaData(void) const { return mIncludeMetaData; } |
| 103 | void setIncludeMetaData(bool val) { mIncludeMetaData = val; } |
| 104 | int getCompressionMethod(void) const { return mCompressionMethod; } |
| 105 | void setCompressionMethod(int val) { mCompressionMethod = val; } |
| 106 | bool getJunkPath(void) const { return mJunkPath; } |
| 107 | void setJunkPath(bool val) { mJunkPath = val; } |
| 108 | const char* getOutputAPKFile() const { return mOutputAPKFile; } |
| 109 | void setOutputAPKFile(const char* val) { mOutputAPKFile = val; } |
| 110 | const char* getManifestPackageNameOverride() const { return mManifestPackageNameOverride; } |
| 111 | void setManifestPackageNameOverride(const char * val) { mManifestPackageNameOverride = val; } |
| 112 | const char* getInstrumentationPackageNameOverride() const { return mInstrumentationPackageNameOverride; } |
| 113 | void setInstrumentationPackageNameOverride(const char * val) { mInstrumentationPackageNameOverride = val; } |
| 114 | bool getAutoAddOverlay() { return mAutoAddOverlay; } |
| 115 | void setAutoAddOverlay(bool val) { mAutoAddOverlay = val; } |
| 116 | bool getGenDependencies() { return mGenDependencies; } |
| 117 | void setGenDependencies(bool val) { mGenDependencies = val; } |
| 118 | bool getErrorOnFailedInsert() { return mErrorOnFailedInsert; } |
| 119 | void setErrorOnFailedInsert(bool val) { mErrorOnFailedInsert = val; } |
Ying Wang | cd28bd3 | 2013-11-14 17:12:10 -0800 | [diff] [blame] | 120 | bool getErrorOnMissingConfigEntry() { return mErrorOnMissingConfigEntry; } |
| 121 | void setErrorOnMissingConfigEntry(bool val) { mErrorOnMissingConfigEntry = val; } |
Adam Lesinski | 282e181 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 122 | |
| 123 | bool getUTF16StringsOption() { |
| 124 | return mWantUTF16 || !isMinSdkAtLeast(SDK_FROYO); |
| 125 | } |
| 126 | |
| 127 | /* |
| 128 | * Input options. |
| 129 | */ |
Adam Lesinski | 0938430 | 2014-01-22 16:07:42 -0800 | [diff] [blame] | 130 | const android::Vector<const char*>& getAssetSourceDirs() const { return mAssetSourceDirs; } |
| 131 | void addAssetSourceDir(const char* dir) { mAssetSourceDirs.insertAt(dir,0); } |
Adam Lesinski | 282e181 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 132 | const char* getCrunchedOutputDir() const { return mCrunchedOutputDir; } |
| 133 | void setCrunchedOutputDir(const char* dir) { mCrunchedOutputDir = dir; } |
| 134 | const char* getProguardFile() const { return mProguardFile; } |
| 135 | void setProguardFile(const char* file) { mProguardFile = file; } |
| 136 | const android::Vector<const char*>& getResourceSourceDirs() const { return mResourceSourceDirs; } |
| 137 | void addResourceSourceDir(const char* dir) { mResourceSourceDirs.insertAt(dir,0); } |
| 138 | const char* getAndroidManifestFile() const { return mAndroidManifestFile; } |
| 139 | void setAndroidManifestFile(const char* file) { mAndroidManifestFile = file; } |
| 140 | const char* getPublicOutputFile() const { return mPublicOutputFile; } |
| 141 | void setPublicOutputFile(const char* file) { mPublicOutputFile = file; } |
| 142 | const char* getRClassDir() const { return mRClassDir; } |
| 143 | void setRClassDir(const char* dir) { mRClassDir = dir; } |
| 144 | const char* getConfigurations() const { return mConfigurations.size() > 0 ? mConfigurations.string() : NULL; } |
| 145 | void addConfigurations(const char* val) { if (mConfigurations.size() > 0) { mConfigurations.append(","); mConfigurations.append(val); } else { mConfigurations = val; } } |
| 146 | const char* getPreferredConfigurations() const { return mPreferredConfigurations.size() > 0 ? mPreferredConfigurations.string() : NULL; } |
| 147 | void addPreferredConfigurations(const char* val) { if (mPreferredConfigurations.size() > 0) { mPreferredConfigurations.append(","); mPreferredConfigurations.append(val); } else { mPreferredConfigurations = val; } } |
| 148 | const char* getResourceIntermediatesDir() const { return mResourceIntermediatesDir; } |
| 149 | void setResourceIntermediatesDir(const char* dir) { mResourceIntermediatesDir = dir; } |
| 150 | const android::Vector<const char*>& getPackageIncludes() const { return mPackageIncludes; } |
| 151 | void addPackageInclude(const char* file) { mPackageIncludes.add(file); } |
| 152 | const android::Vector<const char*>& getJarFiles() const { return mJarFiles; } |
| 153 | void addJarFile(const char* file) { mJarFiles.add(file); } |
| 154 | const android::Vector<const char*>& getNoCompressExtensions() const { return mNoCompressExtensions; } |
| 155 | void addNoCompressExtension(const char* ext) { mNoCompressExtensions.add(ext); } |
| 156 | |
| 157 | const char* getManifestMinSdkVersion() const { return mManifestMinSdkVersion; } |
| 158 | void setManifestMinSdkVersion(const char* val) { mManifestMinSdkVersion = val; } |
| 159 | const char* getMinSdkVersion() const { return mMinSdkVersion; } |
| 160 | void setMinSdkVersion(const char* val) { mMinSdkVersion = val; } |
| 161 | const char* getTargetSdkVersion() const { return mTargetSdkVersion; } |
| 162 | void setTargetSdkVersion(const char* val) { mTargetSdkVersion = val; } |
| 163 | const char* getMaxSdkVersion() const { return mMaxSdkVersion; } |
| 164 | void setMaxSdkVersion(const char* val) { mMaxSdkVersion = val; } |
| 165 | const char* getVersionCode() const { return mVersionCode; } |
| 166 | void setVersionCode(const char* val) { mVersionCode = val; } |
| 167 | const char* getVersionName() const { return mVersionName; } |
| 168 | void setVersionName(const char* val) { mVersionName = val; } |
| 169 | const char* getCustomPackage() const { return mCustomPackage; } |
| 170 | void setCustomPackage(const char* val) { mCustomPackage = val; } |
| 171 | const char* getExtraPackages() const { return mExtraPackages; } |
| 172 | void setExtraPackages(const char* val) { mExtraPackages = val; } |
| 173 | const char* getMaxResVersion() const { return mMaxResVersion; } |
| 174 | void setMaxResVersion(const char * val) { mMaxResVersion = val; } |
| 175 | bool getDebugMode() const { return mDebugMode; } |
| 176 | void setDebugMode(bool val) { mDebugMode = val; } |
| 177 | bool getNonConstantId() const { return mNonConstantId; } |
| 178 | void setNonConstantId(bool val) { mNonConstantId = val; } |
| 179 | const char* getProduct() const { return mProduct; } |
| 180 | void setProduct(const char * val) { mProduct = val; } |
| 181 | void setUseCrunchCache(bool val) { mUseCrunchCache = val; } |
| 182 | bool getUseCrunchCache() const { return mUseCrunchCache; } |
| 183 | const char* getOutputTextSymbols() const { return mOutputTextSymbols; } |
| 184 | void setOutputTextSymbols(const char* val) { mOutputTextSymbols = val; } |
| 185 | const char* getSingleCrunchInputFile() const { return mSingleCrunchInputFile; } |
| 186 | void setSingleCrunchInputFile(const char* val) { mSingleCrunchInputFile = val; } |
| 187 | const char* getSingleCrunchOutputFile() const { return mSingleCrunchOutputFile; } |
| 188 | void setSingleCrunchOutputFile(const char* val) { mSingleCrunchOutputFile = val; } |
| 189 | |
| 190 | /* |
| 191 | * Set and get the file specification. |
| 192 | * |
| 193 | * Note this does NOT make a copy of argv. |
| 194 | */ |
| 195 | void setFileSpec(char* const argv[], int argc) { |
| 196 | mArgc = argc; |
| 197 | mArgv = argv; |
| 198 | } |
| 199 | int getFileSpecCount(void) const { return mArgc; } |
| 200 | const char* getFileSpecEntry(int idx) const { return mArgv[idx]; } |
| 201 | void eatArgs(int n) { |
| 202 | if (n > mArgc) n = mArgc; |
| 203 | mArgv += n; |
| 204 | mArgc -= n; |
| 205 | } |
| 206 | |
| 207 | #if 0 |
| 208 | /* |
| 209 | * Package count. Nothing to do with anything else here; this is |
| 210 | * just a convenient place to stuff it so we don't have to pass it |
| 211 | * around everywhere. |
| 212 | */ |
| 213 | int getPackageCount(void) const { return mPackageCount; } |
| 214 | void setPackageCount(int val) { mPackageCount = val; } |
| 215 | #endif |
| 216 | |
| 217 | /* Certain features may only be available on a specific SDK level or |
| 218 | * above. SDK levels that have a non-numeric identifier are assumed |
| 219 | * to be newer than any SDK level that has a number designated. |
| 220 | */ |
| 221 | bool isMinSdkAtLeast(int desired) { |
| 222 | /* If the application specifies a minSdkVersion in the manifest |
| 223 | * then use that. Otherwise, check what the user specified on |
| 224 | * the command line. If neither, it's not available since |
| 225 | * the minimum SDK version is assumed to be 1. |
| 226 | */ |
| 227 | const char *minVer; |
| 228 | if (mManifestMinSdkVersion != NULL) { |
| 229 | minVer = mManifestMinSdkVersion; |
| 230 | } else if (mMinSdkVersion != NULL) { |
| 231 | minVer = mMinSdkVersion; |
| 232 | } else { |
| 233 | return false; |
| 234 | } |
| 235 | |
| 236 | char *end; |
| 237 | int minSdkNum = (int)strtol(minVer, &end, 0); |
| 238 | if (*end == '\0') { |
| 239 | if (minSdkNum < desired) { |
| 240 | return false; |
| 241 | } |
| 242 | } |
| 243 | return true; |
| 244 | } |
| 245 | |
| 246 | private: |
| 247 | /* commands & modifiers */ |
| 248 | Command mCmd; |
| 249 | bool mVerbose; |
| 250 | bool mAndroidList; |
| 251 | bool mForce; |
| 252 | int mGrayscaleTolerance; |
| 253 | bool mMakePackageDirs; |
| 254 | bool mUpdate; |
| 255 | bool mExtending; |
| 256 | bool mRequireLocalization; |
| 257 | bool mPseudolocalize; |
| 258 | bool mWantUTF16; |
| 259 | bool mValues; |
| 260 | bool mIncludeMetaData; |
| 261 | int mCompressionMethod; |
| 262 | bool mJunkPath; |
| 263 | const char* mOutputAPKFile; |
| 264 | const char* mManifestPackageNameOverride; |
| 265 | const char* mInstrumentationPackageNameOverride; |
| 266 | bool mAutoAddOverlay; |
| 267 | bool mGenDependencies; |
Adam Lesinski | 282e181 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 268 | const char* mCrunchedOutputDir; |
| 269 | const char* mProguardFile; |
| 270 | const char* mAndroidManifestFile; |
| 271 | const char* mPublicOutputFile; |
| 272 | const char* mRClassDir; |
| 273 | const char* mResourceIntermediatesDir; |
| 274 | android::String8 mConfigurations; |
| 275 | android::String8 mPreferredConfigurations; |
| 276 | android::Vector<const char*> mPackageIncludes; |
| 277 | android::Vector<const char*> mJarFiles; |
| 278 | android::Vector<const char*> mNoCompressExtensions; |
Adam Lesinski | 0938430 | 2014-01-22 16:07:42 -0800 | [diff] [blame] | 279 | android::Vector<const char*> mAssetSourceDirs; |
Adam Lesinski | 282e181 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 280 | android::Vector<const char*> mResourceSourceDirs; |
| 281 | |
| 282 | const char* mManifestMinSdkVersion; |
| 283 | const char* mMinSdkVersion; |
| 284 | const char* mTargetSdkVersion; |
| 285 | const char* mMaxSdkVersion; |
| 286 | const char* mVersionCode; |
| 287 | const char* mVersionName; |
| 288 | const char* mCustomPackage; |
| 289 | const char* mExtraPackages; |
| 290 | const char* mMaxResVersion; |
| 291 | bool mDebugMode; |
| 292 | bool mNonConstantId; |
| 293 | const char* mProduct; |
| 294 | bool mUseCrunchCache; |
| 295 | bool mErrorOnFailedInsert; |
Ying Wang | cd28bd3 | 2013-11-14 17:12:10 -0800 | [diff] [blame] | 296 | bool mErrorOnMissingConfigEntry; |
Adam Lesinski | 282e181 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 297 | const char* mOutputTextSymbols; |
| 298 | const char* mSingleCrunchInputFile; |
| 299 | const char* mSingleCrunchOutputFile; |
| 300 | |
| 301 | /* file specification */ |
| 302 | int mArgc; |
| 303 | char* const* mArgv; |
| 304 | |
| 305 | #if 0 |
| 306 | /* misc stuff */ |
| 307 | int mPackageCount; |
| 308 | #endif |
| 309 | |
| 310 | }; |
| 311 | |
| 312 | #endif // __BUNDLE_H |