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