diff options
author | Sergey Ten <sergey.ten6@t-mobile.com> | 2009-03-10 14:29:28 -0700 |
---|---|---|
committer | Josh Guilfoyle <Josh.Guilfoyle@T-Mobile.com> | 2009-07-14 13:50:34 -0700 |
commit | 30f0b7eac75e70e8cedce42b614f33ef5c0a5785 (patch) | |
tree | ed4b1755ac0fbf3d589c6493328b39f27c91f01d /tools | |
parent | bcf0e70fdbdced2a6f3df7369156da0eef9eefaf (diff) | |
download | frameworks_base-30f0b7eac75e70e8cedce42b614f33ef5c0a5785.zip frameworks_base-30f0b7eac75e70e8cedce42b614f33ef5c0a5785.tar.gz frameworks_base-30f0b7eac75e70e8cedce42b614f33ef5c0a5785.tar.bz2 |
This is a patch I've checked in in the old repo and apparently it was not ported to devpde01.
This is a first scoop of bringing in aapt tool on a device. We just build
aapt as a stand-alone executable for both HOST and TARGET platforms.
In future release, we plan to re-factor existing code to produce libaapt
library (static for HOST and shared for TARGET), to make sure that
the functionality implemented by the library would be exposed (via JNI)
to the Java layer. That way, we would be able to invoke aapt in-proc
from Java code, instead of spawning a separate process.
Here is a brief description of the changes:
1. Introduced HOST_LIB compile flag to differentiate HOST and TARGET flavors.
2. Moved ZipFile.cpp and ZipEntry.cpp (libutils) from hostSources to commonSources, DESPITE GOOGLE's COMMENT in Android.mk.
3. Currently, only 3 following commands are supported by aapt on device:
- create a compiled resource package (package command);
- add new resource to existing package (add command);
- remove resource from existing package (remove command).
Diffstat (limited to 'tools')
-rw-r--r-- | tools/aapt/Android.mk | 51 | ||||
-rw-r--r-- | tools/aapt/Command.cpp | 40 | ||||
-rw-r--r-- | tools/aapt/Main.cpp | 6 | ||||
-rw-r--r-- | tools/aapt/ResourceTable.cpp | 4 | ||||
-rw-r--r-- | tools/aapt/ResourceTable.h | 10 | ||||
-rw-r--r-- | tools/aapt/SourcePos.cpp | 17 | ||||
-rw-r--r-- | tools/aapt/XMLNode.cpp | 9 |
7 files changed, 132 insertions, 5 deletions
diff --git a/tools/aapt/Android.mk b/tools/aapt/Android.mk index fdc859c..a8a9c1c 100644 --- a/tools/aapt/Android.mk +++ b/tools/aapt/Android.mk @@ -5,9 +5,8 @@ # LOCAL_PATH:= $(call my-dir) -include $(CLEAR_VARS) -LOCAL_SRC_FILES := \ +commonSources:= \ AaptAssets.cpp \ Command.cpp \ Main.cpp \ @@ -17,8 +16,18 @@ LOCAL_SRC_FILES := \ ResourceTable.cpp \ Images.cpp \ Resource.cpp \ - SourcePos.cpp + SourcePos.cpp + + +# For the host +# ===================================================== + +include $(CLEAR_VARS) +LOCAL_SRC_FILES := $(commonSources) + +LOCAL_CFLAGS += -DHOST_LIB=1 +LOCAL_CFLAGS += -DLIBUTILS_NATIVE=1 $(TOOL_CFLAGS) LOCAL_CFLAGS += -Wno-format-y2k LOCAL_C_INCLUDES += external/expat/lib @@ -50,3 +59,39 @@ LOCAL_MODULE := aapt include $(BUILD_HOST_EXECUTABLE) + +# For the device +# ===================================================== +include $(CLEAR_VARS) + +LOCAL_SRC_FILES:= $(commonSources) + +ifeq ($(TARGET_OS),linux) +# Use the futex based mutex and condition variable +# implementation from android-arm because it's shared mem safe +LOCAL_LDLIBS += -lrt -ldl +endif + +LOCAL_C_INCLUDES += external/expat/lib +LOCAL_C_INCLUDES += external/libpng +LOCAL_C_INCLUDES += external/zlib +LOCAL_C_INCLUDES += external/icu4c/common + +LOCAL_SHARED_LIBRARIES := \ + libz \ + libutils \ + libcutils \ + libexpat \ + libsgl + +ifneq ($(TARGET_SIMULATOR),true) +ifeq ($(TARGET_OS)-$(TARGET_ARCH),linux-x86) +# This is needed on x86 to bring in dl_iterate_phdr for CallStack.cpp +LOCAL_SHARED_LIBRARIES += \ + libdl +endif # linux-x86 +endif # sim + +LOCAL_MODULE := aapt + +include $(BUILD_EXECUTABLE) diff --git a/tools/aapt/Command.cpp b/tools/aapt/Command.cpp index 6f3461d..39acc42 100644 --- a/tools/aapt/Command.cpp +++ b/tools/aapt/Command.cpp @@ -21,9 +21,11 @@ using namespace android; */ int doVersion(Bundle* bundle) { +#ifdef HOST_LIB if (bundle->getFileSpecCount() != 0) printf("(ignoring extra arguments)\n"); printf("Android Asset Packaging Tool, v0.2\n"); +#endif // HOST_LIB return 0; } @@ -42,13 +44,15 @@ ZipFile* openReadOnly(const char* fileName) zip = new ZipFile; result = zip->open(fileName, ZipFile::kOpenReadOnly); if (result != NO_ERROR) { - if (result == NAME_NOT_FOUND) +#ifdef HOST_LIB + if (result == NAME_NOT_FOUND) fprintf(stderr, "ERROR: '%s' not found\n", fileName); else if (result == PERMISSION_DENIED) fprintf(stderr, "ERROR: '%s' access denied\n", fileName); else fprintf(stderr, "ERROR: failed opening '%s' as Zip file\n", fileName); +#endif // HOST_LIB delete zip; return NULL; } @@ -119,6 +123,7 @@ int calcPercent(long uncompressedLen, long compressedLen) int doList(Bundle* bundle) { int result = 1; +#ifdef HOST_LIB ZipFile* zip = NULL; const ZipEntry* entry; long totalUncLen, totalCompLen; @@ -217,6 +222,7 @@ int doList(Bundle* bundle) bail: delete zip; +#endif // HOST_LIB return result; } @@ -341,6 +347,7 @@ const char *getComponentName(String8 &pkgName, String8 &componentName) { int doDump(Bundle* bundle) { status_t result = UNKNOWN_ERROR; +#ifdef HOST_LIB Asset* asset = NULL; if (bundle->getFileSpecCount() < 1) { @@ -690,6 +697,7 @@ bail: if (asset) { delete asset; } +#endif // HOST_LIB return (result != NO_ERROR); } @@ -706,24 +714,32 @@ int doAdd(Bundle* bundle) if (bundle->getUpdate()) { /* avoid confusion */ +#ifdef HOST_LIB fprintf(stderr, "ERROR: can't use '-u' with add\n"); +#endif // HOST_LIB goto bail; } if (bundle->getFileSpecCount() < 1) { +#ifdef HOST_LIB fprintf(stderr, "ERROR: must specify zip file name\n"); +#endif // HOST_LIB goto bail; } zipFileName = bundle->getFileSpecEntry(0); if (bundle->getFileSpecCount() < 2) { +#ifdef HOST_LIB fprintf(stderr, "NOTE: nothing to do\n"); +#endif // HOST_LIB goto bail; } zip = openReadWrite(zipFileName, true); if (zip == NULL) { +#ifdef HOST_LIB fprintf(stderr, "ERROR: failed opening/creating '%s' as Zip file\n", zipFileName); +#endif // HOST_LIB goto bail; } @@ -731,13 +747,18 @@ int doAdd(Bundle* bundle) const char* fileName = bundle->getFileSpecEntry(i); if (strcasecmp(String8(fileName).getPathExtension().string(), ".gz") == 0) { +#ifdef HOST_LIB printf(" '%s'... (from gzip)\n", fileName); +#endif // HOST_LIB result = zip->addGzip(fileName, String8(fileName).getBasePath().string(), NULL); } else { +#ifdef HOST_LIB printf(" '%s'...\n", fileName); +#endif // HOST_LIB result = zip->add(fileName, bundle->getCompressionMethod(), NULL); } if (result != NO_ERROR) { +#ifdef HOST_LIB fprintf(stderr, "Unable to add '%s' to '%s'", bundle->getFileSpecEntry(i), zipFileName); if (result == NAME_NOT_FOUND) fprintf(stderr, ": file not found\n"); @@ -745,6 +766,7 @@ int doAdd(Bundle* bundle) fprintf(stderr, ": already exists in archive\n"); else fprintf(stderr, "\n"); +#endif // HOST_LIB goto bail; } } @@ -767,20 +789,26 @@ int doRemove(Bundle* bundle) const char* zipFileName; if (bundle->getFileSpecCount() < 1) { +#ifdef HOST_LIB fprintf(stderr, "ERROR: must specify zip file name\n"); +#endif // HOST_LIB goto bail; } zipFileName = bundle->getFileSpecEntry(0); if (bundle->getFileSpecCount() < 2) { +#ifdef HOST_LIB fprintf(stderr, "NOTE: nothing to do\n"); +#endif // HOST_LIB goto bail; } zip = openReadWrite(zipFileName, false); if (zip == NULL) { +#ifdef HOST_LIB fprintf(stderr, "ERROR: failed opening Zip archive '%s'\n", zipFileName); +#endif // HOST_LIB goto bail; } @@ -790,15 +818,19 @@ int doRemove(Bundle* bundle) entry = zip->getEntryByName(fileName); if (entry == NULL) { +#ifdef HOST_LIB printf(" '%s' NOT FOUND\n", fileName); +#endif // HOST_LIB continue; } result = zip->remove(entry); if (result != NO_ERROR) { +#ifdef HOST_LIB fprintf(stderr, "Unable to delete '%s' from '%s'\n", bundle->getFileSpecEntry(i), zipFileName); +#endif // HOST_LIB goto bail; } } @@ -836,7 +868,9 @@ int doPackage(Bundle* bundle) N = bundle->getFileSpecCount(); if (N < 1 && bundle->getResourceSourceDirs().size() == 0 && bundle->getJarFiles().size() == 0 && bundle->getAndroidManifestFile() == NULL && bundle->getAssetSourceDir() == NULL) { +#ifdef HOST_LIB fprintf(stderr, "ERROR: no input files\n"); +#endif // HOST_LIB goto bail; } @@ -847,9 +881,11 @@ int doPackage(Bundle* bundle) FileType type; type = getFileType(outputAPKFile); if (type != kFileTypeNonexistent && type != kFileTypeRegular) { +#ifdef HOST_LIB fprintf(stderr, "ERROR: output file '%s' exists but is not regular file\n", outputAPKFile); +#endif // HOST_LIB goto bail; } } @@ -900,7 +936,9 @@ int doPackage(Bundle* bundle) if (outputAPKFile) { err = writeAPK(bundle, assets, String8(outputAPKFile)); if (err != NO_ERROR) { +#ifdef HOST_LIB fprintf(stderr, "ERROR: packaging of '%s' failed\n", outputAPKFile); +#endif // HOST_LIB goto bail; } } diff --git a/tools/aapt/Main.cpp b/tools/aapt/Main.cpp index 71b1a3c..552ff24 100644 --- a/tools/aapt/Main.cpp +++ b/tools/aapt/Main.cpp @@ -129,9 +129,11 @@ int handleCommand(Bundle* bundle) // printf(" %d: '%s'\n", i, bundle->getFileSpecEntry(i)); switch (bundle->getCommand()) { +#ifdef HOST_LIB case kCommandVersion: return doVersion(bundle); case kCommandList: return doList(bundle); case kCommandDump: return doDump(bundle); +#endif // HOST_LIB case kCommandAdd: return doAdd(bundle); case kCommandRemove: return doRemove(bundle); case kCommandPackage: return doPackage(bundle); @@ -364,6 +366,8 @@ bail: result = 2; } - //printf("--> returning %d\n", result); +#ifndef HOST_LIB + printf("--> returning %d\n", result); +#endif return result; } diff --git a/tools/aapt/ResourceTable.cpp b/tools/aapt/ResourceTable.cpp index a09b1a6..943bbeb 100644 --- a/tools/aapt/ResourceTable.cpp +++ b/tools/aapt/ResourceTable.cpp @@ -2117,7 +2117,9 @@ status_t ResourceTable::addSymbols(const sp<AaptSymbols>& outSymbols) { void ResourceTable::addLocalization(const String16& name, const String8& locale) { +#ifdef HOST_LIB mLocalizations[name].insert(locale); +#endif // HOST_LIB } @@ -2136,6 +2138,7 @@ ResourceTable::validateLocalizations(void) status_t err = NO_ERROR; const String8 defaultLocale; +#ifdef HOST_LIB // For all strings... for (map<String16, set<String8> >::iterator nameIter = mLocalizations.begin(); nameIter != mLocalizations.end(); @@ -2195,6 +2198,7 @@ ResourceTable::validateLocalizations(void) } while (comma != NULL); } } +#endif // HOST_LIB return err; } diff --git a/tools/aapt/ResourceTable.h b/tools/aapt/ResourceTable.h index 74ba326..cacc980 100644 --- a/tools/aapt/ResourceTable.h +++ b/tools/aapt/ResourceTable.h @@ -4,14 +4,22 @@ // Build resource files from raw assets. // +// WARNING: Since arm compiler runtime does not include STL, we can't include <map> and <set> types. +// Unless we want to provide our own implementation of these (which should not be too difficult, +// since what we need is a simple hash table which keys are unicode strings and values are sets +// of ASCII chars). On the other hand, since maps/sets are used only to validate localized strings, +// I decided to disable this feature when code is executed on a device. + #ifndef RESOURCE_TABLE_H #define RESOURCE_TABLE_H #include "StringPool.h" #include "SourcePos.h" +#ifdef HOST_LIB #include <set> #include <map> +#endif //HOST_LIB using namespace std; @@ -514,8 +522,10 @@ private: SourcePos mCurrentXmlPos; Bundle* mBundle; +#ifdef HOST_LIB // key = string resource name, value = set of locales in which that name is defined map<String16, set<String8> > mLocalizations; +#endif //HOST_LIB }; class ResourceFilter diff --git a/tools/aapt/SourcePos.cpp b/tools/aapt/SourcePos.cpp index 2761d18..e69b126 100644 --- a/tools/aapt/SourcePos.cpp +++ b/tools/aapt/SourcePos.cpp @@ -1,7 +1,12 @@ +// WARNING! Since arm compiler does not have STL library, +// error reporting is disabled. We need to figure out how do we report errors. + #include "SourcePos.h" #include <stdarg.h> +#ifdef HOST_LIB #include <vector> +#endif //HOST_LIB using namespace std; @@ -26,7 +31,9 @@ struct ErrorPos void print(FILE* to) const; }; +#ifdef HOST_LIB static vector<ErrorPos> g_errors; +#endif //HOST_LIB ErrorPos::ErrorPos() :line(-1), fatal(false) @@ -86,6 +93,7 @@ ErrorPos::operator=(const ErrorPos& rhs) void ErrorPos::print(FILE* to) const { +#ifdef HOST_LIB const char* type = fatal ? "ERROR" : "WARNING"; if (this->line >= 0) { @@ -93,6 +101,7 @@ ErrorPos::print(FILE* to) const } else { fprintf(to, "%s: %s %s\n", this->file.string(), type, this->error.string()); } +#endif // HOST_LIB } // SourcePos @@ -120,6 +129,7 @@ int SourcePos::error(const char* fmt, ...) const { int retval=0; +#ifdef HOST_LIB char buf[1024]; va_list ap; va_start(ap, fmt); @@ -131,6 +141,7 @@ SourcePos::error(const char* fmt, ...) const p--; } g_errors.push_back(ErrorPos(this->file, this->line, String8(buf), true)); +#endif // HOST_LIB return retval; } @@ -155,16 +166,22 @@ SourcePos::warning(const char* fmt, ...) const bool SourcePos::hasErrors() { +#ifdef HOST_LIB return g_errors.size() > 0; +#else + return false; +#endif // HOST_LIB } void SourcePos::printErrors(FILE* to) { +#ifdef HOST_LIB vector<ErrorPos>::const_iterator it; for (it=g_errors.begin(); it!=g_errors.end(); it++) { it->print(to); } +#endif // HOST_LIB } diff --git a/tools/aapt/XMLNode.cpp b/tools/aapt/XMLNode.cpp index d476567..c1c99f5 100644 --- a/tools/aapt/XMLNode.cpp +++ b/tools/aapt/XMLNode.cpp @@ -4,10 +4,15 @@ // Build resource files from raw assets. // +// WARNING! I disabled pseudolocalizing if we run on device, +// since it does not seem important. + #include "XMLNode.h" #include "ResourceTable.h" +#ifdef HOST_LIB #include <host/pseudolocalize.h> +#endif //HOST_LIB #include <utils/ByteOrder.h> #include <errno.h> #include <string.h> @@ -96,13 +101,17 @@ status_t parseStyledString(Bundle* bundle, pseudolocalize = false; } } +#ifdef HOST_LIB if (xliffDepth == 0 && pseudolocalize) { std::string orig(String8(text).string()); std::string pseudo = pseudolocalize_string(orig); curString.append(String16(String8(pseudo.c_str()))); } else { +#endif //HOST_LIB curString.append(text); +#ifdef HOST_LIB } +#endif //HOST_LIB } else if (code == ResXMLTree::START_TAG) { const String16 element16(inXml->getElementName(&len)); const String8 element8(element16); |