1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef AAPT2_ABISPLITTER_H 18 #define AAPT2_ABISPLITTER_H 19 20 #include <memory> 21 #include <string_view> 22 #include <unordered_set> 23 #include <vector> 24 25 #include "configuration/ConfigurationParser.h" 26 #include "filter/Filter.h" 27 28 namespace aapt { 29 30 /** 31 * Filters native library paths by ABI. ABIs present in the filter list are kept and all over 32 * libraries are removed. The filter is only applied to native library paths (this under lib/). 33 */ 34 class AbiFilter : public IPathFilter { 35 public: 36 virtual ~AbiFilter() = default; 37 38 /** Factory method to create a filter from a list of configuration::Abi. */ 39 static std::unique_ptr<AbiFilter> FromAbiList(const std::vector<configuration::Abi>& abi_list); 40 41 /** Returns true if the path is for a native library in the list of desired ABIs. */ 42 bool Keep(std::string_view path) override; 43 44 private: AbiFilter(std::unordered_set<std::string_view> abis)45 explicit AbiFilter(std::unordered_set<std::string_view> abis) : abis_(std::move(abis)) { 46 } 47 48 /** The path prefix to where all native libs end up inside an APK file. */ 49 static constexpr const char* kLibPrefix = "lib/"; 50 static constexpr size_t kLibPrefixLen = 4; 51 const std::unordered_set<std::string_view> abis_; 52 }; 53 54 } // namespace aapt 55 56 #endif // AAPT2_ABISPLITTER_H 57