From 1ab598f46c3ff520a67f9d80194847741f3467ab Mon Sep 17 00:00:00 2001 From: Adam Lesinski Date: Fri, 14 Aug 2015 14:26:04 -0700 Subject: AAPT2: Separate out the various steps An early refactor. Some ideas became clearer as development continued. Now the various phases are much clearer and more easily reusable. Also added a ton of tests! Change-Id: Ic8f0a70c8222370352e63533b329c40457c0903e --- tools/aapt2/Main.cpp | 1265 +------------------------------------------------- 1 file changed, 21 insertions(+), 1244 deletions(-) (limited to 'tools/aapt2/Main.cpp') diff --git a/tools/aapt2/Main.cpp b/tools/aapt2/Main.cpp index 54a7329359f1..248e7ad73a82 100644 --- a/tools/aapt2/Main.cpp +++ b/tools/aapt2/Main.cpp @@ -14,1262 +14,39 @@ * limitations under the License. */ -#include "AppInfo.h" -#include "BigBuffer.h" -#include "BinaryResourceParser.h" -#include "BindingXmlPullParser.h" -#include "Debug.h" -#include "Files.h" -#include "Flag.h" -#include "JavaClassGenerator.h" -#include "Linker.h" -#include "ManifestMerger.h" -#include "ManifestParser.h" -#include "ManifestValidator.h" -#include "NameMangler.h" -#include "Png.h" -#include "ProguardRules.h" -#include "ResourceParser.h" -#include "ResourceTable.h" -#include "ResourceTableResolver.h" -#include "ResourceValues.h" -#include "SdkConstants.h" -#include "SourceXmlPullParser.h" -#include "StringPiece.h" -#include "TableFlattener.h" -#include "Util.h" -#include "XmlFlattener.h" -#include "ZipFile.h" +#include "util/StringPiece.h" -#include -#include -#include -#include -#include -#include #include -#include -#include -#include -#include +#include -constexpr const char* kAaptVersionStr = "2.0-alpha"; +namespace aapt { -using namespace aapt; +extern int compile(const std::vector& args); +extern int link(const std::vector& args); -/** - * Used with smart pointers to free malloc'ed memory. - */ -struct DeleteMalloc { - void operator()(void* ptr) { - free(ptr); - } -}; - -struct StaticLibraryData { - Source source; - std::unique_ptr apk; -}; - -/** - * Collect files from 'root', filtering out any files that do not - * match the FileFilter 'filter'. - */ -bool walkTree(const Source& root, const FileFilter& filter, - std::vector* outEntries) { - bool error = false; - - for (const std::string& dirName : listFiles(root.path)) { - std::string dir = root.path; - appendPath(&dir, dirName); - - FileType ft = getFileType(dir); - if (!filter(dirName, ft)) { - continue; - } - - if (ft != FileType::kDirectory) { - continue; - } - - for (const std::string& fileName : listFiles(dir)) { - std::string file(dir); - appendPath(&file, fileName); - - FileType ft = getFileType(file); - if (!filter(fileName, ft)) { - continue; - } - - if (ft != FileType::kRegular) { - Logger::error(Source{ file }) << "not a regular file." << std::endl; - error = true; - continue; - } - outEntries->push_back(Source{ file }); - } - } - return !error; -} - -void versionStylesForCompat(const std::shared_ptr& table) { - for (auto& type : *table) { - if (type->type != ResourceType::kStyle) { - continue; - } - - for (auto& entry : type->entries) { - // Add the versioned styles we want to create - // here. They are added to the table after - // iterating over the original set of styles. - // - // A stack is used since auto-generated styles - // from later versions should override - // auto-generated styles from earlier versions. - // Iterating over the styles is done in order, - // so we will always visit sdkVersions from smallest - // to largest. - std::stack addStack; - - for (ResourceConfigValue& configValue : entry->values) { - visitFunc