/* * Copyright (C) 2015 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "AppInfo.h" #include "BigBuffer.h" #include "BinaryResourceParser.h" #include "BinaryXmlPullParser.h" #include "BindingXmlPullParser.h" #include "Debug.h" #include "Files.h" #include "Flag.h" #include "JavaClassGenerator.h" #include "Linker.h" #include "ManifestParser.h" #include "ManifestValidator.h" #include "NameMangler.h" #include "Png.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 #include #include #include #include #include #include #include #include #include #include constexpr const char* kAaptVersionStr = "2.0-alpha"; using namespace aapt; /** * 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